Spring Modulith is a none intrusive library to help improve the architecture of spring applications by dividing subpackage into distinct modules. This each module thus encapsulates its own logic, dependencies, and configuration, this promoting separation of concerns and improving maintainability.
This small Inventory Application illustrates how we can take Spring Modulith and add it to some legacy project where currently use hexagonal architecture (with CQRS) and DDD
The Inventory project is a simple inventory application to manage orders of product.
- Explain how the PackageInfo are used to expose internal api and events
- Check if we can override the domain events database schema
- Define how to start the application
- Sample CURL to start order
curl --request POST \
--url http://127.0.0.1:8080/orders \
--header 'Content-Type: application/json' \
--header 'accept: application/json' \
--data '{ "description": "test", "lineItems": [{ "quantity":4,"product": 5}]}'
- Externalized message broker RambitMQ admin http://127.0.0.1:15672/ (myuser,secret)
The idea is that we should declare all classes in the new module as Package-Private / Default Visibility. In Java “package-private” (also referred to as “default”) which means that any code in the same package can access it, but any code in a different package can not, including subclasses. Unfortunately kotlin does not currently support this modifer as explained here But maybe it is possible with the internal modifer
- Spring Tips
- Nice example looking under the hood of modulith
- Open Module
- Would be very useful when trying to migrate to modulith
- Application Events
- modulith uses the outbox pattern to ensure that the events a fired (persisted to the database and time stamped when completed)
- need to check if the modulith events table can be extended and renamed (or vice versa)
- Spring Events
- Transactional Outbox pattern with Spring Boot good read on how to implement our own outbox pattern and using modulith
- Event Sourcing with Spring Modulith
- Extend the events table issue
https://www.javaguides.net/2024/05/spring-modulith-tutorial.html