Architecture Documents for Real Codebases

April 22, 2026 (7mo ago)

Most experienced engineers have no trouble reading unfamiliar code. What slows them down is reading it in the wrong order. A newcomer works through directories top to bottom, while a long-time maintainer jumps straight to the right place using a mental map built over months of reviews and incidents. Maintainers already know that pricing logic actually lives behind the quote builder, that notifications are split between delivery workers and preference storage, and that the intimidating folder at the root is generated glue nobody edits by hand.

A short ARCHITECTURE.md is the cheapest way to hand over that map on day one.

Diagram showing ARCHITECTURE.md mapping product questions to code destinations

What actually belongs in the file

A good architecture document skips the exhaustive package tour and focuses on the questions that burn the most time when left unanswered:

  • What problem the system solves and which constraints shape it
  • Which modules own the core domain concepts
  • Where common product changes usually start
  • Which dependencies are intentional—and which ones are off-limits
  • Which code is generated, external, or deliberately kept boring
  • How cross-cutting concerns work across the repo

That last point is easy to underestimate. Authentication, logging, tracing, permissions, retries, tenancy, billing, migrations, and background jobs rarely live in a single tidy folder. They behave more like the weather of a codebase: they affect everything, and if nobody describes the forecast, every new contributor learns by getting soaked.

To keep the document useful for more than a sprint, write it against stable anchors. Reference symbol names and modules that show up in search instead of line numbers or small helpers. You are building an orientation layer, not an encyclopedia.

Example 1: a SaaS checkout system

Take a B2B SaaS product with workspaces, subscriptions, invoices, and usage-based billing, and suppose a new engineer is asked to add annual discounts.

Without any architectural orientation, the investigation tends to unfold the hard way: search for "price", patch the checkout page, discover the API recalculates totals, patch the handler, notice invoices disagree, patch invoice generation—and finally hear in code review that discounts are modeled as pricing rules and must emit an audit trail.

A few lines in ARCHITECTURE.md prevent that whole detour:

## Billing codemap
 
- `PricingRule` is the source of truth for discounts, trials, coupons, and enterprise overrides.
- Checkout renders prices for display but never computes canonical totals.
- Invoice generation replays pricing rules against metered usage snapshots.
- Payment provider adapters only accept finalized invoices.
- Every pricing rule mutation writes an audit event.

Five bullet points, and a contributor immediately knows where the change starts, what sits downstream, and which invariant a reviewer will check first.

Example 2: a frontend monorepo

Frontend codebases drift in a quieter way. The directory tree usually looks familiar, so the real design hides inside unwritten conventions.

In a larger app with route modules, shared UI primitives, generated API clients, feature collections, and visual fixtures, adding a simple “resend invite” button raises an immediate design question: should the mutation live in a route loader, a feature hook, a collection action, or a client wrapper?

Writing down the layering resolves the debate before the PR is opened:

## Frontend layering
 
- Routes compose feature views and own navigation state.
- Feature modules own product workflows and mutations.
- UI primitives stay reusable and never import feature modules.
- Generated API clients are called through feature-level adapters.
- Visual fixtures live next to the workflow they cover.

That keeps two slow-motion failures from creeping in: shared UI components quietly absorbing business logic, and route files turning into a dumping ground for every workflow in the product.

Example 3: a data ingestion pipeline

Data pipelines need the same treatment because their files are usually named after mechanics rather than ownership. Seeing consumer, normalizer, writer, jobs, schema, and deadletter tells you what moves data around, but not where correctness is enforced.

For a pipeline importing partner inventory feeds, a concise flow summary clears up the whole design:

## Inventory import flow
 
- `FetchJob` downloads raw partner payloads and stores them as immutable input blobs.
- `NormalizeBatch` maps partner fields into internal product candidates.
- `ValidationReport` records rejected rows and warnings before any write occurs.
- `CatalogWriter` is the sole module allowed to mutate live catalog tables.
- Retry workers may replay any stage, so every handler must be idempotent.

Notice what actually matters here: raw inputs never change, live writes have a single owner, and every stage has to tolerate retries. You rarely pick up those guarantees just by clicking through folders.

Layered architecture diagram showing boundaries and invariants

Boundaries matter more than tours

Some of the highest-leverage lines in an architecture document describe what a codebase deliberately refuses to do:

  • Domain logic never imports React.
  • API handlers never open raw database transactions directly.
  • Background workers never call payment providers without an idempotency key.
  • Generated clients are never edited by hand.
  • Reporting queries never read from hot transactional tables.

These constraints shape almost every non-trivial change, yet they are practically invisible when browsing source files—nobody checks in a file called nothing_imports_the_ui.go.

Writing them down is the first step. Pairing them with lightweight enforcement is even better: if feature modules are not supposed to import route modules, a lint rule or dependency check keeps the boundary real. The document explains the why; the tooling catches drift before it settles in.

A template small enough to stay alive

A short file that people actually update beats an ambitious wiki page that everyone praises once and forgets by next quarter. For most repositories, five sections are plenty:

# Architecture
 
## System story
 
Two or three paragraphs explaining what the system does, who uses it,
and which constraints drive the design.
 
## Codemap
 
Name the main modules, the product concepts they own, and where
common changes typically start.
 
## Boundaries and invariants
 
List the rules reviewers care about: dependency direction, data ownership,
generated code, idempotency, security, tenancy, and performance limits.
 
## Cross-cutting concerns
 
Cover auth, logging, tracing, config, migrations, background jobs,
third-party integrations, and test fixtures at a high level.
 
## Keeping this document current
 
Keep it short. Update it when module ownership shifts, a new boundary
appears, or the same review comment comes up twice.

This sits cleanly in the gap between a README and inline code comments—more structural than setup instructions, and high-level enough that routine refactors won’t break it.

When to start writing it

The best cue is catching yourself leave the same review comment a second time:

  • “This belongs in the domain layer.”
  • “Don’t call Stripe directly from here.”
  • “That directory is generated.”
  • “Use the collection instead of fetching inside the component.”
  • “This worker can run twice.”

Repeated comments mean the maintainers carry a map the repository hasn’t written down yet. Put it in ARCHITECTURE.md once, and future reviews can focus on the change itself rather than re-explaining the terrain.

Good documentation won’t magically make a complex system simple—but it makes the complexity legible, which is what teams actually need to move quickly without breaking things.