Agent-skills-standard nextjs-architecture
Structure Next.js projects with Feature-Sliced Design layers, domain-grouped slices, and strict import hierarchy. Use when organizing features into FSD layers, enforcing slice boundaries, or keeping page.tsx thin. (triggers: src/features/**, src/entities/**, src/widgets/**, FSD, Feature Sliced Design, slices, segments)
git clone https://github.com/HoangNguyen0403/agent-skills-standard
T=$(mktemp -d) && git clone --depth=1 https://github.com/HoangNguyen0403/agent-skills-standard "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/nextjs/nextjs-architecture" ~/.claude/skills/hoangnguyen0403-agent-skills-standard-nextjs-architecture && rm -rf "$T"
skills/nextjs/nextjs-architecture/SKILL.mdArchitecture (Feature-Sliced Design)
Priority: P2 (MEDIUM)
Warning: FSD introduces boilerplate. Use it only if project expected to grow significantly (e.g., 20+ features). For smaller projects, simple module-based structure preferred.
Workflow: Create New Feature Slice
- Create feature folder —
withsrc/features/auth/login/
,ui/
,model/
segments.api/ - Add public API — Export via
.src/features/auth/login/index.ts - Wire into page — Import feature widget in
(thin page).app/login/page.tsx - Verify imports — Ensure no upward or cross-slice imports violate layer hierarchy.
Layer Hierarchy
App (app/) -> Widgets -> Features -> Entities -> Shared
See implementation examples for thin page example.
Strategy
- RSC Boundaries: Enforce strict serialization rules for props passed from Server to Client. See RSC Boundaries & Serialization.
- App Layer Thin:
directory (App Router) only for Routing.app/
- Rule:
should only import Widgets/Features. No business logic (page.tsx
,useEffect
) directly in pages.fetch
- 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/
- Layer Hierarchy: Code can only import from layers below it.
->App
->Widgets
->Features
->Entities
.Shared
- Avoid Excessive Entities: not preemptively create Entities.
- Rule: Start logic in
orFeatures
. Move toPages
only when data/logic strictly reused across multiple differing features.Entities - Rule: Simple CRUD belongs in
, notshared/api
.entities
- 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 specific directory layout and layer definitions, see reference documentation.
Architecture Checklist (Mandatory)
-
Layer Imports: any layer import from layer ABOVE it? (App > Widgets > Features > Entities > Shared)
-
Page Logic:
thin, containing only Widgets/Features and zeropage.tsx
/useEffect
?fetch -
RSC Boundaries: Server Components isolated from Client Components with proper 'use client' boundaries?
-
Public API: all access to slice performed via top-level
(public API)?index.ts -
Cross-Slice: slices within same layer (e.g., two features) import from each other directly? (Prohibited)
-
Server Actions: Place them in
folder of Feature (e.g.,model/
).features/auth/model/actions.ts -
Data Access (DAL): Place logic in
folder of 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 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.