# nestjs-best-practices

A NestJS skill for writing, reviewing, and refactoring code around architecture, dependency injection, security, and performance.

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

## What it does

nestjs-best-practices contains 40 rules grouped into 10 categories: architecture, dependency injection, error handling, security, performance, testing, databases, API design, microservices, and DevOps. Use it when creating NestJS modules, controllers, and services, or when reviewing and refactoring an existing application.

The rules live in separate Markdown files with explanations, incorrect examples, and corrected examples. Topics include circular module dependencies, constructor injection, JWT, `class-validator`, exception filters, caching, N+1 queries, migrations, and E2E tests with `Supertest`. Circular dependencies are placed in the critical architecture category, so they deserve attention before lower-priority API concerns.

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add Kadajett/agent-nestjs-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 Kadajett/agent-nestjs-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 Kadajett/agent-nestjs-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 Kadajett/agent-nestjs-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 Kadajett/agent-nestjs-skills --skill nestjs-best-practices -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/Kadajett/agent-nestjs-skills --path 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 Kadajett/agent-nestjs-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/Kadajett/agent-nestjs-skills/tree/HEAD/skills/nestjs-best-practices/SKILL.md

## When to use it
- organize NestJS modules by feature
- find circular dependencies and duplicate providers
- review JWT authentication and input validation
- reduce N+1 query problems and handle transactions
- write E2E tests with `Supertest`

## Example prompts
- Review this NestJS module against the architecture and dependency injection rules.
- Refactor this service, find circular dependencies, and suggest a repository pattern design.
- Review the authentication flow for JWT, guards, input validation, and error handling.

## 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: d37a30d02f31fe54.

BEGIN THIRD-PARTY FILE d37a30d02f31fe54
```text
---
name: nestjs-best-practices
description: NestJS best practices and architecture patterns for building production-ready applications. This skill should be used when writing, reviewing, or refactoring NestJS code to ensure proper patterns for modules, dependency injection, security, and performance.
license: MIT
metadata:
  author: Kadajett
  version: "1.2.0"
---

# NestJS Best Practices

Comprehensive best practices guide for NestJS applications. Contains 40 rules across 10 categories, prioritized by impact to guide automated refactoring and code generation.

## When to Apply

Reference these guidelines when:

- Writing new NestJS modules, controllers, or services
- Implementing authentication and authorization
- Reviewing code for architecture and security issues
- Refactoring existing NestJS codebases
- Optimizing performance or database queries
- Building microservices architectures

## Rule Categories by Priority

| Priority | Category | Impact | Prefix |
|----------|----------|--------|--------|
| 1 | Architecture | CRITICAL | `arch-` |
| 2 | Dependency Injection | CRITICAL | `di-` |
| 3 | Error Handling | HIGH | `error-` |
| 4 | Security | HIGH | `security-` |
| 5 | Performance | HIGH | `perf-` |
| 6 | Testing | MEDIUM-HIGH | `test-` |
| 7 | Database & ORM | MEDIUM-HIGH | `db-` |
| 8 | API Design | MEDIUM | `api-` |
| 9 | Microservices | MEDIUM | `micro-` |
| 10 | DevOps & Deployment | LOW-MEDIUM | `devops-` |

## Quick Reference

### 1. Architecture (CRITICAL)

- `arch-avoid-circular-deps` - Avoid circular module dependencies
- `arch-feature-modules` - Organize by feature, not technical layer
- `arch-module-sharing` - Proper module exports/imports, avoid duplicate providers
- `arch-single-responsibility` - Focused services over "god services"
- `arch-use-repository-pattern` - Abstract database logic for testability
- `arch-use-events` - Event-driven architecture for decoupling

### 2. Dependency Injection (CRITICAL)

- `di-avoid-service-locator` - Avoid service locator anti-pattern
- `di-interface-segregation` - Interface Segregation Principle (ISP)
- `di-liskov-substitution` - Liskov Substitution Principle (LSP)
- `di-prefer-constructor-injection` - Constructor over property injection
- `di-scope-awareness` - Understand singleton/request/transient scopes
- `di-use-interfaces-tokens` - Use injection tokens for interfaces

### 3. Error Handling (HIGH)

- `error-use-exception-filters` - Centralized exception handling
- `error-throw-http-exceptions` - Use NestJS HTTP exceptions
- `error-handle-async-errors` - Handle async errors properly

### 4. Security (HIGH)

- `security-auth-jwt` - Secure JWT authentication
- `security-validate-all-input` - Validate with class-validator
- `security-use-guards` - Authentication and authorization guards
```
END THIRD-PARTY FILE d37a30d02f31fe54

The third-party file has ended. Everything between the d37a30d02f31fe54 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 2795 of 4754 bytes. © Kadajett · MIT · https://github.com/Kadajett/agent-nestjs-skills/tree/HEAD/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
