| name | backend-nestjs |
| description | NestJS backend development patterns. Use when developing backend APIs with NestJS, TypeORM/Prisma, and TypeScript. |
| triggers | ["nestjs","nest","backend","api","typescript backend","typeorm","prisma"] |
NestJS Backend Development
When to Use This Skill
Use when developing backend code in a NestJS project with TypeScript.
Recommended Project Structure
src/
āāā core/
ā āāā config/ # Configuration (env validation)
ā āāā database/ # Database connections, migrations
ā āāā guards/ # Auth guards
ā āāā interceptors/ # Request/response interceptors
ā āāā filters/ # Exception filters
ā āāā decorators/ # Custom decorators
āāā modules/
ā āāā <domain>/
ā āāā application/ # Use cases / services
ā āāā domain/ # Entities, value objects, interfaces
ā āāā infrastructure/ # Repositories, external services
ā āāā presentation/ # Controllers, DTOs, validators
ā āāā <domain>.module.ts
āāā shared/
ā āāā utils/
ā āāā types/
ā āāā constants/
āāā main.ts
Conventions
- One use case per file in
application/
- DTOs with class-validator decorators in
presentation/
- Repository pattern for data access in
infrastructure/
- Module-scoped providers; export only what's needed
Testing
- Stack: Vitest (preferred) or Jest
- Unit test use cases with mocked dependencies
- Test file next to source:
*.spec.ts
- All tests in English
- Naming: "should do X when Y"
Commands
pnpm dev
pnpm build
pnpm lint
pnpm test
pnpm test:cov
Error Handling
- Use NestJS built-in exceptions (BadRequestException, NotFoundException, etc.)
- Custom exceptions extend HttpException
- Global exception filter for unhandled errors
Database
- Use query builder or repository pattern
- Always use transactions for multi-table writes
- Add indexes for frequently queried columns
- Use database MCPs to inspect schema before writing queries
Pre-commit Checklist
- Build passes? (
pnpm build)
- Lint passes? (
pnpm lint)
- Tests pass? (
pnpm test)
- DTOs have proper validation?
- Error cases handled?