Spring Modulith is an opinionated toolkit to build domain-driven, modular applications with Spring Boot. In the same way that Spring Boot has an opinion on the technical arrangement of an application, Spring Modulith implements an opinion on how to structure an app functionally and allows its individual, logical parts to interact with each other. As a result, Spring Modulith enables developers to build applications that are easier to update so they can accommodate changing business requirements over time.
spring modulith translates logical functional architecture into a specific and pragmatic code structure.
The arrangement determines the visibility:
If some classes are inside a internal package, then it should not be called by another module package. The ApplicationModules.of(Application.class).verify(); to test the modularity will fail otherwise.
e.g. example.inventory cannot call the example.order.internal.
Visualize
Describe architecturally important aspects of your system.
Decouple modules by leveraging springApplicationEvents, but still in a single commit boundary!
So we can add a listener:
@ApplicationModuleListenervoid on(OrderCompleted event) { // business logic}
triggered after publisher’s commit boundary
runs asynchronously
creates its own commit boundary
However, what happens if the listener fails (we are dealing with in-memory messaging system)?
Opt-in for automatic backup and replay of events with the Event Publication Registry by inserting rows in a event_publication table in the database.
In other words, the application will be resilient to those failures and will automatically re-consume those events on application restart.
What about 3rd party subscribers?
You can use @Externalized to easily transition to external messaging:
alpha module → spring framework message bus → gamma module