How to understand a Remix codebase
Remix routes are modules that can export a `loader` (server data for GET), an `action` (server handling for form posts) and a default component. Nested routes render inside their parent's `<Outlet />`. Remix v2 was merged into React Router v7, so many Remix apps are mid-migration.
How to tell it's Remix
@remix-run/*packages inpackage.jsonapp/root.tsxand anapp/routes/folder with names likeposts.$id.tsxand_index.tsx- Exports named
loader,actionandmetain route files
Where things usually live
- app/root.tsx
- The HTML document, global links, root loader and error boundary.
- app/routes/
- Flat routes: dots nest URLs (
posts.$id.tsxis/posts/:id),_indexis the index route, a leading_makes a pathless layout. - app/entry.server.tsx
- Server rendering entry; streaming and headers.
- app/entry.client.tsx
- Hydration entry in the browser.
- app/models/ or app/*.server.ts
- Server-only data access; the
.serversuffix keeps it out of the browser bundle. - vite.config.ts
- The Remix Vite plugin and route config options.
Conventions, not rules. Real projects rename and move things, so confirm against the repository.
Where to start reading
app/root.tsx, for global data and layout- The route file for the URL, starting with its
loaderandaction *.server.tsmodules, where database and session code usually lives
How a request moves through the code
- A request matches one or more nested routes from the file names.
- Remix runs every matched route's
loaderin parallel on the server. - Components read loader data with
useLoaderDataand render; children appear inside<Outlet />. - A
<Form method="post">submission calls the route'sactionon the server. - After the action, Remix re-runs the loaders on the page so the UI shows fresh data.
Questions to ask about the repository
- Map each URL to its route file and the loaders that run for it.
- Where are sessions created and read?
- Which actions write to the database, and what do they validate?
- What would change if we migrated this app to React Router v7?
What trips people up
- Flat-route file names encode the URL, so a dot or underscore in a file name is significant.
- Code imported by a route module can leak into the browser bundle unless it lives in a
.serverfile. - Error and catch boundaries are per route, so an error may render far from where it was thrown.