Part 02 / Topic 7 of 9
Colocation: files that live in app/ without becoming routes
A route only exists once a folder contains a page.tsx (or route.ts) — nothing else about a folder's contents matters to the router. That means ordinary files — data, helpers, types — can sit right next to your route files in app/ without any risk of accidentally becoming a URL. harness/app/store/lib/products.ts is exactly this: a plain data module imported by every page above, colocated inside app/store/ purely because that is where it is used.
export type Product = {
id: string;
name: string;
price: number;
category: string;
city: string;
};
export const products: Product[] = [
{ id: "p1", name: "Jaipur Blue Pottery Vase", price: 1299, category: "home-decor", city: "Jaipur" },
{ id: "p2", name: "Banarasi Silk Saree", price: 4999, category: "clothing", city: "Varanasi" },
{ id: "p3", name: "Chennai Filter Coffee Set", price: 899, category: "kitchen", city: "Chennai" },
];
Proof that this folder is not a route, even though it sits inside app/store/:
$ curl -s -o /dev/null -w "%{http_code}\n" http://localhost:PORT/store/lib
404
No page.tsx lives in app/store/lib/, so there is nothing for the router to serve at /store/lib — the folder is invisible to routing, exactly as the installed package's own project-structure guide describes: "project files can be safely colocated inside route segments in the app directory without accidentally being routable."
Next.js also ships a second, explicit way to say "this folder is not a route," for cases where relying on "no page.tsx" doesn't feel safe enough — for example a work-in-progress page you don't want live yet. Prefixing a folder name with an underscore, _folderName, opts that folder and everything inside it out of routing, even if it does contain a page.tsx. Proven for real: add app/store/_draft/page.tsx — a fully valid page component — and it never appears in the build's route table at all, and the URL it would have had still 404s:
$ npm run build
...
Route (app)
┌ ○ /
├ ○ /_not-found
├ ○ /store
├ ○ /store/about
├ ○ /store/contact
├ ○ /store/products
├ /store/products/[id]
│ ├ ◐ /store/products/[id]
│ ├ ○ /store/products/p1
│ ├ ○ /store/products/p2
│ └ ○ /store/products/p3
└ /store/search/[...terms]
├ ◐ /store/search/[...terms]
├ ○ /store/search/silk
└ ○ /store/search/pottery
(No /store/_draft line anywhere, even though its page.tsx is real.)
$ curl -s -o /dev/null -w "%{http_code}\n" http://localhost:PORT/store/_draft
404
Apna Bazaar doesn't keep a _draft folder in the harness — it was created, tested, and removed for this section — because the storefront has nothing to hide yet. Exercise 6 has you build and prove this yourself.
Full file: examples/07-colocated-products-data.ts.
Done here? The practice set for Part 2 — including the solutions — is on the part page.