liveBook · Manning

Module

As explained in Clean Applications with Hexagonal Architecture

A module is a cohesive software unit whose implementation and dependencies are organized behind a defined boundary.

A framework import in a handler can quietly turn an architectural boundary into a convention. A module makes that boundary part of the build: it is a separately declared unit with its own dependencies, so code cannot import types that are absent from its dependency graph. section 6.1

Choose modules around boundaries worth protecting. Separate parts that should not import each other; keep parts together when separation adds ceremony without protecting a real boundary. The resulting module list can also serve as a map of the architecture. section 6.1

Listing 6.1 Parent POM: The hexagonal blueprint
<project>
  <groupId>com.writeflow</groupId>
  <artifactId>writeflow</artifactId>
  <packaging>pom</packaging>
 
  <modules>
    <module>shared-kernel</module>
    <module>application-core</module>
    <module>rest-adapter</module>
    <module>persistence-adapter</module>
    <module>notification-adapter</module>
    <module>spring-boot-assembly</module>
  </modules>
 
</project>
 

The parent POM lists a shared kernel, application core, adapters, and a separate assembly module. section 6.1

The application core can itself contain domain, input-port, output-port, and application modules. Dependency direction matters: inner modules must not reference outer modules. For example, the domain depends on the shared kernel, not on adapters or a dependency-injection framework. section 6.1

Table 6.1 Module dependency rules
Module
May depend on
Must NOT depend on
domain
shared-kernel
application, adapters, DI framework
input-ports
shared-kernel
domain, application, adapters, DI framework
output-ports
shared-kernel
domain, application, adapters, DI framework
application
domain, input-ports, output-ports, shared-kernel
adapters, DI framework
rest-adapter
input-ports, shared-kernel, MVC framework
domain, output-ports, other adapters
persistence-adapter
domain, shared-kernel, Data framework
input-ports, output-ports, other adapters
notification-adapter
output-ports, shared-kernel
domain, input-ports, other adapters
spring-boot-assembly
all modules, DI framework
— (it is the root)

The dependency rules specify what each module may and must not depend on. section 6.1

Compile-time boundaries prevent wrong dependencies, but they do not connect interfaces to implementations at runtime. The assembly module depends on the other modules and uses Spring Boot to find implementations and inject them. Its responsibility is wiring, not application logic; the core does not need to know how it was assembled. section 6.2 section 6.6

Module visibility is not a complete architectural specification. ArchUnit tests can check relationships, annotations, and naming across the assembled classpath, complementing the imports that Maven rejects at compile time. section 7.1 section 7.9

How Clean Applications with Hexagonal Architecture covers it

How deep it goes
Explains module selection and dependency rules, then distinguishes compile-time visibility from runtime wiring and test-time architectural checks.
Examples
Uses a parent POM and an application-core POM to organize a domain, ports, adapters, and Spring Boot assembly.
What you can do after
Configure Maven modules to protect chosen dependency boundaries and use an assembly module to wire implementations at runtime.
How it connects
Connects modules to hexagonal architecture, dependency injection, ports and adapters, and architectural fitness functions.

Also explained in

Compare how 44 books explain module →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Clean Applications with Hexagonal Architecture. The section links point to the parts of the book it draws on.