Documentation Maintenance
This guide explains how the paiOS documentation system is structured and how to maintain it. Understanding this is crucial for keeping our documentation synchronized with the code.
Architecture Overview
Section titled “Architecture Overview”We use a Hybrid Documentation Strategy for our codebase to provide the best developer experience:
- Native Starlight Integration: Rustdoc JSON is converted to MDX files. This provides a consistent look and feel, native search, and integrated navigation.
- Standard rustdoc HTML: The traditional
cargo docoutput is generated and hosted alongside Starlight. This provides the deep-dive technical details Rust developers are familiar with. - Protocol Buffer Documentation: Proto files are automatically parsed and converted to MDX, providing integrated gRPC API documentation with the same look and feel as the rest of the documentation.
Directory Structure
Section titled “Directory Structure”docs/scripts/: Contains the logic for generating documentation.rustdoc-gen.mjs: Converts Rustdoc JSON (unstable) to MDX.rustdoc-html.mjs: Generates and copies standard HTML docs.proto-doc-gen.mjs: Parses Protocol Buffer files and generates MDX documentation.
docs/public/reference/rustdoc/html/: Where the static rustdoc HTML files live.docs/src/content/docs/reference/rust/: Where the generated Rust MDX files are stored.docs/src/content/docs/reference/api.mdx: Where the generated Protocol Buffer documentation is stored.docs/src/pages/reference/rustdoc/: Contains the Astro redirect logic.
Common Tasks
Section titled “Common Tasks”Generating Documentation
Section titled “Generating Documentation”Documentation generation is automatically part of the main build process:
# From the docs directorynpm run buildTo run only the documentation generation:
# Generate Rust documentation (both MDX and HTML)npm run gen:rustdoc && npm run gen:rustdoc:html
# Generate Protocol Buffer documentationnpm run gen:proto
# Generate all documentationnpm run gen:rustdoc && npm run gen:rustdoc:html && npm run gen:protoUpdating the Generation Logic
Section titled “Updating the Generation Logic”For Rust Documentation:
If you add new Rust modules or change the crate structure:
- Check
docs/scripts/rustdoc-gen.mjsto ensure the module hierarchy is still handled correctly. - The script uses the
nightlytoolchain for JSON export. You need to set up your environment:
# Install nightly toolchainrustup toolchain install nightly
# Add the required JSON documentation componentrustup component add rust-docs-json --toolchain nightlyNote: Documentation generation will automatically use the +nightly modifier when running through our scripts.
For Protocol Buffer Documentation:
If you add or modify .proto files:
- Place your
.protofiles inengine/proto/. - The
proto-doc-gen.mjsscript will automatically detect and parse them. - The script supports two modes:
- protoc-gen-doc (if installed): Uses the external tool for better formatting
- Built-in parser (fallback): Parses proto files directly without external dependencies
- Generated documentation is written to
docs/src/content/docs/reference/api.mdx.
To install protoc-gen-doc for enhanced formatting (optional):
go install github.com/pseudomuto/protoc-gen-doc/cmd/protoc-gen-doc@latestRouting and Redirects
Section titled “Routing and Redirects”To provide clean URLs like /reference/rustdoc/engine/index, we use Astro’s native redirect system in astro.config.mjs.
Important:
- Never place static files directly in
public/reference/rustdoc/engine/as they will override the Astro redirect routes. - The actual files are stored in
public/reference/rustdoc/html/.
Preventing Regressions (AI Agents)
Section titled “Preventing Regressions (AI Agents)”When working with AI agents like Cursor or TaskMaster:
- Ensure they are aware of the
docs-maintenancerule set. - If an agent modifies the documentation structure, verify that the
npm run buildstill successfully generates all formats (Rust MDX, Rust HTML, and Proto MDX). - Check that the
dist/output contains both the MDX pages and thehtml/subdirectory in the correct locations. - Verify that
api.mdxis generated correctly when proto files are present.