Documentation Standards
Enterprise-level documentation standards for production engineering teams. These rules apply to code comments, API documentation, README files, architecture decision records, and runbooks.
Why Documentation Matters in Production
Good documentation reduces the time it takes to:
- onboard a new team member
- debug an incident at 2am
- review a pull request safely
- understand a decision made six months ago
Documentation that is out of date is worse than no documentation. Every standard here is chosen to keep documentation close to the code and easy to maintain.
Levels of Documentation
flowchart LR
A[Code] --> B[Inline Comments]
A --> C[API Docs]
A --> D[Module README]
A --> E[ADR]
A --> F[Runbook]
| Level | Purpose | Where it lives |
|---|---|---|
| Inline comments | Explain non-obvious logic | Next to the code |
| API documentation | Describe contracts and examples | OpenAPI spec, XML doc comments |
| Module README | Setup, architecture, local run | Root of each service or library |
| ADR | Record architectural decisions | docs/decisions/ |
| Runbook | Operational procedures | docs/runbooks/ |
Inline Comments
Write comments that explain why, not what. The code already shows what it does.
// Avoid: restating the code
// Increment the counter
counter++;
// Prefer: explaining the reason
// Offset by one because the page index is zero-based but the display is 1-based
var displayPage = pageIndex + 1;
When to write a comment:
- the logic is non-obvious or counter-intuitive
- there is a known limitation or workaround in place
- a business rule is being enforced that is not obvious from names alone
When not to write a comment:
- to explain a method that should simply have a better name
- to narrate every line of straightforward code
API Documentation
Every public API endpoint must be documented with a description, input schema, and response examples.
C# with XML doc comments
/// <summary>
/// Creates a new order for a customer.
/// Returns 422 if the payload fails validation.
/// </summary>
/// <param name="request">The order creation request payload.</param>
/// <param name="cancellationToken">Propagated cancellation token.</param>
/// <returns>The created order identifier and summary.</returns>
[HttpPost]
[ProducesResponseType(typeof(CreateOrderResponse), StatusCodes.Status201Created)]
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status422UnprocessableEntity)]
public async Task<IActionResult> CreateOrder(
CreateOrderRequest request,
CancellationToken cancellationToken)
Python with FastAPI docstrings
@router.post("/orders", status_code=201, response_model=CreateOrderResponse)
async def create_order(request: CreateOrderRequest) -> CreateOrderResponse:
"""
Create a new order for a customer.
Returns 422 if the request fails validation.
Returns 201 with the created order summary on success.
"""
Module README
Every deployable service or shared library must have a README at its root.
Required sections
## ServiceName
One sentence describing what this service does and who owns it.
### Architecture overview
Brief description of the technology stack and key design decisions.
### Prerequisites
- .NET 9 SDK
- Docker 24+
- PostgreSQL 16
### Local development
Steps to run the service locally.
### Environment variables
| Variable | Description | Required |
|---|---|---|
| DATABASE_URL | Connection string for the main database | Yes |
| PAYMENT_API_KEY | API key for the payment provider | Yes |
### Running tests
Command to run unit and integration tests.
### Deployment
Link to deployment pipeline and environment overview.
Keep this file accurate. Stale READMEs erode trust faster than no README at all.
Architecture Decision Records (ADRs)
An ADR captures a significant architectural or technical decision and its rationale. It is a short, durable record that explains why a choice was made.
File naming
docs/
decisions/
0001-use-postgresql-as-primary-store.md
0002-event-driven-order-notifications.md
0003-adopt-react-query-for-server-state.md
ADR template
## ADR-0001: Use PostgreSQL as the primary data store
### Status
Accepted
### Date
2024-11-01
### Context
The Orders service needs a relational store with ACID guarantees and strong support
for complex queries. The team has existing operational experience with PostgreSQL.
### Decision
Use PostgreSQL 16 as the primary data store for the Orders service.
### Consequences
- Positive: strong query capabilities, reliable transactions, familiar tooling
- Negative: requires managed hosting; not suitable for document-heavy workloads
When to write an ADR
- choosing a framework or database
- adopting a new pattern or integration strategy
- replacing an existing technology
- any decision that future engineers might question
Runbooks
A runbook describes how to operate a service in production. It is the operational companion to the README.
Runbook structure
## Service Name - Runbook
### Common alerts
#### HighErrorRate
**Trigger:** Error rate exceeds 5% for 5 minutes.
**Impact:** Customers may fail to complete orders.
**Investigation steps:**
1. Check recent deployments in the pipeline.
2. Review error logs filtered by `level=error` in the last 30 minutes.
3. Check the payment provider status page.
**Resolution:** Roll back the last deployment if a code change is the cause.
---
### Restart the service
```powershell
kubectl rollout restart deployment/orders-service -n production
Scale up under load
kubectl scale deployment/orders-service --replicas=5 -n production
Runbooks should be tested. If a runbook is written but never validated, it cannot be trusted during an incident.
---
### Documentation in Pull Requests
Every pull request that changes behaviour must update documentation in the same change.
Checklist:
- updated inline comments if logic changed
- updated API docs if contract changed
- updated README if setup or configuration changed
- added or updated an ADR if a significant architectural decision was made
- updated or created a runbook entry if operational behaviour changed
---
### Common Pitfalls
- documentation written once and never updated
- ADRs never reviewed or superseded when decisions change
- runbooks that reference outdated commands or deprecated tools
- README files with incorrect setup steps that waste new developer time
- over-documenting obvious code while under-documenting operational behaviour
---
### Key Takeaways
- document why, not what
- keep documentation in the same repository as the code it describes
- a README, ADR, and runbook together cover the full lifecycle of a service
- documentation updated in the same pull request as code is the only documentation that stays accurate
- test runbooks before relying on them in incidents