Est.

Layered Architecture Violations in Agent-Modified Codebases

Agents write working code that quietly crosses layer boundaries.

Sponsored by Graphide

Shipped by Agents Editors
· 8 min read · Updated
Cover illustration for “Layered Architecture Violations in Agent-Modified Codebases”
Software Architecture · October 20, 2026 · 8 min read · 1,825 words

Layered architecture violations in agent-modified codebases are structural failures. Agents optimize for completing a prompt, while architecture depends on boundaries that a working implementation can quietly cross. Those boundaries survive agent-speed development only when machine-readable rules, deterministic checks and a living dependency graph turn architectural intent into enforceable constraints.

Why agents produce architectural violations even when they write correct code

An agent can pass every functional test and still destroy an architecture. Functional correctness establishes that the code produces the expected behavior. An implementation can return the right result while putting database access in a controller or linking domains that were meant to stay separate. The immediate task succeeds, but the architecture loses a boundary.

The cause is an optimization mismatch. AI coding agents optimize for prompt completion and lack a model of the intentional boundaries behind the code. They cannot infer from code alone why a team chose event sourcing for one service or banned inheritance from the domain layer. Those choices depend on decisions that the implementation does not necessarily record. Without that intent, a deliberate restriction can look like an incidental convention that the next change may ignore.

A bounded context window compounds the mismatch because an agent cannot hold the full codebase in simultaneous awareness. Its reasoning can therefore remain local even when a dependency has global consequences. This is a hardware constraint beyond the reach of better prompting alone. Architecture Without Architects calls architecture shaped by natural-language prompts rather than deliberate, recorded design “vibe architecting”. The paper identifies five mechanisms behind implicit architectural choices and demonstrates that prompt wording alone can produce structurally different systems for the same task.

The specific violation patterns agents produce and why those patterns are predictable

Because the cause is structural, the resulting violations form a recognizable family. A controller querying the database directly is the clearest example of local optimization defeating layered separation. The agent finds a short path to the requested behavior, while the repository layer remains an unenforced convention. Nothing about the returned result necessarily exposes the bypass. The diagnostic feature is therefore not broken behavior but a responsibility placed in the wrong layer.

An agent can reuse a pattern from training data or an adjacent file without understanding that two domains were intentionally decoupled. A module then reaches into another bounded context because the available code appears to solve the immediate problem. Dependency cycles arise when an agent resolves a dependency by importing whatever satisfies it. Unlike the direct controller query, the cycle may become visible only when the dependency graph is examined as a whole.

Architecture Without Architects describes prompt-architecture coupling, where a prompt that implies tool calls, a retrieval pipeline or structured output validation leads the agent to add the matching infrastructure to the generated code. That infrastructure changes the system’s structure even though there is no deliberate decision record for it. Across these patterns, surface organization is a poor diagnostic substitute for dependency analysis. Generated code can look modular because it is split into files and modules, yet still cross the deeper boundaries those divisions were meant to protect.

How violation volume compounds silently before anyone notices

A boundary violation does more than add one defect to an architectural backlog. It also supplies a precedent for subsequent generation. Once a controller queries the database directly, the next agent working in that area can treat the existing implementation as the pattern to follow. The exception becomes evidence of what the codebase permits. As that evidence spreads, further violations become both more likely and harder to distinguish from accepted design.

This is why architectural drift compounds rather than accumulating as a series of independent mistakes. Each change alters the material from which the next agent reasons, so generated code can reinforce a broken convention. The debt also takes shape as the code is generated, before the system runs. Functional testing may show no problem at first because the new dependencies still let the code do what was requested. The structural cost can remain invisible until restructuring exposes how far the implementation has moved from its intended boundaries.

The scale of this degradation follows code volume, regardless of the visibility of individual failures. Violations can grow rapidly and persist regardless of repository size or popularity, while neither functional correctness nor detailed prompting reliably prevents the decay. This relationship is described as a Volume-Quality Inverse Law. Agent-generated debt also has a distinct “machine signature” rather than merely reproducing familiar human error patterns. Together, repetition and unfamiliarity make accumulating architectural violations difficult to recognize through ordinary inspection, even while each individual change appears understandable.

Why the human review pipeline cannot catch violations at agent speed

Human review is poorly matched to this problem because its usual interface is a diff. Large, cross-file diffs ask a reviewer to reconstruct relationships from a linear presentation of isolated changes. An edit in one place may be easy to follow while its effect on layer boundaries stays hidden elsewhere in the change. Understanding that effect requires a view of what the files now depend on. The format therefore obscures precisely the information needed to judge architectural correctness.

Meta’s RADAR system, presented at ASE 2026, provides a concrete account of the volume pressure. RADAR documents substantial year-over-year growth in significant lines of code per human-landed diff and in per-developer diff volume, with agentic AI responsible for the majority of that growth. It also documents a decline in the share of diffs receiving timely review as volume rose. High approval rates do not resolve that mismatch when merged changes still contain problems that careful review could have caught.

The underlying asymmetry is economic as well as informational. Generating a change gets much cheaper, but the cost of understanding what it does to the architecture falls more slowly. Hiring more people and improving the process cannot close that gap at agent speed. Nor does a second agent reliably supply the missing architectural view, since AI code reviewers consistently miss architectural drift, business logic correctness and subtle concurrency issues. A pipeline built around diff approval cannot enforce boundaries on its own when the interface cannot handle the volume or show what reviewers need to reason through.

