Next.js Structure Specialist
1. Overview
This skill specializes in initializing and structuring Next.js applications using the App Router and Business-Oriented Modular Architecture. It enforces a strict organization where code is grouped by Business Domain (Modules) rather than technical type. This ensure that the project structure "screams" its intent, making it easier to scale and maintain.
2. Prerequisites & Context
- •Required Tools:
- •
run_command: To executenpx create-next-appand install dependencies. - •
write_to_file: To create directory structures and configuration files. - •
list_dir: To verify the current project state.
- •
- •Environment: Node.js 18.17+ environment.
- •Input:
- •Project name.
- •List of Business Concepts (e.g., Checkout, Authentication, Inventory).
3. Workflow
- •Analyze Request: Identify the core Business Modules of the application.
- •Scaffold Base Project: Run
npx create-next-app@latestwith strict flags. - •Implement Modular Architecture:
- •Create
src/app. - •Define Module Route Groups
(module-name)for each business domain. - •Enforce Module Isolation: All components, hooks, and actions related to a module MUST be inside that module's directory (
_components,_hooks). - •Create strict root files:
layout.tsx,page.tsx,loading.tsx,error.tsx,not-found.tsx.
- •Create
- •Configure Aliases: Update
tsconfig.jsonto support module-based imports. - •Clean & Verify: Remove technical groupings (like a global
components/folder for feature components) and enforce business grouping.
4. Detailed Instructions & Rules
Critical Rules
- • Rule 1: Structure by Business Module: The top-level folders in
src/appMUST represent Business Domains (e.g.,(billing),(user-management)), not technical layers. - • Rule 2: Colocation is King: All files related to a specific business module (UI, logic, state) MUST be colocated within that module's folder.
- • Rule 3: App Router & Route Groups: Use Route Groups
(module)to define module boundaries without polluting the URL structure. - • Rule 4: Strict Isolation: A module should NOT import private internal details of another module. Shared logic must go to
shared/. - • Rule 5: Screaming Architecture: A developer looking at the file tree should instantly understand what the business does, not just that it's a Next.js app.
Formatting Guidelines
- •File Naming: Use kebab-case.
- •Directory Structure:
src/app/(business-module)/feature/... - •Code Style: Functional components, TypeScript.