RepoDoc: Building Better Code Documentation with Knowledge Graphs — AI Innovations and Insights 145
Writing documentation feels satisfying until the next pull request makes part of it outdated.
For large, fast-changing repositories, keeping documentation trustworthy can be harder than creating it.
Why Repository Documentation Keeps Falling Behind
Current LLM-powered documentation tools can generate documentation, but producing repository-level docs that are well structured, coherent, affordable, and accurate as the codebase evolves remains difficult.
Three core problems stand out.
Fragmented Documentation Structure: Most existing tools split code by directory, file, or fixed token limits rather than by functionality and dependency relationships. Under those designs, documentation can become fragmented: individual APIs may be described, while cross-module relationships and an architectural overview are harder to preserve.
High Generation Costs: In the two representative baselines, RepoAgent injects caller-callee context, while CodeWiki carries source code, submodule documentation, and structural information into higher-level prompts. This context stacking increases token use and runtime, especially as repositories grow.
Inaccurate Incremental Updates: A small code change can affect far more than the file where it was made. Its impact may spread through function calls, inheritance relationships, interface implementations, and module dependencies. Existing approaches often detect changes only at the file level. Others regenerate all documentation from scratch. Neither design performs the graph-based semantic impact analysis that RepoDoc uses to target documentation components after a change.

In one sentence, existing approaches can write documentation, but they do not treat a code repository as a connected system that continuously evolves.
So here comes a simple idea: build a repository knowledge graph called RepoKG and use it throughout the entire documentation lifecycle. RepoKG can organize code by function and meaning, retrieve only the context that matters, and trace code changes through dependency relationships. As a result, only the documentation that is genuinely affected needs to be updated.
RepoDoc: From Stale Docs to Living Documentation
RepoDoc takes a graph-first approach: it turns a code repository into a knowledge graph, then uses that graph to generate and maintain documentation.
The initial generation pipeline has three phases: RepoKG construction, module clustering, and documentation generation. Incremental maintenance is a separate four-stage workflow.

1. Build the Repository Knowledge Graph, RepoKG
For Python, RepoDoc uses the language’s native AST; for the other supported languages, it uses Tree-sitter to extract functions, classes, interfaces, and modules. It then maps relationships between them, including function calls, imports, inheritance, interface implementations, and containment.

