Nest.js Project
Language: TypeScript October 1, 2025
Instruction file for Nest.js backend framework with Node.js.
---
applyTo: "**/*.controller.ts, **/*.service.ts, **/*.module.ts"
---
# Nest.js Development Instructions (2025)
_Last updated: October 2025_
- Always use the fetch tool to look up the latest Nest.js documentation: https://docs.nestjs.com
- Use Nest.js 10+ for building scalable Node.js backend applications
- Leverage TypeScript decorators and dependency injection
- Follow modular architecture with controllers, services, and modules
- Use Nest CLI for code generation
- Implement proper validation with class-validator
**Core Principles:**
- Use modules to organize application into cohesive blocks
- Implement controllers for routing and request handling
- Use services (providers) for business logic
- Leverage dependency injection throughout the application
- Follow single responsibility principle
- Use decorators for metadata and configuration
**Architecture:**
- Organize code by feature modules
- Use shared modules for common functionality
- Implement proper module imports and exports
- Use global modules sparingly
- Create DTOs (Data Transfer Objects) for validation
- Separate concerns: controllers, services, repositories
**Controllers:**
- Use @Controller() decorator for routing
- Implement proper HTTP method decorators (@Get, @Post, etc.)
- Use route parameters with @Param()
- Use query parameters with @Query()
- Use request body with @Body()
- Implement proper response handling
**Providers (Services):**
- Use @Injectable() decorator for services
- Implement business logic in services
- Use constructor-based dependency injection
- Create provider scopes appropriately (singleton, request, transient)
- Follow interface segregation principle
**Validation:**
- Use class-validator decorators in DTOs
- Enable ValidationPipe globally
- Implement custom validators when needed
- Use transform option for type coercion
- Handle validation errors properly
**Database:**
- Use TypeORM or Prisma for database access
- Implement repository pattern for data access
- Use migrations for schema changes
- Define entities with proper decorators
- Implement proper relations and transactions
**Authentication:**
- Use @nestjs/passport for authentication
- Implement JWT strategy for token-based auth
- Use guards for route protection
- Implement refresh token rotation
- Store secrets in environment variables
**Guards and Interceptors:**
- Use guards for authentication and authorization
- Implement interceptors for response transformation
- Use pipes for data transformation and validation
- Create custom decorators for reusable logic
- Use exception filters for error handling
**Error Handling:**
- Use built-in HTTP exceptions (NotFoundException, BadRequestException)
- Implement global exception filters
- Return proper status codes
- Log errors for monitoring
- Provide meaningful error messages
**Testing:**
- Use Jest for unit and integration testing
- Test controllers with TestingModule
- Mock dependencies in service tests
- Use e2e tests for API endpoints
- Implement proper test coverage
**Microservices:**
- Use @nestjs/microservices for microservice architecture
- Implement transport layers (TCP, Redis, RabbitMQ)
- Use message patterns for communication
- Implement proper error handling
- Use hybrid applications when needed
**Summary:**
> For all Nest.js work, always use the fetch tool to look up the latest documentation from https://docs.nestjs.com. Build enterprise-grade, scalable Node.js applications. Nest.js TypeScript Backend Node.js Framework