A modern, production-ready Next.js 16 starter template featuring robust authentication, database management, and optimized route organization.
- Next.js 16 (App Router): Utilizing the latest React 19 features and Turbopack.
- Better Auth: Comprehensive authentication system with session management.
- Automated Migrations: Database migrations are automatically applied on application launch.
- Drizzle ORM: Type-safe database interactions with PostgreSQL.
- Route Groups & Security Proxy:
(authenticated): Private routes protected by a server-side layout proxy.(guest): Public-only routes (Login/Register) with auto-redirect for logged-in users.
- Path Aliases: Standardized
@/*imports for clean and reliable module resolution. - Biome: Ultra-fast linting and formatting.
- Tailwind CSS 4: Modern styling with native CSS variable support.
βββ app/
β βββ (authenticated)/ # Protected routes (requires login)
β β βββ layout.tsx # Security Proxy & Permission check
β β βββ page.tsx # Dashboard / Home
β βββ (guest)/ # Public routes (login, register)
β β βββ layout.tsx # Guest-only redirect logic
β β βββ login/
β β βββ register/
β βββ api/auth/ # Better Auth API handlers
β βββ layout.tsx # Root layout
βββ components/ # UI Components (shadcn/ui)
βββ lib/
β βββ db/ # Drizzle schema and client
β βββ auth.ts # Server-side Auth config
β βββ auth-client.ts # Client-side Auth hook
βββ drizzle/ # Generated migrations
Copy .env.example to .env.local and fill in your credentials:
cp .env.example .env.localStart the local database using Docker:
bun db:upGenerate migrations after making changes to your schema:
bun db:generateNote: Migrations are automatically applied when the application starts (via instrumentation.ts). You can also run them manually using bun db:migrate.
Install dependencies and run the server:
bun install
bun devOpen http://localhost:3000 to see your app.
bun dev: Start development server with Turbopack.bun lint:fix: Run Biome to fix linting and formatting.bun db:generate: Generate migration files from your schema.bun db:migrate: Manually apply migrations to the database.bun db:studio: Open Drizzle Studio to explore your data.
The app/(authenticated)/layout.tsx file acts as a centralized security proxy. It checks for a valid session before rendering any children.
A commented-out placeholder is available in the layout to implement role-based access control (RBAC):
// const userRole = session.user.role;
// if (!allowedRoles.includes(userRole)) redirect('/dashboard?error=denied');