LESSON 6

Architecture Documentation

Document architecture with a small set of honest views: context, containers, components, runtime flows, cross-cutting concepts, and quality scenarios, kept consistent with the code.

Introduction

In the architecture course, you designed SignalDesk: its patterns, data model, API, scalability approach, and trade-offs. Since then, the code has been written. Architecture documentation now has a different job: not to describe what was intended, but to give people an accurate mental model of what exists, quickly.

The goal is not completeness. A 100-page document nobody reads or updates is worse than five pages that are true.

Learning Objectives

  • Identify the audiences and questions of architecture documentation.
  • Describe a system with context, container, and component views.
  • Document runtime behavior for the key flows.
  • Capture cross-cutting concepts such as tenancy, security, errors, and AI usage.
  • State constraints, quality requirements, risks, and technical debt.
  • Keep diagrams and text consistent with the code.
  • Use AI to draft views and to find inconsistencies.

1. Audiences and Questions

Audience Questions
New engineer Where do I make a change? What talks to what?
Operator or on-call What runs where? What breaks if this fails?
Security or compliance reviewer Where does data flow? What are the trust boundaries?
Product or delivery lead What are the constraints and risks?
Future maintainer Why is it shaped like this? (see ADRs, lesson 7)

Architecture documentation answers “what are the main parts, how do they fit together, and what rules apply across all of them.” It does not describe every class.

2. Zoom Levels: The C4 Model

The C4 model offers four zoom levels. Use the first three; the fourth (code) is the code itself.

Level Shows Audience
1. System context The system as a box, its users, and external systems Everyone
2. Containers Separately deployable or runnable parts: web app, API, worker, database, queue Engineers, operators
3. Components Major building blocks inside one container Engineers working in it
4. Code Classes and functions Generated or read from code

“Container” here means a runnable unit, not necessarily a Docker container.

A container view for SignalDesk, as diagram source:

1
2
3
4
5
6
7
8
9
10
flowchart TB
    admin([Admin user]) --> web[Web app]
    dev([Integrating developer]) --> api
    web --> api[API service]
    api --> db[(PostgreSQL database)]
    api --> queue[(Job queue)]
    queue --> worker[Import and summary worker]
    worker --> db
    worker --> llm[[External model provider]]
    api -. emits events .-> hooks[Webhook delivery]

Under each diagram, write a short table: each element, its responsibility in one sentence, its technology, and who owns it. The picture shows relationships; the text states the facts the picture cannot.

Guidelines:

  • Every box and arrow is labeled. An arrow means a specific interaction (“HTTPS/JSON”, “enqueues job”).
  • One level per diagram; do not mix a component inside a container diagram.
  • Use a legend if notation is not obvious.
  • Show external dependencies and trust boundaries, since they carry risk.
  • Include a date or version, and a link to the source.

3. A Lightweight Structure

A proven template for architecture documents is arc42. You need not adopt it in full; use it as a checklist and map it to what you already produced.

Section Content SignalDesk source
Introduction and goals What the system is for; top quality goals; stakeholders Product vision, SRS
Constraints Technical, organizational, and legal limits Architecture course
Context and scope System context view; external interfaces Context diagram
Solution strategy Key approaches in a few sentences Architecture patterns chosen
Building blocks Containers and components Container and component views
Runtime view Key scenarios Sequence diagrams
Deployment view Where containers run Deployment diagram (developed in the DevOps course)
Cross-cutting concepts Rules that apply across parts Section 5
Decisions Pointer to ADRs Lesson 7
Quality requirements Quality scenarios Architecture course, QA strategy
Risks and technical debt Known weaknesses Risk register
Glossary Terms Glossary

Keep each section short. Where a section has nothing to say yet, write “Not yet documented” instead of deleting it; an honest gap is useful.

4. Runtime Views

Static diagrams show structure; they do not show behavior. Document the few flows that matter most: those that cross containers, carry risk, or are hard to infer from code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
sequenceDiagram
    participant U as Admin
    participant A as API
    participant Q as Job queue
    participant W as Worker
    participant D as Database
    U->>A: POST /imports (CSV file)
    A->>D: create import (queued)
    A->>Q: enqueue import job
    A-->>U: 202 Accepted (import id)
    Q->>W: deliver job
    W->>D: insert valid rows (skip duplicates)
    W->>D: record rejected rows
    W->>D: mark import completed
    U->>A: GET /imports/id
    A-->>U: status and counts

Beside each sequence, note: what happens on failure (crash, retry, duplicate delivery), where data is persisted, and which step is asynchronous. For SignalDesk, the import flow, the summary generation flow with the model provider, and the authentication and workspace-scoping flow are candidates.

5. Cross-Cutting Concepts

