Agent skill
Next.js Architecture (FSD)
Scalable project structure using Feature-Sliced Design (FSD).
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/other/architecture-hoangnguyen0403-agent-skills-standar-2
Metadata
Additional technical details for this skill
- labels
-
nextjs architecture fsd folder-structure
- triggers
-
{ "files": [ "src/features/**", "src/entities/**", "src/widgets/**" ], "keywords": [ "FSD", "Feature Sliced Design", "slices", "segments" ] }
SKILL.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
- RSC Boundaries: Enforce strict serialization rules for props passed from Server to Client. See RSC Boundaries & Serialization.
- App Layer is Thin: The
app/directory (App Router) is only for Routing.- Rule:
page.tsxshould only import Widgets/Features. No business logic (useEffect,fetch) directly in pages.
- Rule:
- 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.
- Bad:
- Layer Hierarchy: Code can only import from layers below it.
App->Widgets->Features->Entities->Shared.
- Avoid Excessive Entities: Do not preemptively create Entities.
- Rule: Start logic in
FeaturesorPages. Move toEntitiesonly when data/logic is strictly reused across multiple differing features. - Rule: Simple CRUD belongs in
shared/api, notentities.
- Rule: Start logic in
- Standard Segments: Use standard segment names within slices.
ui(Components),model(State/actions),api(Data fetching),lib(Helpers),config(Constants).- Avoid:
components,hooks,servicesas segment names.
Structure Reference
For the specific directory layout and layer definitions, see the reference documentation.
- FSD Folder Structure
- Bundling & Compatibility
- Runtime Selection (Edge/Node)
- Debug Tricks & MCP
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 infeatures/*/ui.
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?