Agent skill
nestjs
NestJS modular API architecture with controllers, services, guards, middleware, and dependency injection patterns. Use when: building API endpoints, implementing services, creating guards/interceptors, handling authentication/authorization, or any backend business logic with NestJS
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/data/nestjs-kaxuna1-ecomsite
SKILL.md
NestJS Skill
NestJS provides a structured, Angular-inspired architecture for Node.js backends. It enforces separation of concerns through modules, controllers, and services with built-in dependency injection. Use decorators for routing, validation, and metadata.
Quick Start
Module Structure
// src/products/products.module.ts
@Module({
imports: [TypeOrmModule.forFeature([Product])],
controllers: [ProductsController],
providers: [ProductsService],
exports: [ProductsService],
})
export class ProductsModule {}
Controller Pattern
// src/products/products.controller.ts
@Controller('products')
export class ProductsController {
constructor(private readonly productsService: ProductsService) {}
@Get()
findAll(@Query() query: FindProductsDto) {
return this.productsService.findAll(query);
}
@Post()
@UseGuards(JwtAuthGuard)
create(@Body() dto: CreateProductDto, @Request() req) {
return this.productsService.create(dto, req.user.id);
}
}
Service Pattern
// src/products/products.service.ts
@Injectable()
export class ProductsService {
constructor(
@InjectRepository(Product)
private readonly productRepo: Repository<Product>,
) {}
async findAll(query: FindProductsDto): Promise<Product[]> {
return this.productRepo.find({ where: query });
}
}
Key Concepts
| Concept | Usage | Example |
|---|---|---|
| Module | Feature boundary, DI container | @Module({ providers: [...] }) |
| Controller | HTTP routing, request handling | @Controller('users') |
| Service | Business logic, injectable | @Injectable() |
| Guard | Auth/authorization checks | @UseGuards(AuthGuard) |
| Pipe | Validation, transformation | @UsePipes(ValidationPipe) |
| Interceptor | Response transformation, logging | @UseInterceptors(LoggingInterceptor) |
Common Patterns
Global Validation
// main.ts
app.useGlobalPipes(new ValidationPipe({
whitelist: true,
forbidNonWhitelisted: true,
transform: true,
}));
Exception Filter
@Catch(HttpException)
export class HttpExceptionFilter implements ExceptionFilter {
catch(exception: HttpException, host: ArgumentsHost) {
const ctx = host.switchToHttp();
const response = ctx.getResponse<Response>();
const status = exception.getStatus();
response.status(status).json({
statusCode: status,
message: exception.message,
timestamp: new Date().toISOString(),
});
}
}
See Also
- routes - Controller routing patterns
- services - Service layer and DI
- database - TypeORM/Prisma integration
- auth - Guards and authentication
- errors - Exception handling
Related Skills
- See the typescript skill for strict typing patterns
- See the prisma skill for database ORM alternative to TypeORM
- See the postgresql skill for database design
- See the zod skill for runtime validation
- See the jest skill for unit testing NestJS services
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?