Production ready template

Build Scalable Apps with Feature-Based Architecture

A starter template for building scalable applications with Next.js and a feature-based architecture. All-in one tools, from scratch to production with Next.js, Better Auth and Drizzle.

# Clone the repository

git clone https://github.com/MicrowebPG/nextjs-template
// the stack

Built on proven tools

Every dependency is chosen for reliability, developer experience, and production readiness.

NX

Next.js

React framework with Turbopack for blazing fast builds and server components.

RC

React

Latest React with improved performance, new hooks, and concurrent features.

BA

Better Auth

Modern auth library with email/password, RBAC, and session management.

DZ

Drizzle ORM

Lightweight type-safe ORM that compiles to raw SQL. Zero runtime overhead.

TW

Tailwind CSS

Latest utility-first CSS with enhanced performance and new architecture.

TS

TypeScript

End-to-end type safety across the entire stack, from schema to UI.

HK

Husky

Git hooks for automated linting, formatting, and quality enforcement.

CL

Commitlint

Conventional commit message validation for clean, readable git history.

// architecture

Feature-based structure

Organize by feature, not file type. Each domain owns its components, logic, types, and tests.

Co-located features

Each feature contains its own components, hooks, types, and utilities — everything in one place.

Clear boundaries

Features communicate through well-defined interfaces. No cross-feature imports creating hidden coupling.

Scale naturally

Add new features by creating a new folder. Remove features by deleting one. Zero entanglement.

project structure
1src/
2├── app/
3│ ├── api/auth/[...all]/
4│ ├── globals.css
5│ ├── layout.tsx
6│ └── page.tsx
7├── db/
8│ ├── schema/
9│ ├── index.ts
10│ └── utils.ts
11├── features/
12│ └── auth/
13│ ├── components/
14│ ├── lib/
15│ ├── types/
16│ └── index.ts
17└── lib/
18 └── utils.ts
// authentication

Auth that just works

Better Auth handles the complexity. Email/password, roles, sessions — configured and ready to go.

CORE

Email & Password

Built-in support for traditional email and password authentication flows.

RBAC

Role-Based Access

Three user roles — USER, ADMIN, DEVELOPER — with granular permissions.

SESSION

Session Management

Secure sessions with 7-day expiry, daily refresh, IP and user-agent tracking.

ADAPTER

Database Adapter

Drizzle adapter for seamless PostgreSQL storage of users, accounts, and sessions.

// database

Schema to query, type-safe

Drizzle ORM with PostgreSQL. Define schemas in TypeScript, get full type inference everywhere.

schema/auth.ts
1// src/db/schema/auth.ts
2 
3export const roleEnum = pgEnum(
4 "role", ["USER", "ADMIN", "DEV"]
5);
6 
7export const users = pgTable("users", {
8 id: text("id").primaryKey(),
9 email: text("email").notNull().unique(),
10 username: text("username").notNull(),
11 name: text("name").notNull(),
12 role: roleEnum("role").default("USER"),
13 emailVerified: boolean("email_verified")
14 .default(false),
15 ...timestamps,
16});

Type-safe queries

Full TypeScript inference from schema definition to query result.

PostgreSQL native

Direct pg driver — no abstraction layers standing in the way.

Schema-driven

Define your schema in TypeScript, then push or generate migrations.

Zero overhead

Drizzle compiles to raw SQL at build time. No runtime query builder penalty.