| name | api-add-module |
| description | Scaffolds a complete NestJS hexagonal module with all 4 layers — domain, application, infrastructure, presentation. Use when starting a new bounded context or feature module. Requires /api-setup-shared. |
api-add-module
Full scaffold of a new NestJS hexagonal module following the 4-layer architecture.
Project context
Read the ## Configuration section in .claude/CLAUDE.md for {SHARED_ROOT} and {MODULE_ROOT}.
Prerequisites
Verify shared base classes exist before starting:
{SHARED_ROOT}/cqrs/typed-command.ts
{SHARED_ROOT}/cqrs/typed-query.ts
{SHARED_ROOT}/errors/base-domain.error.ts
{SHARED_ROOT}/errors/base-feature-exception.filter.ts
If any are missing, run /api-setup-shared first.
Steps
-
Create folder structure under {MODULE_ROOT}/{module-name}/:
application/commands/ application/queries/
domain/errors/
infrastructure/
presentation/controllers/ presentation/dto/ presentation/in-proc/
-
DI tokens — {module-name}.tokens.ts
Load references/tokens-template.md.
-
Domain errors — domain/errors/
Load references/domain-errors-template.md.
For entities: run /api-add-domain-entity.
-
Application module — application/{module-name}.module.ts
Load references/application-module-template.md.
-
Infrastructure layer — for each aggregate, run /api-add-domain-entity (steps 5–7).
-
Presentation layer — exception filter, controller, DTOs, optional in-proc facade
Load references/presentation-template.md.
-
Root module — {module-name}.module.ts
Load references/root-module-template.md.
-
Register — add {ModuleName}Module to imports in the app root module.
Limitations
- Does not create Prisma schema or migrations — add models to
schema.prisma and run prisma migrate dev.
- Does not scaffold domain events or BullMQ processors — add manually as needed.
- In-proc interface path (
{SHARED_ROOT}/in-proc/) may differ per project — adjust accordingly.