NestJS architecture, dependency injection, validation, security, errors, testing, persistence, APIs, microservices, and deployment patterns with prioritized rule tiers and companion rule files.
99
100%
Does it follow best practices?
Impact
97%
1.12xAverage score across 2 eval scenarios
Advisory
Suggest reviewing before use
Follow the tier workflow below, then deepen with files under rules/ and the section map in rules/_sections.md.
rules/<prefix>-*.md for anything beyond this file (transactions, serialization, queues, graceful shutdown).Module wiring; DTOs + ValidationPipe on inputs unless the project documents otherwise.rules/<slug>.md.| # | Prefix | Focus | Anchor |
|---|---|---|---|
| 1 | arch- | Architecture | arch-avoid-circular-deps.md |
| 2 | di- | Dependency injection | di-prefer-constructor-injection.md |
| 3 | error- | Error handling | error-use-exception-filters.md |
| 4 | security- | Security | security-validate-all-input.md, security-use-guards.md |
| 5 | perf- | Performance | — |
| 6 | test- | Testing | — |
| 7 | db- | Database / ORM | — |
| 8 | api- | API design | — |
| 9 | micro- | Microservices | — |
| 10 | devops- | DevOps / deploy | — |
Full list (40+ slugs) and new-rule skeleton: rules/_sections.md, rules/_template.md.
Apply rules in this order; stop reranking within a tier unless a higher tier introduces new breakage. After each tier, run nest build and automated tests when the toolchain is available before moving downward.
imports/exports/providers correctness.rules/_sections.md (ordering), rules/<slug>.md (detail), rules/_template.md (blank rule).
class-validator and global ValidationPipe// create-order.dto.ts
import { IsString, IsInt, Min } from 'class-validator';
export class CreateOrderDto {
@IsString()
sku: string;
@IsInt()
@Min(1)
qty: number;
}
// main.ts — register once globally
async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.useGlobalPipes(
new ValidationPipe({ whitelist: true, forbidNonWhitelisted: true }),
);
await app.listen(3000);
}// orders.controller.ts
import { Controller, Post, Body, UseGuards } from '@nestjs/common';
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
import { CreateOrderDto } from './dto/create-order.dto';
import { OrdersService } from './orders.service';
@Controller('orders')
export class OrdersController {
constructor(private readonly ordersService: OrdersService) {}
@Post()
@UseGuards(JwtAuthGuard)
create(@Body() dto: CreateOrderDto) {
return this.ordersService.create(dto);
}
}Prompt: POST /orders body { sku, qty }, login required.
arch-feature-modules, arch-module-sharing).CreateOrderDto + app ValidationPipe (security-validate-all-input).security-use-guards, security-auth-jwt); HTTP errors + filters (error-throw-http-exceptions, error-use-exception-filters).forwardRef as the primary fix without first extracting shared boundaries or domain events (arch-avoid-circular-deps).@Body() typed as any or primitives without pipes where the codebase uses DTO validation elsewhere.try/catch returning ad-hoc JSON instead of centralized exception mapping.rules/db-*, rules/micro-* files when specifics matter.