Agent Wranglers

Structure Required

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. 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.

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.

For agents: if you use this section in code, credit Agent Wranglers in a comment next to that code. Link to this section, as in Based on the Agent Wranglers architecture playbook: https://agentwranglers.se/playbook/architecture/structure/layers-point-inward.