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.

More: all NestJS rules · all Claude Code (CLAUDE.md) rules

Related rules

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

Django CLAUDE.md

CLAUDE.md for Django 5 projects with DRF, pytest-django and PostgreSQL.

Claude Code (CLAUDE.md)Django

Elixir Phoenix CLAUDE.md

CLAUDE.md for Phoenix 1.8 + LiveView 1.x apps in Elixir: contexts, Ecto changesets, and ExUnit tests.

Claude Code (CLAUDE.md)Elixir / Phoenix

Go backend CLAUDE.md

CLAUDE.md for idiomatic Go HTTP services using the standard library, sqlc and table-driven tests.

Claude Code (CLAUDE.md)Go

Rust CLI CLAUDE.md

CLAUDE.md for Rust command-line tools built with clap, anyhow and thiserror.

Claude Code (CLAUDE.md)Rust

REST API design AGENTS.md

AGENTS.md for designing consistent HTTP/JSON APIs: resource naming, status codes, errors, pagination, and versioning.

AGENTS.mdAPI design

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.