Directory Overview
App Directory (src/app/)
The app/ directory uses Next.js 13+ App Router with file-based routing.
Authentication Routes
API Proxy (src/app/api/[...path]/route.ts)
The catch-all API proxy automatically injects JWT tokens into requests forwarded to your backend.
How it works:
- Client makes request to
/api/users/me - Proxy fetches JWT from Better Auth using the current session
- JWT is injected as
Authorization: Bearer <token>header - Request is forwarded to
BACKEND_API_URL/api/users/me - Backend response is returned to client
BACKEND_API_URL in your .env file (server-side only):
.env
Components Directory (src/components/)
UI Components (src/components/ui/)
Pre-built shadcn/ui components:
button.tsx- Button primitivecard.tsx- Card containerinput.tsx- Form input
Demo Components
The boilerplate includes demo components that you can remove when building your app:auth-status.tsx- Displays current authentication statusapi-test.tsx- Tests the fetch-based API clientapi-test-axios.tsx- Tests the Axios-based API client
Core Components
Keep these components in your production app:login-required.tsx- HOC for protecting authenticated routestheme-provider.tsx- Dark/light mode providertheme-toggle.tsx- Theme switcher buttonfade-in.tsx- Animation wrapper
Library Directory (src/lib/)
Authentication Configuration
API Clients
Two API client implementations are provided:api-client.ts- Fetch-based (zero dependencies)api-client-axios.ts- Axios-based (with interceptors)
Database Directory (src/db/)
Schema Definition (src/db/schema.ts)
The database schema is defined using Drizzle ORM. Better Auth automatically manages these tables:
src/db/schema.ts
Adding Custom Tables
Add your own tables toschema.ts:
src/db/schema.ts
Migrations (src/db/migrations/)
SQL migration files are generated by Drizzle Kit when you run npm run db:generate.
Key Configuration Files
Root Directory
| File | Purpose |
|---|---|
drizzle.config.ts | Drizzle ORM configuration |
.env.example | Environment variable template |
package.json | Dependencies and scripts |
next.config.ts | Next.js configuration |
tailwind.config.ts | Tailwind CSS configuration |
tsconfig.json | TypeScript configuration |
Environment Variables
See Getting Started for the complete list of required environment variables.Routing Structure
Next.js App Router automatically creates routes based on folder structure:| Route | File | Description |
|---|---|---|
/ | app/page.tsx | Home page |
/login | app/login/page.tsx | Login page |
/signup | app/signup/page.tsx | Registration page |
/api/auth/* | app/api/auth/[...all]/route.ts | Better Auth endpoints |
/api/* | app/api/[...path]/route.ts | JWT-injecting proxy |
Learn more about App Router in the Next.js documentation.