Learn about the Storefront Next project structure to navigate code quickly and follow conventions that keep your codebase maintainable as it grows.
Overview
A Storefront Next project is built on React Router 7 in framework mode, and uses Vite as the build tool. The structure separates your app code (src/) from configuration files at the project root.
The routes/ directory contains your page components. Storefront Next uses React Router’s file-based routing, where file names determine URL paths.
1src/routes/2├── _index.tsx # Home page (/)3├── category.$.tsx # Category pages (/category/*)4├── product.$productId.tsx # Product pages (/product/:productId)5├── cart.tsx # Cart page (/cart)6├── checkout.tsx # Checkout (/checkout)7├── account.tsx # Account layout8├── account._index.tsx # Account home (/account)9├── account.orders.tsx # Order history (/account/orders)10└── action.cart-item-add.tsx # Server action for adding to cart
File Naming Conventions
Pattern
Example
URL
Purpose
_index.tsx
_index.tsx
/
Index route (renders at parent path)
name.tsx
cart.tsx
/cart
Static route
$param
product.$productId.tsx
/product/:productId
Dynamic segment that captures a value
$.tsx
category.$.tsx
/category/*
Splat/catch-all route
parent.child.tsx
account.orders.tsx
/account/orders
Nested route
action.*
action.cart-item-add.tsx
—
Server action (not a navigable page)
Files starting with underscore (_) have special meaning. _index.tsx renders at the parent path, while a _layout.tsx file creates a layout wrapper without adding a URL segment.
Note
The routes.ts file configures routing behavior. The flatRoutes() function scans your src/routes/ directory and generates route configuration automatically based on file names. You rarely have to modify this file.
The root.tsx file is your app’s entry point. It exports several key pieces that define your app’s behavior:
Export
Purpose
middleware
Server middleware chain (auth, locale detection)
clientMiddleware
Client middleware chain (runs during client navigation)
loader
Root data loader (fetches data needed by all pages)
Layout
HTML document structure (<html>, <head>, <body>)
default (App)
Application shell with header, footer, and <Outlet /> for page content
Most customization happens in middleware and the App component. Typically, you only need to modify Layout when changing document-level meta tags or adding scripts.
Configuration Files
File
Purpose
config.server.ts
Commerce API connection and storefront settings. See Configuration.
Here’s how the project structure guides you when adding a new feature:
1src/2├── routes/3│ ├── wishlist.tsx # 1. Page at /wishlist4│ └── action.wishlist-add.tsx # 2. Server action for adding items5├── components/6│ └── wishlist/7│ ├── wishlist-item.tsx # 3. UI components8│ └── wishlist-empty.tsx9├── hooks/10│ └── use-wishlist.ts # 4. Hook for wishlist operations11└── lib/12 └── api/13 └── wishlist.ts # 5. API client functions
This separation keeps your code organized.
Routes define what URLs exist and load data.
Components handle presentation.
Hooks manage stateful logic.
Lib contains pure functions and API calls.
Customizing Entry Files
React Router provides default entry files for client hydration and server rendering. These entry files are hidden by default but can be revealed for advanced customization.
1npx react-router reveal
This command creates entry.client.tsx and entry.server.tsx in your src/ directory.
When to customize:
Initialize client libraries before hydration
Add custom error reporting (for example, Sentry)
Modify server response headers
Customize streaming behavior
For most projects, the default entry files work without modification.