Repo Cartographer

io.github.builditwithgk由 GitHub 账号 builditwithgk 发布v1.0.1更新于 Oct 24, 2026

Maps any repo into an architecture diagram (Mermaid/Graphviz) and enforces architecture rules in CI

已验证STDIO仅桌面开发者工具数据与分析

概览

AI 生成的概览

把本地代码仓库转成架构图并检查架构规则,并通过 MCP 工具提供结果。

可以做什么
把仓库目录解析为确定性事实:语言、框架、入口点、模块,以及 JavaScript/TypeScript 和 Python 的仓库内导入关系。基于这些事实生成 Mermaid 或 Graphviz DOT 草稿图,以及自包含的 HTML 渲染页面。check 命令依据规则文件标记禁止的跨边界导入和依赖环,并可把现有违规记录为基线,使只有新增违规才会失败。
适用场景
适合让助手解释不熟悉的代码库、为拉取请求或新人文档起草架构图,或在合并时用架构规则把关。同一个可执行文件也能作为普通命令行工具供人和 CI 使用,无需 AI 客户端。
运行要求
需要 Node.js 18 或更高版本;该包通过 stdio 在本地运行,例如使用 npx。未声明任何账号、API 密钥或环境变量。渲染出的 HTML 页面在浏览器中打开时会从 CDN 加载 Mermaid 或 Viz。
安装前请注意
扫描是只读的且不发起网络请求,但 map 和 check 命令会写出文件,例如 architecture.html、.mermaid、.dot 以及基线文件,因此请指向你确实打算修改的路径。生成的 HTML 在打开时会从 CDN 拉取渲染库。check 命令在出现错误级违规时以非零状态退出,可能导致 CI 构建失败。

安装

在 SourceWeft 中

  1. 打开 控制台中的 Repo Cartographer,将其添加到工作区。
  2. 为需要使用其工具的对话启用该服务。

Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。

其他 MCP 客户端

参照 仓库 中的启动说明。

README

repo-cartographer

Understand any codebase in 60 seconds. An MCP server that turns any repository into an architecture diagram.

[TypeScript] [License] [Version] [MCP] [Architecture]

Point your LLM at a folder and get back an architecture map: languages, frameworks, entry points, modules, and an import graph — rendered as a Mermaid diagram you can drop into a PR, a doc, or an onboarding guide.

It is model-agnostic. It speaks the Model Context Protocol over stdio, so it works with Claude Code, Claude Desktop, Cursor, Cline, Copilot, or the OpenAI Agents SDK — no Claude-specific dependency.

Why it's different

The server extracts hard facts. The model does the reasoning.

repo-cartographer never tries to "understand" your code semantically. It parses deterministic facts — file tree, import edges, manifests, framework detection, entry points — and hands your LLM structured JSON plus a draft diagram. Your model turns those facts into the final narrative and a refined diagram.

That split keeps the server small, fast, testable, and portable — and it means the diagram is grounded in what's actually in the repo, not hallucinated.

Example output

Running generate_diagram against this repo produces (a draft the model then refines):

mermaid
flowchart TD    n0["src · 2 files"]    n1["src/lib · library code · 9 files"]    n2["src/resources · resource handlers · 1 file"]    n3["src/tools · tool implementations · 4 files"]    n0 --> n1    n0 --> n2    n0 --> n3    n1 --> n0    n3 --> n0    n3 --> n1

A self-contained, shareable HTML render is committed under examples/ (both a high-level and a file-level detail view).

Install & run

Requires Node.js 18+.

bash
# Run directly (no install)npx -y repo-cartographer
# …or from sourcegit clone https://github.com/builditwithgk/repo-cartographercd repo-cartographernpm installnpm run buildnode dist/index.js

The server communicates over stdio; AI clients launch it that way. You can also use it directly from a terminal — see below.

Command line (no AI needed)

The same binary is dual-mode: with no arguments it's the MCP server; with a subcommand it's a plain CLI for humans and CI.

bash
# Draw a diagram — path in, architecture.html outnpx -y repo-cartographer map ./my-projectnpx -y repo-cartographer map ./my-project --level detail -o docs/architecturenpx -y repo-cartographer map ./my-project --format dot   # Graphviz DOT instead of Mermaid
# Enforce architecture rules (exits 1 on an error-level violation — use it in CI)npx -y repo-cartographer check ./my-project --config .cartographer.yml

Zip-friendly: if you point it at an extracted "Download ZIP" folder (repo-main/ wrapper and all), it detects the wrapper and maps the real repo root — noted in the output, never silent.

Two output notations, one strategy: Mermaid because that's where people read it (GitHub renders it natively in PR comments and READMEs), DOT because that's what their tools eat (pipe it into Graphviz, Backstage, or anything else: dot -Tsvg architecture.dot). Both come with the same shareable HTML page and role-colored modules. When the repo has a .cartographer.yml, its diagram: section supplies the defaults for --level, --format and -o; explicit flags always win.

