Agent skill · software engineering · affaan-m

nestjs-patterns

NestJS architecture patterns for modules, controllers, providers, DTO validation, guards, interceptors, config, and production-grade TypeScript backends. Use when building or reviewing a NestJS backend — modules, providers, DTO validation, guards, or interceptors.

Why this skill is useful

Provides specific NestJS architectural patterns and TypeScript best practices that enhance the AI's ability to generate production-grade backend code.

What it needs

About 3k tokens when loaded. Last updated 2026-08-06. 238,342 stars on the source repository.

What this skill does

NestJS Development Patterns Production-grade NestJS patterns for modular TypeScript backends. When to Activate Building NestJS APIs or services Structuring modules, controllers, and providers Adding DTO validation, guards, interceptors, or exception filters Configuring environment-aware settings and database integrations Testing NestJS units or HTTP endpoints Project Structure Keep domain code inside feature modules. Put cross-cutting filters, decorators, guards, and interceptors in common/. Keep DTOs close to the module that owns them. Bootstrap and Global Validation Always enable whitelist and forbidNonWhitelisted on public APIs. Prefer one global validation pipe instead of repeating validation config per route. Modules, Controllers, and Providers Controllers should stay thin: parse HTTP input, call a provider, return response DTOs. Put business logic in injectable services, not controllers. Export only the providers other modules genuinely need. DTOs and Validation Validate every request DTO with class-validator. Use dedicated response DTOs or serializers instead of returning ORM entities directly. Avoid leaking internal fields such as password hashes, tokens, or audit columns. Auth, Guards, and Request Context Keep auth strategies and guards module-local unless they are truly shared. Encode coarse access rules in guards, then do resource-specific authorization in services. Prefer explicit request types for authenticated request objects. Exception Filters and Error Shape Keep one consistent error envelope across the API. Throw framework exceptions for expected client errors; log and wrap unexpected failures centrally. Config and Environment Validation Validate env at boot, not lazily at first request. Keep config access behind typed helpers or config services. Split dev/staging/prod concerns in config factories instead of branching throughout feature code. Persistence and Transactions Keep repository / ORM code behind providers that speak domain language. …

How to use it

Reference it in AdaL, Claude Code, Cursor or any coding agent — nothing to install:

@skills affaan-m/nestjs-patterns--9c3f5c

View the source on GitHub

Browse the @skills marketplace