AI doesn’t like your architecture

I told my AI coding agent ‘Domain Driven Design (DDD)’ and I got a pipeline. A bad, cobbled together, patchwork pipeline.

You see my AI agents don’t like my architecture. They have an architecture of their own in mind, and over five months and two products they kept building it instead of mine. It cost me hundreds of tickets of rework and hundreds of wasted hours.

I suspect your agents won’t like your architecture either. Here are five things that will force your AI to behave architecturally, each learned the hard way:

  1. Write your architecture down as rules a machine can check.
  2. Make each architecture rule fail the build, with a message that teaches.
  3. Point your gates at today’s code, and double-check they push in the right direction.
  4. Use an AI review where a gate can’t protect you.
  5. If all else fails, rebuild.

First, what the architectural drift looks like, and a bit about my goals with AI-assisted development.

Useless 'Do not step on the lawn' sign at Schönbrunn

Useless ‘Do not step on the lawn’ sign at Schönbrunn. Photo: Herzi Pinki, Wikimedia Commons, CC BY-SA 4.0, resized.


What the architecture drift looks like

Your architecture might be event-driven, services, vertical slices, hexagonal or layers. Mine is a functional take on a rich domain model, where the rules about a thing live with the thing, not in services around it. A rule here is a piece of business logic, such as “you can’t change a workspace while its customer is inactive”. A customer is a type, and the rules about customers are pure functions in a module beside it (Wlaschin, 2018). Simple, right. Nothing fancy there. But I didn’t get what I asked for. The AI built something else.

I’m not the first to see this problem. Thoughtworks warns that “Increased use of AI coding agents can accelerate drift from the intended codebase and architecture designs” (Thoughtworks, 2026), and one study found architectural smells (signs of poor structure, such as tangled dependencies) rising almost in lockstep with the volume of AI-generated code (Zhu et al., 2026).

What I saw is more specific than drift. Whatever architecture you choose, the agent has a habit of its own. In my experience that habit is the pipeline: it’s the agent’s default design. Ask it for something that takes A and produces B, and it builds a pipeline: read the input, transform it, write the output. Pipelines are great and there are many instances when a pipeline is exactly what is needed: a chain of pure functions is one, and in an event-driven system the pipeline is the design. The trouble for me was is where the business rules went. Mine landed in the I/O (at the entrance to the first pipe, where the input is read, or at the exit from the last, where the output is written), or in semi-random places in between. Anywhere but with the thing, the entity, that they’re about. I noticed the trend very early on, back in July when working on a delivery-metrics tool, and my decision log said why: “The last build’s shape drifted through the agents, whose instinct is to organise around the data flow.”

I don’t know why AI likes pipelines, but my guess is training gravity: the pipeline is everywhere in the code these models learned from, and once your own codebase has a pipeline, the agent copies the pattern from there too because, for an AI agent, code has primacy over documents.


The AI experiment at 3F Consulting

I’ve led engineering organisations of up to 170 people, and I’m fascinated by how software gets built and driven to make it better. 3F Consulting is my lab for that: one person and lots of agents, testing how a team could work, so I can take what works to the next team I lead.

The lab is set up the way I run development teams. With a real team I don’t review the code: I’m accountable for quality and for reaching the goal, so that’s where I focus. I am Lazy on purpose, so in the 3F process the code is checked by the gates and by a reviewing session separate from the one that wrote it. That’s deliberate: the lab is an experiment in building software no human needs to review line by line.

I’m not the only one chasing a process where the AI does the review. Take Uncle Bob Martin, for example: “I don’t review code written by agents. I measure things like test coverage, dependency structure, cyclomatic complexity, module sizes, mutation testing” (Martin, 2026).


1. Write your architecture down as rules a machine can check

I wrote my architectural intent down everywhere: in my principles, in a document on functional domain modelling, and in each product’s technical design. My second product, spec-controller (it checks that a codebase’s tests match its specifications), had a design that said, in plain words, “every domain rule lives on a concept.”

It didn’t matter. Within three months, the code that renders that product’s report was counting and judging domain data in nine places. The renderer even worked out for itself how many claims were out of balance, a business rule the domain should own. Worse, one of the central questions the product answers, which steps in your build count as quality checks, was being decided by the code that reads the build file. That’s like an accounting system where the code that reads your bank statement decides which payments count as income. Add a second bank, and that rule has to be written twice, and the two copies will drift apart.

