A layer boundary written on a diagram is easy to forget when a deadline looms. An architectural fitness function turns that boundary into an automated check: if the code breaks the rule, the build can stop before the change moves further down the pipeline. section 4.4.3 section 13.12
A unit test might ask whether a tax calculation returns the right result. A fitness function asks whether the code respects an architectural requirement, such as a dependency boundary. This provides a second line of defense when folders alone cannot enforce the rule or the compiler cannot see it. section 4.4.3 section 13.4.1
Keep the UI away from the database
Suppose an architectural decision says the UI must not talk directly to the database. A fitness function checks that boundary and fails the build if a change skips the required layer. The automated check runs before human review; the pull request still gives reviewers a chance to assess architectural compliance. section 2.7.2
Libraries such as NetArchTest and ArchUnit can examine compiled code as a dependency graph. Tests can assert rules about class relationships, naming conventions, and package dependencies—for example, that a layer does not depend on a layer above it. section 13.4.1
Figure 13.7 Architectural Fitness Functions: Automated guardrails for design integrity. By using libraries like NetArchTest or ArchUnit, your pipeline programmatically parses compiled binary artifacts into an internal dependency graph. It evaluates this graph against rules like the Downward Dependency Rule, instantly blocking non-compliant pull requests and preventing structural decay without relying on manual code reviews.

Follow the path from compiled artifacts to a dependency graph, rule evaluation, and a blocked non-compliant change. section 13.4.1
Introduce guardrails without turning them into a wall:
- Start with one critical boundary rather than enforcing every rule at once; a flood of failing builds can overwhelm the team. section 13.4.4
- Make the check a blocking gate when enforcement is required. A warning in a log can be ignored. section 13.4.4
- Give an older codebase a gradual on-ramp. Applying strict validation everywhere immediately can halt development. section 13.4.4

