How Automatic Wiki Generation Creates Markdown Pages in code‑review‑graph
The code-review-graph CLI tool automatically converts detected code communities into markdown wiki pages through the generate_wiki command in code_review_graph/wiki.py, using Jinja templates with optional LLM-powered summaries.
The code-review-graph repository by tirth8205 provides a graph-based code analysis system that can export its findings as publishable documentation. The automatic wiki generation feature transforms community detection results into a structured set of markdown files, ready for GitHub Wikis or static site generators.
How Community Detection Feeds Wiki Generation
The wiki creation pipeline begins during the standard graph build process. When you run code-review-graph build, the list_communities tool—defined in communities.py—clusters related nodes into logical groups. These communities represent architectural boundaries: packages, subsystems, or domain layers.
Each community object carries three pieces of metadata:
- A name (e.g., "Data Processing" or "Auth Middleware")
- A description (structural context)
- A member node list (files, functions, or classes belonging to the group)
This community data becomes the input for the markdown generation phase.
The generate_wiki Implementation in wiki.py
The core orchestration lives in code_review_graph/wiki.py. The generate_wiki() function processes every detected community through four distinct steps:
1. URL-Safe Slug Generation
The private helper _slugify() converts community names into filesystem-safe identifiers:
- Lowercases all characters
- Replaces non-alphanumerics with dashes
- Truncates to 80 characters
- Appends incrementing suffixes (
-2,-3, …) to resolve collisions
This guarantees unique filenames like data-processing.md or auth-middleware-2.md even when community names overlap semantically.
2. Template Rendering
Each page is rendered from a Jinja-style template containing:
- YAML frontmatter with
title,community_id, and optionalsummaryfields - Summary section—either a placeholder or AI-generated prose
- Members list—bullet points linking to graph-view URLs for each node
3. File Output
Pages are written to .code-review-graph/wiki/<slug>.md relative to repository root. The directory is created automatically if absent.
4. Optional LLM Enrichment
When the [wiki] extra is installed (pip install "code-review-graph[wiki]") and a local Ollama server is available, the tool queries the model to generate natural-language summaries. Without this dependency, pages contain only structural metadata—still functional, but without explanatory prose.
CLI Commands for Wiki Operations
Invoke the full pipeline with a single subcommand:
# Build the graph and detect communities
code-review-graph build
# Generate all markdown pages
code-review-graph wiki
The command outputs a concise summary: X pages generated, Y updated.
For programmatic access to individual pages, use the companion tool:
# Retrieve a specific page by community name (partial matches accepted)
code-review-graph get-wiki-page "Data Processing"
The get_wiki_page function (also in wiki.py) enables downstream automation—ideal for web UIs or CI pipelines that need to surface documentation without parsing the filesystem directly.
Installing LLM-Powered Summaries
To enable natural-language generation:
# Install with wiki extras
pip install "code-review-graph[wiki]"
# Ensure Ollama is running locally
ollama serve
# Generate pages with AI summaries
code-review-graph wiki
Pages produced with this configuration open with a coherent paragraph describing the community's purpose and relationships, rather than placeholder text.
File Structure and Key Source Locations
| File Path | Purpose |
|---|---|
code_review_graph/wiki.py |
generate_wiki(), get_wiki_page(), _slugify() implementations |
code_review_graph/communities.py |
list_communities tool for community detection |
docs/USAGE.md |
User documentation for the wiki CLI command |
docs/COMMANDS.md |
Reference for generate_wiki_tool and get_wiki_page_tool |
docs/TROUBLESHOOTING.md |
Guidance on the [wiki] extra dependency |
Summary
- The
code-review-graph wikicommand triggers automatic markdown generation viagenerate_wiki()incode_review_graph/wiki.py - Community data originates from the
list_communitiestool incommunities.py - The
_slugify()helper ensures unique, URL-safe filenames with collision handling - Templates include YAML frontmatter, optional LLM summaries, and linked member lists
- Output directory is
.code-review-graph/wiki/with one.mdfile per community - Install
code-review-graph[wiki]and run Ollama locally to enable AI-generated prose
Frequently Asked Questions
What triggers the automatic wiki generation?
The generate_wiki command runs explicitly when you execute code-review-graph wiki. It does not run automatically during build or update—you must invoke it separately after communities are detected. This design separates expensive graph computation from optional documentation export.
Why are my wiki pages missing descriptive summaries?
The prose summaries require the [wiki] extra dependency and a running Ollama server. Without these, generate_wiki() skips the LLM call and leaves placeholder text. Check that you installed with pip install "code-review-graph[wiki]" and that ollama serve is accessible on your system.
How does the tool handle duplicate community names?
The _slugify() function in wiki.py appends numeric suffixes (-2, -3, etc.) when slug collisions occur. This guarantees unique filenames while preserving human-readable names in the YAML frontmatter title field.
Can I customize the markdown template?
The current implementation uses a hardcoded template structure within generate_wiki(). For custom formatting, you would need to fork code_review_graph/wiki.py and modify the rendering logic directly—no external template path is configurable in the current release.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →