Nextjs architecture

From HoangNguyen0403/agent-skills-standard · View interactive version

Nextjs architecture is an AI agent skill from the GitHub repository HoangNguyen0403/agent-skills-standard. 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.

How to use this skill

Skill file

Architecture (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

  1. Create feature folder — src/features/auth/login/ with ui/, model/, api/ segments.
  2. Add public API — Export via src/features/auth/login/index.ts.
  3. Wire into page — Import feature widget in app/login/page.tsx (thin page).
  4. 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

  1. RSC Boundaries: Enforce strict serialization rules for props passed from Server to Client. See RSC Boundaries & Serialization.
  2. App Layer Thin: app/ directory (App Router) only for Routing.
  1. Slices over Types: Group code by Business Domain (User, Product, Cart), not by File Type (Components, Hooks, Utils).
  1. Layer Hierarchy: Code can only import from _layers below it_.
  1. Avoid Excessive Entities: not preemptively create Entities.
  1. Standard Segments: Use standard segment names within slices.

Structure Reference

For specific directory layout and layer definitions, see reference documentation.

Architecture Checklist (Mandatory)

Anti-Patterns

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.