Part 28 · Further improvements

Modulith: enforce domain boundaries before distribution

Prerequisites: 01-ecosystem

What is a legitimate module dependency?

Quotes module: internal rules; Policies API: published boundary; Policies internals: private implementation; Billing module: separate responsibility. Connections: Quotes module to Policies API (allowed dependency); Policies API to Policies internals (implementation); Policies API to Billing module (explicit collaboration)
Logical domain boundaries inside one process. The figure does not imply separate services or databases. [S54]

Goal & mental model verified

Spring Modulith derives application modules from a Boot application structure and supports boundary verification. Modules expose APIs/named interfaces while keeping implementation details internal.

[S54]

Worked example · design exercise synthesis

Separate quotes, policies and billing into modules. Quotes calls the published policy API or emits a domain event; it should not reach directly into billing’s internal persistence package.

[S54]

Engineering decision synthesis

Use a modular monolith when one deployment can satisfy operational needs. This preserves local interactions while clarifying boundaries, but independent scaling/deployment may later justify extraction.

[S54]

Pitfall & diagnosis synthesis

Package names alone cannot prevent coupling if public internals are widely imported. Replacing calls with events changes consistency and failure semantics; it is not automatically an improvement.

[S54]

Improve & validate synthesis

Run module dependency verification and focused module tests. Track coupling and change ownership before extracting a service; choose extraction based on an actual deployment constraint.

[S54]
Keep this: Make boundaries real before making them remote.
Check yourself: Does Modulith require microservices?

No. It is designed to structure modules within a Spring Boot application.

Sources & further reading

  1. [S54] Modulith fundamentals

    Spring project maintainers · documentation · accessed 2026-10-09 · Documentation retrieved 2026-10-09

    Supports: Module boundaries; Named interfaces; Dependency verification

    Read the linked section to validate the mechanism and its version-specific constraints.