An enterprise-grade NestJS starter built for teams that care about code structure at scale. Ships with CQRS, strict TypeScript, JWT auth (RS256), and multi-runtime support β all wired with zero configuration drift.
# 1. Clone
npx degit NarHakobyan/awesome-nest-boilerplate my-nest-app
cd my-nest-app
# 2. Configure
cp .env.example .env
# Set DB_HOST, DB_PORT, DB_USERNAME, DB_PASSWORD, DB_DATABASE
# Paste your JWT_PRIVATE_KEY and JWT_PUBLIC_KEY (see .env.example for examples)
# 3. Install & run
pnpm install
pnpm start:devOpen http://localhost:3000. The API docs are at /documentation.
Prefer a database out of the box?
docker-compose up -d postgresfirst.
| CQRS β Commands, queries, handlers | JWT Auth (RS256) β Login, register, RBAC | TypeORM + PostgreSQL β Entities, migrations |
Strict TypeScript β No any, ESM, verbatim modules |
i18n β Multi-language (en_US, ru_RU) | Swagger β Auto-generated API docs |
| Vite HMR β Instant dev reload | UUID v7 β Time-sortable primary keys | Biome + ESLint β Linting & formatting |
| Helmet + Rate Limiting β Built-in security | CORS β Configurable origins | Validation β Custom decorators, DTO guards |
| Node / Bun / Deno β Multi-runtime | OpenAPI MCP β AI assistants call your API |
A typical CQRS flow β command, handler, and service wired through NestJS DI:
// ββ Command ββββββββββββββββββββββββββββββββββββββββββββββ
export class CreatePostCommand extends Command {
constructor(
public readonly userId: Uuid,
public readonly dto: CreatePostDto,
) {
super();
}
}
// ββ Handler ββββββββββββββββββββββββββββββββββββββββββββββ
@CommandHandler(CreatePostCommand)
export class CreatePostHandler {
constructor(
@InjectRepository(PostEntity)
private repo: Repository<PostEntity>,
) {}
async execute({ userId, dto }: CreatePostCommand): Promise<PostEntity> {
return this.repo.save(this.repo.create({ ...dto, userId }));
}
}
// ββ Service ββββββββββββββββββββββββββββββββββββββββββββββ
@Injectable()
export class PostService {
constructor(private commandBus: CommandBus) {}
@Transactional()
create(userId: Uuid, dto: CreatePostDto): Promise<PostEntity> {
return this.commandBus.execute(new CreatePostCommand(userId, dto));
}
}flowchart LR
A[Request] --> B[Guard]
B --> C[Controller]
C --> D[Command / Query Bus]
D --> E[Handler]
E --> F[Service]
F --> G[Repository]
G --> H[(PostgreSQL)]
Every feature module follows this structure:
src/
βββ common/ # Shared DTOs, base entity
βββ constants/ # Enums, role types
βββ database/ # Migrations, TypeORM config
βββ decorators/ # @AuthUser, @UUIDParam, @UseDto
βββ filters/ # Global exception filters
βββ guards/ # Auth guards (JWT, roles)
βββ i18n/ # Translation files (en_US, ru_RU)
βββ interceptors/ # Language, translation interceptors
βββ modules/
β βββ auth/ # JWT auth (RS256), login/register
β βββ user/ # User CRUD, RBAC
β βββ post/ # Post CRUD, CQRS example
β βββ agent/ # AI agent (ai-sdk v6)
β βββ chat/ # Chat history (JSONB)
βββ shared/ # Global services, config
βββ validators/ # Custom validation decorators
Copy .env.example β .env. Most variables come pre-configured with working defaults. You only need to change these:
| Variable | What to set |
|---|---|
DB_HOST, DB_PORT, DB_USERNAME, DB_PASSWORD, DB_DATABASE |
PostgreSQL connection (or use docker-compose up -d postgres β defaults match) |
JWT_PRIVATE_KEY |
RS256 private key β generate your own or use the example PEM in .env.example |
JWT_PUBLIC_KEY |
RS256 public key β matching public key |
Every other variable in .env.example has a working default for local development. Optional features (NATS, S3, Email, AI providers) are off by default β enable them when you need them.
| Node.js | Bun | Deno |
|---|---|---|
pnpm start:dev |
bun start:dev:bun |
deno task start |
pnpm test |
bun test |
deno task test |
pnpm build:prod |
bun build:bun |
deno task buildr |
Node is the primary runtime. Bun and Deno support is included for teams that prefer them.
- Rename the project β update
nameinpackage.json - Update
.envβ replace the JWT keys and DB credentials with your own - Update
LICENSEβ change the author name - Customize this README β replace it with your project's docs
- Architecture β CQRS, repository pattern, DI, entity-DTO mapping
- Setup & Development β first-time setup, scripts, debugging
- Code Generation β NestJS schematics for scaffolding
- Naming Cheatsheet β file, class, and variable conventions
- Linting β Biome + ESLint setup
- OpenAPI MCP β AI assistants calling your API