How to understand a Next.js (App Router) codebase
In an App Router project the folder tree under `app/` is the route map. Components are Server Components unless a file says `"use client"`, so the first job when reading is to work out which code runs on the server, which ships to the browser, and where the boundary sits.
How to tell it's Next.js (App Router)
- An
app/directory (orsrc/app/) containinglayout.tsxandpage.tsxfiles nextinpackage.jsondependencies and anext.config.tsornext.config.js- Files starting with
"use client"or"use server"directives - Special files such as
loading.tsx,error.tsx,not-found.tsxandroute.ts
Where things usually live
- app/layout.tsx
- Root layout: the
<html>shell, fonts, providers and anything shared by every page. - app/**/page.tsx
- One page per route. The folder path is the URL;
[slug]folders are dynamic segments. - app/**/route.ts
- Route handlers: HTTP endpoints exporting
GET,POSTand so on. - app/(group)/
- Route groups. Parentheses organise files and share layouts without changing the URL.
- components/
- Shared UI. Check each file for
"use client"to see what runs in the browser. - lib/ or server/
- Data access, auth helpers and server-only logic called from pages and actions.
- proxy.ts (or middleware.ts)
- Runs before routes match: redirects, rewrites and auth checks. Next.js 16 renamed
middleware.tstoproxy.ts. - next.config.ts
- Build and runtime settings: redirects, images, experimental flags such as Cache Components.
Conventions, not rules. Real projects rename and move things, so confirm against the repository.
Where to start reading
app/layout.tsx, to see global providers and what wraps every page- The
page.tsxfor the route you care about, then follow its imports proxy.tsormiddleware.ts, because it can redirect a request before any page runsnext.config.ts, for rewrites, redirects and flags that change behaviour
How a request moves through the code
- The request hits
proxy.ts(ormiddleware.ts) if one exists, which may redirect, rewrite or add headers. - Next.js matches the URL to a folder under
app/and renders the layouts from the root down to that segment. - The
page.tsxServer Component runs on the server, fetching data directly or through helpers inlib/. - Client Components marked
"use client"are rendered to HTML on the server, then hydrated in the browser. - Form submissions and mutations call Server Actions (
"use server"functions) orroute.tshandlers. - Cached data is reused until it is revalidated, so check
"use cache",revalidatePathandrevalidateTagcalls when output looks stale.
Questions to ask about the repository
- Which components in this app are Client Components, and why does each one need to be?
- Trace what happens from submitting the sign-up form to the user record being saved.
- Where is authentication enforced: in proxy, in layouts, in Server Actions or in route handlers?
- Which routes are dynamic, and what data does each one fetch?
- What does
next.config.tschange about the default behaviour?
What trips people up
- A layout does not re-render on navigation between its child pages, so auth checks placed only in a layout can be skipped by client-side navigation to sibling pages; check pages or data access too.
- Importing a server-only module into a Client Component silently pulls it toward the browser bundle; look for the
server-onlypackage guarding sensitive modules. - Older tutorials describe
getServerSidePropsandpages/; those belong to the Pages Router and don't apply here. - Caching rules changed between major versions, so check the
nextversion inpackage.jsonbefore trusting an explanation of why data is or isn't fresh.