I am making a family day care application and I thought I would try DDD / CQRS / ES, but I have problems designing the units. The domain can be described quite simply:
- The child receives registration
- Baby can arrive
- Child can leave
The goal is to track visit times, create invoices, write notes (for example, what was done for lunch, injuries, etc.) against visits. These other actions will certainly be the most common interaction with the system, as the visit starts once a day, but something interesting happens all the time.
The invariant I'm struggling with is:
- A child cannot arrive if he is already here.
As far as I can see, I have the following options
1. The single root of the Child aggregate
Create a single Child root with the ChildEnrolled , ChildArrived and ChildLeft
It seems simple, but since I want every event to be associated with a visit, this means that the visit will be the essence of the Child aggregate, and every time I want to add a note or something else, I have all the visits for this children have ever been. It seems ineffective and rather irrelevant - the child himself and every other visit simply have nothing to do with what the child has for lunch.
2. Aggregate Roots for Child and Visit
Child will only generate ChildEnrolled , and Visit will be the source of ChildArrived and ChildLeft . In this case, I do not know how to preserve the invariant, except that Visit accepts the service for this purpose, which I saw is not recommended.
Is there any other way to force an invariant to apply to this design?
3. This is a false invariant.
I suppose this is possible, and I have to protect against several people signing up for the same child at the same time, or latency, which means that the user clicks the "login" button several times. I do not think this is the answer.
4. I miss something obvious
It seems most likely - of course, this is not some special snowflake, how is it normal? I can hardly find examples with multiple ARs, not to mention lists.