How quangdungluong/codewiki works
1. Overall shape
- This is a two-tier application: a Next.js frontend in frontend/ and a Python backend API in api/ with shared internal tooling in utils/.
- The product goal is to take a GitHub repo URL or owner/repo pair, analyze the codebase, and present generated diagrams, a wiki, and chat-based Q&A.
2. Frontend boundary
- The frontend is a Next.js App Router app with repo-scoped routes like /[owner]/[repo] and /[owner]/[repo]/diagram.
- It is responsible for user interaction, route navigation, language/theme UI, and rendering outputs such as markdown, Mermaid diagrams, repo trees, and chat panels.
- Key UI pieces include Ask, Mermaid, WikiTreeView, ProcessedProjects, and DiagramLoading.
3. Frontend data flow
- Frontend hooks such as useDiagram and useProcessedProjects likely call the backend to fetch generated artifacts and processing status.
- websocketClient.ts indicates at least part of the chat or generation flow is streamed over WebSockets, not just plain HTTP.
- parseRepoInput and getRepoUrl suggest the UI accepts multiple repo input forms and normalizes them into a canonical repository identifier.
4. Backend API layer
- The backend entry points are api/main.py and api/api.py, which likely expose the public HTTP routes used by the frontend.
- api/models.py, api/config.py, and api/language_config.py provide request/response schemas and runtime configuration.
- api/stream_chat.py suggests a dedicated streaming endpoint or protocol for incremental AI responses.
5. Repository ingestion and analysis pipeline
- The utils/ package contains the core pipeline for turning a repo into structured knowledge:
- repo_downloader.py fetches source code.
- repository_parser.py and repository_structure.py extract file hierarchy and code structure.
- document_pipeline.py appears to build the document corpus used for wiki generation and retrieval.
- This is the main boundary between raw GitHub content and generated product artifacts.
6. AI and retrieval subsystem
- api/rag.py and utility modules like ollama_embedder.py, prompts.py, and token_utils.py indicate a RAG-style pipeline for repo-aware answering.
- api/services/gemini_service.py suggests LLM generation is delegated to Google Gemini.
- The architecture likely combines:
- repo-derived documents and structure,
- embeddings for retrieval,
- prompt assembly,
- LLM generation for wiki pages, summaries, diagrams, and chat answers.
7. GitHub and repository metadata integration
- api/services/github_service.py and utils/token_utils.py show support for public and private repositories, with token-based GitHub access.
- api/processed_projects.py and frontend/components/ProcessedProjects.tsx imply the system tracks which repositories have already been analyzed so users can revisit them without full reprocessing.
8. Generated outputs
- The application produces at least three user-facing artifact types:
- System diagrams via api/generate_diagram.py and the diagram page.
- Wiki content via api/wiki.py and api/wiki_cache.py.
- Chat answers via api/stream_chat.py and api/rag.py.
- frontend/components/Markdown.tsx and Mermaid.tsx are the rendering boundary for these generated outputs.
9. Persistence and caching
- utils/localdb_manager.py and api/wiki_cache.py indicate some persisted local state for generated content and/or repo metadata.
- utils/redis_tasks.py strongly suggests Redis-backed asynchronous task handling or job coordination for long-running repo analysis.
- api/processed_projects.py is likely the registry used to avoid redundant recomputation and to surface prior results in the UI.
10. Async execution and long-running work
- Repo analysis and AI generation are likely too slow for synchronous request/response, so the system appears to split work into:
- request initiation from the frontend,
- background processing via Redis/task utilities,
- status polling or streaming updates back to the UI.
- This is consistent with separate loading components and WebSocket client code.
11. External service dependencies
- The main external dependencies that materially shape the architecture are:
- GitHub API for repository access.
- Gemini for LLM generation.
- Ollama or a local embedding backend for vectorization.
- Redis for task coordination and possibly caching.
- These services are not incidental; they define how repo ingestion, retrieval, and generation are executed.
12. Local development and deployment shape
- docker-compose.yaml suggests the stack is intended to run as multiple cooperating services locally.
- The presence of separate frontend/backend trees and shared utility modules points to a deployable split between UI and API, with stateful support services alongside them.
13. Quality gates
- Tests in tests/ cover chat and repository structure behavior, which aligns with the two most critical backend concerns: correct understanding of codebases and correct answer generation.
- GitHub workflows and pre-commit/lint configs indicate CI is used to keep both the Python and TypeScript sides consistent.
14. How to draw the architecture
- A good diagram would show:
- User → Next.js frontend,
- Frontend → backend API over HTTP/WebSocket,
- Backend → GitHub, Gemini, embedding backend/Ollama, Redis, local cache/DB,
- Backend pipeline producing diagram/wiki/chat artifacts,
- Frontend rendering those artifacts in markdown/Mermaid/tree views.
- The main system boundary is the repo analysis and generation backend; the UI is primarily a presentation and interaction layer.
Main entry points: api.py Public routes · rag.py RAG layer · repository_parser.py Repo parser · generate_diagram.py Diagram gen
Components 25
Frontend
Next.js UI and client-side state
- App shell · Top-level pages, layout, and repo-scoped routes
frontend/app - Repo view · Main repository workspace and summary view
frontend/app/[owner]/[repo]/page.tsx - Diagram view · Dedicated system diagram page
frontend/app/[owner]/[repo]/diagram/page.tsx - UI widgets · Ask panel, markdown, Mermaid, tree, and loading states
frontend/components - Client hooks · Fetches diagrams and processed project status
frontend/hooks - Repo parsing · Converts user input into canonical repo identifiers
frontend/utils - WebSocket client · Streams chat or generation updates to the UI
frontend/utils/websocketClient.ts
Backend API
Python API, generation, and retrieval services
- API entry · HTTP entrypoints and route wiring
api/main.py - Public routes · Primary endpoints for app features
api/api.py - Chat stream · Incremental chat responses and message flow
api/stream_chat.py - Diagram gen · Produces system diagrams for repositories
api/generate_diagram.py - Wiki service · Generates wiki content and cacheable pages
api/wiki.py - RAG layer · Repo-aware answering and prompt assembly
api/rag.py - GitHub access · Repository metadata and source access
api/services/github_service.py - Gemini service · Delegates generation to Gemini
api/services/gemini_service.py - Project registry · Tracks analyzed repositories and reuse state
api/processed_projects.py
Repo Pipeline
Shared ingestion and analysis utilities
- Downloader · Fetches repository source for analysis
utils/repo_downloader.py - Repo parser · Builds file and code structure from source
utils/repository_parser.py - Doc pipeline · Creates documents used for wiki and retrieval
utils/document_pipeline.py - Structure model · Represents parsed repository hierarchy
utils/repository_structure.py - Tasks and cache · Background jobs plus local persistence
utils/redis_tasks.py
External Services
Third-party systems used by the app
- Redis · Async coordination for long-running work
- GitHub · Remote repository source
- Gemini · Model generation backend
- Embeddings · Local or Ollama-based embedding generation
utils/ollama_embedder.py
Connections 28
- Repo view → UI widgets: renders · Repository view composes key widgets
- Diagram view → UI widgets: renders · Diagram route uses shared presentation components
- App shell → Repo view: routes to · App router hosts repo-scoped page
- App shell → Diagram view: routes to · App router hosts diagram page
- UI widgets → WebSocket client: updates via · Chat and generation UI receive streamed updates
- Client hooks → Public routes: fetches · Hooks query backend for artifacts and status
- Client hooks → Project registry: reads · Processed projects view status and history
- Repo parsing → Public routes: normalizes for · Canonical repo identifiers are sent to backend
- WebSocket client → Chat stream: streams · WebSocket client connects to incremental chat flow
- API entry → Public routes: mounts · Main application exposes API modules
- Public routes → Chat stream: serves · Public API includes chat streaming
- Public routes → Diagram gen: serves · Public API includes diagram generation
- Public routes → Wiki service: serves · Public API includes wiki artifact generation
- Public routes → RAG layer: serves · Public API exposes repo-aware Q&A
- RAG layer → GitHub access: retrieves from · RAG uses repository metadata and source access
- RAG layer → Doc pipeline: retrieves context from · Repo documents feed answer generation
- RAG layer → Gemini service: generates with · Answers and summaries are produced by Gemini
- Diagram gen → Repo parser: analyzes · Diagram generation depends on parsed structure
- Wiki service → Doc pipeline: builds from · Wiki content is derived from the document corpus
- Downloader → GitHub access: downloads via · Repository source comes from GitHub
- Repo parser → Downloader: consumes · Parser works on downloaded repository contents
- Repo parser → Structure model: produces · Parsed hierarchy becomes a reusable structure model
- Doc pipeline → Repo parser: derives from · Document corpus is built from parsed code structure
- Tasks and cache → Redis: coordinates with · Long-running jobs are coordinated through Redis
- Project registry → Tasks and cache: persists via · Registry likely backed by local or cached state
- RAG layer → Embeddings: embeds with · Retrieval uses vectorization backend
- Diagram gen → Gemini: generates with · Diagram synthesis uses LLM generation
- Wiki service → Gemini: generates with · Wiki content is generated by Gemini