首页/ AI 技能 / @skilllib/skill-2014279364442009602
Skill站外收录 @skilllib/skill-2014279364442009602

architecture

采用功能切片设计实现业务域驱动的代码组织,通过层级化模块划分确保逻辑复用与依赖单向流动,适用于需长期迭代的大型应用,避免过早抽象以减少维护成本。

0.0 (0) 624 次安装 原作者 编程导航
收录于 2026-01-22
软件开发 AI 技能

Skills.MD

# Architecture (Feature-Sliced Design) ## **Priority: P2 (MEDIUM)** Adopt **Feature-Sliced Design (FSD)** for scalable applications. **Warning**: FSD introduces boilerplate. Use it only if the project is expected to grow significantly (e.g., 20+ features). For smaller projects, a simple module-based structure is preferred. ## Strategy 1. **App Layer is Thin**: The `app/` directory (App Router) is **only** for Routing. - _Rule_: `page.tsx` should only import Widgets/Features. No business logic (`useEffect`, `fetch`) directly in pages. 2. **Slices over Types**: Group code by **Business Domain** (User, Product, Cart), not by File Type (Components, Hooks, Utils). - _Bad_: `src/components/LoginForm.tsx`, `src/hooks/useLogin.ts` - _Good_: `src/features/auth/login/` containing both. 3. **Layer Hierarchy**: Code can only import from _layers below it_. - `App` -> `Widgets` -> `Features` -> `Entities` -> `Shared`. 4. **Avoid Excessive Entities**: Do not preemptively create Entities. - _Rule_: Start logic in `Features` or `Pages`. Move to `Entities` **only** when data/logic is strictly reused across multiple differing features. - _Rule_: Simple CRUD belongs in `shared/api`, not `entities`. 5. **Standard Segments**: Use standard segment names within slices. - `ui` (Components), `model` (State/actions), `api` (Data fetching), `lib` (Helpers), `config` (Constants). - _Avoid_: `components`, `hooks`, `services` as segment names. ## Structure Reference For the specific directory layout and layer definitions, see the reference documentation. - [**FSD Folder Structure**](references/fsd-structure.md) ## Integration with Next.js Core - **Server Actions**: Place them in the `model/` folder of a Feature (e.g., `features/auth/model/actions.ts`). - **Data Access (DAL)**: Place logic in the `model/` folder of an Entity (e.g., `entities/user/model/dal.ts`). - **UI Components**: Base UI (shadcn) belongs in `shared/ui`. Feature-specific UI belongs in `features/*/ui`.

评论 0

还没有评论,来抢沙发。