Enforces a colocation-first approach for Next.js App Router projects, grouping components, pages, and logic within route folders for modularity and maintainability.
Structure your Next.js apps with a colocation-first approach. Colocation means placing components, pages, and related logic together within their route folders. This aligns with the Next.js App Router's design, making features self-contained and easier to manage.
_components/, _hooks/, _types/): Use underscore-prefixed folders to opt out of the routing system and store route-specific logic/UI._components/ folder.app/
├── (logical-group)/ # Route Group: Group features by domain (e.g. auth, dashboard, marketing)
│ ├── feature-name/
│ │ ├── page.tsx
│ │ ├── layout.tsx
│ │ ├── _components/ # Route-specific UI
│ │ ├── _hooks/ # Route-specific state/logic
│ │ └── _types/ # Route-specific interfaces
├── globals.css
├── layout.tsx
├── components/ # Global UI primitives (Shadcn, Base UI)
├── lib/ # Shared libraries and utilities
├── hooks/ # Global reusable hooks
├── types/ # Global shared TypeScript types
└── middleware.ts # App-wide middleware
Prefixing folders with an underscore (e.g., _components) prevents Next.js from considering them as route segments.
_components/ (or similar) within a route folder for elements that belong exclusively to that route."use client" only when interactivity is needed. Colocation makes it easier to see where the client/server boundary is.(dashboard)/_components or (dashboard)/_hooks.lib/ or hooks/ if it is used across disparate feature groups.app/dashboard/settings).page.tsx for the main content._components/ folder for any UI primitives needed specifically for this page._components/ folder.components/: Avoid putting every component in a single top-level folder._components/ is always underscored to avoid accidental route generation._components/ folders; always try to import from sibling or child folders, never "up" into a specific child's private folder from a global context.