Rules that apply everywhere are the easiest to forget and the most damaging when violated. Document each once, where engineers will look for it.

  • Tenancy and workspace isolation: how workspace scope is enforced, where, and what tests protect it.
  • Authentication and authorization: how identity is established and permissions checked.
  • Error handling and retries: error format, which errors are retried, idempotency.
  • Logging, metrics, and tracing: what is recorded and what must never be logged.
  • Data model and persistence rules: migrations, constraints, retention.
  • Use of AI components: what data is sent to the model provider, how outputs are validated, evidence linking, fallback when the provider fails, and cost controls.
  • Configuration and secrets: how they are supplied and where they must not appear.
  • Security boundaries: trust boundaries, input validation, dependencies.

State each concept as a rule with a reason and a pointer to where it is implemented and tested.

6. Quality Scenarios, Risks, and Debt

Tie the architecture to what it must achieve and where it is weak.

  • Quality scenarios: specific, measurable statements. “A 50,000-row import completes without blocking other requests (illustrative target).” Link each scenario to the tests or monitoring that check it, from the quality course.
  • Risks: carry forward the architecture risk register, updated with what testing and implementation revealed.
  • Technical debt: shortcuts taken knowingly, with consequences and the condition under which they should be repaid.

Honesty here builds trust. A document that lists no risks and no debt will not be believed.

7. Keeping Architecture Documentation True

Architecture documentation drifts quietly because nothing fails when it is wrong. Counter this deliberately:

  • Derive what you can. Container lists from deployment configuration, dependency graphs from import analysis, database diagrams from the schema, and API views from the contract. Generated views are correct by construction.
  • Check consistency automatically. For example, a script that compares container names in the diagram source with service names in the deployment configuration, or fails when a module imports another module that the architecture forbids.
  • Date and own each view. Front matter with an owner and a “last verified” date (lesson 10).
  • Review on change. The pull request checklist asks whether the change affects structure, flows, or cross-cutting rules.
  • Walk it with a newcomer. The best test of architecture documentation is whether a new engineer can use it to find where a change belongs.

8. Using AI for Architecture Documentation

AI can read a repository faster than a person and sketch a first view. Treat that sketch as a hypothesis.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
Act as a software architect documenting an existing system.

Inputs:
- Repository tree and key configuration files (deployment, build,
  dependency manifests): [paste]
- Module entry points and import relationships: [paste]
- Existing architecture notes, ADRs, and the SRS: [paste]

Tasks:
1. Propose a system context view and a container view as diagram
   source, listing for each element its responsibility and the file
   or configuration that evidences it.
2. Propose a component view for the API container, with evidence.
3. Draft a sequence for the import flow from the code, citing the
   functions involved.
4. List cross-cutting rules the code appears to follow (tenant
   scoping, error format), with example locations, and cases where
   it appears not to follow them.
5. List differences between the existing architecture notes and
   the code.

Mark anything inferred rather than evidenced. Do not add components
that have no evidence in the inputs.

Review each element: does it exist, is the relationship real, is anything missing? Pay particular attention to arrows, because plausible but nonexistent connections are the model’s most common error.

A second, valuable use is consistency review: give the model the diagrams, the prose, the ADRs, and the deployment configuration, and ask it to list contradictions, undefined terms, and components that appear in one but not the others. Then check each finding.

9. Practical Exercise

For SignalDesk (or your project):

  1. Write the system context and container views as diagram source, with an element table beneath each.
  2. Write one component view for the container with the most change.
  3. Write runtime views for the import flow, the summary generation flow, and the workspace-scoping flow, including failure behavior.
  4. Document at least five cross-cutting concepts, each as a rule, a reason, and a pointer to code and tests.
  5. List quality scenarios, linked to the tests or monitoring that check them, and update the risk register and technical debt list.
  6. Run the AI prompt, verify each claim against the repository, and record what was wrong.
  7. Add at least one automated consistency check between documentation and configuration or code.
  8. Have a person unfamiliar with the codebase use only the document to say where they would add a new CSV validation rule.

Verification

You are ready to continue when:

  • A newcomer can explain the system’s main parts and flows from your documents.
  • Every diagram element and arrow is labeled and has a described responsibility.
  • Cross-cutting rules are stated with reasons and with pointers to where they are implemented and tested.
  • Gaps, risks, and technical debt are stated, not hidden.
  • At least one view is generated from code or configuration, and one consistency check runs automatically.
  • Each view has an owner and a verification date.

Key Takeaways

  • Architecture documentation builds an accurate mental model; it does not describe everything.
  • Use context, container, and component views, plus runtime views for the flows that matter.
  • Document cross-cutting rules with reasons, and tie them to tests.
  • Be honest about risks and debt; derive and check views to keep them true.
  • AI can sketch from the repository, but every box and arrow must be verified.

What’s Next?

Diagrams show what the architecture is. The reasons behind it live in decisions, and decisions that are not recorded are forgotten or reopened. Next, we manage Architecture Decision Records over their whole lifecycle.