Home › NestJS › NestJS CLAUDE.md

NestJS CLAUDE.md

CLAUDE.md for NestJS 11 APIs in TypeScript: modules, DTO validation, providers, and e2e tests.

Claude Code (CLAUDE.md)NestJS

How to use

Save this as CLAUDE.md in your repository root, commit it, and your agent will pick it up automatically. Edit the commands to match your project.

CLAUDE.mdDownload  
# CLAUDE.md: NestJS 11 API

## Commands
- `npm run start:dev` · `npm run test` · `npm run test:e2e` · `npm run lint` · `npm run build`

## Structure
- One module per feature: `src/<feature>/{<feature>.module.ts, .controller.ts, .service.ts, dto/, entities/}`. Generate with `npx nest g resource <feature>`.
- Controllers are thin: parse input, call a service, return a DTO. Business logic lives in services.
- Validate every input with `class-validator` DTOs and a global `ValidationPipe({ whitelist: true, forbidNonWhitelisted: true, transform: true })`.
- Config through `@nestjs/config` with a validated schema; inject `ConfigService`, never read `process.env` in services.
- Throw Nest HTTP exceptions (`NotFoundException`, ...) from services only when the service is HTTP-specific; otherwise throw domain errors and map them in an exception filter.
- Auth with guards (`@UseGuards`) and custom decorators for the current user. Don't check auth inside handlers.
- Document endpoints with `@nestjs/swagger` decorators on DTOs.
- Database access goes through the repository/ORM the project already uses (Prisma, TypeORM or Drizzle); no raw SQL strings with interpolation.

## Testing
- Unit test services with `Test.createTestingModule` and mocked providers.
- E2E tests with `supertest` against the app built from `AppModule`.

## Don't
- Don't create circular module imports; if you need `forwardRef`, restructure instead.

## Done when
Lint, unit tests, e2e tests and build all pass.

Related rules

AWS CDK (TypeScript) CLAUDE.md

CLAUDE.md for AWS CDK v2 apps in TypeScript: constructs, least-privilege grants, snapshot tests, and safe deploys.

Claude Code (CLAUDE.md)AWS CDK

Bun runtime CLAUDE.md

CLAUDE.md for TypeScript projects on Bun 1.2+: bun test, Bun.serve, built-in SQLite/Postgres, and bundling.

Claude Code (CLAUDE.md)Bun

Claude Agent SDK CLAUDE.md

CLAUDE.md for building agents with the Claude Agent SDK (Python/TypeScript): options, tools, permissions, and hooks.

Claude Code (CLAUDE.md)LLM apps & agents

Code reviewer subagent (Claude Code)

A Claude Code subagent definition that reviews the current diff for bugs, security, and tests, reporting by severity.

Claude Code (CLAUDE.md)Agent workflows

Get new rules weekly

One email a week: fresh rule files, agent tips, and what's changing in Cursor, Claude Code and Copilot. Free, unsubscribe anytime.

Opens the Rulestack Newsletter on beehiiv in a new tab. Or subscribe directly on beehiiv.