Skip to main content

Living Documentation: link docs to code and check freshness when signatures change

Project description

Living Documentation

Living Documentation Check License: MIT

A tool that links documentation to code so it stays up to date. When function signatures, APIs, or arguments change, the system marks related documentation paragraphs as "possibly outdated" and suggests what to fix.

Goals

  • Code ↔ doc linking: explicit mapping between code entities (functions, classes, APIs) and documentation fragments
  • Freshness checking: after code changes — mark outdated sections and suggest updates
  • Contextual view (planned): show the relevant doc fragment in the IDE when hovering over a function or method call
  • Docs next to code: store documentation in the repository and view it as a site with navigation and search

Where to Start (recommendation)

Recommended order:

  1. Code ↔ documentation mapping format — without it, you can't unambiguously link a doc paragraph to a code entity. Define this first.
  2. Repository structure and stack — one language for MVP (Python), shared architecture for future languages and IDE support.
  3. Prototype on one example — one module, one doc page, code parser, and a check that "the document is outdated after a code change."

In short: first the format and structure, then a minimal prototype.

Architecture Overview

┌─────────────────┐     ┌──────────────────┐     ┌─────────────────────┐
│  Code parser    │────▶│  Link graph      │◀────│  Doc parser         │
│  (AST / API)    │     │  (code_id ↔ doc) │     │  (markdown + anchors)│
└────────┬────────┘     └────────┬──────────┘     └─────────────────────┘
         │                      │
         ▼                      ▼
┌─────────────────┐     ┌──────────────────┐
│  Change         │     │  Report / site   │
│  detector       │────▶│  "outdated" +    │
│  (diff / hash)  │     │  suggestions     │
└─────────────────┘     └──────────────────┘
  • Code parser: extracts signatures (name, arguments, types) and unique identifiers (e.g., module.function or file:line).
  • Doc parser: parses Markdown with explicit anchors (see spec/code-doc-mapping.md), associating paragraphs/blocks with code_id.
  • Link graph: stores (code_id, doc_fragment_id) pairs. When code changes (new signature/hash), related fragments are marked as "possibly outdated."
  • Change detector: compares current code state (signatures/hashes) with the last saved state.

Extensibility: code and doc parsers are per-language plugins; the graph and report are shared.

Documentation Format

  • Primary format: Markdown in the repository (e.g., a docs/ folder or next to modules).
  • Linking to code: anchors in Markdown (see spec/code-doc-mapping.md), optionally plus annotations in code (docstring tags) that reference a fragment id.
  • Site: generate a static site (MkDocs, Docusaurus, or custom) from the same Markdown files; navigation and search on top of the generated site.

MVP (First Iteration)

  • Language: Python
  • Features:
    • Parse modules (functions, methods, signatures)
    • One documentation page with anchors to those entities
    • Check: when a signature changes in code, the related doc paragraph is marked as outdated
  • Extensibility: abstractions for the code parser and anchor format to support more languages and IDE integration later.

Repository Structure

LiveDoc/
├── README.md                 # this file
├── spec/
│   └── code-doc-mapping.md  # anchor format and code↔doc mapping
├── src/
│   └── livedoc/
│       ├── __init__.py
│       ├── core/            # link graph, change detector
│       ├── parsers/         # Python code parser, doc parser
│       └── report/          # "outdated" report, future site generation
├── tests/
├── examples/                # sample project for testing MVP
│   ├── sample_module/
│   └── docs/
└── pyproject.toml

Quick Start (Add to Your Project)

  1. Install: pip install livedoc (or pip install -e . from this repo)

  2. Create docs in docs/ with anchors linking to code:

    <!-- livedoc: code_id = "mymodule.calc:add" -->
    ## add
    Adds two numbers.
    
  3. First run (saves code signatures):

    livedoc --docs docs
    
  4. CI: Add to your workflow:

    - run: pip install livedoc && livedoc --docs docs
    
  5. Optional: Add .livedocignore in project root (one pattern per line) to exclude paths:

    build
    scripts
    

Running the MVP (This Repo)

# Install (optional, for livedoc command)
pip install -e .

# Check links and freshness for the example (from repo root)
python -m livedoc.cli examples --docs docs

# First run saves code signatures to examples/.livedoc/code_signatures.json.
# After changing a function/method signature, the next run will show
# related doc fragments as "possibly outdated" with a diff of old vs new signature.
# To update signatures after editing docs: --update

# Options:
#   --ignore PATTERN   Exclude paths (e.g. --ignore mytests, can be repeated)
#   --format json      Machine-readable output for CI/scripts
#   .livedocignore     File with ignore patterns (one per line)

CI (GitHub Actions)

The workflow .github/workflows/livedoc.yml runs livedoc check on push and pull requests. The examples/.livedoc folder with signatures is committed so CI has a baseline. If code changes without updating docs or without --update, the job fails.

Publishing to PyPI

pip install build twine
python -m build
twine upload dist/*

Requires a PyPI account and token. First time: twine upload dist/* will prompt for credentials.

Next Steps

  • Add parsers for other languages in parsers/
  • IDE integration: LSP or extension (show docs on hover)
  • Generate and serve a documentation site with "outdated" highlights

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

living_doc-0.1.0.tar.gz (15.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

living_doc-0.1.0-py3-none-any.whl (14.1 kB view details)

Uploaded Python 3

File details

Details for the file living_doc-0.1.0.tar.gz.

File metadata

  • Download URL: living_doc-0.1.0.tar.gz
  • Upload date:
  • Size: 15.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.0

File hashes

Hashes for living_doc-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c16cd93c1348b8538d47f293769071da4f9fbe987b6ec167297ddf439e20278f
MD5 50bca749a7999f526fbd5aa7c36bf22d
BLAKE2b-256 82b11eb837fef77a971302483d2623a8606c8b36b7773895d2c0a48cd9d118cf

See more details on using hashes here.

File details

Details for the file living_doc-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: living_doc-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 14.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.0

File hashes

Hashes for living_doc-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ba698a4b38539245eb144b445cef422bd9f220faca7952d3c7773aad10ef908e
MD5 02d17dfe88848b58a32a1eb7b6c66cfd
BLAKE2b-256 122b6e6ea79742ef5a87e17d31842feac4c578c02d56785b526ebf70d91c39d9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page