You can create private folders by prefixing the folder name with an underscore (_). These folders and their subfolders are excluded from the routing system and treated as internal implementation details:
app/blog/_components/Post.tsx
app/blog/_lib/data.tsAlthough Next.js allows colocating files safely inside the app directory by default, private folders offer added benefits:
To organize routes without affecting the URL, wrap folder names in parentheses. These folders are ignored in the final URL path:
app/(marketing)/page.tsx → /
app/(shop)/cart/page.tsx → /cartRoute groups are useful for:
Next.js supports placing your application code (including app) inside an optional src folder. This helps separate app logic from configuration files:
src/app/page.tsx
src/components/Button.tsxHere are a few common strategies for organizing your project:
app: Keep routing in app and shared logic in root-level foldersapp: Place shared folders like components or lib inside app(marketing) or (shop)layout.tsx and add one inside each route groupaccount, cart) into a shared grouploading.tsx inside a route group like (overview)By using private folders, route groups, and flexible structure strategies, you can build well-organized, scalable, and maintainable Next.js applications. These patterns help separate routing, UI, and internal logic while improving developer experience and project clarity.