Skillshub nextjs-architecture
Scalable project structure using Feature-Sliced Design (FSD). Use when structuring a Next.js project with Feature-Sliced Design architecture. (triggers: src/features/**, src/entities/**, src/widgets/**, FSD, Feature Sliced Design, slices, segments)
git clone https://github.com/ComeOnOliver/skillshub
T=$(mktemp -d) && git clone --depth=1 https://github.com/ComeOnOliver/skillshub "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/HoangNguyen0403/agent-skills-standard/nextjs-architecture" ~/.claude/skills/comeonoliver-skillshub-nextjs-architecture && rm -rf "$T"
skills/HoangNguyen0403/agent-skills-standard/nextjs-architecture/SKILL.mdArchitecture (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
directory (App Router) is only for Routing.app/- Rule:
should only import Widgets/Features. No business logic (page.tsx
,useEffect
) directly in pages.fetch
- Rule:
- Slices over Types: Group code by Business Domain (User, Product, Cart), not by File Type (Components, Hooks, Utils).
- Bad:
,src/components/LoginForm.tsxsrc/hooks/useLogin.ts - Good:
containing both.src/features/auth/login/
- 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
orFeatures
. Move toPages
only when data/logic is strictly reused across multiple differing features.Entities - Rule: Simple CRUD belongs in
, notshared/api
.entities
- Rule: Start logic in
- Standard Segments: Use standard segment names within slices.
(Components),ui
(State/actions),model
(Data fetching),api
(Helpers),lib
(Constants).config- Avoid:
,components
,hooks
as segment names.services
Structure Reference
For the specific directory layout and layer definitions, see the reference documentation.
Architecture Checklist (Mandatory)
-
Layer Imports: Does any layer import from a layer ABOVE it? (App > Widgets > Features > Entities > Shared)
-
Page Logic: Is
thin, containing only Widgets/Features and zeropage.tsx
/useEffect
?fetch -
RSC Boundaries: Are Server Components isolated from Client Components with proper 'use client' boundaries?
-
Public API: Is all access to a slice performed via the top-level
(public API)?index.ts -
Cross-Slice: Do slices within the same layer (e.g., two features) import from each other directly? (Prohibited)
-
Server Actions: Place them in the
folder of a Feature (e.g.,model/
).features/auth/model/actions.ts -
Data Access (DAL): Place logic in the
folder of an Entity (e.g.,model/
).entities/user/model/dal.ts -
UI Components: Base UI (shadcn) belongs in
. Feature-specific UI belongs inshared/ui
.features/*/ui
Anti-Patterns
- No cross-slice imports: Slices in the same layer must not import from each other directly.
- No business logic in
: Pages import Widgets/Features only; zeropage.tsx
/useEffect
.fetch - No file-type folders: Group by domain (
), not type (features/auth/
,components/
).hooks/ - No premature Entity creation: Start in Features; move to Entities only on strict reuse.