Skip to content
Projects

NarHakobyan/awesome-nest-boilerplate

View on GitHub

About

Awesome NestJS Boilerplate ๐Ÿ˜, Typescript ๐Ÿ’ช, Postgres ๐ŸŽ‰, TypeORM ๐Ÿฅณ

Learning & Education

How these counts are measured

Measured star growth

in 24h
-1
in 7 days
-3
in 15 days
-5
in 1 month
-5

Net star changes over overlapping periods, not daily totals. Missing measurements are left blank. Stars measure attention, not software quality.

README.md

Original

Awesome NestJS Boilerplate v11

License NestJS Node CI

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.

Quick Start

# 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:dev

Open http://localhost:3000. The API docs are at /documentation.

Prefer a database out of the box? docker-compose up -d postgres first.

What's Inside

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

Taste of the Codebase

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));
  }
}

Architecture

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

Full architecture โ†’

Environment Variables

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.

All environment variables โ†’

Multi-Runtime Support

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.

Making It Your Own

  1. Rename the project โ€” update name in package.json
  2. Update .env โ€” replace the JWT keys and DB credentials with your own
  3. Update LICENSE โ€” change the author name
  4. Customize this README โ€” replace it with your project's docs

Documentation

  1. Architecture โ€” CQRS, repository pattern, DI, entity-DTO mapping
  2. Setup & Development โ€” first-time setup, scripts, debugging
  3. Code Generation โ€” NestJS schematics for scaffolding
  4. Naming Cheatsheet โ€” file, class, and variable conventions
  5. Linting โ€” Biome + ESLint setup
  6. OpenAPI MCP โ€” AI assistants calling your API

Community

Discuss on GitHub โ†’


Sponsored by M One & HR Drone

Explore related projects

Loadingโ€ฆ