Architectural rules constrain relationships and properties that the compiler may allow but the intended design forbids. As ArchUnit tests, they inspect compiled classes and turn violations into build failures, making boundaries enforceable rather than dependent on code review. section 7.0 section 7.1
Use rules to check properties that module boundaries and the type system do not fully enforce:
- Restrict which packages or classes may depend on one another. section 7.1
- Keep annotations in their intended layers and enforce class naming or structural conventions. section 7.0
- Guard project-specific decisions, such as allowing only the persistence adapter to call domain reconstitution methods. section 9.7.2
A dependency boundary
A publish handler can compile while accepting a persistence adapter directly, bypassing a repository interface. An ArchUnit rule can reject that relationship; Maven module boundaries alone may not catch it when both classes are available on the assembled test classpath. section 7.1
Figure 7.1 ArchUnit tests surround the production architecture as a test-time verification layer. They act as executable documentation of the intended boundaries and help prevent architectural erosion.
The diagram shows ArchUnit tests as a test-time verification layer around production architecture. section 7.0

