In the ground since Sat Nov 08 2025
Last watered inSat Nov 08 2025
A NestJS module encapsulates related functionality (controller + service + dependencies) into a reusable, isolated unit. Creating a new module involves 4 files: the module definition, controller, service, and registration in the app module.
Real Example: Created sdk-runtime module for Peek-a-boo to separate runtime API endpoints from admin endpoints, demonstrating proper separation of concerns in NestJS.
Modules help organize code by domain/feature:
Create a new module when:
Example from Peek-a-boo:
Same domain (feature flags), but different purposes warrant separate modules.
Key Points:
Key Points:
Key Points:
Create sdk-runtime.service.ts with:
Create sdk-runtime.controller.ts with:
Create sdk-runtime.module.ts with:
Add new module to app.module.ts imports array.
If multiple modules need the same service:
For truly global services (config, logging):
For modules that need configuration:
NestJS:
❌ Bad: CommonModule with unrelated stuff ✅ Good: AuthModule, UserModule, EmailModule
❌ Bad:
✅ Good:
❌ Bad:
✅ Good:
Issue: NestJS can't inject a dependency.
Solution:
Issue: Module A imports Module B which imports Module A.
Solution:
Issue: Endpoints return 404.
Solution:
The sdk-runtime module demonstrates:
Files created:
Total time to create: ~15 minutes for a production-ready module.
A well-structured module is self-contained, testable, and easy to understand.