Documentation
Writing documentation people use — the four kinds of docs (tutorials, how-to guides, reference, explanation), READMEs, design docs and RFCs, architecture decision records, API docs, runbooks, diagrams as code, docs as code, and writing clearly for your audience.
Code tells a computer what to do. Documentation tells people why the system exists, how to use it, how it works, and what was decided along the way. Good docs make onboarding faster, reduce interruptions, prevent repeated mistakes, and let a team scale beyond what fits in anyone's head.
Know your audience and purpose
Before writing, answer: who will read this, what do they already know, and what do they need to do after reading? A new user, an integrating developer, a teammate on call at 3 a.m. and a future maintainer need very different documents.
The four kinds of documentation (Diátaxis)
| Type | Oriented to | Answers | Example |
|---|---|---|---|
| Tutorial | Learning | "Teach me" — a guided first success | "Build your first app in 15 minutes" |
| How-to guide | A task | "How do I…?" — steps for a specific goal | "How to rotate API keys" |
| Reference | Information | "What exactly is…?" — complete, accurate, terse | API reference, CLI flags, config options |
| Explanation | Understanding | "Why?" — background, concepts, trade-offs | "How our caching works and why" |
Mixing them is the most common docs problem: a tutorial derailed by every option, or a reference page that tries to teach. Keep each page one type and link between them.
The README
The front door of every repository. A good README answers, in order:
# invoice-service
Generates, stores and emails invoices for Acme orders.
## Quick start
git clone … && cd invoice-service
cp .env.example .env
docker compose up -d && npm install && npm run dev # http://localhost:3000
## Running tests
npm test # unit
npm run test:int # integration (needs Docker)
## Architecture
Express API → PostgreSQL; PDF rendering in a worker via the `invoices` queue.
See docs/architecture.md.
## Deployment
Merges to main deploy automatically via GitHub Actions. Runbook: docs/runbook.md.
## Ownership
Team Billing · #billing-eng · on-call via PagerDuty "billing"Test your README: can a new teammate get the project running using only it? If not, fix it — and ideally automate setup so the instructions stay short.
Design docs and RFCs
Before building something significant, write a design document (or RFC) and get feedback — changing a document is far cheaper than changing a system.
Typical structure:
- Context and problem: what's happening, why it matters, and who is affected.
- Goals and non-goals: what success looks like; what's explicitly out of scope.
- Proposed design: architecture, data model, APIs, key flows — with diagrams.
- Alternatives considered: and why they were rejected. Often the most valuable section.
- Trade-offs and risks: performance, cost, security, privacy, operational burden, migration.
- Rollout plan: phases, feature flags, migrations, rollback, monitoring.
- Open questions.
Keep it as short as the decision allows — a two-page doc that gets read beats a twenty-page one that doesn't. Share it early as a draft; reviewers' questions improve it. This is the same structure as a system design interview (System design).
Architecture decision records (ADRs)
Design docs get stale; the decisions remain important. An ADR is a short, immutable record of one significant decision, stored in the repo (docs/adr/0007-use-postgres-for-ledger.md):
# 7. Use PostgreSQL for the ledger
Status: Accepted (2026-11-18). Supersedes ADR 3.
## Context
We need strongly consistent, transactional storage for money movements,
with ~2k writes/s at peak and strict auditability.
## Decision
Use PostgreSQL (managed, multi-AZ) with append-only ledger tables.
## Consequences
+ ACID transactions and mature tooling; the team knows it well.
− Vertical write scaling limits; we'll revisit partitioning above ~10k writes/s.
− Requires disciplined migrations.When someone asks "why on earth do we use X?", the ADR answers — including the context that made it sensible at the time. Decisions are superseded by new ADRs, not edited.
API documentation
- Generate reference docs from the source of truth: OpenAPI specs, GraphQL schemas, protobuf files, docstrings/Javadoc/TSDoc (REST, GraphQL and gRPC).
- Every endpoint or function: purpose, parameters, return values, errors, auth requirements, rate limits, and at least one runnable example.
- Add tutorials and how-to guides for common integration tasks; reference alone doesn't teach.
- Document versioning and deprecation policies (Semantic versioning).
- Test examples in CI (doctests, executed code samples) so they don't rot.
Operational documentation
- Runbooks / playbooks: for each alert, what it means, how to diagnose, and how to mitigate — written for a stressed person at 3 a.m. Link them from the alert (Monitoring and SRE).
- Postmortems: blameless write-ups of incidents and their follow-ups.
- Service catalogue: owners, dependencies, dashboards, SLOs, on-call rotation (Backstage and similar internal developer portals).
- Onboarding guides for new teammates.
Code-level documentation
- Docstrings for public functions, classes and modules: what it does, parameters, return value, errors, examples.
- Comments explain why, not what (Clean code).
- Types are documentation the compiler checks — prefer expressive types over prose where possible.
- Tests are executable documentation of behaviour (Testing).
Diagrams
A good diagram often replaces pages of text. Use the C4 model levels to choose the right zoom: context (the system and its users and neighbours), containers (apps, databases, queues), components (inside one container), and code (rarely needed).
Prefer diagrams as code — Mermaid, PlantUML, D2, Structurizr — stored with the docs, reviewable in PRs, and easy to update:
sequenceDiagram
Client->>API: POST /invoices
API->>DB: insert invoice
API->>Queue: publish invoice.created
Worker->>Queue: consume
Worker->>Email: send PDFLabel every arrow, include a legend if shapes or colours carry meaning, and date diagrams that describe a changing system.
Docs as code
Treat documentation like code: Markdown in the repository, reviewed in PRs alongside the code change, built and published by CI (Docusaurus, MkDocs, Sphinx, Starlight, Next.js — like this site), with link checking and linting (Vale for style). Docs that live next to the code and change in the same PR stay accurate far longer than a separate wiki.
Writing clearly
- Lead with the point: the answer or action first, details after (inverted pyramid).
- Short sentences, plain words, active voice: "Run the migration" — not "The migration should be run".
- Concrete examples beat abstract descriptions.
- Structure for scanning: descriptive headings, lists, tables, code blocks; one idea per paragraph.
- Define terms and acronyms on first use; keep terminology consistent.
- Be inclusive and global: avoid idioms and jargon that don't translate; write for readers whose first language isn't English.
- Keep it current: delete or mark outdated docs — wrong documentation is worse than none. Put owners and "last reviewed" dates on important pages.
- Write for a specific audience and purpose; separate tutorials, how-to guides, reference and explanation.
- READMEs should get a newcomer running quickly and point to architecture, deployment and owners.
- Design docs capture problem, goals, design, alternatives, trade-offs and rollout before building.
- ADRs record significant decisions and their context immutably.
- Generate API reference from specs and add runnable, tested examples; keep runbooks for every alert.
- Use C4-level diagrams as code; keep docs in the repo and review them with code changes.
- Write clearly: point first, plain language, examples, scannable structure — and keep docs current.