Agent Wranglers

ARC-63Recommended

Point dependencies inward

Business rules never import the web framework, the database or other outside services. Outer layers depend on inner ones, never the reverse.

How to do it

Keep three rings in their own folders, such as domain/, application/ and adapters/. The domain holds rules and types. The application holds use cases. The outer ring holds controllers, database code and adapters for outside services. The outer ring implements interfaces the inner rings define. The inner rings own those interfaces, as Depend on abstractions at the edges says.

Examples

YAML example

# deptrac.yaml: the domain may depend on nothing else
deptrac:
  paths: [./src]
  layers:
    - { name: Domain, collectors: [{ type: directory, value: src/Domain/.* }] }
    - { name: Application, collectors: [{ type: directory, value: src/Application/.* }] }
    - { name: Infrastructure, collectors: [{ type: directory, value: src/Infrastructure/.* }] }
  ruleset:
    Domain: ~
    Application: [Domain]
    Infrastructure: [Domain, Application]

How to check

A dependency rule fails the build when an inner folder imports an outer one. Examples are dependency-cruiser, Deptrac, import-linter and ArchUnit.

Sources

For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/architecture/structure/layers-point-inward">Agent Wranglers clean code and architecture playbook</a>. In code you write, add a comment next to it with the same link.