Back to Skills

nestjs-best-practices

Provides comprehensive NestJS best practices including modular architecture, dependency injection scoping, exception filters, DTO validation with class-validator, and Drizzle ORM integration. Use when designing NestJS modules, implementing providers, creating exception filters, validating DTOs, or integrating Drizzle ORM within NestJS applications.

315stars37forksUpdated 8/3/2026

Security Assessment

Safe(95/100)
Security Score95/100

About nestjs-best-practices

nestjs-best-practices is a code-quality and architecture reference for NestJS applications, grounded in the official NestJS documentation. It solves the problem of inconsistent structure and anti-patterns in NestJS codebases by codifying enforceable rules across modular architecture, dependency injection scoping, the request lifecycle, error handling, DTO validation, and Drizzle ORM integration, with rationale, do/don't tables, and reusable code templates.

The SKILL.md prescribes strict module encapsulation (one @Module per domain feature, exporting only what other modules need, avoiding forwardRef and the god-module anti-pattern), correct provider scope selection (DEFAULT singletons versus REQUEST and TRANSIENT with constructor injection), and a clear view of the request pipeline (middleware, guards, interceptors, pipes, handler, exception filters). For error handling it recommends extending HttpException, domain-specific exception classes, a global ExceptionFilter, and the Result pattern while never swallowing exceptions. Validation guidance enforces a global ValidationPipe with transform and whitelist, class-validator decorators on all DTO properties, and separate Create/Update/Response DTOs. Database guidance wraps the Drizzle client in an injectable provider, uses the Repository pattern and transactions, and keeps DB logic out of controllers. It ships reference files per topic (module boundaries, DI scoping, exception filters, validation, Drizzle patterns, architecture) and controller/service/module code templates.

It targets TypeScript backend developers designing or refactoring NestJS modules, reviewing code for anti-patterns, or onboarding to an existing NestJS codebase.

FAQ

What areas of NestJS does it enforce?

Modular architecture, dependency injection scoping, the request lifecycle, error handling, DTO validation with class-validator, and Drizzle ORM integration — each backed by a dedicated reference file of enforcement rules.

When should I use REQUEST or TRANSIENT provider scope?

Default to DEFAULT (singleton) for stateless services and repositories; use REQUEST only for per-request data like tenant/user context and TRANSIENT for stateful utilities or per-consumer caches, and always prefer constructor injection.

How does it approach validation?

Enable ValidationPipe globally with transform: true and whitelist: true, decorate all DTO properties with class-validator, use class-transformer for coercion, and create separate DTOs for Create, Update, and Response operations.

What ORM does it target?

Drizzle ORM — wrapped in an injectable provider, accessed via the Repository pattern, with schemas per domain module, transactions for multi-step operations, and no database logic in controllers.

Does it provide starting code?

Yes — it bundles controller, service, and module templates plus reference files on module boundaries, DI scoping, exception filters, validation, and architecture.

All Files

10 files
references/arch-module-boundaries.md2.6 KB
View
SKILL.md7.2 KB
View
assets/templates/controller-template.ts1.4 KB
View
references/architecture.md5.2 KB
View
assets/templates/module-template.ts0.6 KB
View
references/db-drizzle-patterns.md4.9 KB
View
references/api-validation-dto.md3.9 KB
View
references/error-exception-filters.md4.4 KB
View
assets/templates/service-template.ts1.5 KB
View
references/di-provider-scoping.md3.3 KB
View

Install nestjs-best-practices

Download and extract the skill files to your .claude/skills/ directory.

Quick Setup:

  1. Copy the skill folder to .claude/skills/
  2. Claude will automatically detect and use the skill