Kicking around ideas related to an architecture combining the best of DDD, CQRS and REST, I keep trying to organize concepts in my brain.
Warning: This is a braindump. Looking for feedback.
When I think about throwing REST on top of CQRS, I keep envisioning multiple models of reality. This assumes a significantly complex Domain Model and application requirements.
Models:
1. Client Model, a representation on the client for view binding, etc.
2. Application Model, developed in terms of application state, exposed as representations of resources via REST services.
3. Reporting Model (Query), query results to the application (DTO's).
4. Domain Model, developed in terms of business language and processes.
5. Data Model, developed for persistence.
Query sequence:
1. Client follows a GET request to a REST service.
2. REST service goes through a thin data layer to grab DTO's for constructing the resource representation requested by the client.
3. REST service returns the constructed representation to the client.
4. Client builds its own model based on the GET response and binds to the UI.
Command sequence:
1. Client submits a request to a REST service, asking to alter a resource (PUT, POST, DELETE, etc.).
2. REST service constructs a command and pushes it to the command queue.
3. REST service responds to the client with 202 Accepted.
4. A command handler processes the command through the Domain Model, which publishes events.
5. Event handlers fire. Some event handlers will persist changes to a data store.
There are certainly many variations on this, especially for less complex scenarios.
I would love to come up with a demo, maybe starting with BDD style specs in the Gherkin syntax. GitHub can make collaboration around this easy-peasy.
What are your thoughts?
--
Kevin Swiber