nestjs
Skill33 starsChanged 22 days agoMITView on GitHub
Use when building NestJS services. Covers module structure, providers and scopes, validation pipes, guards and interceptors, TypeORM/Prisma integration, and testing. Trigger on "nest can't resolve dependencies", "add a guard for auth", "validation pipe not working", "test my nest module". Do not use for API contract decisions like pagination or versioning — see the api-design skill.
We split this skill into the rules it gives an agent
2 rules. 0 are common, 1 is distinctive, and 1 is very specific to this project.
0
Common
Most of the 4 edited versions we read keep these.
1
Distinctive
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 56
Do not inject the repository into the controller.
- Very specific: line 58
Use ConfigModule with a validation schema so a missing environment variable fails at boot.
“Common” is measured: kept by at least 6 in 10 of the 4 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
NestJS
Purpose
Build NestJS applications where the module graph reflects the domain, validation happens at the edge, and cross-cutting concerns live in guards and interceptors rather than being copied into every controller.
When to Use
- Building or reviewing a NestJS service.
- Structuring modules, providers, and their scopes.
- Implementing authentication, authorization, and request validation.
- Writing unit and end-to-end tests for a Nest application.
Capabilities
- Module and provider design, including dynamic modules.
- Validation with
class-validatorand the globalValidationPipe. - Guards (authorization), interceptors (cross-cutting), filters (error mapping).
- Data access with Prisma or TypeORM, correctly scoped.
- Testing with the Nest testing module and Supertest.
Inputs
- The domain boundaries the modules should follow.
- The authentication scheme and the authorization model.
- The persistence layer.
Outputs
- Modules that encapsulate a domain and export only their public services.
- A global validation pipe with whitelisting enabled.
- Controllers that are thin, and services that contain the logic.
Workflow
- Model the modules on the domain — One module per bounded capability, exporting the services other modules may use. A module that exports everything is not a boundary.
- Enable strict validation globally —
whitelist: trueandforbidNonWhitelisted: true. Without these, a client can send extra fields and your DTO will happily carry them into the service. - Push cross-cutting concerns out of controllers — Auth in a guard, logging and timing in an interceptor, error mapping in an exception filter.
- Keep providers stateless and singleton — Request-scoped providers cascade: anything that injects one becomes request-scoped too, and performance degrades quietly.
- Test at two levels — Unit tests for services with mocked dependencies, and end-to-end tests through the real HTTP stack with a real (containerized) database.
Best Practices
ValidationPipewithoutwhitelist: trueis decoration, not validation. Extra properties pass straight through.transform: trueon the pipe converts payloads into DTO class instances — otherwise your@Typedecorators and defaults do nothing.- Circular module dependencies are a design smell.
forwardRefis an escape hatch that hides a boundary you drew wrong. - Do not inject the repository into the controller. The controller's job is HTTP; the service's job is the domain.
- Global exception filters map domain errors to HTTP status codes in one place. Throwing
HttpExceptionfrom a service couples the domain to the transport. - Use
ConfigModulewith a validation schema so a missing environment variable fails at boot.
Examples
Validation, guard, and thin controller:
// main.ts
app.useGlobalPipes(
new ValidationPipe({
whitelist: true, // strip unknown properties
forbidNonWhitelisted: true, // and reject the request if any are present
transform: true, // instantiate the DTO class
}),
);export class CreateOrderDto {
@IsUUID() customerId!: string;
@IsArray()
@ArrayMinSize(1)
@ValidateNested({ each: true })
@Type(() => OrderLineDto)
lines!: OrderLineDto[];
}
@Controller("orders")
@UseGuards(JwtAuthGuard, TenantGuard)
export class OrdersController {
constructor(private readonly orders: OrdersService) {}
@Post()
@HttpCode(HttpStatus.CREATED)
create(@Body() dto: CreateOrderDto, @CurrentUser() user: User): Promise<OrderView> {
return this.orders.place(user.tenantId, dto);
}
}Domain errors mapped centrally:
@Catch(DomainError)
export class DomainExceptionFilter implements ExceptionFilter {
catch(error: DomainError, host: ArgumentsHost) {
const status = {
NOT_FOUND: 404,
CONFLICT: 409,
INVALID: 422,
}[error.kind] ?? 400;
host.switchToHttp().getResponse().status(status).json({
type: `https://api.example.com/errors/${error.kind.toLowerCase()}`,
title: error.message,
status,
});
}
}Notes
- Request-scoped providers instantiate a new instance per request and force the entire injection chain above them to do the same. Measure before using one.
- Nest's
TestingModulelets you override any provider, which is almost always preferable to mocking a module's internals. - Interceptors run around the handler and can transform the response. That makes them the right place for a response envelope — and the wrong place for business logic.
Other versions5 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 5
- youlaitech/youlai-skills★ 63same name
- G1Joshi/Agent-Skills★ 15same name
- nguyenchilong/claude-skills-fullstacks★ 1same name
- conjure-3301/skills★ 0same name
- zeeshanalimughal/claude-skills★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository137 other files it gives its agents.
- agent-instructionsSkill
- agent-memorySkill
- hooksSkill
- plugin-developmentSkill
- skill-authoringSkill
- skill-reviewSkill
- slash-commandsSkill
- subagentsSkill
- agent-designSkill
- context-engineeringSkill
- fine-tuningSkill
- llm-cost-optimizationSkill
- llm-evaluationSkill
- llm-integrationSkill
- mcp-serverSkill
- ml-pipelineSkill
- model-selectionSkill
- prompt-engineeringSkill
- ragSkill
- structured-outputSkill
- api-designSkill
- background-jobsSkill
- cachingSkill
- djangoSkill
- event-driven-architectureSkill
- fastapiSkill
- graphqlSkill
- microservicesSkill
- realtime-websocketsSkill
- spring-bootSkill
- competitive-analysisSkill
- lead-researchSkill
- product-analysisSkill
- resumeSkill
- user-researchSkill
- database-performanceSkill
- data-modelingSkill
- data-qualitySkill
- pandasSkill
- postgresSkill
- sparkSkill
- brand-guidelinesSkill
- generative-artSkill
- themingSkill
- ui-reviewSkill
- visual-designSkill
- architecture-decisionsSkill
- bug-fix-protocolSkill
- cli-developmentSkill
- code-reviewSkill
- debuggingSkill
- design-patternsSkill
- domain-modelingSkill
- git-workflowSkill
- legacy-modernizationSkill
- refactoringSkill
- repository-explorationSkill
- simple-designSkill
- system-designSkill
- aws-cdkSkill
- The first 60 shown.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

