AI maintainability / C# architecture, not prompt tricks

Make a C# codebase cheaper for agents to change correctly

Every extra file an agent must open before it can edit one rule costs tokens, review time, and first-pass mistakes. Prompts cannot fix that. Shape the architecture so the change is small, local, and explicit. (This guide calls each extra file a hop.)

Files touched vs Layered
45% Operation-local
Modular lands at 55%. Layered is the 100% baseline. How this was measured.
Pillar 1

Token cost

How much context an agent must load and emit to ship one product rule. Types that exist only to satisfy layers (DTO, command, query, contract, exception) are wasted context. Extra detail in the file you actually edit — like a closed list of outcomes — is not.

Typical change vs Layered Modular 60% · Operation-local 86%
Pillar 2

Developer involvement

Navigation before the first edit, files a human must review, and forgotten registration points. Agents still need a person when finding the right file is a search problem.

Files opened to understand Modular 56% · Operation-local 38%
Pillar 3

Correct output

First-pass completeness, compile-time outcome coverage, and tests that actually hit persistence. Mocked layers can be green while the query is wrong.

First-pass completeness (estimated) Layered 40% · Modular 75% · Operation-local 90%

Layered

100% baseline

Controller, service façade, mediator, handler, repository, unit of work, factory. Business errors as exceptions. Every new field fans out across projects.

  • The agent cannot answer “what happens on this command?” in one folder.
  • Mirrored DTOs and contracts duplicate the same facts across every layer.
Review surface 100%

Modular

Cheapest tokens

Feature handlers that call a few modules in one process. Shared status vocabulary. No separate Domain / Application / Infrastructure solutions.

  • Smallest patch once the agent already knows the modules.
  • Still a composition root and shared types to keep in mind.
Token budget 60%

Operation-local

Cold-start complete

One file owns request, rules, persistence, closed outcomes, and HTTP mapping. A map names the file. Copy a template instead of inventing a layer.

  • Fewest files touched. A playbook removes “where does this go?”
  • Extra tokens live inside the operation as documentation, not as hop tax.
Files touched 45%
The guide

Eight topics you can take back to your own codebase

Each topic is drawn from a measured change on three C# apps that implement the same functionality in three different architectures. The advice is the architecture, not the domain of those apps. The question is always the same: how many files, concepts, and dependencies does an agent need before it can safely change this code? That question is the overarching metric.

Start with the numbers

See the relative cost of a typical product-rule change

Layered C# is indexed at 100%. Modular and Operation-local are shown as percentages for tokens, developer involvement, and correct-output proxies.