Which AI Models Does CodeWiki Use for Diagram Generation?
CodeWiki generates architecture diagrams exclusively using Google Gemini 2.5 Pro through a dedicated service wrapper that streams Mermaid code via FastAPI endpoints.
CodeWiki is an open-source tool that transforms repository structures into visual architecture diagrams. Understanding which AI models does CodeWiki use for diagram generation helps developers evaluate output quality and integration requirements. The codebase relies on a single, specific large language model to produce Mermaid diagram syntax from repository analysis.
Google Gemini 2.5 Pro as the Core AI Model
CodeWiki delegates all diagram generation tasks to Google Gemini 2.5 Pro. The model identifier is hardcoded in the service configuration as "gemini-2.5-pro" within api/services/gemini_service.py at lines 13-15. This specific model version handles the complete pipeline: analyzing repository structures, mapping component relationships, and generating valid Mermaid diagram code.
The choice of Gemini 2.5 Pro reflects its strong performance in code generation and structured output tasks. Unlike multi-model architectures, CodeWiki centralizes all AI operations through this single model endpoint, simplifying configuration and ensuring consistent output formatting.
How CodeWiki Integrates Gemini for Diagram Generation
The integration follows a service-oriented architecture with clear separation between the AI client wrapper and the API routing layer.
The GeminiService Wrapper
The GeminiService class in api/services/gemini_service.py encapsulates all interactions with the Google Gemini API. It initializes the model client with the specific version identifier and exposes methods for streaming content generation. This wrapper handles authentication, request formatting, and response parsing, isolating the FastAPI routes from direct API dependencies.
The FastAPI Router and Streaming Architecture
The api/generate_diagram.py file defines the /api/diagram/generate endpoint that orchestrates the generation workflow. When invoked, it instantiates GeminiService and executes a multi-step streaming process:
- Repository Analysis: Fetches and parses the target repository structure
- Component Mapping: Uses Gemini to identify architectural components via
SYSTEM_SECOND_PROMPTfromutils/prompts.py - Diagram Generation: Streams final Mermaid code using
SYSTEM_THIRD_PROMPTtemplates
The endpoint returns Server-Sent Events (SSE) to stream progress and final output to the client.
import httpx
import json
# Replace with your repository details
payload = {
"owner": "quangdungluong",
"repo": "codewiki",
"token": None # optional GitHub token for private repos
}
url = "http://localhost:8000/api/diagram/generate"
async def generate():
async with httpx.AsyncClient() as client:
resp = await client.post(url, json=payload, timeout=120)
async for line in resp.aiter_lines():
# The endpoint streams SSE events; each line contains JSON with a `diagram` field once completed
data = json.loads(line.removeprefix("data: "))
if "diagram" in data:
print("Mermaid diagram:\n", data["diagram"])
break
# asyncio.run(generate())
Prompt Engineering and Mermaid Code Generation
CodeWiki relies on carefully engineered system prompts defined in utils/prompts.py to guide Gemini 2.5 Pro toward valid Mermaid syntax. The file contains SYSTEM_SECOND_PROMPT for component relationship mapping and SYSTEM_THIRD_PROMPT for final diagram generation. These prompts instruct the model to output raw Mermaid code without markdown formatting, ensuring the generated diagrams can be rendered directly by the frontend without additional parsing.
The api/models.py file defines Pydantic schemas like DiagramRequest that validate incoming API requests, while api/main.py registers the diagram router with the main FastAPI application instance.
Summary
- CodeWiki uses Google Gemini 2.5 Pro exclusively for all diagram generation tasks, configured in
api/services/gemini_service.py. - The architecture streams Mermaid diagram code via FastAPI endpoints defined in
api/generate_diagram.py. - System prompts in
utils/prompts.pyguide the model to produce valid, renderable Mermaid syntax without markdown wrappers. - The
/api/diagram/generateendpoint accepts repository details and returns Server-Sent Events containing the generated diagram.
Frequently Asked Questions
Which specific AI model does CodeWiki use?
CodeWiki uses Google Gemini 2.5 Pro as its sole AI model for diagram generation. The model identifier "gemini-2.5-pro" is explicitly set in the GeminiService class within api/services/gemini_service.py.
How does CodeWiki stream diagram generation?
The FastAPI endpoint in api/generate_diagram.py implements Server-Sent Events (SSE) to stream content from Gemini. When you POST to /api/diagram/generate, the endpoint returns a streaming response where each chunk contains progress updates or the final Mermaid diagram code.
Can I use a different AI model with CodeWiki?
Currently, CodeWiki does not support swapping AI models through configuration. The GeminiService hardcodes the Gemini 2.5 Pro model identifier. To use a different model, you would need to modify the service initialization in api/services/gemini_service.py and potentially adjust the prompts in utils/prompts.py for model-specific formatting.
What diagram format does CodeWiki generate?
CodeWiki generates Mermaid diagram code. The system prompts specifically instruct Gemini to output raw Mermaid syntax (e.g., graph TD or flowchart LR) without markdown code blocks, allowing the frontend to render diagrams directly using Mermaid.js.
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 →