I'm trying to design a monolithic application following DDD and clean code. Lets say I have Users
, User Types
, Products
, Product Types
and Purchases
. I want to implement using different modules.
At the moment I'm thinking in Users
, including the user types, Products
, the same including the service types, and Purchases
.
Each module contains uses cases, domain models and infrastructure components for its entities. Since I want to have the modules loosely decoupled between them I was thinking to make communication using events.
My problem is when I trying, for example, to create a Purchase I will have a CreatePurchase
use case in Purchases
module, receiving UserId
, ProductId
and maybe other data related to the purchase. But in Purchases
module don't have any information about Products
and Users
, lets say for verify the ids are valids.
How can I solve this problem? I can assume in Purchases module that the ids are valids but in some other layer I have to verify for this.
Another option that I have thought of is to replicate certain information between modules handling the events, but it does not seem entirely correct to me to have the ids of Users and Products in Purchases just to verify if they exist.
In the same way, If I have another module, for example Billing
, that clearly is a different module than Purchases
, and at some point need to use purchases to generate an invoice or other reports, how can I get this data if there is in a different module?
Of course, I'm trying to do all this without to have direct dependencies from one module on another, just handling events that are all across the modules.