golang-ddd-cqrs
Golang DDD CQRS
Use this skill to split application logic into clear commands and queries without turning Go code into ceremony-heavy enterprise scaffolding.
Start Here
- Use CQRS when a service has meaningful write-side behavior, mixed read and write models, or application services that are hard to reason about.
- Skip or minimize CQRS when the service is mostly simple CRUD or login-like flows with little business behavior.
Workflow
- Split the use cases into writes and reads.
- Commands mutate state and may return errors.
- Queries return data and should not perform business mutations.
- Name them in business language.
- Prefer
ScheduleTraining,CancelTraining,ApproveReschedule,AvailableHours. - Avoid default CRUD names unless the business really speaks that way.
- Introduce separate handlers when it improves clarity.
- Use one command handler type per command when the logic or dependencies differ.
- Use one query handler type per query when read concerns differ.
- Keep interfaces narrow and owned by the handler that consumes them.
- Keep handlers orchestration-only.
- Domain rules belong in the domain layer.
- Transport mapping belongs in ports.
- Database or external API details belong in adapters.
- Shape the ports around CQRS.
- HTTP or gRPC ports may call commands directly.
- If a create command needs a follow-up read, prefer
204 No Contentpluscontent-locationwhen practical, or execute an explicit query after the command. - Keep port-specific error translation at the edge.
- Test the application layer as orchestration.
- Mock repositories and outbound services with tiny handwritten mocks.
- Keep business-scenario assertions in domain tests unless the behavior truly belongs to application orchestration.
Guardrails
- Do not create separate command and query packages if the service is still trivial.
- Do not let commands return large read models by default.
- Do not hide business logic in command handlers just because they are convenient.
- Do not keep one giant application service if separate handlers would shrink interfaces and tests.
Use These References
- Read references/cqrs-guidelines.md for naming, packaging, and tradeoffs.
- Read references/application-tests-and-errors.md for handler testing and transport-agnostic errors.
Deliverables
- command and query boundaries that match the use cases,
- business-oriented names,
- narrow handler-owned interfaces,
- thin transport code,
- handler tests focused on orchestration instead of domain internals.
More from joeyave/golang-ddd-skills
golang-ddd-architecture
Design and refactor Go service architecture for DDD-style systems. Use when a Go codebase needs explicit ports/app/domain/adapters boundaries, dependency rules, interface placement, composition-root dependency injection, separate transport and database models, or help deciding whether DDD, Clean Architecture, or CQRS are justified.
13golang-ddd-refactor
Refactor existing Go code toward a behavior-first, invariant-protecting domain model. Use when business rules live in handlers or repositories, shared structs couple DB and API models, entities expose setters or mutable public fields, or a service needs domain methods, constructors, private state, repository update closures, and focused domain tests.
12golang-ddd
Entry-point router for Go architecture and refactoring tasks focused on DDD-style services. Use when working on a Go service and you want one skill to decide whether the task is primarily about architecture boundaries, domain-first refactoring, pragmatic CQRS, or delivery and test support. This skill should select one or more companion skills and apply them in the right order.
10golang-ddd-infrastructure
Support Go services by keeping infrastructure, security boundaries, and automated tests aligned with the application architecture. Use when working on Terraform, Cloud Run, Cloud Build or CI, docker-compose environments, integration or component test setup, repository authorization boundaries, service-to-service authentication, or secure internal operations.
10