liveBook · Manning

Module

As explained in Testing Spring Boot Applications

An application module is a bounded, cohesive structural unit of an application that groups related components around a business or technical boundary and exposes a defined interface to other modules.

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.
ch05 f05 garniermoiroux

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

How Testing Spring Boot Applications covers it

How deep it goes
Defines package boundaries, visibility rules, dependency verification, and module-scoped tests, but leaves event-based and runtime features unexplored.
Examples
Uses City, Weather, and Preferences modules, plus a Weather test that stubs the CityService dependency.
What you can do after
Apply it via Spring Modulith to verify module boundaries and run tests scoped to a single module.
How it connects
Connects to Spring Modulith, Java packages, cyclic dependencies, Spring Boot test slices, and Mockito.

Also explained in

Compare how 44 books explain module →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Testing Spring Boot Applications. The section links point to the parts of the book it draws on.