Agent Skills: NestJS Architecture Expert

Design decoupled, testable NestJS module boundaries with feature, core, and shared modules. Use when structuring module imports, creating feature modules, or enforcing separation of concerns in NestJS. (triggers: **/*.module.ts, main.ts, NestFactory, Module, Controller, Injectable)

UncategorizedID: hoangnguyen0403/agent-skills-standard/nestjs-architecture

Install this agent skill to your local

pnpm dlx add-skill https://github.com/HoangNguyen0403/agent-skills-standard/tree/HEAD/skills/nestjs/nestjs-architecture

Skill Files

Browse the full folder contents for nestjs-architecture.

Download Skill

Loading file tree…

skills/nestjs/nestjs-architecture/SKILL.md

Skill Metadata

Name
nestjs-architecture
Description
"Design decoupled, testable NestJS module boundaries with feature, core, and shared modules. Use when structuring module imports, creating feature modules, or enforcing separation of concerns in NestJS. (triggers: **/*.module.ts, main.ts, NestFactory, Module, Controller, Injectable)"

NestJS Architecture Expert

Priority: P0 (CRITICAL)

Design decoupled, testable modules with clear boundaries.

Workflow: Create a New Feature Module

  1. Generate modulenest g module users creates the feature module.
  2. Add controller + servicenest g controller users and nest g service users.
  3. Register dependencies — Import TypeOrmModule.forFeature([User]) in the module.
  4. Validate inputs — Apply class-validator decorators on all DTOs.
  5. Check circular deps — Run madge --circular src/ to verify no cycles.

Module Structure Example

See implementation examples

Implementation Guidelines

  • Modules: Feature Modules (Auth) vs Core (Config/DB) vs Shared (Utils).
  • Controllers: Thin controllers, fat services. Verify DTOs here.
  • Services: Business logic only. Use Repository pattern for DB.
  • Config: Use @nestjs/config, never process.env directly.

Architecture Checklist (Mandatory)

  • [ ] Circular Deps: Are there any circular dependencies? (Use madge).
  • [ ] Env Validation: Is Joi/Zod schema used for env vars?
  • [ ] Exception Filters: Are global filters catching unhandled errors?
  • [ ] DTO Validation: Are class-validator decorators on all inputs?
  • [ ] Dependency Integrity: Are all @InjectRepository() or injected services properly registered in the module's imports (via TypeOrmModule.forFeature) or providers?

Anti-Patterns

  • No Global Scope: Avoid global pipes/guards unless truly universal.
  • No Direct Entity: Don't return ORM entities; return DTOs.
  • No Business in Controller: Move logic to Service.
  • No Manual Instantiation: Use DI, never new Service().

References