A modern, opinionated Next.js + API template designed to build scalable applications fast.
This template combines Next.js App Router, an internal typed API, modular backend architecture, authentication, database access, and a clean frontend structure — all ready to be reused across multiple projects.
⚡ This template is powered by Bun for faster installs and execution. 🤖 also includes Copilot instructions to ensure consistent code generation.
- Next.js App Router
- Internal API architecture (decoupled core)
- Modular backend structure (domain-based modules)
- End-to-end type safety
- Authentication ready (Better Auth)
- Database ready (PostgreSQL + Drizzle)
- Middleware & plugin system
- Environment validation
- Scalable frontend structure
- Docker-ready
src/
├─ app/ # Next.js App Router
│ ├─ (public)/
│ ├─ (protected)/
│ └─ api/[[...slugs]]/ # API adapter
│
├─ api/ # API core (framework-agnostic)
│ ├─ app.ts
│ ├─ config/
│ ├─ database/
│ ├─ modules/
│ └─ shared/
│
├─ components/ # Shared UI components
├─ features/ # Domain-based frontend features
├─ lib/ # Shared frontend utilities
└─ styles/bun installCreate a .env file in the project root:
DATABASE_URL=postgresql://pgadmin:password@localhost:5432/docker
NEXT_PUBLIC_URL=http://localhost:3000
BETTER_AUTH_URL=http://localhost:3000
BETTER_AUTH_SECRET=your-secret-keyTip
There's a docker-compose.yml file in the project root if you need to run the database using Docker.
bun devThe app will be available at:
http://localhost:3000
- Lives in
src/api - Completely decoupled from Next.js
- Uses a factory pattern (
createApiApp) - Can be reused in other environments
src/app/api/[[...slugs]]/route.tsThis file connects Next.js to the API core.
Each backend module follows the same structure:
modules/example/
├─ example.route.ts
├─ example.service.ts
└─ index.tsThis makes the system predictable and scalable.
Authentication is handled via Better Auth and configured through environment variables.
The system is designed to support:
- Public routes
- Protected routes
- Role-based access (extensible)
bun dev # Run development server
bun build # Build for production
bun start # Start production server
bun lint # Lint project
bun lint:fix # Lint and auto-fix- Copy an existing module (e.g.
example) - Rename files and exports
- Register it in
registerModules
That’s it.
MIT License.
