An application module is a cohesive group of related features organized around a business or technical boundary. In Spring Modulith, a module is represented by a Java package and exposes a defined API to other modules. section 5.5.1
A module boundary establishes which code other modules may use:
- Public classes at the package root form the exposed API. Package-private visibility can keep implementation classes internal; Modulith can also mark public classes as internal or place them in an .internal sub-package. section 5.5.1
- Spring Modulith can verify that modules use only other modules’ public APIs and have no cyclic dependencies. Accessing an internal class across a module boundary is valid Java but breaches the module contract. section 5.5.1
- A module test loads the module’s beans and configuration across application layers, while excluding other modules. Stub dependencies from excluded modules with test beans or test configuration. section 5.5.2
Figure 5.5 The module structure of our project. Each module has a public API visible to other parts of the application, and classes that implement internal behavior. Arrows symbolize dependencies between modules, in our case, direct API calls.
The architecture diagram shows modules’ public APIs, internal implementations, and direct dependencies. section 5.5.1
Listing 5.12 Modulith architecture verification
class ModularityTests {
@Test
void verifyStructure() {
var modules = ApplicationModules.of(WeatherApplication.class);
System.out.println(modules); #1
modules.verify(); #2
}
}
The test verifies the inferred module structure with ApplicationModules.of(...).verify(). section 5.5.1











































