The Principle
Place files next to the code that uses them. Route-specific components go in acomponents/ folder inside their route group. Shared components go in the nearest common parent. Globally shared code lives in packages/.
This is the layout of the main app:
components/ folder never becomes a route because it contains no page.tsx. Next.js only creates routes for folders with a page or route file, so component files can sit inside the router tree without affecting URLs.
Where Things Live
| Scope | Location | Example |
|---|---|---|
| Route group | app/(authenticated)/components/ | The sidebar and header for authenticated pages |
| Single app | apps/web/components/ | A component used across one app’s routes |
| All apps | packages/design-system/ | Buttons, cards, inputs from @repo/design-system |
Route Groups
Route groups wrap related routes without affecting the URL. Parenthesized folder names like(authenticated) and (unauthenticated) organize code while keeping paths clean:
layout.tsx for shared UI: the authenticated layout renders the sidebar and providers, the unauthenticated layout wraps the auth forms.
Server and Client Boundaries
Keep"use client" at the leaf level. Page files and layouts run as Server Components by default. Push client interactivity (state, events, hooks) into the components/ folder:
apps/app/app/(authenticated)/page.tsx
apps/app/app/(authenticated)/components/search.tsx
Colocating Non-Component Files
Routes can colocate more than components. Server actions and route handlers live inside the sameapp/ tree:
In a Monorepo
mf² splits shared code into packages. The colocation hierarchy extends across the monorepo:- Route group
components/: shared by routes in one group - App-level
components/: shared across routes in one app @repo/design-system: shared across all apps- Other
@repo/*packages: shared utilities, hooks, configs
@repo/design-system serves every app. A component in (authenticated)/components/ serves one route group.
The hierarchy tells an agent where to put new code. Route-specific component: the route group’s components/ folder. Shared across apps: @repo/design-system. Convention replaces guesswork.