Skip to content

Latest commit

Β 

History

455 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

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)]
Loading

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

About

Awesome NestJS Boilerplate 😍, Typescript πŸ’ͺ, Postgres πŸŽ‰, TypeORM πŸ₯³

Resources

Stars

2.8k stars

Watchers

35 watching

Forks

Releases

Packages

Used by

Contributors

Languages