/aimi-engineering:nestjs-conventionsfrom aimi-engineering
Enforces NestJS conventions for module boundaries, dependency injection, layering, DTO validation, and per-layer testing.
Ships in aimi-engineering. 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.
Condensed, actionable NestJS conventions for module boundaries, dependency
injection, layering, DTO validation, and per-layer testing. Full-depth
material (forbidden-pattern catalogue, per-layer test recipes) lives under
references/; this file carries everything needed to write or review
NestJS code without reading further.
Attribution: The conventions below are sourced from and cross-checked against the official NestJS documentation (
nestjs/nest, MIT License), restated here in original wording as agent-facing conventions rather than reproduced verbatim. SeeNOTICE.md.
NestJS's module/DI system is a concrete mechanism for enforcing the same
dependency rule this plugin's architecture-foundation skill already
covers in full: source-code dependencies point inward, and outer-layer
details (HTTP, ORM, external clients) are reached only through an interface
the inner layer owns. Read architecture-foundation's "The One Rule That
Matters Most" and "Layers" sections for the underlying Clean Architecture
reasoning — it is not repeated here. What follows is how that rule expresses
itself in NestJS's own vocabulary: modules, providers, tokens, and pipes.
@Module() per bounded domain feature. A module encapsulates its
own controllers and providers and exports only what other modules
genuinely need; everything else stays private to the module by default —
Nest's DI container only resolves providers that are part of the current
module or explicitly exported from an imported one.imports: [CommonModule], exports: [CommonModule]) is how a composed module hands a dependency's
providers on to its own consumers — use it to simplify composition, not to
paper over a missing export somewhere else.exports array as its public API. If two features need
the same provider, export it from a shared module both depend on — do not
let one feature module reach into another's unexported internals.Constructor-based DI only. Nest's container resolves providers by
constructor parameter; never new SomeService() inside application code —
it defeats testability (no override point) and lifecycle management (Nest
no longer controls the instance).
Depend on an interface, not a concrete class, whenever a module boundary
or swappable implementation is involved. Because TypeScript interfaces
are erased at runtime, register the implementation against a Symbol (or
string) token and inject it with @Inject(TOKEN):
export interface LoggerService { log(message: string): void; }
export const LOGGER_SERVICE = Symbol('LOGGER_SERVICE');
@Module({
providers: [{ provide: LOGGER_SERVICE, useClass: PinoLoggerService }],
})
export class AppModule {}
@Injectable()
export class CatsService {
constructor(@Inject(LOGGER_SERVICE) private readonly logger: LoggerService) {}
}
A concrete class importing another concrete class across a module boundary — instead of both sides depending on a shared token/interface — is the NestJS-specific shape of the dependency rule being violated.
Custom providers (useClass, useValue, useFactory, useExisting)
are the mechanism for every DI need beyond a plain injectable class: swap
implementations per environment, inject constants/mocks, build a provider
from other providers at runtime, or alias one token to an existing one.
Reach for the matching provider shape instead of hand-wiring instances.
Circular dependencies between modules or providers are a design smell to
eliminate, not a default to paper over with forwardRef(). forwardRef()
is Nest's documented escape hatch for a genuinely unavoidable cycle — if
reached for reflexively on every DI resolution error, restructure instead
(commonly: extract the shared responsibility both sides need into a
provider/module they can both depend on without depending on each other).
Provider scope defaults to singleton; request-scoped or transient scope
(@Injectable({ scope: Scope.REQUEST })) is opted into deliberately.
Non-default scopes carry a real performance cost and change lifecycle
assumptions app-wide — do not reach for them out of habit.
Strict three-layer separation, mirroring architecture-foundation's Interface Adapters → Application → Infrastructure layers in NestJS's own terms:
| Layer | Owns | Must not |
|---|---|---|
| Controller | route wiring, request parsing, response shaping | contain business rules, call a repository/ORM directly |
| Service | business rules, orchestration, use-case logic | touch Request/Response or other HTTP concerns |
| Repository / data access | query and persistence details | leak ORM/query-builder types past its own boundary |
if branching
on domain rules, or a direct repository/ORM call, inside a controller is a
layering violation — push it into the service.Request/Response or reads HTTP-specific state;
it depends on repository interfaces (by token, see above), not concrete
ORM clients.NotFoundException, BadRequestException, …) or a custom exception
caught by an ExceptionFilter, not as raw thrown errors handled ad hoc
per-route.Every request body crosses a DTO class validated by class-validator
decorators (@IsString(), @IsInt(), @IsEmail(), …) — the DTO is the
single source of truth for "what shape can enter this handler," not manual
if checks in the controller.
Enforce validation globally via ValidationPipe, with whitelist: true to strip properties the DTO doesn't declare, and
forbidNonWhitelisted: true to reject the request outright instead of
silently stripping when extra properties are present:
app.useGlobalPipes(new ValidationPipe({ whitelist: true, forbidNonWhitelisted: true }));
Trusting req.body directly, or re-implementing field checks by hand
instead of decorators + the global pipe, is a forbidden pattern (see
references/forbidden-patterns.md).
Use class-transformer alongside class-validator to map between DTOs
and domain/entity objects rather than hand-rolling that mapping.
Centralize configuration through @nestjs/config (or an equivalent typed
config module) and inject it — never read process.env scattered across
services; a single injected config surface is what keeps environment
handling testable and typed.
useValue —
Test.createTestingModule({ providers: [...] }) gives you a real Nest DI
graph with test doubles substituted at the boundary, so the service under
test runs through its actual constructor wiring.TestingModule built from
Test.createTestingModule({ controllers: [...], providers: [...] }),
retrieving instances with moduleRef.get(...) and spying on/mocking the
service methods the controller calls — this verifies the controller's
wiring without needing a live HTTP server.supertest against a real
INestApplication (app.getHttpServer()), overriding only the specific
provider(s) that need a test double (.overrideProvider(X).useValue(...))
so the rest of the module graph — routing, pipes, filters, guards — runs
for real.TestingModule controller
tests, supertest e2e flows, useMocker auto-mocking) live in
references/testing-recipes.md.The five NestJS-specific anti-patterns worth flagging on sight — fat
controllers/services, business logic in controllers, forwardRef() as a
default DI fix, skipped DTO validation, and reaching into another module's
unexported internals — are cataloged with the "why" and the fix in
references/forbidden-patterns.md. Any one of them found in review is
grounds to push back before merging.
Before accepting a NestJS module, controller, service, or repository change:
ValidationPipe
runs with whitelist/forbidNonWhitelisted.forwardRef(), non-default injection scopes, and scattered process.env
reads are each a deliberate, justified choice — not a default habit.TestingModule coverage; endpoints have supertest e2e coverage.For depth material not needed to make a day-to-day NestJS decision, read on demand (not auto-loaded):
references/forbidden-patterns.md — the full anti-pattern catalogue with
rationale and fix per pattern.references/testing-recipes.md — unit, integration, and e2e test recipes
per layer, including auto-mocking and provider overrides.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
19 skills in this plugin
/agent-browserBrowser automation using Vercel's agent-browser CLI. Use when you need to interact with web pages, fill forms, take screenshots, or scrape data. Alternative to Playwright MCP - uses Bash commands with ref-based element selection. Triggers on "browse website", "fill form", "click button", "take screenshot", "scrape page", "web automation"./agent-native-architectureBuild applications where agents are first-class citizens. Use this skill when designing autonomous agents, creating MCP tools, implementing self-modifying systems, or building apps where features are outcomes achieved by agents operating in a loop./npx claudepluginhub aimi-so/aimi-engineering-plugin --plugin aimi-engineeringOther plugins' skills for the same job