Building the modular monolith
Since the modules are independent and decoupled from each other, we need to create something to orchestrate the calls between them. This is where the mediator pattern comes in.
The mediator pattern encourages the decoupling of components that need to work together by eliminating direct communication between them. Instead of interacting directly, these components communicate through a mediator that is responsible for coordinating their interactions. This approach reduces dependencies between components as they no longer need to know about each other and rely solely on the mediator. As a result, the system becomes more flexible and maintainable, with each component depending only on the mediator rather than being tightly coupled to several others. Figure 6.7 shows a representation of the mediator pattern.

Figure 6.7 – The mediator pattern
Before diving into the code, let’s take a quick look at how the mediator pattern differs...