nestjs-best-practices

Applies 40 prioritized NestJS architecture, security, and performance rules when writing or reviewing code.

Updated Jul 9, 2026
One-click install
npx skills add https://github.com/octanutri-clin/octaclin --skill nestjs-best-practices-octanutri-clin
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: nestjs-best-practices
Source: https://github.com/octanutri-clin/octaclin/tree/main/.agents/skills/nestjs-best-practices
Command: npx skills add https://github.com/octanutri-clin/octaclin --skill nestjs-best-practices-octanutri-clin

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? NestJS codebases often accumulate architectural problems like circular dependencies, god services, N+1 queries, and missing input validation that cause runtime crashes and security gaps. This Skill provides a structured rulebook of 40 best practices across 10 categories so AI-assisted code generation and review follow proven NestJS patterns. ## Core Features & Use Cases - Prioritized Rule Catalog: 40 rules organized by impact (CRITICAL to LOW-MEDIUM) across architecture, dependency injection, error handling, security, performance, testing, database, API design, microservices, and DevOps. - Incorrect vs Correct Examples: Each rule file shows anti-pattern code alongside the recommended implementation with explanations. - Use Case: When refactoring a NestJS service that directly returns TypeORM entities from controllers, apply the api-use-dto-serialization rule to add class-transformer serialization and prevent leaking sensitive fields like password hashes. ## Quick Start Review my NestJS users module using the nestjs-best-practices rules and fix any architecture or security violations.

Frequently Asked Questions about nestjs-best-practices

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I avoid circular dependencies in NestJS modules?

Extract shared logic into a third module that both modules import, or use event-driven communication with @nestjs/event-emitter so modules react to events without direct imports. Circular dependencies are the leading cause of NestJS runtime crashes.

How do I prevent NestJS controllers from exposing sensitive entity fields?

Use class-transformer with @Exclude() decorators on sensitive entity fields and enable ClassSerializerInterceptor globally. For different response shapes, create explicit response DTOs with @Expose() and use plainToInstance for serialization.

Should I use TypeORM synchronize true in production NestJS apps?

No, synchronize can drop columns and data in production. Use TypeORM migrations for all schema changes, set synchronize to false, and enable migrationsRun so schema updates are versioned and reversible.

How do I fix N+1 query problems in NestJS with TypeORM?

Use the relations option in find calls or leftJoinAndSelect in QueryBuilder to eager-load related entities in a single query. For GraphQL, use DataLoader to batch and cache per-request queries.

When should I use @Global() modules in NestJS?

Reserve @Global() for truly cross-cutting concerns like configuration, logging, and database connections. Overusing it hides dependencies, complicates testing, and makes module requirements unclear.