AI Rules Hub
AI Rules Hub
Log In

Next.js feature-based architecture rules

No description provided.

Install via CLI
$ npx @airuleshub/cli@latest add nextjs-feature-based-architecture-rules

Rule Content

šŸŽÆ RULE: ROUTING + FEATURES MUST BE SEPARATED

  • app/ → routing only
  • features/ → business logic

šŸ“ FOLDER STRUCTURE (NEXT.JS)

src/ā”‚ā”œā”€ā”€ app/                              # Next.js App Router│   ā”œā”€ā”€ layout.tsx│   ā”œā”€ā”€ globals.css││   ā”œā”€ā”€ (public)/│   │   ā”œā”€ā”€ layout.tsx│   │   ā”œā”€ā”€ page.tsx                  # landing│   │   └── login/│   │       └── page.tsx││   ā”œā”€ā”€ (protected)/│   │   ā”œā”€ā”€ layout.tsx│   │   └── dashboard/│   │       └── page.tsx││   ā”œā”€ā”€ (admin)/│   │   └── admin/│   │       └── page.tsx││   └── api/                          # route handlers│       └── auth/│           └── route.tsā”‚ā”œā”€ā”€ features/│   ā”œā”€ā”€ auth/│   │   ā”œā”€ā”€ components/│   │   │   ā”œā”€ā”€ LoginForm.tsx│   │   │   └── RegisterForm.tsx│   │   ││   │   ā”œā”€ā”€ hooks/│   │   │   ā”œā”€ā”€ useLogin.ts│   │   │   └── useSession.ts│   │   ││   │   ā”œā”€ā”€ queries/│   │   │   ā”œā”€ā”€ auth.queries.ts│   │   │   └── auth.mutations.ts│   │   ││   │   ā”œā”€ā”€ services/│   │   │   └── auth.api.ts│   │   ││   │   ā”œā”€ā”€ types/│   │   │   └── auth.types.ts│   │   ││   │   ā”œā”€ā”€ utils/│   │   │   └── auth.utils.ts│   │   ││   │   ā”œā”€ā”€ constants/│   │   │   └── auth.constants.ts│   │   ││   │   └── index.ts│   ││   ā”œā”€ā”€ rules/│   │   ā”œā”€ā”€ components/│   │   ā”œā”€ā”€ hooks/│   │   ā”œā”€ā”€ queries/│   │   ā”œā”€ā”€ services/│   │   ā”œā”€ā”€ types/│   │   ā”œā”€ā”€ utils/│   │   ā”œā”€ā”€ constants/│   │   └── index.tsā”‚ā”œā”€ā”€ shared/│   ā”œā”€ā”€ components/│   ā”œā”€ā”€ hooks/│   ā”œā”€ā”€ lib/│   │   ā”œā”€ā”€ api.ts│   │   ā”œā”€ā”€ query-client.ts│   │   └── auth.ts│   ā”œā”€ā”€ utils/│   ā”œā”€ā”€ constants/│   └── types/ā”‚ā”œā”€ā”€ providers/│   └── QueryProvider.tsxā”‚ā”œā”€ā”€ middleware.ts                    # auth / route guardsā”‚ā”œā”€ā”€ styles/│   └── globals.cssā”‚ā”œā”€ā”€ config/│   └── env.tsā”‚ā”œā”€ā”€ types/│└── next.config.js

⚔ NEXT.JS RULES

  • app/ MUST NOT contain business logic
  • All logic MUST live inside features/
  • Server components MUST NOT include client-side logic unnecessarily
  • TanStack Query MUST be used for client-side server state
  • API routes MUST remain thin (no heavy logic)
  • Middleware MUST handle authentication and routing guards

🚫 COMMON FORBIDDEN

  • API calls inside components
  • Cross-feature imports
  • Global business logic
  • useEffect for fetching
  • Monolithic folders

Command Palette

Search for a command to run...