Skip to content

EDnotSheeran/next-app-template

Repository files navigation

Next App Template

Next App Template

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.


✨ Features

  • 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

📁 Project Structure

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/

🚀 Getting Started

1. Install dependencies

bun install

2. Configure environment variables

Create 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-key

Tip

There's a docker-compose.yml file in the project root if you need to run the database using Docker.

3. Run the development server

bun dev

The app will be available at:

http://localhost:3000

🧠 Architecture Overview

API Core

  • Lives in src/api
  • Completely decoupled from Next.js
  • Uses a factory pattern (createApiApp)
  • Can be reused in other environments

API Adapter

src/app/api/[[...slugs]]/route.ts

This file connects Next.js to the API core.

Modules

Each backend module follows the same structure:

modules/example/
├─ example.route.ts
├─ example.service.ts
└─ index.ts

This makes the system predictable and scalable.


🔐 Authentication

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)

🧪 Scripts

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

🧩 Creating a New Module

  1. Copy an existing module (e.g. example)
  2. Rename files and exports
  3. Register it in registerModules

That’s it.


📄 License

MIT License.

About

A modern, production-ready Next.js fullstack template with Shadcn UI components. Build faster with pre-configured authentication, database integration, and responsive design patterns — everything you need to launch your next project.

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Contributors