As an exercise to building websites and putting DDD to practice, I am currently in the planning stages of creating a crowd voting app based on a video game I play often. The video game allows people to build bases of which can then be attacked by other players. In the app, I want users to be able to either vote up or vote down a base. Voting a base up will increase its score while voting a base down will decrease its score.
I have identified both Users and Bases as aggregates to my domain, where bases will hold a score value based on how many users have voted the base up and down. When a base aggregate is voted up by a user aggregate, the base aggregate will check if the user aggregate has already voted that base up. The following will happen:
- If the user aggregate has voted the base up, the base aggregate's score will remain the same.
- If the user aggregate has not voted on the base aggregate yet, the base aggregate's score will be incremented by one.
- If the user aggregate has voted down the base aggregate, the base aggregate's score will be incremented by two.
The opposite will occur when a user votes a base down. Thus the invariant will hold such that a bases score = (user up votes - user down votes) of which the base aggregate will be responsible upholding. This implies that the base aggregate will be responsible for keeping track of which users have voted on it.
I also want to implement a feature where a user can view all bases they have voted up. This would imply that the user aggregate would be responsible for keeping track of which bases they have voted on.
Which domain aggregate should keep responsibility of maintaining which user has voted on which base? Should I create a new voting aggregate that would maintain these responsibilities?