check reads a rules file and flags forbidden cross-boundary imports and dependency cycles — deterministically, no LLM involved, so it's safe to gate a merge:

yaml
# .cartographer.ymlrules:  forbidden:    - from: "src/ui/**"      to:   "src/db/**"      reason: "UI must go through the service layer, not the DB directly."  cycles: error        # error | warn | off

Adopting on an existing codebase? Record today's violations as an accepted baseline, so only new ones fail the build:

bash
npx -y repo-cartographer check . --update-baseline   # writes .cartographer-baseline.json

Commit that file; later runs auto-detect it and pass unless a PR introduces a new violation.

Architecture governance in CI (GitHub Action)

A composite action (action.yml) runs check on every PR — failing the build on an error-level violation and posting a sticky comment with the diagram and any violations:

yaml
# .github/workflows/architecture.ymlon: pull_requestpermissions: { contents: read, pull-requests: write }jobs:  architecture:    runs-on: ubuntu-latest    steps:      - uses: actions/checkout@v4      - uses: builditwithgk/repo-cartographer@v1        with: { path: ., config: .cartographer.yml }

This repo dogfoods it in .github/workflows/architecture.yml. Full design + phases: docs/github-action.md.

Use it with Claude Code

bash
claude mcp add repo-cartographer -- npx -y repo-cartographer

Then ask: "Use repo-cartographer to map ./my-project and draw me an architecture diagram."

Claude Desktop

Add to claude_desktop_config.json:

json
{  "mcpServers": {    "repo-cartographer": {      "command": "npx",      "args": ["-y", "repo-cartographer"]    }  }}

Use it with the OpenAI Agents SDK

Same server, a different model — the whole point of MCP:

python
import asynciofrom agents import Agent, Runnerfrom agents.mcp import MCPServerStdio
async def main():    async with MCPServerStdio(        params={"command": "npx", "args": ["-y", "repo-cartographer"]},    ) as cartographer:        agent = Agent(            name="Cartographer",            instructions=(                "Use the repo tools to gather facts, then refine the draft "                "Mermaid diagram into a clean architecture map."            ),            mcp_servers=[cartographer],        )        result = await Runner.run(agent, "Map ./my-project and explain its architecture.")        print(result.final_output)
asyncio.run(main())

Tools & resources

ToolWhat it returns
map_repo(path, level?, format?, outPath?)The one-shot flow. Point it at a folder and get a downloadable architecture diagram (architecture.html + .mermaid/.dot) plus a facts summary and the draft source inline — in a single call.
scan_repo(path)Languages, frameworks, entry points, top-level modules (with role guesses), and a manifest summary — as JSON facts.
build_import_graph(path)Intra-repo import/require edges for JS/TS + Python. Nodes are files, auto-collapsed to module level for large repos.
generate_diagram(path, level?, format?)A draft diagram. level = "high" (modules, default) or "detail" (files grouped by module); format = "mermaid" (default) or "dot" (Graphviz).
render_diagram(source, outPath, format?)Writes a self-contained, styled .html (renders via CDN: Mermaid, or Viz for DOT) plus the raw .mermaid/.dot file.
Resource
about://authorWho built this and how to reach them (Markdown).

Most of the time you just want map_repo — "path in, diagram out." Reach for the four granular tools only when you want to compose the steps yourself (e.g. let the model refine the diagram source between generate_diagram and render_diagram).

How it stays fast on big repos

  • Languages: JavaScript/TypeScript and Python (v1).
  • Skips node_modules, .git, dist, build, venv, __pycache__, vendor, and other build/dependency/cache directories (plus all hidden dirs).
  • Caps the number of files scanned and bytes read per file; collapses the import graph to directory level past a threshold. Anything capped is reported in the output — never dropped silently.
  • No network calls at scan time. (The rendered HTML pulls Mermaid from a CDN only when you open it in a browser.)
  • Deterministic: output is sorted and stable, so diagrams don't churn between runs.

Development

bash
npm run dev        # run from source with tsxnpm run build      # type-check + emit to dist/npm test           # unit tests (node:test, no build step needed)npm run typecheck  # type-check src/ and test/ together, no emit

Tests cover the deterministic core — import resolution (JS/TS + Python), module collapsing, cycle detection, rule globs, baseline diffing, Mermaid rendering and the check end-to-end path. They run against src/ via tsx, so there is no build step and no test framework dependency.

Author

Built by Gopi K Aitham (builditwithgk) — see about://author, or scaleup-solutions.in. Available for freelance and contract work on AI, agent, and MCP tooling.

License

MIT

来源:README.md,提交 2da0787

工具

0
SourceWeft 尚未在沙箱中启动过该软件包,因此其工具未知。

版本历史

1
  1. v1.0.1最新Sep 16, 2026

评分

已满足适用检查项的 50%

该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。

  • 近 30 天内可连通25 分

    请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。

  • 已声明认证方式10 分

    请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。

  • 已列出工具15 分

    请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。

  • 描述必需15 分
  • 图标10 分
  • 文档15 分
  • 许可证10 分