Others find the same. More specific requirements made no measurable difference to the smells (Zhu et al., 2026). Context files, the instruction files you give an agent such as AGENTS.md or CLAUDE.md, “do not generally improve task success rates” and add over 20% to inference cost (Gloaguen et al., 2026). OpenAI, building a product entirely with its own agents: “Documentation alone doesn’t keep a fully agent-generated codebase coherent” (Lopopolo, 2026).

Do: write the architecture down, but as architecture rules something can check. Avoid: answering drift with more documents.


2. Make each architecture rule fail the build, with a message that teaches

OpenAI’s answer: “When documentation falls short, we promote the rule into code” (Lopopolo, 2026). Böckeler calls these controls computational, “deterministic and fast, run by the CPU”, as opposed to inferential ones like instruction files and AI review (Böckeler, 2026). The agent can’t talk its way past a build that won’t go green.

Here’s an example. In my second product, the engine (the code that holds the business rules) must be pure: it works only on the data it’s given, and never reaches out to the clock or the environment. That keeps the business rules testable with plain data, and it stops the outside world quietly shaping the domain, which is where a pipeline starts. The architecture rule is an ESLint rule, in the project’s eslint.config.js, and it turns the build red when any file in the engine breaks it:


// eslint.config.js
{
  files: ["packages/core/src/**/*.ts"], // the engine
  rules: {
    "no-restricted-globals": ["error",
      { name: "process", message: "the engine stays testable with data alone" },
      { name: "Date", message: "the engine reads no clock — the instant arrives as an argument" },
    ],
  },
},

In plain words: no file in the engine (packages/core/src) may use process, which reads the environment, or Date, which reads the clock. Each ban carries a message, and the message tells the agent how to fix it: pass the time in as an argument instead. OpenAI does the same: “we write the error messages to inject remediation instructions into agent context” (Lopopolo, 2026). None of this is new; architects have called such checks fitness functions for years (Thoughtworks, 2017). What’s new is an agent that drifts on every change.

That product now runs 29 fitness functions on every change, and since mid-September its import rules alone (architecture rules about which code may use which) have stopped nine changes before they merged, against 666 that did merge in that time. That’s about one in 74: rare, but each one is drift caught before it lands. For example, on 13 November the agent made one adapter, the code that reads the input files, import a type from another adapter, the one that holds the run’s request. The import rule says each adapter keeps to its own folder and is “handed everything else” by the commands that call it. The build went red at 07:07. By 07:10 the agent had removed the import and passed the file’s path in as a plain string instead. Its commit message: “An input read imports nothing from the run request, as the import rule says.”

Do: turn each architecture rule you can into a gate, with a message that teaches. Avoid: gates that only say no.

If I started a new codebase tomorrow, I wouldn’t wait to rediscover these. On day one I’d gate a pure domain, adapters that can’t reach into each other, no “service” or “manager” modules inside the domain, and no import cycles: the drift I’ve already seen. Everything else waits until I see it happen (I’m a big fan of Pain Driven Development).


3. Point your gates at today’s code, and double-check they push in the right direction

A gate checks only what it’s pointed at. During one bout of rework in October/November, my import gates were still pointed at old folder names, and the drift simply moved into the new folders.

Worse, a gate can push the agent toward the pipeline. My first product had a limit of 400 lines per file. When one module, work-item.ts, grew past it, the agent’s obvious fix was a new work-item-operations.ts: a service layer, with the business rules drained out of the thing they belong to. My own gate was doing it. I lifted the limit off the domain’s core modules, and added the opposite gate: anything in the domain whose name ends in “operations”, “service” or “manager” turns the build red. It’s crude (work-item-helpers.ts would slip through), but it catches the agent’s favourite names. And it’s only inside the domain: there, those names mean rules leaving their concept, while a service at a system boundary is fine.

Do: when you restructure, move the gates with the code, and ask what each gate pushes the agent towards. Avoid: size limits that reward splitting a concept apart.


4. Use an AI review where a gate can’t protect you

Some architecture rules can’t be turned into a gate, because checking them takes judgement about what the code means. For my design the key one is that each business rule lives with the concept it’s about. That’s the heart of domain-driven design, and it’s exactly the rule the pipeline breaks. Your design will have its own rules like this; they may not be this one.

A gate can stop a business rule from going to some places, such as an adapter that reaches into another adapter. But among the places it allows, it can’t see where the rule actually went: it can’t tell whether a rule about customers sits in the customer module or in the report renderer. A renderer that imports the customer type can still judge customers inline, and every gate stays green. Types fence some of it, by making illegal states impossible to represent (Wlaschin, 2018), but no type says which module a rule belongs in. I haven’t found a tool that can make that call.

