error-prone icon indicating copy to clipboard operation
error-prone copied to clipboard

upward dependency violation check

Open Pankraz76 opened this issue 3 months ago • 0 comments

Suggestion: Rule for Layered Package Dependency Violations

Following the discussion in https://github.com/TNG/ArchUnit/issues/33#issuecomment-3636346820, I would like to propose a new warning rule that detects imports between packages that share a common root but violate a layered architecture structure—specifically, rules inspired by the Layered Architecture Rule and classical inward-only dependency flow.

Motivation

In a layered architecture (e.g., based on the Entity–Control–Boundary pattern): https://en.wikipedia.org/wiki/Entity%E2%80%93control%E2%80%93boundary

  • Inner layers (e.g., entity) should never depend on outer layers (e.g., control, boundary).
  • Dependencies are intended to flow only inward (or downward), not outward (upward).

Example of an incorrect dependency:

  • An entity class directly imports a control or boundary class.

This is the opposite of the intended architectural direction.

Limitation

This kind of rule only works if the project actually structures packages in a layered way. If all packages exist on the same level, such as:

  • boundary
  • control
  • entity

(which unfortunately is very common), this rule cannot infer layering automatically.

Proposed Idea

Assuming a hierarchical, layered package structure such as:

  • boundary
    • control
      • entity

A simpler bottom-up prevention check could ensure that all dependencies only flow inward or downward, but never upward, following classical layered-architecture principles.

This would help enforce classic layered-architecture principles in a lightweight way without requiring a full architecture definition.

  • https://github.com/TNG/ArchUnit/issues/33

Pankraz76 avatar Dec 10 '25 14:12 Pankraz76