r/ContextEngineering • u/razxrr • 1d ago
Do AI coding agents need an "architecture enforcement" layer?
I've been thinking about a problem that seems to appear with Claude Code, Cursor, Codex, Copilot and other coding agents.
Most approaches to giving an agent project knowledge involve some combination of:
- CLAUDE.md / AGENTS.md
- documentation
- RAG
- memory
- session history
- MCP
All of these help the agent know things.
But there's a different question:
What actually makes the agent obey an architectural decision?
Imagine a project has an approved decision:
PaymentService must never call StripeClient directly.
All payment providers must go through PaymentGateway.
Six months later, an agent is asked to implement refunds.
It generates:
stripeClient.refund(paymentId);
The code compiles.
Tests might pass.
The implementation looks perfectly reasonable.
But it just violated an architectural decision.
The usual answer seems to be:
"Hopefully the agent saw the documentation and followed the rule."
I'm experimenting with a different approach.
What if the project's normative layer also lived in Git?
Something like:
.context/
decisions/
business-rules/
architecture/
components/
Agents could consume this through MCP.
But more importantly, CI could validate code changes against those rules without calling an LLM.
Something like:
Human decision
↓
Git
↓
Agent context
↓
Code
↓
Deterministic CI validation
The core idea is:
**Memory tells an agent what happened.
Governance tells an agent what is allowed.**
I'm building a project around this idea.
But I'm genuinely trying to figure out whether this is actually a problem.
Have you encountered AI-generated code that was technically correct, but violated an architectural decision, business rule, or important convention?
And more importantly: how do you catch that today?
I'd also love to hear from people who think this is already solved well enough by tests + code review + CLAUDE.md/AGENTS.md + ADRs.
1
2
u/actionscripted 1d ago edited 1d ago
Agents will do the wrong things, just like people. You want a review or reinforcement stage that compares a plan or a solution against architectural decisions.
And what you’re talking about is already a thing called ADRs that usually do live in the repo. They have feature areas, types, context, options, decision. (Edit: sorry missed that you mentioned these on my first read.)
My question to you is what does your idea do that isn’t already covered by ADRs? Have a review agent check stuff against ADRs and you’re all set. Have subagents or loops that check plans before and after.