SOP: Layered Domain Architecture
Use this SOP when the agent keeps violating boundaries, duplicating logic across layers, or producing code that becomes hard to review after a few sessions.
Goal
Make domain boundaries explicit enough that agents can move quickly without silently degrading structure.
Target Model
Within a business domain, prefer this directional flow:
Types -> Config -> Repo -> Service -> Runtime -> UI
Cross-cutting concerns should enter through explicit providers or adapters. Shared utils stay outside the domain and should not accumulate domain logic.
Setup Checklist
- Define the current domains in
ARCHITECTURE.md. - Write allowed dependency directions in
ARCHITECTURE.md. - Record cross-cutting interfaces such as auth, telemetry, and external APIs.
- Add one short note for the hardest current boundary violation.
- Decide what should be enforced mechanically by lint, tests, or scripts.
Execution SOP
- Map the codebase into domains before touching implementation style.
- For each domain, identify the allowed layer sequence.
- Identify all cross-cutting concerns and route them through providers or adapters.
- Move ambiguous shared logic either into the owning domain or into truly generic utils.
- Document the rules in
ARCHITECTURE.md. - Add one executable guardrail for the highest-cost violation.
- Update quality scoring after the change.
Definition Of Done
- A fresh agent can tell which layer owns a change.
- UI code no longer reaches into repo or external side effects directly.
- Cross-cutting concerns have named entry points.
- At least one important boundary is enforced mechanically.
Repo Artifacts To Update
ARCHITECTURE.mddocs/QUALITY_SCORE.mddocs/design-docs/when the rationale changeddocs/PLANS.mdor the active execution plan