TechDocs: Docs Next to the Code
Documentation in a wiki drifts away from the code it describes: nobody updates the wiki page in the same pull request as the code. Docs-like-code fixes that by keeping Markdown in the service's repository, reviewing it with the code and publishing it automatically. Backstage's implementation is TechDocs: MkDocs-based docs that appear on the entity's page in the portal, next to its owner, APIs and deployments.
The three pieces
Markdown in the repository, usually in
docs/, with anmkdocs.ymlat the root.An annotation in
catalog-info.yamltelling Backstage where the docs are:yamlmetadata: name: linkly annotations: backstage.io/techdocs-ref: dir:. # mkdocs.yml is in the same directory as this fileA build and a publisher: MkDocs with the
techdocs-coreplugin turns the Markdown into a static site, which is stored somewhere Backstage can read it.
A minimal mkdocs.yml:
site_name: linkly
nav:
- Overview: index.md
- Architecture: architecture.md
- Runbook: runbook.md
- API: api.md
plugins:
- techdocs-coreBasic vs recommended setup
| Basic | Recommended | |
|---|---|---|
| Who builds | the Backstage backend, on first view (techdocs.builder: local) |
the service's CI pipeline, with techdocs-cli |
| Where it's stored | local disk of the backend | object storage (S3, GCS, Azure Blob), techdocs.builder: external |
| Good for | trying it out | production: builds are reviewed, fast to view, no MkDocs in the backend |
The CI job for the recommended setup, as a sample (it needs the cloud bucket and credentials):
# .github/workflows/techdocs.yaml (sample)
name: techdocs
on:
push:
branches: [main]
paths: [docs/**, mkdocs.yml]
permissions:
id-token: write # OIDC to the cloud, no stored keys
contents: read
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- uses: actions/setup-node@v5
with: {node-version: 24}
- uses: actions/setup-python@v6
with: {python-version: "3.13"}
- run: pip install mkdocs-techdocs-core
- run: npx @techdocs/cli generate --no-docker --verbose
- uses: aws-actions/configure-aws-credentials@v5
with:
role-to-assume: arn:aws:iam::123456789012:role/techdocs-publisher
aws-region: eu-west-1
- run: npx @techdocs/cli publish --publisher-type awsS3 --storage-name acme-techdocs --entity default/component/linklyWhat every service's docs should contain
The golden path puts a skeleton of these pages into every new service, so writing docs is filling in blanks rather than starting from nothing:
| Page | Contents | Read by |
|---|---|---|
index.md |
what the service does, who owns it, how to run it locally | everyone |
architecture.md |
a diagram, dependencies, data flows, decisions (link ADRs) | new team members, reviewers |
runbook.md |
one section per alert: what it means, how to check, how to fix (SRE: runbooks) | on-call |
api.md |
links to the API entity and its OpenAPI definition | consumers |
slo.md |
the SLO document (SRE: writing an SLO document) | product, on-call |
Checking docs in the pull request
Two cheap checks catch most broken docs before they're published: every page in nav exists, and every relative link points at a file that exists. Both need nothing more than yq and grep:
mkdir -p linkly/docs && cd linkly
cat > mkdocs.yml <<'EOF'
site_name: linkly
nav:
- Overview: index.md
- Architecture: architecture.md
- Runbook: runbook.md
- SLO: slo.md
plugins:
- techdocs-core
EOF
printf '# linkly\n\nSee the [runbook](runbook.md) and the [architecture](architecture.md).\n' > docs/index.md
printf '# Architecture\n\nDecisions are in [ADRs](adr/0001-redis-cache.md).\n' > docs/architecture.md
printf '# Runbook\n\n## LinklyHighErrorRate\n\nCheck the [dashboard](https://grafana.example.com/d/linkly).\n' > docs/runbook.md
errors=0
echo "nav entries:"
for page in $(yq '.nav[] | .[]' mkdocs.yml); do
if [ -f "docs/$page" ]; then echo " ok $page"; else echo " MISSING $page"; errors=$((errors + 1)); fi
done
echo "relative links:"
for md in docs/*.md; do
grep -o '](\([^)#]*\.md\))' "$md" | sed 's/^](//; s/)$//' | while read -r target; do
[ -f "$(dirname "$md")/$target" ] || echo " BROKEN $md -> $target"
done
done | tee links.txt
errors=$((errors + $(wc -l < links.txt)))
grep -q 'techdocs-core' mkdocs.yml && echo "plugin techdocs-core: ok"
echo "$errors problem(s)"nav entries:
ok index.md
ok architecture.md
ok runbook.md
MISSING slo.md
relative links:
BROKEN docs/architecture.md -> adr/0001-redis-cache.md
plugin techdocs-core: ok
2 problem(s)
In CI you would also run techdocs-cli generate (MkDocs fails on some structural problems) and, optionally, a prose linter such as Vale for house style.
Docs as a scorecard input
Whether a service has docs is easy to measure from the catalog (the annotation is there) and from the repo (the files exist and were touched in the last N months). Those facts feed the next lesson's scorecards. Measuring whether docs are good is harder: the most useful proxy is asking on-call engineers after each incident whether the runbook helped.
Test yourself
What does backstage.io/techdocs-ref: dir:. tell Backstage?
- Where the source code is
- That the docs (mkdocs.yml) are in the same directory as the catalog-info.yaml
- To disable docs
- The docs URL in S3
In the recommended TechDocs setup, who builds the docs site?
- The Backstage backend on first view
- The service's CI pipeline, which publishes the result to object storage
- Developers on their laptops
- MkDocs inside the browser