In an application to handle employee leaves, I decided to try CQRS & event sourcing and came up with the following flow of events.
app events
- leave-application-received
- leave-application-validation-failed
- leave-application-accepted
- leave-applied
- manager-notified
- leave-approved
- leave-rejected
- user-notified
- calendar-updated
from the domain perspective, only applied, approved/rejected are the key events, while other events are more like an application log events.
To implement that in a code, I am making following classes
//command
class ApplyLeave (startDate, numberOfDays) {
...
...
}
// aggregate root
class EmployeeLeave () {
handleApplication(leaveApplication)
{
... code to handle application ...
... raise events ...
}
}
//event
class LeaveApproved(id, timestamp)
{
}
Considering this is my first take on cqrs and event sourcing, I am bit worried if I am doing its the right way. my questions are
- should there be events like application-received which is just a log of http request received? I think it has no meaning in domain, so it should not be recorded, but on the other hand, if a request failed half way, knowing that a request was received might be useful?
- if having app events like application-received is ok, should I create two event stores? domain-events and app-events?
I might be completely off the track, because I read a lot of articles but didn't find any sample code on how to actually implement cqrs+es.