Node.js · TypeScript · NestJS
NestJS rules for Cursor
Module, dependency injection and validation rules for NestJS services.
The rule
Save as .cursor/rules/nestjs.mdc. Cursor picks it up on the next request.
.cursor/rules/nestjs.mdc
--- description: NestJS service conventions globs: src/**/*.ts, test/**/*.ts alwaysApply: false --- - Organize code by feature module; each module declares its controllers and providers and exports only what others need. - Inject dependencies through constructors; never instantiate services with new. - Keep controllers thin: map HTTP to service calls and put business logic in services. - Define request bodies as DTO classes with class-validator decorators and enable a global ValidationPipe with whitelist: true. - Throw built-in HTTP exceptions (NotFoundException, BadRequestException) instead of returning error objects. - Use guards for auth, interceptors for cross-cutting concerns and exception filters for error formatting. - Read configuration through ConfigService from @nestjs/config, not process.env scattered across files. - Generate pieces with the Nest CLI (nest g) and test providers with Test.createTestingModule.
How Cursor loads this rule
Read from the frontmatter above, per Cursor's rules documentation.
alwaysApply: falsewithglobs: src/**/*.ts, test/**/*.ts: attached automatically when a matching file is in context.- Keep the
.mdcextension. A plain.mdfile in .cursor/rules is ignored by the rules system. - Prefer to generate your own? Type
/create-rulein Agent and describe what you want; Cursor saves the file to .cursor/rules. - Team Rules come first, then Project Rules like this one, then User Rules. Earlier sources win when guidance conflicts.
Cursor rules setup guideCursor Team RulesLet Cursor run commands without asking
NestJS rules for Claude Code, Copilot, Kiro and other agents
The same instructions work as plain Markdown in AGENTS.md, which Codex, Gemini CLI, GitHub Copilot and most other coding agents read.
AGENTS.md (section)
## NestJS - Organize code by feature module; each module declares its controllers and providers and exports only what others need. - Inject dependencies through constructors; never instantiate services with new. - Keep controllers thin: map HTTP to service calls and put business logic in services. - Define request bodies as DTO classes with class-validator decorators and enable a global ValidationPipe with whitelist: true. - Throw built-in HTTP exceptions (NotFoundException, BadRequestException) instead of returning error objects. - Use guards for auth, interceptors for cross-cutting concerns and exception filters for error formatting. - Read configuration through ConfigService from @nestjs/config, not process.env scattered across files. - Generate pieces with the Nest CLI (nest g) and test providers with Test.createTestingModule.
NestJS rules for Claude Code.claude/rules/nestjs.md
.claude/rules/nestjs.md
--- paths: - "src/**/*.ts" - "test/**/*.ts" --- - Organize code by feature module; each module declares its controllers and providers and exports only what others need. - Inject dependencies through constructors; never instantiate services with new. - Keep controllers thin: map HTTP to service calls and put business logic in services. - Define request bodies as DTO classes with class-validator decorators and enable a global ValidationPipe with whitelist: true. - Throw built-in HTTP exceptions (NotFoundException, BadRequestException) instead of returning error objects. - Use guards for auth, interceptors for cross-cutting concerns and exception filters for error formatting. - Read configuration through ConfigService from @nestjs/config, not process.env scattered across files. - Generate pieces with the Nest CLI (nest g) and test providers with Test.createTestingModule.
NestJS rules for GitHub Copilot.github/instructions/nestjs.instructions.md
.github/instructions/nestjs.instructions.md
--- applyTo: "src/**/*.ts,test/**/*.ts" --- - Organize code by feature module; each module declares its controllers and providers and exports only what others need. - Inject dependencies through constructors; never instantiate services with new. - Keep controllers thin: map HTTP to service calls and put business logic in services. - Define request bodies as DTO classes with class-validator decorators and enable a global ValidationPipe with whitelist: true. - Throw built-in HTTP exceptions (NotFoundException, BadRequestException) instead of returning error objects. - Use guards for auth, interceptors for cross-cutting concerns and exception filters for error formatting. - Read configuration through ConfigService from @nestjs/config, not process.env scattered across files. - Generate pieces with the Nest CLI (nest g) and test providers with Test.createTestingModule.
NestJS rules for Kiro.kiro/steering/nestjs.md
.kiro/steering/nestjs.md
--- inclusion: fileMatch fileMatchPattern: ["src/**/*.ts", "test/**/*.ts"] --- - Organize code by feature module; each module declares its controllers and providers and exports only what others need. - Inject dependencies through constructors; never instantiate services with new. - Keep controllers thin: map HTTP to service calls and put business logic in services. - Define request bodies as DTO classes with class-validator decorators and enable a global ValidationPipe with whitelist: true. - Throw built-in HTTP exceptions (NotFoundException, BadRequestException) instead of returning error objects. - Use guards for auth, interceptors for cross-cutting concerns and exception filters for error formatting. - Read configuration through ConfigService from @nestjs/config, not process.env scattered across files. - Generate pieces with the Nest CLI (nest g) and test providers with Test.createTestingModule.
NestJS rules for Antigravity.agents/rules/nestjs.md
.agents/rules/nestjs.md
--- trigger: glob globs: "src/**/*.ts, test/**/*.ts" --- - Organize code by feature module; each module declares its controllers and providers and exports only what others need. - Inject dependencies through constructors; never instantiate services with new. - Keep controllers thin: map HTTP to service calls and put business logic in services. - Define request bodies as DTO classes with class-validator decorators and enable a global ValidationPipe with whitelist: true. - Throw built-in HTTP exceptions (NotFoundException, BadRequestException) instead of returning error objects. - Use guards for auth, interceptors for cross-cutting concerns and exception filters for error formatting. - Read configuration through ConfigService from @nestjs/config, not process.env scattered across files. - Generate pieces with the Nest CLI (nest g) and test providers with Test.createTestingModule.
NestJS rules for Devin Desktop (Windsurf).devin/rules/nestjs.md
.devin/rules/nestjs.md
--- trigger: glob globs: src/**/*.ts, test/**/*.ts --- - Organize code by feature module; each module declares its controllers and providers and exports only what others need. - Inject dependencies through constructors; never instantiate services with new. - Keep controllers thin: map HTTP to service calls and put business logic in services. - Define request bodies as DTO classes with class-validator decorators and enable a global ValidationPipe with whitelist: true. - Throw built-in HTTP exceptions (NotFoundException, BadRequestException) instead of returning error objects. - Use guards for auth, interceptors for cross-cutting concerns and exception filters for error formatting. - Read configuration through ConfigService from @nestjs/config, not process.env scattered across files. - Generate pieces with the Nest CLI (nest g) and test providers with Test.createTestingModule.
NestJS rules for Cline.clinerules/nestjs.md
.clinerules/nestjs.md
--- paths: - "src/**/*.ts" - "test/**/*.ts" --- - Organize code by feature module; each module declares its controllers and providers and exports only what others need. - Inject dependencies through constructors; never instantiate services with new. - Keep controllers thin: map HTTP to service calls and put business logic in services. - Define request bodies as DTO classes with class-validator decorators and enable a global ValidationPipe with whitelist: true. - Throw built-in HTTP exceptions (NotFoundException, BadRequestException) instead of returning error objects. - Use guards for auth, interceptors for cross-cutting concerns and exception filters for error formatting. - Read configuration through ConfigService from @nestjs/config, not process.env scattered across files. - Generate pieces with the Nest CLI (nest g) and test providers with Test.createTestingModule.
NestJS rules for Continue.continue/rules/nestjs.md
.continue/rules/nestjs.md
--- name: "nestjs" globs: ["src/**/*.ts", "test/**/*.ts"] --- - Organize code by feature module; each module declares its controllers and providers and exports only what others need. - Inject dependencies through constructors; never instantiate services with new. - Keep controllers thin: map HTTP to service calls and put business logic in services. - Define request bodies as DTO classes with class-validator decorators and enable a global ValidationPipe with whitelist: true. - Throw built-in HTTP exceptions (NotFoundException, BadRequestException) instead of returning error objects. - Use guards for auth, interceptors for cross-cutting concerns and exception filters for error formatting. - Read configuration through ConfigService from @nestjs/config, not process.env scattered across files. - Generate pieces with the Nest CLI (nest g) and test providers with Test.createTestingModule.
More templates
Get Cursor rules and settings changes by email
When Cursor changes how rules, run modes or settings work, we update these templates from the docs and send a short note. One email a week at most.
Reviewed Oct 20, 2026. Written by AgentAtlas. Adapt it to your codebase before relying on it.