nestjs-best-practices

Applies 40 prioritized NestJS rules covering architecture, dependency injection, security, and performance.

1|1|Updated Oct 3, 2021
One-click install
npx skills add https://github.com/benjr70/Smart-Smoker-V2 --skill nestjs-best-practices-benjr70
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: nestjs-best-practices
Source: https://github.com/benjr70/Smart-Smoker-V2/tree/main/.claude/skills/nestjs
Command: npx skills add https://github.com/benjr70/Smart-Smoker-V2 --skill nestjs-best-practices-benjr70

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 prioritized best practices so code is written and reviewed against proven patterns from the start. ## Core Features & Use Cases - Prioritized Rule Catalog: 40 rules across 10 categories (architecture, DI, error handling, security, performance, testing, database, API design, microservices, DevOps), each ranked by impact from CRITICAL to LOW-MEDIUM. - Incorrect vs. Correct Examples: Every rule file shows an anti-pattern code sample alongside the corrected implementation with explanations. - Use Case: When refactoring a NestJS service that injects repositories directly and returns entities from controllers, reference the repository-pattern and DTO-serialization rules to restructure data access and prevent sensitive field exposure. ## Quick Start Review my NestJS users module against the architecture and security best practices and suggest fixes for any 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 fix circular dependencies between NestJS modules?

Circular dependencies are resolved by extracting shared logic into a third module that both modules import, or by using event-driven communication with @nestjs/event-emitter so modules react to events without direct imports. Forward references work but indicate architectural problems.

How to structure a NestJS project by feature modules?

Organize code into self-contained feature modules where each domain (users, orders) holds its own controllers, services, entities, and DTOs. Avoid grouping by technical layer, and export only the providers other modules actually need.

What is the correct way to validate input in NestJS controllers?

Use class-validator decorators on DTO classes combined with a global ValidationPipe configured with whitelist and transform options. Built-in pipes like ParseUUIDPipe and ParseIntPipe handle common parameter transformations declaratively.

Does NestJS support avoiding N+1 database queries with TypeORM?

Yes, use the relations option in find calls or QueryBuilder joins to eager-load related entities in a single query. For GraphQL, DataLoader batches per-request queries, and enabling query logging in development helps detect N+1 patterns.

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 invisible from import declarations.

Why should synchronize be disabled in TypeORM production configs?

The synchronize option can drop columns, tables, or data when entity schemas change, making it unsafe for production. Use TypeORM migrations instead, which provide versioned, reversible schema changes consistent across all environments.