Turn any GitHub repository into an interactive diagram for visualization in seconds.
You can also replace hub with diagram in any Github URL to access its diagram.
- 👀 Instant Visualization: Convert any GitHub repository structure into a system design / architecture diagram
- 🎨 Interactivity: Click on components to navigate directly to source files and relevant directories
- ⚡ Fast Generation: Powered by GPT-5-family models, with OpenAI for user-supplied browser keys and optional OpenRouter for self-hosted deployments
- 🖼️ Export Options: Copy Mermaid code or download the generated diagram as PNG
- 🌐 API Access: Public API available for integration (WIP)
- Frontend: Next.js, TypeScript, Tailwind CSS, ShadCN
- Backend: FastAPI (Railway) or Next.js Route Handlers, selected explicitly via environment
- Storage: Cloudflare R2 (diagram artifacts) + Upstash Redis (quota and failure summaries)
- AI: OpenAI or OpenRouter (via
AI_PROVIDER) - Deployment: Vercel (frontend) + Railway (backend)
- CI/CD: GitHub Actions
- Analytics: PostHog, Api-Analytics
- Vercel serves the Next.js frontend
- Railway runs the long-lived FastAPI generation backend in production
- Cloudflare R2 stores successful diagram artifacts
- Upstash Redis stores complimentary quota state and short-lived terminal failure summaries
- OpenAI
gpt-5.4-miniis the default server-side generation model
There is no Postgres or Neon runtime path anymore.
GitDiagram supports two generation backends:
fastapi: external FastAPI servicenext: in-repo Next.js Route Handlers that validate Mermaid in-process and can be deployed on Vercel with the checked-in Bun runtime config
Frontend routing is explicit:
NEXT_PUBLIC_GENERATION_BACKEND=fastapiwithNEXT_PUBLIC_GENERATE_API_BASE_URL=https://<your-backend>/generatefor the production-style path- or
NEXT_PUBLIC_GENERATION_BACKEND=next
- Successful generations: R2 object per repo artifact
- Terminal failures with no saved artifact: Upstash Redis TTL summary
- Complimentary daily quota: Upstash Redis hash
- Private repo persistence: separate R2 namespace derived from the provided GitHub token
I created this because I wanted to contribute to open-source projects but quickly realized their codebases are too massive for me to dig through manually, so this helps me get started - but it's definitely got many more use cases!
Given any public (or private!) GitHub repository it generates diagrams in Mermaid.js with GPT-5-family models. The default setup uses GPT-5.4 mini through OpenAI, while self-hosted operators can optionally point the backend at OpenRouter via environment configuration.
When you submit a GitHub repo URL, GitDiagram asks the GitHub API for the repo's default branch, a recursive file tree, and the README, while filtering out noisy assets and dependency folders. It feeds that repo snapshot into a streamed generation pipeline where one model pass writes a plain-English architecture explanation and a second pass turns that explanation plus the file tree into a structured graph of systems, nodes, edges, and real repo paths.
That graph is validated against the actual file tree, retried with feedback if it contains bad paths or invalid connections, then compiled into Mermaid and validated again before it is shown. Any node tied to a real path becomes clickable back to GitHub, and the final explanation, graph, diagram, and terminal generation state are stored in Cloudflare R2 and Upstash Redis so the app can reopen an existing result or show where a run failed.
One implementation detail worth knowing: the Next backend validates Mermaid in-process in src/server/generate/mermaid-validator.ts, while the FastAPI backend invokes the thin Bun wrapper in backend/scripts/validate_mermaid.mjs backed by backend/lib/mermaid-validator.ts. Both use the same Mermaid + DOMPurify bootstrap approach, so the Railway backend runtime remains intentionally mixed Python + Bun.
You can simply click on "Private Repos" in the header and follow the instructions by providing a GitHub personal access token with the repo scope.
You can also self-host this app locally (backend separated as well!) with the steps below.
- Clone the repository
git clone https://github.com/ahmedkhaleel2004/gitdiagram.git
cd gitdiagram- Install root dependencies
bun install- Install backend FastAPI-side dependencies
bun run install:backendThis keeps the backend's Python environment managed by uv and installs the backend Mermaid validator's Bun dependencies from backend/bun.lock.
- Set up environment variables (create .env)
cp .env.example .envThen edit the .env file with your backend AI credentials and optional GitHub personal access token.
Example local OpenRouter setup:
AI_PROVIDER=openrouter
OPENROUTER_API_KEY=...
OPENROUTER_MODEL=openai/gpt-5.4
OPENROUTER_SITE_URL=http://localhost:3000
OPENROUTER_APP_NAME=GitDiagramExample OpenAI setup:
AI_PROVIDER=openai
OPENAI_API_KEY=...
OPENAI_MODEL=gpt-5.4-mini
OPENAI_COMPLIMENTARY_GATE_ENABLED=false
OPENAI_COMPLIMENTARY_DAILY_LIMIT_TOKENS=10000000
OPENAI_COMPLIMENTARY_MODEL_FAMILY=gpt-5.4-miniIf you want GitDiagram to use only the complimentary OpenAI daily mini quota on the default server key, set OPENAI_COMPLIMENTARY_GATE_ENABLED=true. When enabled, the backend stops default-key generations before a request would exceed the configured daily limit, while user-supplied API keys still bypass the gate.
Storage notes:
- successful diagrams live in R2 as JSON artifacts
- short-lived failure summaries live in Upstash
- there is no Postgres/Neon runtime path anymore
- Set up Cloudflare R2 and Upstash Redis
Create:
- two private R2 buckets, one for public artifacts and one for private artifacts
- one Upstash Redis database
Then fill in these required env vars in .env:
R2_ACCOUNT_IDR2_ACCESS_KEY_IDR2_SECRET_ACCESS_KEYR2_PUBLIC_BUCKETR2_PRIVATE_BUCKETCACHE_KEY_SECRETUPSTASH_REDIS_REST_URLUPSTASH_REDIS_REST_TOKEN
- Run frontend
bun run devYou can now access the website at localhost:3000.
This is the simplest local mode and works with:
NEXT_PUBLIC_GENERATION_BACKEND=next
Run FastAPI backend only if you want production parity:
docker-compose up --build -d
docker-compose logs -f apiTo use the FastAPI backend from the frontend, set:
NEXT_PUBLIC_GENERATION_BACKEND=fastapiNEXT_PUBLIC_GENERATE_API_BASE_URL=http://localhost:8000/generate
To use the built-in Next.js Route Handlers instead, set:
NEXT_PUBLIC_GENERATION_BACKEND=next
For a full machine setup guide (Bun/Python/uv versions + verification), see docs/dev-setup.md.
Quick validation:
bun run check
bun run test
bun run buildRailway backend docs: docs/railway-backend.md.
Contributions are welcome! Please feel free to submit a Pull Request.
Shoutout to Romain Courtois's Gitingest for inspiration and styling
- Implement font-awesome icons in diagram
- Implement an embedded feature like star-history.com but for diagrams. The diagram could also be updated progressively as commits are made.
