/engineering-paved-path:nestjs-best-practicesfrom engineering-paved-path
NestJS application patterns for TypeScript backends — modules and providers, dependency injection and injection tokens, the composition root, thin controllers, guards/interceptors/pipes/filters and their execution order, validation at the edge, ConfigModule and typed configuration, lifecycle hooks, exception filters, and testing with Test.createTestingModule. Use when building, wiring, reviewing or debugging a NestJS application: adding a module or a provider, resolving 'Nest can't resolve dependencies of X', choosing an injection scope, registering a global guard, shaping an error response, writing a testing module, or upgrading a NestJS major. Trigger terms: NestJS, Nest, @nestjs/common, @nestjs/core, app.module.ts, @Module, @Injectable, @Controller, provider, injection token, forwardRef, ValidationPipe, exception filter, APP_GUARD, Test.createTestingModule, nest build, nest start. NestJS runtime and wiring ONLY — NOT which layer a file belongs to (use engineering-paved-path:onion-architecture), NOT TypeORM query, migration or entity mechanics (use engineering-paved-path:typeorm-patterns), NOT PostgreSQL schema design (use engineering-paved-path:postgresql-table-design), NOT Zod schema mechanics (use engineering-paved-path:zod).
Trending skills
7-day visitors to each skill page
Ships in engineering-paved-path. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
How a NestJS application is wired, what breaks it, and why. Runtime and wiring only — not layering (engineering-paved-path:onion-architecture), not ORM mechanics (engineering-paved-path:typeorm-patterns), not schema design (engineering-paved-path:postgresql-table-design), not Zod (engineering-paved-path:zod).
The HTTP application. Modules, DI, the request pipeline, validation,
configuration, lifecycle and testing are covered. Nest's other surfaces are
not, and they have their own seams: microservice transports
(@nestjs/microservices — message patterns, custom transporters,
RpcException instead of HttpException), GraphQL (@nestjs/graphql —
resolvers, the schema-first/code-first split, GqlExecutionContext, which
makes an HTTP-shaped guard or filter silently wrong), WebSockets
(@nestjs/websockets) and queues. The DI, module and testing rules apply
to all of them; the controller, validation-pipe and exception-filter rules
assume an HTTP context. If the work is in one of those surfaces, take the
wiring rules from here and the surface's own mechanics from its documentation.
This skill assumes nothing about your repository beyond what you tell it. When applying it, first locate (or ask for): the application root, the composition root (the module NestFactory.create() is given), the feature-module directory, the bootstrap file, and the test commands and their filename conventions. If the project documents its own conventions — an AGENTS.md, CLAUDE.md, ARCHITECTURE.md, or a repository skill — those take precedence over anything here.
Only @nestjs/common, @nestjs/core, a platform adapter and reflect-metadata are always present. Everything else below is a separate package a project either has or does not, and this skill never assumes it:
| Concern | Always available | Common packages — use whichever the project already has |
|---|---|---|
| Validation at the edge | the pipe seam (useGlobalPipes, @UsePipes) | class-validator + class-transformer with ValidationPipe; or a schema library behind a small custom pipe |
| Configuration | providers, factories, process.env | @nestjs/config |
| Persistence | nothing | @nestjs/typeorm, @nestjs/mongoose, a hand-written provider |
| Rate limiting | the guard seam | @nestjs/throttler |
| Caching | nothing | @nestjs/cache-manager |
| Tests | nothing | @nestjs/testing plus the project's runner (Jest, Vitest, node:test) |
| HTTP platform | the adapter seam | @nestjs/platform-express (the default) or @nestjs/platform-fastify |
One caveat this table cannot hide: where a rule touches the raw request or response object — the passthrough-response and streaming sections of rules/controllers.md, and route-path syntax — the behaviour is the adapter's, not Nest's. Those passages assume @nestjs/platform-express. On the Fastify adapter the seams are identical but the objects underneath are not; verify against Fastify's API before applying them.
Write against the seam, not the package. Where a rule below shows a specific library, it is one instantiation — the surrounding principle holds whatever the project uses, and introducing a package the project does not have is a dependency decision for its owners, never a step in following this skill.
Establish the project's major before applying anything on this page. Read
it from the lockfile — @nestjs/core — not from this table. Most of what
follows is stable across recent majors, but the rows marked since are not,
and applying a v12 fact to a v10 codebase produces confidently wrong advice.
When the project's major is older than the baseline, the relevant deltas are
in rules/versions-and-upgrades.md, which
reads in both directions.
| Fact | Value | Applies to |
|---|---|---|
| Latest major | NestJS 12, released 2026-08-27 (release notes, migration guide) | — |
| Node.js | v20.19+ or v22.12+ to run; v21/v23/v25 unsupported. CLI generators need v22.22.3+/v24.15+/v26+ | v12; older majors allow older Node |
| Module format | Core packages ship as ESM. Migrating your app to ESM is optional — CJS apps keep working through Node's require(esm) | since v12; v11 and earlier are CJS |
| Decorators | Legacy TS decorators: experimentalDecorators + emitDecoratorMetadata, even in the ESM project template. TC39/Stage-3 decorators are not supported | all majors |
| Default HTTP adapter | Express 5 | since v11. v10 and earlier ship Express 4 — the route-syntax rules in rules/controllers.md differ |
| TypeScript | typescript-starter pins ^6.x. TypeScript 7 currently breaks nest build/nest start — it dropped the programmatic Compiler API (nest-cli#3479, open) | any major using the Nest CLI |
| Config validation | Standard Schema by default (Zod/Valibot/ArkType); Joi needs Joi 18+ and moves its settings under validationOptions.libraryOptions | since v12. Before v12 it is Joi-shaped, flat validationOptions, any Joi version |
class-transformer | Last tagged release 0.5.1 (2021). Treat it as frozen, not evolving | all majors |
Everything not marked since — modules and the composition root, DI and the
import type trap, controllers, validation semantics, the enhancer pipeline
and its order, exception filters, lifecycle hooks, testing — holds across v10,
v11 and v12 alike.
See rules/versions-and-upgrades.md for the full v12 breaking-change list and the upgrade traps.
// main.ts
import { NestFactory } from '@nestjs/core';
import { ValidationPipe } from '@nestjs/common';
import type { INestApplication } from '@nestjs/common';
import { AppModule } from './app.module';
// Exported so tests can apply the SAME hardening — see rules/testing.md.
export function configurePlatform(app: INestApplication): void {
app.useGlobalPipes(new ValidationPipe({ whitelist: true, transform: true }));
app.enableShutdownHooks();
}
async function bootstrap() {
const app = await NestFactory.create(AppModule);
configurePlatform(app);
await app.listen(process.env.PORT ?? 3000);
}
// Guard the side effect so importing this file from a test does not start a server.
if (require.main === module) void bootstrap();
modules.md → dependency-injection.mddependency-injection.md (§ the import type trap first — it is the most common cause that compiles clean)controllers.md → validation.md → exceptions.mdenhancers.md → exceptions.mdconfiguration.mdtesting.mdversions-and-upgrades.mdpersistence.md, then engineering-paved-path:typeorm-patternstsconfig requirements, reflect-metadata, decorator metadata, ESM vs CJS@Global(), circular importsimport type trap, injection scopes, optional dependencies@Res({ passthrough: true }), streamingclass-validator DTOs, ValidationPipe options, transformation trapsReflectorHttpException hierarchy, custom errors, exception filters, error envelopesConfigModule, validation, typed access, fail-closed factoriesTypeOrmModule wiring, repository injection, the module boundaryTest.createTestingModule, overrides, hermetic vs booted tests, cross-suite leakagemodules.md.design:paramtypes, which the compiler writes. Anything that erases that emission (import type, an interface as a parameter type, a missing decorator) breaks DI at boot and only at boot — see dependency-injection.md.class-validator decorators plus a global ValidationPipe. A service must be callable from a unit test with a plain object.configuration.md).testing.md.README.md (opens in a new tab)rules/configuration.md (opens in a new tab)rules/controllers.md (opens in a new tab)rules/dependency-injection.md (opens in a new tab)rules/enhancers.md (opens in a new tab)rules/exceptions.md (opens in a new tab)rules/lifecycle.md (opens in a new tab)rules/modules.md (opens in a new tab)rules/persistence.md (opens in a new tab)rules/testing.md (opens in a new tab)rules/typescript-setup.md (opens in a new tab)rules/validation.md (opens in a new tab)rules/versions-and-upgrades.md (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
12 skills in this plugin
/frontend-architectureFolder structure and code organization for React + Next.js (App Router) projects. Use this skill whenever the user asks where files should live (components, hooks, utils, helpers, lib, services, constants, types), how to break a component into smaller pieces, how to organize a feature folder, where to put business logic, when to use a barrel index, or how to lay out app/ in Next.js (route groups, private folders). Trigger on phrases like 'folder structure', 'project structure', 'where should I put', 'how to organize', 'where do constants go', 'utils vs helpers', 'app router structure'. Covers organization decisions only — NOT React hook rules or render patterns (use engineering-paved-path:react-best-practices) and NOT Next-specific runtime behavior (use engineering-paved-path:next-best-practices)./mermaid-diagramCreate Mermaid diagrams in markdown. Use when the user wants to visualize workflows, architectures, API flows, data models, state machines, or system designs. Covers flowcharts, sequence diagrams, class diagrams, ER diagrams, state diagrams, and more./next-best-practicesNext.js best practices - file conventions, RSC boundaries, data patterns, async APIs, metadata, error handling, route handlers, image/font optimization, bundling/onion-architectureLayering and dependency-rule conventions for TypeScript backends, with an optional pure-engine package. Use whenever editing or adding backend code; whenever adding a new module / use case / repository / adapter / outbound port / shared contract; whenever the question is *where should this live* on the backend (HTTP edge vs service vs repository vs adapter vs platform vs shared); whenever reviewing a backend PR for layer violations (ORM in a service, SDK import in a controller, `process.env` in a pure engine package, services importing other modules' services, SDK imports leaking past the adapter boundary). Trigger phrases: 'new endpoint', 'new module', 'where should this go', 'add a repository', 'add an adapter', 'wire up a port', 'consume X from a service', 'the engine needs to read', 'service is doing too much'. Layering and dependency placement ONLY — NOT NestJS runtime and wiring mechanics (use engineering-paved-path:nestjs-best-practices), NOT TypeORM query and migration mechanics (use engineering-paved-path:typeorm-patterns), NOT Zod schema mechanics (use engineering-paved-path:zod). For the client side use engineering-paved-path:frontend-architecture./postgresql-table-designUse this skill when designing or reviewing a PostgreSQL-specific schema. Covers best-practices, data types, indexing, constraints, performance patterns, and advanced features/react-best-practicesModern React best practices and anti-pattern catalog (2025-26). Use when writing, reviewing, or refactoring React components, hooks, and state management. Covers component design, state patterns, hooks misuse, performance, data fetching, and code organization.npx claudepluginhub yamchinsky/dev-digest-ai-marketplace --plugin engineering-paved-path