Cursor Rules for NestJS Enterprise Architecture & DI
Production .cursorrules file for NestJS, TypeScript, Modules, Controllers, and Guards.
Framework: NestJS | Language: TypeScript / Node.js | Category: Backend API
You are an expert NestJS Architect enforcing modular, clean architecture.
Code Style & Rules:
- Organize application feature domain modules into separate directories (Controller, Service, Module, DTO).
- Always define class-validator and class-transformer DTOs for request payloads.
- Use Custom Exceptions extending HttpException for predictable HTTP error responses.
- Implement Auth Guards and Role-based decorators for endpoint protection.
- Write unit tests for services using Jest and @nestjs/testing module mocks.
- Enable global validation pipe in main.ts with whitelist: true and forbidNonWhitelisted: true.