Auto-generated Project Wiki
Relevant source files
The following files were used as context for generating this wiki page:
The Auto-generated Project Wiki is a feature within the code-review-graph project designed to transform the structural data of a code knowledge graph into a navigable, human-readable Markdown documentation suite. It primarily focuses on representing code "communities"—clusters of related functions and classes detected via algorithms like Leiden—alongside their execution flows and dependencies.
This system enables developers and AI agents to gain a high-level architectural understanding of a codebase without manually parsing the source. The wiki is stored locally within the .code-review-graph/wiki/ directory and includes an index page for navigation and detailed pages for each detected community.
Sources: code_review_graph/wiki.py:1-12, code_review_graph/tools/docs.py:186-200, code_review_graph/main.py:461-477
Architecture and Data Flow
The wiki generation process follows a specific pipeline: it extracts community data from the GraphStore (SQLite database), processes it into Markdown content, and writes it to the local filesystem. It uses a "slugification" mechanism to ensure community names are converted into safe, unique filenames.
Generation Logic
The generate_wiki function coordinates the creation of the documentation. It identifies all communities stored in the graph and generates a corresponding .md file for each. To prevent data loss or file overwrites when two communities have similar names, the system appends a numeric suffix to colliding slugs.
Page Components
Each community page is structured to provide a comprehensive view of a code cluster:
- Overview: Displays metadata such as size (node count), cohesion score, and the dominant programming language.
- Members Table: Lists the first 50 nodes (functions, classes) within the community, including their file paths and line ranges.
- Execution Flows: Identifies the top 10 execution paths that pass through members of the community, including criticality and depth scores.
- Dependencies: Breaks down cross-community relationships into "Outgoing" (targets outside the community) and "Incoming" (sources outside the community) edges.
Sources: code_review_graph/wiki.py:27-131
Key Functions and Tools
The wiki system is exposed through both internal API functions and MCP (Model Context Protocol) tools for AI integration.
Core Implementation Functions
| Function | Purpose |
|---|---|
generate_wiki | The main entry point for creating/updating the wiki directory. |
get_wiki_page | Retrieves the content of a specific wiki page via community name lookup. |
_slugify | Converts community names to safe filenames (e.g., "Auth Service" to "auth-service"). |
_generate_community_page | Internal helper that constructs the Markdown string for a single community. |
Sources: code_review_graph/wiki.py:20-221
MCP Tools for AI Agents
These tools allow AI coding assistants to interact with the generated wiki:
generate_wiki_tool: Triggers the generation process. It can be forced to regenerate all pages using theforce=Trueparameter.get_wiki_page_tool: Allows an agent to read specific architectural documentation based on a community name.
Sources: code_review_graph/main.py:461-487, code_review_graph/tools/docs.py:186-241
Integration with Architecture Mapping
The wiki is a key component of the project's architecture mapping workflow. Prompts like architecture_map suggest calling generate_wiki_tool to create a formal record of the codebase structure.
Implementation Details
File Handling and Change Detection
The generation logic is designed for efficiency. By default, it performs change detection by comparing existing file content with the newly generated Markdown. It only updates files on disk if the content has actually changed, unless the force flag is used.
# snippet from code_review_graph/wiki.py
if filepath.exists() and not force:
existing = filepath.read_text(encoding="utf-8", errors="replace")
if existing == content:
pages_unchanged += 1
page_entries.append((slug, name, comm["size"]))
continue
Sources: code_review_graph/wiki.py:168-174
Dependency and Flow Analysis
The wiki module queries the GraphStore for both execution flows and edges. It filters get_flows results to find paths that intersect with the specific member_set of a community. For dependencies, it uses get_outgoing_targets and get_incoming_sources to identify how the community interacts with the rest of the system.
Sources: code_review_graph/wiki.py:79-129, tests/test_integration_v2.py:116-160
Conclusion
The Auto-generated Project Wiki provides a persistent, structured documentation layer that bridges the gap between raw code analysis and architectural understanding. By leveraging community detection and flow tracing, it offers a dynamic view of the project that updates alongside the code, accessible to both human developers and automated tools.