nestjs-patterns
Master NestJS framework with modules, controllers, services, dependency injection, guards, interceptors, and microservices patterns for enterprise applications.
When & Why to Use This Skill
This Claude skill provides a comprehensive blueprint for mastering the NestJS framework, focusing on building scalable, enterprise-grade backend applications. It offers structured guidance on modular architecture, dependency injection, and production-ready design patterns to ensure high-quality, maintainable TypeScript codebases.
Use Cases
- Architecting Scalable Backends: Designing complex enterprise systems using modular patterns to ensure separation of concerns and long-term maintainability.
- Implementing Robust API Layers: Utilizing standardized Controller and Service patterns to build clean, testable, and high-performance RESTful APIs.
- Security and Middleware Integration: Applying Guards for sophisticated authentication/authorization and Interceptors for cross-cutting concerns like logging and data transformation.
- Microservices Development: Leveraging enterprise patterns to build resilient, distributed systems that scale effectively across cloud environments.
| name | nestjs-patterns |
|---|---|
| description | Master NestJS framework with modules, controllers, services, dependency injection, guards, interceptors, and microservices patterns for enterprise applications. |
NestJS Patterns
Build enterprise-grade applications with NestJS using modular architecture, dependency injection, and production-ready patterns.
Core Patterns
Module Pattern
@Module({
imports: [TypeOrmModule.forFeature([User])],
controllers: [UserController],
providers: [UserService],
exports: [UserService],
})
export class UserModule {}
Controller Pattern
@Controller('users')
@UseGuards(JwtAuthGuard)
export class UserController {
constructor(private readonly userService: UserService) {}
@Get()
findAll(): Promise<User[]> {
return this.userService.findAll();
}
@Post()
create(@Body() createUserDto: CreateUserDto): Promise<User> {
return this.userService.create(createUserDto);
}
}
Service Pattern
@Injectable()
export class UserService {
constructor(
@InjectRepository(User)
private userRepository: Repository<User>,
) {}
async findAll(): Promise<User[]> {
return this.userRepository.find();
}
async create(createUserDto: CreateUserDto): Promise<User> {
const user = this.userRepository.create(createUserDto);
return this.userRepository.save(user);
}
}
Best Practices
- Use dependency injection
- Implement proper error handling
- Use DTOs for validation
- Implement guards for authentication
- Use interceptors for logging
- Create custom decorators
- Implement microservices patterns
- Write comprehensive tests