What deterministic enforcement looks like and why it is the only mechanism that works at this scale

Diagram: Why Mechanical Enforcement Outperforms Review at Agent Speed. Visualizes: Show the contrast between two paths a boundary violation can take: the diff-review path (agent writes code → large cross-file diff → reviewer reconstructs…

When review cannot keep up, machines must enforce the routine boundary rules. A context-file instruction saying that controllers must go through services remains a suggestion that an agent can ignore under prompt pressure. A compiled rule that fails the build changes the status of that instruction. The implementation must satisfy the boundary before it can pass the gate. For an encoded constraint, compliance no longer depends on whether a reviewer notices the violation.

Architecture tests make that distinction executable. A rule violation either prevents the build from passing or it does not, with no reviewer judgment needed for the encoded condition. This determinism matters because enforcement can run regardless of how large or convincing the generated change appears. Architecture Without Architects calls for decision records and describes plan-build workflows as analogous to fitness functions for governing implicit architectural choices. Decision records preserve the reason for a boundary, while executable checks give its enforceable form a repeatable test.

tsarch, an ArchUnit-inspired tool for TypeScript, can turn naming and access conventions into unit tests and use a Stop hook to feed the results back to a coding agent. The agent then receives a failure signal before human review. Open Policy Agent (OPA) and its Rego language bring policy-as-code to deployment governance, setting the bounds within which AI-driven decisions take effect. The common mechanism is not a particular product but a constraint that remains binding as code moves toward production.

The objection that fitness functions only catch known violations — and why it does not defeat the argument

The strongest objection is correct. Fitness functions encode known constraints, so an agent can introduce a novel violation that no existing rule anticipates. Passing an architecture test therefore proves compliance with the tested rules. tsarch and ArchUnit belong with architecture documents and human review as lines of defense. They are not permission to merge agent-generated code without examination.

That limit does not support abandoning mechanical enforcement. Without it, every violation depends on someone recognizing the problem in a diff, including violations whose detection requires no judgment once the boundary is defined. Deterministic checks remove common, low-ambiguity failures from that burden, including direct database calls from controllers, cross-context imports and dependency cycles. Human attention can then concentrate on novel relationships, unrecorded assumptions and high-stakes architectural decisions. The relevant comparison is therefore not perfect automation against imperfect automation, but targeted human review with or without a dependable mechanical baseline.

Using an agent to review another agent’s output does not eliminate the need for that baseline. AI reviewers make more suggestions than human reviewers, but fewer of their suggestions get adopted, and they miss architectural drift in particular. More suggestions are not equivalent to stronger enforcement of a dependency boundary. The proportionate conclusion is that deterministic checks and human judgment perform different jobs. Checks reject known forbidden structures, while people assess whether the permitted structure still serves the system’s intended design.

How to structure enforcement so architectural boundaries survive agent-speed development

Enforcement that works has three layers: machine-readable boundary rules, CI checks that block merges that break those rules and a living architectural model of the code. Begin by encoding layered separation, dependency inversion and bounded context limits in the language-appropriate fitness function tool. A rule that controllers must not access the database directly expresses a constitutional constraint binding on prompted implementations. The decision behind that rule belongs in the architectural record. Its executable form checks a generated implementation’s compliance with the boundary.

Wire those rules into CI so a violation exits non-zero and blocks the merge. The check must run on every commit, whatever the diff size, so it remains required even when a change looks safe, which is where faster GitHub Actions runners such as Graphide CI, a service that runs a team's existing jobs on its own runners so the same verdict arrives with less waiting, keep a mandatory gate from becoming a bottleneck. This makes the gate independent of the amount of attention available for review. Maintain the architectural model against what actually exists in the code. A current dependency graph becomes the source of truth for the system’s implemented relationships, while the rules state which relationships are allowed.

Formal, machine-readable specifications provide upstream prevention by giving agents a more precise target than vague prompts. They complement enforcement rather than replace it, because a specification still covers only what its author anticipated. Developers decide what should exist and how its parts should relate, while the graph exposes the relationships agents create and the CI gate rejects encoded boundary violations. The role shifts from approving generated changes line by line to steering the architecture and relying on enforcement to catch the mechanical breaches.

Sources

  1. Architecture Without Architects: How AI Coding Agents Shape Software Architecture
  2. Faster Code, Deeper Debt? A Multivocal Literature Review on Technical Debt and Its Early Signs in LLM-Assisted Software Development
  3. Don't Blame the Large Language Model: How Agent Harness Evolution Shapes Coding Agent Quality
  4. From Human-Centric to Agentic Code Review: The Impact of Different Generations of Generative AI Technology on Review Quality
  5. AI-Generated Smells: An Analysis of Code and Architecture in LLM- and Agent-Driven Development
  6. The Spec Growth Engine: Spec-Anchored, Code-Coupled, Drift-Enforced Architecture for AI-Assisted Software Development
  7. ContextCov: Deriving and Enforcing Executable Constraints from Agent Instruction Files

More in Software Architecture