| name | api-add-command |
| description | Creates a CQRS command + handler + in-memory test in a NestJS hexagonal module. Use when adding a write operation (state change) to a module. Command and handler live in the same file. Requires /api-setup-shared. |
api-add-command
Creates {command-name}.command.ts (command + handler) and {command-name}.command.spec.ts (in-memory test), then registers the handler.
Project context
Read the ## Configuration section in .claude/CLAUDE.md for {SHARED_ROOT} and {MODULE_ROOT}.
Prerequisites
Run these skills first (in order):
/api-init-project — project scaffold
/api-setup-shared — shared base classes (TypedCommand, BaseDomainError, etc.)
/api-add-module — module scaffold (tokens, errors, controller)
/api-add-domain-entity — entity, repository, builder, in-memory repo
Steps
-
Create folder — application/commands/{command-name}/
Name in kebab-case, imperative verb: join-campaign, create-order, cancel-subscription.
-
Create command file — {command-name}.command.ts
Load references/command-template.md for the exact structure.
-
Create test file — {command-name}.command.spec.ts
Load references/test-template.md for the exact structure.
If using BaseLogger, pass new InMemoryLogger() as the second constructor argument.
-
Register handler — add XxxCommandHandler to the providers array in
application/{module-name}.module.ts and add the corresponding import at the top of that file.
Limitations
- Does not scaffold
InMemorySomeRepository or SomeBuilder — run /api-add-domain-entity first.
- Logger injection is optional. If not using
BaseLogger, use NestJS native Logger or omit.