Skip to main content

repo2diagram

Turn any codebase into an interactive architecture diagram — in one command.

Runs on your machine with local models (Ollama). Works as a CLI, an MCP server for Claude Code / Claude Desktop / Cursor, and an agent skill.

CI PyPI License: MIT

repo2diagram on the MCP Python SDK

uvx repo2diagram modelcontextprotocol/python-sdk --open

Why

Every new codebase starts with the same hour of clicking through folders to figure out what talks to what. repo2diagram reads the real import graph, groups files into modules, and (optionally) asks an LLM to label each one — so you get an accurate map, not a hallucinated one.

  • Real structure, not guesses — modules and arrows come from static analysis of imports (Python, JS/TS incl. tsconfig path aliases, Go, Rust, Java/Kotlin/Scala, C#). The LLM only writes the labels.
  • Private by default — works with local models via Ollama, or with no model at all. Your code never has to leave your machine.
  • Interactive — click any box to see what it does, its files, what it uses and what uses it. Search, pan/zoom, dark mode, export SVG / Mermaid.
  • PR blast radius — --diff main highlights the modules a branch touches and every module that depends on them, locally or as a GitHub Action comment on every PR.
  • Works in your AI tools — MCP server for Claude Code, Claude Desktop and Cursor; skill for coding agents.

See it on real projects: gallery — ripgrep, the MCP Python SDK, eShopOnWeb, Vercel's AI chatbot, Spring PetClinic and more.

Install

pip install repo2diagram        # or: uv tool install repo2diagram / pipx install repo2diagram

Or run it without installing: uvx repo2diagram.

Usage

repo2diagram                         # current directory → <name>-architecture.html
repo2diagram ~/code/my-app --open    # open in the browser when done
repo2diagram vercel/ai-chatbot       # any GitHub repo (owner/repo or URL)
repo2diagram --diff main             # highlight what this branch changed + its blast radius
repo2diagram -o ARCHITECTURE.md      # Markdown with a Mermaid diagram (renders on GitHub)
repo2diagram -f mermaid -o -         # raw Mermaid to stdout
repo2diagram -f json                 # the full graph for your own tooling
repo2diagram --no-llm                # static analysis only — instant, no model needed
repo2diagram --watch                 # live diagram on localhost that redraws as you code
Flag What it does
-o, --output FILE Output path; format inferred from .html .md .mmd .json (- = stdout)
--diff [REF] Mark modules changed since REF (default main) and everything that depends on them
--no-llm Skip model calls, use heuristic labels
--provider, --model Override the configured model for one run
--all Also draw tests, docs, examples and CI folders
--direction TD Top-down instead of left-to-right
--open Open the HTML when done
-w, --watch Serve a live diagram at http://127.0.0.1:8484 that redraws on every save (--port, --no-open)

Models

repo2diagram picks a model automatically: a running Ollama first, then Claude if ANTHROPIC_API_KEY is set, otherwise static labels. Configure it once with the CLI:

# Local (default) — free and private
ollama pull qwen2.5-coder:7b
repo2diagram config set provider ollama

# Claude
repo2diagram config set provider anthropic
repo2diagram config set api_key sk-ant-...          # or export ANTHROPIC_API_KEY

# Anything OpenAI-compatible: OpenAI, OpenRouter, LM Studio, vLLM, llama.cpp …
repo2diagram config set provider openai
repo2diagram config set base_url http://localhost:1234/v1
repo2diagram config set model qwen2.5-coder-7b-instruct
repo2diagram config set api_key ...                  # if the server needs one

repo2diagram config show      # keys are redacted
repo2diagram doctor           # what's installed and which model will be used

Settings live in ~/.config/repo2diagram/config.json (chmod 600). Env vars R2D_PROVIDER, R2D_MODEL, R2D_BASE_URL, R2D_API_KEY override it. Labels are cached in ~/.cache/repo2diagram, so re-runs are instant and only changed modules hit the model.

Use it from Claude Code, Claude Desktop or Cursor (MCP)

repo2diagram setup claude-code --yes       # runs: claude mcp add repo2diagram -- repo2diagram mcp
repo2diagram setup claude-desktop --yes    # merges into claude_desktop_config.json (backup kept)
repo2diagram setup cursor --yes            # merges into ~/.cursor/mcp.json

Or add it by hand:

{ "mcpServers": { "repo2diagram": { "command": "uvx", "args": ["repo2diagram", "mcp"] } } }

Then just ask: "Draw the architecture of this repo", "What's the blast radius of my branch vs main?", "Explain the server/auth module".

Tool Purpose
diagram_repo Mermaid diagram + module table (+ saves the interactive HTML)
repo_structure Modules, import edges, entry points and dependencies as JSON
module_details One module in depth: files, uses / used-by, key file excerpts
diff_impact Changed modules and their blast radius vs a git ref

Inside an MCP client no API key is needed — the tools return the structure and your assistant does the explaining. Pass summarize: true to use your configured model instead.

Blast radius on every pull request (GitHub Action)

Post a diagram of what each PR touches — and which modules depend on it — as a PR comment that updates on every push.

# .github/workflows/architecture.yml
name: Architecture impact
on: pull_request
permissions:
  contents: read
  pull-requests: write
jobs:
  impact:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - uses: adityasingh-ops/repo2diagram@v0

Locally, the same report is repo2diagram --diff main -f pr.

Use it as an agent skill

Copy skills/repo2diagram into ~/.claude/skills/ (or your agent's skills folder). The agent will reach for it whenever you ask for an architecture overview or a PR impact check.

How it works

  1. Scan — list files (respects .gitignore), skip vendored and generated folders.
  2. Group — open up container folders (src/, packages/, apps/ …) until the repo splits into a readable set of modules; flat packages are drawn file by file.
  3. Link — parse imports (Python AST, JS/TS with tsconfig aliases per package, Go modules, Rust mod/use across workspace crates, JVM packages, C# namespaces) and count module-to-module references.
  4. Label — heuristics, or one small LLM call per module (cached by content hash).
  5. Render — Mermaid with the ELK layout engine, wrapped in a single self-contained HTML file.

Python API

from repo2diagram import build_graph
from repo2diagram.render import render

graph, diff = build_graph("path/to/repo", summarize_with_llm=False, diff_base="main")
print(render(graph, "mermaid"))

Contributing

git clone https://github.com/adityasingh-ops/repo2diagram && cd repo2diagram
uv sync && uv run pytest

More import resolvers (Ruby, PHP, Swift, Dart, C/C++) are the most wanted contributions — see resolvers.py.

License

MIT

Metadata

Release files for repo2diagram 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for repo2diagram 0.2.1
File Size Uploaded Provenance Actions
repo2diagram-0.2.1.tar.gz 215.3 kB With provenance Details for repo2diagram-0.2.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for repo2diagram 0.2.1
File Interpreter ABI Platform Actions
repo2diagram-0.2.1-py3-none-any.whl Python 3 none any Details for repo2diagram-0.2.1-py3-none-any.whl

Total release size: 258.0 kB

Release files / repo2diagram-0.2.1.tar.gz

Download URL repo2diagram-0.2.1.tar.gz
Size 215.3 kB
Tags Source
SHA-256 checksum
How to use checksums
759ed4e53f84f2936e29c534a306c9ffca93a08288b6c4f0666af6fe02516ac7
BLAKE2b-256 checksum
How to use checksums
0b73cc7e4a607dc2eddd28c991b3f144738edc7b9bf34daeed9e161af5849d23
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 29, 2026.

Transparency log

Release files / repo2diagram-0.2.1-py3-none-any.whl

Download URL repo2diagram-0.2.1-py3-none-any.whl
Size 42.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e3b32a313706f716f3965e366d085efefa53d7f439f902c11d17fb5a1a6858ec
BLAKE2b-256 checksum
How to use checksums
9113965bd760d02a4a9d8213c130c27af0fd62b7ad626be9b1da30f6422b9eaf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 29, 2026.

Transparency log

Security for repo2diagram 0.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for repo2diagram-0.2.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 29, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page