Treat documentation like code. Covers docs-as-code tooling, ADRs, API documentation, runbooks, and keeping documentation current alongside your codebase.
Documentation-as-Code is the practice of treating documentation as source code that lives in version control and is built as part of the software delivery pipeline. This approach applies when documentation must remain synchronized with code, or when teams need to maintain multiple versions of technical content alongside releases.
Documentation-as-Code begins with placing documentation files in the same repository as source code. These files are typically stored in a dedicated directory such as docs/ or documentation/. The format is usually Markdown (*.md) but may include reStructuredText or other markup languages supported by the build system.
The typical workflow involves editing documentation files directly in the repository, committing changes alongside code changes, and building documentation artifacts during the CI/CD pipeline. Documentation is not stored in a separate wiki or content management system; it is treated as part of the source tree.
Documentation files are usually versioned with the same Git history as the code they describe. Each commit should include documentation updates that reflect the corresponding code changes. When a feature is added, the documentation should be included in the same pull request or merge request as the implementation.
Documentation is built using tools that convert source files into static web pages or other formats. Common tools include:
The build process typically uses a configuration file such as mkdocs.yml, config.toml, or mkdocs.json to define how source files are processed and organized. The configuration specifies the source directory, output directory, navigation structure, and any plugins or extensions.
Example MkDocs configuration:
site_name: My Project Documentation
nav:
- Home: index.md
- API Reference: api-reference.md
- User Guide: user-guide.md
theme:
name: material
The build process should validate documentation syntax, check for broken links, and ensure all code examples compile or execute correctly. This validation typically runs as part of the CI pipeline.
Documentation versions are handled by maintaining separate branches or tags in Git that correspond to software releases. Each versioned release has its own documentation branch (e.g., release/v1.2, release/v2.0) or tag that is built and published independently.
Version-specific documentation requires careful handling of links between versions. Cross-references should be relative when possible, or use version-aware URLs that redirect to the correct version of content.
Documentation versioning should align with software versioning practices. When a major version changes, documentation should also be versioned to match. This means maintaining multiple documentation branches simultaneously.
Documentation should be co-located with code that it describes. For example, API documentation for a library should reside in the same repository as the library source code. This ensures that documentation changes are reviewed alongside code changes and that documentation is always current with the implementation.
Code examples in documentation should be tested to ensure they compile or execute correctly. This can be done by including executable code blocks or by running integration tests that verify documentation content matches actual behavior.
Changes to documentation follow the same review and approval workflow as code changes. Pull requests containing documentation updates must be reviewed and approved before merging. Reviewers should check not only for correctness but also for clarity, completeness, and consistency with existing documentation.
Documentation reviews should consider whether changes are consistent with existing patterns in the documentation set, whether examples are complete and correct, and whether the content accurately reflects current implementation details.
Published documentation is typically served from a static site hosted on platforms like GitHub Pages, Netlify, or custom infrastructure. The publishing process involves building the documentation site and uploading it to the hosting platform.
Documentation sites should include features such as search functionality, version selection, and navigation aids. These features help users find information quickly and access documentation for different software versions.
The most frequent failure in Documentation-as-Code is allowing documentation to drift from code without synchronization. This happens when documentation changes are not required to be part of the same commit or pull request as code changes.
Documentation builds can silently fail due to broken links or missing files. The build process should validate all references and ensure that every documented feature has a corresponding implementation.
Documentation quality is maintained through consistent formatting, use of templates, and adherence to style guides. This includes consistent terminology, structure, and presentation of information.
Documentation should be written for the intended audience, whether that's end users, developers, or system administrators. The tone and technical level should match the expected reader's expertise.
Documentation structure is defined in configuration files that specify navigation, grouping, and organization. These files define how documentation is presented to readers and how they can navigate between topics.
Navigation should be intuitive and reflect the logical flow of information. Cross-references between documents should be clear and consistent. Each document should have a clear purpose and scope.
Documentation validation should include checking for broken links, missing images, and syntax errors in markup files. The validation process should run automatically as part of the CI pipeline before code changes are merged.
Validation tools can check that all code examples compile correctly, that API references match actual implementations, and that documentation is consistent across versions.
Documentation may depend on external resources such as images, code samples, or data files. These dependencies should be versioned alongside documentation and managed through the same source control system.
When documentation references external APIs or services, those references should be stable and documented with appropriate version information to avoid broken links in future releases.
This page was rewritten on 15 October 2026. It replaced a templated version that was not specific to its own title. How these pages are written and checked. If anything here is wrong, tell us at [email protected] and we will correct it.
We use cookies for analytics (Google Analytics) and advertising (Google AdSense) to improve your experience and support free content. Privacy Policy