nestjs-best-practices

Provides 40 prioritized NestJS architecture, security, and performance rules for code generation and review.

Updated Jun 5, 2026
One-click install
npx skills add https://github.com/1t1sCooL/zazyvala-bot --skill nestjs-best-practices-1t1scool
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: nestjs-best-practices
Source: https://github.com/1t1sCooL/zazyvala-bot/tree/main/.agents/skills/nestjs-best-practices
Command: npx skills add https://github.com/1t1sCooL/zazyvala-bot --skill nestjs-best-practices-1t1scool

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) components.

What problem does it solve? NestJS codebases often suffer from circular dependencies, god services, improper module sharing, and inconsistent error handling that cause runtime crashes and maintenance pain. This Skill gives AI agents and developers a structured, impact-prioritized rulebook to write, review, and refactor NestJS code correctly. ## Core Features & Use Cases - 40 Rules Across 10 Categories: Covers architecture, dependency injection, error handling, security, performance, testing, database/ORM, API design, microservices, and DevOps, each ranked by impact from CRITICAL to LOW-MEDIUM. - Incorrect vs. Correct Examples: Every rule includes real TypeScript code showing the anti-pattern and the recommended implementation with explanations and official documentation references. - Composable Rule Files: Individual rules live in rules/ with YAML frontmatter, compiled into a single AGENTS.md via a build script for easy maintenance and extension. - Use Case: When refactoring a NestJS service that injects five unrelated dependencies, apply the event-driven decoupling and single-responsibility rules to split it into focused services communicating via @nestjs/event-emitter. ## Quick Start Ask the agent to review your NestJS module for circular dependencies and improper provider sharing using the nestjs-best-practices guidelines.

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?

Avoid circular dependencies by extracting shared logic into a third module that both modules import, or by using event-driven communication with @nestjs/event-emitter. Forward references exist but indicate architectural problems and are the leading cause of runtime crashes.

What is the best way to structure a NestJS project?

Organize by feature modules rather than technical layers, keeping each feature's controllers, services, entities, and DTOs together in one directory. This enables faster onboarding and development compared to grouping all controllers or services separately.

Does NestJS support constructor injection over property injection?

Yes, constructor injection is the preferred pattern because dependencies are explicit, testable, and visible in the class signature. Property injection hides dependencies and complicates mocking in unit tests with the NestJS testing module.

How do I validate input in NestJS controllers?

Use DTOs with class-validator decorators and a global ValidationPipe configured with whitelist and transform options. Built-in pipes like ParseUUIDPipe and ParseIntPipe handle common type conversions and reject invalid input automatically.

When should I use the repository pattern in NestJS?

Use custom repositories when services contain complex query logic such as query builders with joins, grouping, or conditional filters. This keeps services focused on business logic, simplifies mocking in tests, and isolates database implementation details.

Why does providing the same service in multiple NestJS modules cause bugs?

Providing a service in multiple modules creates separate instances with independent state, causing memory waste and inconsistent behavior. Instead, define the service in one dedicated module, export it, and import that module wherever the service is needed.