Command Block
A command represents an intent to change the system. It may succeed, fail validation, or be rejected by business rules.
When To Use It
Use a Command block when a user, policy, integration, or scheduled process asks the system to do something that may change business state: Approve Claim, Reserve Inventory, Change Subscription Plan, Assign Driver.
Required Data
- Name: imperative verb phrase, such as Cancel Order.
- Initiator: actor, policy, external system, or schedule that issues the command.
- Target aggregate: aggregate that decides whether the command is allowed.
- Input fields: data required to make the decision.
- Success event or events: events emitted when the command succeeds.
- Rejection reasons: business reasons the command may not be accepted.
Recommended Data
- Authorization rule: who is allowed to issue it.
- Idempotency key: how duplicate command submissions should be handled.
- Validation rules: required fields, ranges, formats, and cross-field checks.
- Expected latency: immediate, background, scheduled, or externally dependent.
- User feedback: success message, rejection message, and next visible state.
Connections
- Usually starts from an Actor, User Interface, Policy, or External System.
- Should be handled by one primary Aggregate.
- Should produce at least one Domain Event when successful.
Examples
Business Commands
- Place Order
- Approve Expense Report
- Open Insurance Claim
- Schedule Patient Appointment
- Allocate Driver To Route
CRUD Commands
- Create Supplier
- Update Product
- Archive Cost Centre
Generation Notes
Code Genie uses command definitions to generate command contracts, handlers, validation paths, application services, authorization hooks, and user interface actions. Avoid commands named after database operations unless you are intentionally designing CRUD.