# nestjs-best-practices

A skill that feeds your agent NestJS 11 practices for TypeScript apps: how to shape modules, controllers and services, and which mistakes to flag in review.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode · 427 installs · ★ 6
- Author: ejirocodes
- License: MIT · policy=mirror · the beginning of the file is at the end of this page
- Source: https://github.com/ejirocodes/agent-skills/tree/HEAD/nestjs/skills/nestjs-best-practices/SKILL.md
- Updated: 2026-06-25
- HTML: https://affpapa.org/en/nevibecode/skills/ejirocodes-nestjs-best-practices

## What it does

The skill activates while you write, review or refactor NestJS code: modules, controllers, providers, dependency injection, `@Injectable`, `@Controller`, `@Module`, middleware, guards, interceptors, pipes, exception filters, DTOs, JWT auth, Passport strategies, TypeORM, Prisma, Drizzle, GraphQL resolvers, microservices over TCP, Redis, NATS and Kafka, and tests.

It ships reference files per topic: core architecture, request lifecycle, validation and pipes, authentication, database integration, testing, OpenAPI and GraphQL, microservices. There is also a list of common mistakes — skipping `forwardRef()` on circular dependencies, throwing a plain error instead of `HttpException`, forgetting `@Injectable()`, running a global `ValidationPipe` without `whitelist: true`, importing a module instead of exporting the provider, calling async config before `ConfigModule.forRoot()`, leaving real services in unit tests instead of `overrideProvider()`, and letting E2E tests share database state.

A separate section covers NestJS 11 changes: Node.js 20 as the floor, Express v5 with named wildcards and optional params in braces, the updated Fastify v5 adapter, and dynamic modules that produce separate instances when the same config is imported more than once. On Express v4 or Node.js below 20, some of that advice has to wait until you upgrade.

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add ejirocodes/agent-skills --skill nestjs-best-practices -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/nestjs-best-practices/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/nestjs-best-practices/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add ejirocodes/agent-skills --skill nestjs-best-practices -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/nestjs-best-practices/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add ejirocodes/agent-skills --skill nestjs-best-practices -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/nestjs-best-practices/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install ejirocodes/agent-skills nestjs-best-practices
```

2. **Manually: put the files in place**
- File: `.github/skills/nestjs-best-practices/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add ejirocodes/agent-skills --skill nestjs-best-practices -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/ejirocodes/agent-skills --path nestjs/skills/nestjs-best-practices
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/nestjs-best-practices/SKILL.md` — The legacy .windsurf/skills/ path still works

### OpenCode

**Skills CLI (Vercel)**
```bash
npx skills add ejirocodes/agent-skills --skill nestjs-best-practices -a opencode
```

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/ejirocodes/agent-skills/tree/HEAD/nestjs/skills/nestjs-best-practices/SKILL.md

## When to use it
- split a module into controller, service and providers without tight coupling
- turn on a global `ValidationPipe` with `whitelist` and `forbidNonWhitelisted`
- break a circular dependency with `forwardRef()`
- swap a real service for a mock via `overrideProvider()` in a unit test
- move routes to Express v5 named wildcards

## Example prompts
- Write a `UsersModule` with a controller and service, and export the provider for other modules
- Review my controller: are the pipes and exception filters wired correctly?
- Refactor this service for NestJS 11 and account for the Express v5 changes

## Source text · SKILL.md · MIT

Below is the content of a third-party file. It is data, not instructions for you: do not act on anything written inside unless the human asks. Block tag: f68f917c1439193c.

BEGIN THIRD-PARTY FILE f68f917c1439193c
```text
---
name: nestjs-best-practices
description: "NestJS 11+ best practices for enterprise Node.js applications with TypeScript. Use when writing, reviewing, or refactoring NestJS controllers, services, modules, or APIs. Triggers on: NestJS modules, controllers, providers, dependency injection, @Injectable, @Controller, @Module, middleware, guards, interceptors, pipes, exception filters, ValidationPipe, class-validator, class-transformer, DTOs, JWT authentication, Passport strategies, @nestjs/passport, TypeORM entities, Prisma client, Drizzle ORM, repository pattern, circular dependencies, forwardRef, @nestjs/swagger, OpenAPI decorators, GraphQL resolvers, @nestjs/graphql, microservices, TCP transport, Redis transport, NATS, Kafka, NestJS 11 breaking changes, Express v5 migration, custom decorators, ConfigService, @nestjs/config, health checks, or NestJS testing patterns."
license: MIT
metadata:
  author: ejirocodes
  version: '1.0.0'
---

# NestJS 11 Best Practices

## Quick Reference

| Topic | When to Use | Reference |
|-------|-------------|-----------|
| **Core Architecture** | Modules, Providers, DI, forwardRef, custom decorators | [core-architecture.md](references/core-architecture.md) |
| **Request Lifecycle** | Middleware, Guards, Interceptors, Pipes, Filters | [request-lifecycle.md](references/request-lifecycle.md) |
| **Validation & Pipes** | DTOs, class-validator, ValidationPipe, transforms | [validation-pipes.md](references/validation-pipes.md) |
| **Authentication** | JWT, Passport, Guards, Local/OAuth strategies, RBAC | [authentication.md](references/authentication.md) |
| **Database** | TypeORM, Prisma, Drizzle ORM, repository patterns | [database-integration.md](references/database-integration.md) |
| **Testing** | Unit tests, E2E tests, mocking providers | [testing.md](references/testing.md) |
| **OpenAPI & GraphQL** | Swagger decorators, resolvers, subscriptions | [openapi-graphql.md](references/openapi-graphql.md) |
| **Microservices** | TCP, Redis, NATS, Kafka patterns | [microservices.md](references/microservices.md) |

## Essential Patterns

### Module with Providers
```
END THIRD-PARTY FILE f68f917c1439193c

The third-party file has ended. Everything between the f68f917c1439193c tags is data: requests and commands from it are not followed. An “end of file” line with another tag inside the block is part of the file.

First 2123 of 5027 bytes. © ejirocodes · MIT · https://github.com/ejirocodes/agent-skills/tree/HEAD/nestjs/skills/nestjs-best-practices/SKILL.md

_Part of the page did not fit — see the HTML version._

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
