Private folders and colocation
What you need to know
Colocation means keeping implementation files near the route that uses them. In App Router, a plain module inside app is not automatically a page. An underscore-prefixed folder explicitly keeps its subtree out of file-system routing. This lets a feature contain helpers without implying new public URLs.
By the end, you can: separate private implementation from route files; design feature modules.
Catalog feature organization
app/catalog/ page.tsx BookBadge.tsx _lib/ availability.ts _components/ ShelfLabel.tsxExpected behavior (not framework-tested): Only /catalog is a page in this tree. The other files are imported by code that needs them.
How it works
Ordinary modules can live inside app without an underscore. The private-folder convention is useful when names might otherwise resemble routes, but it does not prevent imports, enforce server-only execution or restrict data access. A literal URL segment that starts with an underscore can use an encoded %5F folder prefix; use this only when that URL is actually required. Keep database and credential-handling modules on the server and project only public fields to clients.
app/catalog/_lib/availability.ts
export function availability(copies: number) { return copies > 0 ? "In stock" : "Unavailable";}// Example: availability(0) returns "Unavailable".Expected behavior (not framework-tested): A page can import this pure helper with a relative path. The file does not create an availability endpoint.
Common mistake
Do not put a page.tsx in _components expecting it to appear at /catalog/_components. Move intended pages into public segments. Do not rely on an underscore to hide sensitive data from a client bundle.
Practice and verification
Place a BookBadge, a stock-label function and a /catalog/returns page in a feature tree. Identify which files are imported modules and which own public URLs.
Scope: App Router, proposed Next.js 16.x, Cache Components disabled for these labs. Snippets assume a reviewed TypeScript app and are static examples; framework behavior has not been executed. Exact supported patch and dependency set must be verified before running.
Further reading: Organization · Layouts