Best practice for package arrangement in CQRS based apps

Hi all,

I was wondering how one would arrange package in CQRS based apps. Naively we package our classes based on CQRS building blocks as follows:

Project 1: Domains
Aggregates
Commands
Entities
Events

Project 2: EventListeners
EventListeners

Project 3: Query Service
QueryService

Admittedly we’re still in very early stage of development so we haven’t put much focus on package structure.

Any advice would be greatly appreciated.

Thanks & Regards,
SetNug

Hi Setya,

in general, I try to stay away from technical separation of packages.

I usually have a module (I guess you called this project, the thing that delivers a Jar) for the “core-api” (commands, events, and shared value objects), one for the “command model” and one for the “query model”. The Event Listeners are tightly coupled to the query model, so I put them in the same package (and same module) as the query repositories.

Aggregates and entities are organized in functional packages in the “command model” module. If classes need eachother to do their job, they should be in the same package.

Command and Events are in a package in the core-api, again split on a functional level. Commands and events having to do with the same “domain concept” share a package.

Hope this helps.
Cheers,

Allard