nestjs-patterns

spjoshis's avatarfrom spjoshis

Master NestJS framework with modules, controllers, services, dependency injection, guards, interceptors, and microservices patterns for enterprise applications.

⭐1stars🔀0forks📁View on GitHub🕐Updated Dec 30, 2025

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.
namenestjs-patterns
descriptionMaster 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

  1. Use dependency injection
  2. Implement proper error handling
  3. Use DTOs for validation
  4. Implement guards for authentication
  5. Use interceptors for logging
  6. Create custom decorators
  7. Implement microservices patterns
  8. Write comprehensive tests

Resources