Abstract
Large-scale codebases present significant challenges for automated documentation due to context window limitations and architectural complexity. We present CodeWiki, an open-source framework that utilizes a recursive "divide-and-conquer" agent system to generate architecture-aware documentation. By decomposing repositories into hierarchical module trees and synthesizing documentation bottom-up, CodeWiki captures high-level design patterns often missed by flat summarization tools. We also introduce CodeWikiBench, a benchmark employing hierarchical AI-driven rubrics for evaluation. Our results show that CodeWiki outperforms existing baselines, particularly in scripting languages, achieving a 68.79% average quality score and gaining strong human preference.
Introduction
While Large Language Models (LLMs) are excellent at documenting individual functions or files, they struggle with "repository-level" documentation. Two main hurdles exist:
- Context Limits: Large codebases far exceed the memory (context window) of even the most advanced LLMs, making it impossible for a model to "see" the entire system at once.
- Architectural Blindness: Existing tools often produce a flat list of summaries but fail to capture the "big picture"—how modules interact, how data flows through the system, and the high-level design patterns that govern the project.
Furthermore, evaluating whether a generated README is actually good is notoriously difficult. Traditional metrics like BLEU or ROUGE only measure how much the text "overlaps" with a reference, failing to capture whether the documentation is technically accurate or architecturally sound.
Methods: The CodeWiki Framework
CodeWiki employs a three-phase approach to bridge the gap between low-level code and high-level architecture:
- Top-Down Hierarchical Decomposition: The system uses static analysis (AST parsing) to build a dependency graph of the repository. It then breaks the codebase into a "module tree," ensuring that each piece is small enough for an LLM to process while maintaining logical boundaries.
- Recursive Agent System: A "divide-and-conquer" agent workflow processes the tree. If a module is still too complex, the agent dynamically delegates sub-tasks to specialized sub-agents. This allows the system to scale to repositories of arbitrary size.
- Bottom-Up Synthesis: Once the "leaf" modules are documented, the system synthesizes these details upward. It doesn't just aggregate text; it uses LLMs to generate high-level overviews and visual artifacts, such as Mermaid-based architecture and data-flow diagrams.
Evaluation and CodeWikiBench
For evaluation, the authors created CodeWikiBench, a multilingual benchmark consisting of 7 prominent open-source repositories covering a wide range of scales (86K to 1.4M lines of code) and seven mainstream programming languages (Python, JavaScript, TypeScript, C#, Java, C, and C++).
Instead of simple text comparison, CodeWikiBench uses a "Rubric Generator Agent" to extract requirements from official documentation. Then, a panel of "Judge Agents" evaluates the generated documentation against these specific, hierarchical criteria. This "LLM-as-a-Judge" approach is guided by a hierarchical rubric, breaking complex evaluations into binary "adequacy decisions" for higher reliability.
Key Results and Insights
CodeWiki achieved an average quality score of 68.79%, outperforming the leading closed-source baseline (DeepWiki) by 4.73%. The framework showed particularly strong gains in scripting languages like TypeScript (+18.54%) and Python (+9.41%).
Key insights from the study include:
- Relationships > Summaries: Repository documentation is about relationships, not just content. By focusing on the dependency graph, CodeWiki preserves the "mental map" of the architecture.
- Language Sensitivity: Documentation quality is heavily influenced by the programming language. Scripting languages are significantly easier for AI to document than systems languages (C, C++), likely due to the latter's complex memory management and metaprogramming patterns.
- Human Validation: In a pilot study, humans preferred CodeWiki’s documentation in 77.8% of cases, citing better coverage of repository architecture.
- Scalability: Recursive delegation allowed CodeWiki to handle the 1.4M LOC Wazuh repository effectively, whereas "whole-repo" prompting methods typically fail at that scale.
Conclusion and Future Work
While CodeWiki represents a significant step forward, performance on systems languages like C and C++ remains lower (around 53-64%) due to complex constructs like pointers and templates. Future work aims to improve parsing strategies for these languages and explore "version-aware" documentation that automatically updates as a codebase evolves, acting as a semantic bridge for tasks like code migration.
Summary updated