How he-yufeng/repowiki works
1. Repo shape: a Python backend plus a separate browser frontend.
The core product lives under src/repowiki/ and can run as a CLI, a FastAPI server, or a terminal chat tool. The frontend/ directory is a React + Vite TypeScript UI that talks to the backend API. This is not a single monolith; it is a pipeline-oriented backend with a thin web presentation layer.
2. Primary entry points.
repowiki/__main__.py and cli.py provide command-line commands such as scan, serve, chat, and config. The same backend capabilities are exposed through server/app.py and routers under server/routers/. The web app is a consumer of those backend endpoints rather than an independent analysis engine.
3. Repository ingestion boundary.
Input comes from either a local filesystem path (ingest/local.py) or a GitHub URL (ingest/github.py). That boundary matters because everything downstream operates on a normalized project snapshot, regardless of source. The README indicates scans respect .gitignore, .repowikiignore, and common secret-file exclusions.
4. Scanning and file selection.
core/scanner.py is the first major processing stage. It walks the tree, detects languages, identifies candidate files, and filters out binaries, generated bundles, and oversized or irrelevant content. This stage is the main “context control” gate before any graph or LLM work happens.
5. Dependency graph and file ranking.
core/graph.py builds a cross-file dependency graph and applies PageRank-style ranking to identify important files and a guided reading path. The README explicitly notes import-aware resolution for Python package-relative imports and JavaScript/TypeScript relative modules, so the graph is a core architectural subsystem rather than a cosmetic feature.
6. LLM analysis pipeline.
core/analyzer.py orchestrates multi-pass structured analysis of the scanned repo. It feeds selected file content and tree context into the LLM layer, likely producing project overview, module summaries, architecture notes, and reading guidance. Prompt templates live in llm/prompts.py, and the actual model access is abstracted by llm/client.py around litellm.
7. Wiki assembly and document model.
core/wiki_builder.py turns analysis artifacts into a coherent wiki structure. Supporting types in core/models.py define the data shapes passed across scan, graph, analysis, and export layers. This is the internal “content product” boundary: raw repo data becomes structured documentation objects.
8. Caching and repeat scans.
core/cache.py provides SQLite-backed caching keyed by content hash, allowing re-scans to skip unchanged files. The README positions SQLite as the only persistence dependency, which keeps the architecture local-first and avoids external databases.
9. Retrieval and Q&A path.
core/rag.py implements terminal Q&A retrieval using TF-IDF rather than embeddings. That means the chat path is separate from the documentation-generation path: it indexes repo text, retrieves relevant snippets, and then asks the LLM to answer grounded in those snippets. This is the architecture behind repowiki chat.
10. Export layer with three output modes.
export/markdown.py, export/json_export.py, and export/html.py render the wiki into different delivery formats. Markdown is a directory of files, JSON is structured machine-readable output, and HTML is a self-contained artifact with Mermaid diagrams included. Export is a distinct boundary after analysis, not part of scanning.
11. Web backend and frontend responsibilities.
server/app.py and routers scan.py, wiki.py, and chat.py expose the analysis pipeline over HTTP. The frontend pages in frontend/src/pages/ (Home, WikiView, ChatView) and components like WikiSidebar, WikiContent, and MermaidDiagram provide the browsing experience. The frontend is therefore a presentation and navigation layer over wiki data, not the source of truth.
12. Configuration and external dependencies.
config.py centralizes runtime settings, including model selection and API keys. The README shows config precedence from CLI flags to environment variables to a user config file, with provider-specific API keys for LLM access. The key external integration is the LLM provider layer via litellm; everything else is local filesystem, GitHub fetch/clone, SQLite, and browser UI.
13. Quality gates and delivery pipeline.
Tests cover scanner, graph, RAG, and export behavior (tests/test_scanner.py, test_graph.py, test_rag.py, test_markdown_export.py, test_html_export.py). GitHub Actions workflows in .github/workflows/ci.yml and publish.yml indicate the project is packaged and released as a distributable Python tool with CI validation.
14. Useful diagram boundaries to draw.
A good architecture diagram would show: input sources → ingestion → scanning/filtering → dependency graph + ranking → LLM analysis → wiki assembly → export/API responses; with a side path for retrieval/chat and a separate presentation boundary for the React frontend. The biggest internal seams are ingestion vs analysis, analysis vs export, and offline CLI processing vs online server/UI consumption.
Main entry points: wiki_builder.py Wiki builder · analyzer.py Analyzer · App.tsx UI app · api.ts API client
Components 29
Python backend
CLI, server, ingestion, analysis, export, and retrieval pipeline.
- CLI entry · Command-line interface and main executable entrypoints.
src/repowiki/__main__.py - Local ingest · Loads a repository snapshot from a local filesystem path.
src/repowiki/ingest/local.py - GitHub ingest · Fetches or clones repository content from a GitHub URL.
src/repowiki/ingest/github.py - Scanner · Walks the tree, filters noise, detects languages, and selects candidate files.
src/repowiki/core/scanner.py - Dep graph · Builds cross-file dependency links and ranks important files.
src/repowiki/core/graph.py - Cache · SQLite-backed cache for reusing unchanged scan and analysis results.
src/repowiki/core/cache.py - Analyzer · Runs multi-pass structured analysis over selected files and repo context.
src/repowiki/core/analyzer.py - Prompts · Prompt templates used by the analysis pipeline.
src/repowiki/llm/prompts.py - LLM client · Abstracts model/provider access through litellm.
src/repowiki/llm/client.py - Models · Shared data shapes passed between scan, graph, analysis, and export stages.
src/repowiki/core/models.py - Wiki builder · Converts analysis artifacts into a structured wiki document.
src/repowiki/core/wiki_builder.py - RAG chat · TF-IDF based retrieval and grounded terminal Q&A path.
src/repowiki/core/rag.py - Markdown export · Renders the wiki as a directory of Markdown files.
src/repowiki/export/markdown.py - JSON export · Produces structured machine-readable wiki output.
src/repowiki/export/json_export.py - HTML export · Builds a self-contained HTML artifact with diagrams.
src/repowiki/export/html.py - API server · HTTP application exposing scan, wiki, and chat endpoints.
src/repowiki/server/app.py - Scan API · Server routes for repository scanning and ingestion.
src/repowiki/server/routers/scan.py - Wiki API · Server routes for wiki retrieval and document access.
src/repowiki/server/routers/wiki.py - Chat API · Server routes for chat and Q&A interactions.
src/repowiki/server/routers/chat.py
Browser frontend
React/Vite UI that consumes backend API responses.
- UI app · Vite/React browser application shell.
frontend/src/App.tsx - API client · Browser-side API wrapper for backend requests.
frontend/src/lib/api.ts - Home · Frontend landing and entry page.
frontend/src/pages/Home.tsx - Wiki view · Frontend page for browsing wiki content.
frontend/src/pages/WikiView.tsx - Chat view · Frontend page for conversational Q&A.
frontend/src/pages/ChatView.tsx - Sidebar · Navigation component for wiki structure.
frontend/src/components/WikiSidebar.tsx - Content pane · Displays rendered wiki text and sections.
frontend/src/components/WikiContent.tsx - Diagram view · Renders Mermaid diagrams in the browser.
frontend/src/components/MermaidDiagram.tsx
Connections 39
- CLI entry → Config: reads settings · CLI resolves runtime configuration and model selection.
- CLI entry → Local ingest: scan local · CLI can start from a local filesystem repository.
- CLI entry → GitHub ingest: scan remote · CLI can start from a GitHub repository source.
- Local ingest → Scanner: snapshot · Local source is normalized before scanning.
- GitHub ingest → Scanner: snapshot · GitHub source is normalized before scanning.
- Scanner → Cache: memoize · Scanner consults cache to skip unchanged work.
- Scanner → Dep graph: selected files · Scan output feeds dependency graph construction.
- Dep graph → Analyzer: ranked path · Important files and reading order guide analysis.
- Dep graph → Models: structural data · Graph produces shared repository structure objects.
- Analyzer → Prompts: uses templates · Analysis is driven by structured prompt templates.
- Analyzer → LLM client: model calls · Analyzer delegates generation to the model client.
- LLM client → Config: provider config · Model client uses configured API keys and model settings.
- Analyzer → Cache: reuse results · Analysis can reuse cached file and repo outputs.
- Analyzer → Wiki builder: artifacts · Structured analysis is assembled into wiki content.
- Wiki builder → Models: populate docs · Wiki builder emits typed document structures.
- RAG chat → LLM client: answer with context · Retrieval pipeline sends grounded snippets to the model.
- RAG chat → Cache: reuse index · Chat path can reuse cached repo state.
- Wiki builder → Markdown export: render markdown · Wiki structure can be exported as Markdown files.
- Wiki builder → JSON export: render json · Wiki structure can be exported as machine-readable JSON.
- Wiki builder → HTML export: render html · Wiki structure can be exported as standalone HTML.
- API server → Scan API: mounts · FastAPI app mounts scan routes.
- API server → Wiki API: mounts · FastAPI app mounts wiki routes.
- API server → Chat API: mounts · FastAPI app mounts chat routes.
- Scan API → Local ingest: accepts local · HTTP scan API can ingest local repositories.
- Scan API → GitHub ingest: accepts remote · HTTP scan API can ingest GitHub repositories.
- Wiki API → Wiki builder: serve wiki · Wiki endpoints expose built documentation.
- Chat API → RAG chat: serve chat · Chat endpoints expose retrieval-based Q&A.
- UI app → API client: uses client · React app communicates through the API wrapper.
- UI app → Home: navigates · App shell hosts the home page.
- UI app → Wiki view: navigates · App shell hosts the wiki browser page.
- UI app → Chat view: navigates · App shell hosts the chat page.
- Wiki view → Sidebar: shows · Wiki page uses the navigation sidebar.
- Wiki view → Content pane: shows · Wiki page renders wiki content.
- Wiki view → Diagram view: shows diagrams · Wiki page renders architecture diagrams.
- API client → Wiki API: fetch wiki · Browser retrieves wiki data from the backend API.
- API client → Chat API: fetch chat · Browser sends chat requests to the backend API.
- API client → Scan API: trigger scan · Browser can trigger repository scans through the API.
- CI/CD → CLI entry: tests package · CI validates the Python tool entrypoints and workflows.
- CI/CD → UI app: builds ui · CI validates the browser frontend build.