So the judgement goes into the design, and an AI review checks the code against it. Every design of mine now answers one question before any code: which module owns each new business rule? I decide that myself, in the design I sign off. After each delivery, a second AI session, not the one that wrote the code, reads the code against that design and flags any rule that landed somewhere else. That review is a model’s judgement too, so it’s the backstop, not the decision. The pull hasn’t gone: in one week in November, the agent put rules in the wrong place three times. But each was caught and moved within about a day.

Do: for each architecture rule a gate can’t check, write the answer into the design and have a separate AI session check the code against it after each delivery. Avoid: trusting green gates to mean the architecture is right.


5. If all else fails, rebuild

Over two months to mid-October, “a domain rule in the wrong place, drifting back after each clean-up” was my most expensive rework pattern: about 326 tickets at most, roughly one in six of everything completed in those two months. They’re small tickets (my two delivery sessions, the AI sessions that write the code, get through 900-odd in four weeks, as I described in Lazy on purpose, where I review the specifications and the design, not the code), but in October I wrote in my log: “I’ve lost count of the increments we have completed, all of which were meant to solve this problem.”

In November I deleted the second product’s code and rebuilt it from its executable specifications, the Gherkin scenarios I’d reviewed, keeping nothing. An earlier attempt had rebuilt around some of the old code, and most of the problems its reviews found were in the code I’d kept. The first pieces of work after the rebuild were clean, but that’s too early to call.

I could do that because I had two things: executable specifications to rebuild from, and no live users or data to migrate. Without both, rebuild one module at a time behind the gates, not the whole product.

Do: when clean-ups keep coming back, rebuild from the executable specification, a module at a time if you have live users. Avoid: keeping old code because it already works. That’s where the drift was hiding.


What changes with a team

I’m one person and I am accountable for everything. So what changes with ten or thirty engineers each running agents?

Well, all five of my suggestions still apply, but ownership of each might be delegated. The senior techie in the room (architect, tech lead, VP of Engineering, whatever) is responsible for the architecture rules (1), the AI review that covers what no gate can (4), and any rebuild decision (5). The gates themselves (2 and 3) are code, so someone owns them like any other code.

With a bigger team there is also more capacity for human reviews. For my 3F experiment I want to avoid these, but with a bigger team we have the option to include them where they add most value. Do the AI review first, then the human review. I imagine this more like exploratory testing where there is not a fixed script but instead the reviewer is looking for new places where the AI is drifting from the architectural design.


And one warning

Don’t hold a rule too tightly either. Davidson’s agent kept an out-of-date storage abstraction because an architecture decision record (a short written note of a design decision) said so, then added another layer to stay compatible (Davidson, 2026). A rule that has stopped being right is drift too.

Your AI agent will always pull back to its habit. You won’t stop it. What you can do is catch it sooner. Last week, my slips were each caught within a day, not months later.

So, what’s your architecture? And how long does it take you to notice when your agent has replaced it?


References

Böckeler, B. (2026, April 2). Harness engineering for coding agent users. martinfowler.com. https://martinfowler.com/articles/harness-engineering.html

Davidson, D. (2026, September 1). Coding agents love decision records. https://duncandavidson.com/agents-love-decisions

Gloaguen, T., Mündler-Sasahara, N., Müller, M. N., Raychev, V., & Vechev, M. (2026). Evaluating AGENTS.md: Are repository-level context files helpful for coding agents? (arXiv:2602.11988). https://arxiv.org/abs/2602.11988

Martin, R. C. [@unclebobmartin]. (2026, April 14). I don’t review code written by agents… [Post]. X. https://x.com/unclebobmartin/status/2044114698451476492

Lopopolo, R. (2026, February 11). Harness engineering: Leveraging Codex in an agent-first world. OpenAI. https://openai.com/index/harness-engineering/

Thoughtworks. (2017, November). Architectural fitness function. Technology Radar. https://www.thoughtworks.com/radar/techniques/architectural-fitness-function

Thoughtworks. (2026, April 15). Architecture drift reduction with LLMs. Technology Radar. https://www.thoughtworks.com/radar/techniques/architecture-drift-reduction-with-llms

Wlaschin, S. (2018). Domain modeling made functional: Tackle software complexity with domain-driven design and F#. Pragmatic Bookshelf. https://pragprog.com/titles/swdddf/domain-modeling-made-functional/

Zhu, Y. C., Tsantalis, N., & Rigby, P. C. (2026). AI-generated smells: An analysis of code and architecture in LLM- and agent-driven development (arXiv:2605.02741). https://arxiv.org/abs/2605.02741

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.