Encoding Architectural Intent as Graph Constraints Agents Can Violate and Report
Graph constraints turn architectural intent into merge-blocking checks.
Sponsored by Graphide

Architecture drift in AI-generated codebases occurs when generated code satisfies local checks while departing from intended layers, dependency directions, or module boundaries. This article explains how to detect and prevent that drift by encoding architectural intent as graph constraints. Prompts guide generation, but deterministic checks that name violations and block merges turn structural intent into enforceable rules.
Why agents break architecture silently and at scale
Agents select frameworks, wire dependencies, and configure infrastructure as part of generating code. Those choices shape the architecture even when nobody asks for an architectural change. Konrad et al. call this “vibe architecting,” where prompt wording shapes infrastructure. The decisions are implicit, but their effects are structural. A prompt can therefore change a system’s design without presenting that change as a decision requiring review.
Tests may pass while intended functionality remains absent, and code that works in isolation may conflict with project patterns or undocumented assumptions. The Anthropic Institute’s June 2026 report stated that code output per engineer in Q2 was eight times higher than in 2024, with a large majority of code merged into the company’s official repository written by Claude. That figure illustrates the potential review gap. Generation can leave more of the architecture to review without people understanding more of it.
Why prose architectural intent degrades as agent load increases
Adding architectural requirements to a prompt does not turn them into guarantees. Researchers call this loss of compliance constraint decay, because agents do better at unconstrained generation than when they have many conventions to follow. A 2026 study found that imposing Clean Architecture cost roughly nine percentage points in assertion pass rate. Stacking constraints into a fully specified setup caused capable configurations to decline substantially.
Tang’s empirical study on constraint encoding found that models systematically overestimated compliance compared with rule-based scoring. Counter-intuitive constraints failed at rates of ten to one hundred percent, while conventional constraints achieved near-perfect compliance. Architectural boundaries are especially at risk when they rule out the implementation pattern a model uses by default. AGENTS.md and structured system prompts can place those boundaries in context, but context alone supplies no independent verification of the output. The distinction is between telling an agent what to build and checking what it built.
How to detect divergence by encoding architectural intent as a graph constraint
A graph constraint expresses a rule over named code entities and their relationships. Instead of asking an agent to respect layering, it identifies the layers and specifies which dependency edges are permitted or forbidden. An analysis engine evaluates that predicate against the code’s graph. The evaluation returns a pass or a named violation. This makes the boundary testable rather than dependent on how an agent interprets prose.
Three properties make the rule enforceable in practice. It identifies concrete entities, defines their allowed relationship, and produces a deterministic, auditable result. A violation can point to a field, call site, or file path, giving the agent or developer a specific repair target. The constraint belongs in a version-controlled file so that changes to intent become reviewable changes themselves. Its evaluator can then supply the result that a CI check uses to block a merge, and teams that want that check to return the same verdict with less waiting can run their existing GitHub Actions jobs on Graphide CI, a faster GitHub Actions runner service built for agent-written code.
Konrad et al. propose a conformance layer that compares generated dependency graphs with declared constraints. Their example, “no new database dependencies without review,” illustrates the distinction between a general preference and a checkable boundary. The relevant relationship is a database dependency. The conformance layer flags departures before they propagate, rather than asking a reviewer to reconstruct the rule from documentation. Enforcement remains bounded by the entities and relationships the analysis can actually observe.
How existing tools implement graph constraint enforcement, and where each falls short
Deptrac implements this model for PHP through named layers and rulesets defining which layers may depend on which others. It statically analyses the codebase and reports violations, while visual dependency graphs support onboarding and architecture reviews. The team supplies the architectural model. That model can be layered, hexagonal, DDD, or custom, but the tool’s static view has a firm limit. Dynamic instantiation escapes its analysis, so dependency checks cannot establish every runtime relationship.
TNG Technology Consulting’s ArchUnit targets Java and reports violations through offending fields, call sites, and file locations. With the tool in the build pipeline, teams get those reports before violations become costly to fix. SonarQube Server added Design & Architecture capabilities in its 2025 Release 2, providing similar constraint validation. These are enforcement capabilities. Their presence does not, however, establish a complete workflow for reviewing planned architecture against built architecture.
The open-source MCP tool code-review-graph parses a codebase with Tree-sitter and targeted fallbacks, stores a queryable graph, and exposes callers, dependents, blast radius, and architecture in a single tool call. Benchmarks across six real open-source repositories showed meaningful token reduction for structural context. Prometheus constructs a Neo4j graph from ASTs across a wide range of languages and exposes graph traversal plus read_file. These approaches help an agent find its way through relationships, but that alone does not keep it within the relationships that are allowed.
A hybrid approach pairs Spectral, ArchUnit, and Spring Modulith with LLM evaluation for semantic violations that deterministic rules cannot express. The LLM also helps repair the findings. This pattern approaches a closed enforcement loop, but it is not yet automated end-to-end. Across these implementations, the shared gap is specific. No existing tool brings together in one workflow an engine-neutral architecture spec whose meaning is documented, checks of the whole plan before generation, and views that people can review to see how the built architecture differs from the plan and what a proposed spec change would affect.
The three enforcement moments and why only one reliably stops violations before they propagate
Pre-generation enforcement places constraints in system prompts or AGENTS.md before the agent writes code. This can preserve coherence over a task and reduce violations. It does not produce an independently verifiable compliance result. The disagreement over pre-generation versus post-generation control turns on that distinction, because improving the probability of compliance is not the same as proving compliance. Tang’s findings on constraints that oppose model defaults rule out prompt encoding alone as a dependable gate.
Post-generation validation checks the output with local linting or pre-commit hooks and may catch a violation before a developer reviews the diff. This shortens the feedback path for repair. It can still follow substantial compute spent producing code that will be rejected, and its operation depends on a correctly configured local environment. It is also bypassable. CI validation supplies the required backstop by making a passing constraint check a condition of merge, independent of the prompt and local setup.
The Cline security incident of December 21, 2025 illustrates the consequences of permissive CI boundaries. Its configuration used allowed_non_write_users: "*", allowing any GitHub user to trigger a bot with Bash, Read, Write, Edit, Glob, Grep, WebFetch, and WebSearch access on Actions runners. Use all three enforcement moments while reserving the merge decision for required CI checks.
What the enforcement loop looks like in practice, from graph spec to CI exit code
The work starts with a version-controlled constraint spec that names the layers or modules and states which dependency edges are allowed and which are forbidden. This can be deptrac.yaml, a JUnit test class for ArchUnit, or a custom schema. A rule left out of the spec will go unenforced. Writing the spec is itself a design review, because the team has to turn broad architectural language into decisions about specific relationships. The artifact records what the validator is expected to judge.
Next, graph extraction establishes what the code actually imports and calls. Static analysis can use Tree-sitter, AST parsing, or language-server-grade type resolution to build that graph from the code as evidence of structure. Its limits must remain explicit, because static extraction does not provide a complete account of runtime dynamic instantiation. The extracted graph provides a strong safety net alongside thoughtful design.
The evaluator then tests each constraint against that graph and reports the specific entity, call or import, and file location involved in a violation. ArchUnit’s reporting model provides the relevant standard of specificity. On large codebases, blast-radius analysis extends this view by tracing affected callers, dependents, and tests. Graph-based context on a large Next.js monorepo can narrow review to a small handful of files, exposing relationships that a diff alone does not show.
Finally, the CI step exits non-zero whenever a constraint is violated, and the failed check blocks the merge. The violation report makes the agent’s departure named and addressable. This is the point where guidance becomes enforcement. The generated output is judged against the versioned spec. The same explicit rule can then guide a local repair and the next validation check.
The constraint maintenance problem, who keeps the spec current as agents change the codebase
Constraint definitions still require humans who understand the architecture to write and maintain them. A deptrac.yaml that was correct six months ago may no longer express a legitimate design change, especially when the reasoning remains only in an ADR, a diagram, or a developer’s head. As agents produce more code, keeping the spec up to date takes more work. Even with intent encoded, people still have to decide what the architecture should become.
Enforcement does, however, make conflicts with the recorded intent visible. When code departs from an old boundary, the check fails and presents a concrete disagreement for review. Detection depends on rules encoded in the spec, leaving omissions in a stale spec unenforced. The enforced boundaries give people a clear place to discuss whether a change is intended or amounts to accidental drift.
The alternative requires sustained architectural attention across an expanding volume of diffs. A survey of more than 15,000 professional developers found the vast majority using AI coding agents at work at least weekly, with a growing share having most of their code generated by agents. That volume favors maintaining explicit boundaries over relying on careful review alone. Konrad et al. propose using the same architectural decision records and governance for choices made by agents as for choices made deliberately by humans. For a legitimate architectural change, updating the spec in the same commit creates a reviewable diff of intent, making the versioned spec a machine-readable ADR rather than a replacement for the reasoning behind it.
What the developer’s job becomes when architectural intent is encoded and enforced
With machine-enforced constraints, developers gain more control by setting the boundaries within which agents build. The scarce work becomes design, context boundaries, and intent. The leading pattern in 2026 is bounded autonomy, with clear operational limits, mandatory escalation paths for high-stakes decisions, and comprehensive audit trails. Graph constraints enforce the structural boundaries at the code level within that broader model.
Putting architectural checks in CI
Choose an architecture-test or dependency-rule tool that supports your language and the constraints you can explicitly encode. Commit its rules with the code, run the documented command in CI, and make the resulting check required where those rules should prevent a merge. Test the gate with an intentionally forbidden dependency before relying on it. Such checks enforce the rules you specify; they do not establish that every aspect of the architecture or runtime behavior is correct.
Updated November 5, 2026: obsolete CLI examples removed. Use the selected tool’s current installation and command documentation.


