TopoCode 使用文档

源码架构分析平台 · 深度代码学习的「分析显微镜」

一、产品简介

TopoCode 是面向「深度代码学习」场景的源码架构分析平台。它不是一句提示词生成架构图的效率工具,而是通过静态代码解析、依赖图计算、社区发现算法和 AI 辅助分析,帮助你逐层理解项目架构、提升架构认知水平。

核心能力

  • 项目导入与管理 — 本地目录导入、文件树浏览、分组管理
  • 多语言代码解析 — 基于 Tree-sitter 的 AST 解析,支持 18+ 编程语言
  • 架构可视化 — 依赖图 / 调用图 / 社区结构图(D3.js / Cytoscape)
  • 社区发现 — Louvain / Leiden 算法自动识别代码模块(社区)结构
  • AI 架构分析 — LLM 驱动的 Agent 工作流,自动生成组件分析与架构概览文档
  • 交互式 AI 助手 — 基于项目上下文的智能问答,支持工具调用
  • 外脑知识库 — 分析文档持久化,构建「存储 → 分析 → 使用」闭环
  • Architect 工作台 — 语义资产 / 需求 / 设计 / Coding Agent 实施全链路
  • MCP 接口 — 对外部 Agent/工具提供 Model Context Protocol(HTTP)接入
隐私说明:除用户自行配置的云端 LLM API 外,代码解析、图计算、架构分析、文档服务等所有功能均在本地运行,项目源码和解析数据不会上传至任何外部服务器。
运行形态:Web 应用(浏览器访问本地服务 :3456),无桌面端依赖;服务器 / 虚拟机 / 容器均可直接运行。

二、安装与启动

前置要求

  • Node.js >= 20.0.0,Python >= 3.10,npm(或 pnpm)、pip
  • 推荐运行环境:CPU 4 核+ / 内存 16 GB+ / 磁盘 10 GB+(Linux / macOS / Windows)
  • 分析主要依赖主流云端模型:4 核 8G 即可满足基本使用;如需接入本地模型,建议大显存 GPU 且模型能力足够

从源码安装

git clone https://github.com/topocode/topoone-ui
cd topoone-ui
npm run setup   # 创建 .venv + pip install -e(核心 + 4 子项目后端)+ npm install

启动与访问

npm run serve   # 等价于 topo serve:supervisor 拉起 9 进程,网关监听 :3456
npm run status  # 查看进程状态(topo status)
bash scripts/serve.sh stop   # 停止

首次启动会生成访问 token(见终端输出)。浏览器访问:

http://localhost:3456/#token=<token>

开发模式

npm run dev   # core 后端 + 4 前端 dev server 并发
npm run build # core bundle + portal + 4 子项目前端构建
截图待补拍:终端 topo serve 启动与 token 输出images/zh/serve-token.png

三、门户与界面总览

TopoCode 为 Monorepo 多子项目形态,统一门户提供入口导航。所有界面经本地网关 :3456 反向代理访问:

URL子项目说明
/ · /home门户统一门户首页,项目与子应用入口
/appworkbench 主工作台项目导入、分析、可视化、知识库
/projects · /viewer · /web-rootdocs 文档浏览(:3481)架构文档浏览与渲染
/chatchat AI 对话(:3483)会话 / 技能 / 草稿
/architectarchitect 工作台(:3470)语义资产 / 需求 / 设计 / Coding Agent

界面语言(中文 / English)在设置中切换,AI 分析输出同步遵循所选语言。

截图待补拍:统一门户首页images/zh/portal-home.png
截图待补拍:主工作台整体布局images/zh/workbench-layout.png

四、项目管理与基线设定

4.1 导入项目

在主工作台导入本地源码目录(支持拖拽),导入后可分组管理(项目与分组为 M:N 关系)、浏览文件树。TopoCode 直接解析磁盘上的源码文件,不依赖完整编译环境。

代码生成项目提示:若项目包含 protobuf、graphql-codegen、go generate 等代码生成步骤,生成源码不在原始代码中,导入前可先手动执行生成命令,使生成文件纳入分析范围。
截图待补拍:项目导入(拖拽目录)images/zh/project-import.png
截图待补拍:项目列表与分组images/zh/project-list.png

4.2 基线设定

架构概览页提供「基线设定」卡片,自动识别三种基线形态并给出对应操作:

  • Git 仓库 — 以 git 历史为基线,支持基线刷新与变更 diff
  • codegraph — 使用外部 codegraph CLI 产出的符号索引(目标项目 .codegraph/codegraph.db),是 architect 语义资产的符号源
  • 自管基线 — 无 git 环境时由 TopoCode 自管快照

codegraph 缺失时系统自动降级为轻量文件扫描;可用 topo doctor 检测环境健康度。基线设定完成后会触发组件命名(AI 语义命名),可在概览页查看命名进度或重新执行。

截图待补拍:概览页基线设定卡片images/zh/baseline-init.png

五、架构分析

5.1 解析流水线

  1. 语法解析 — Tree-sitter AST 解析、符号提取(纯静态,不依赖 LLM,约 2~5 分钟)
  2. 图构建 — 调用图 / 依赖图 / 文件中心度计算(NetworkX)
  3. 社区发现 — Louvain / Leiden 算法识别模块(社区)结构
  4. 文件预摘要 — LLM 批量摘要(可选,约 1 分钟/个,数百文件需数小时)
  5. 组件分析 — LLM 多轮对话分析组件职责(1~5 分钟/个)
  6. 架构概览 — 综合摘要生成架构概览文档(1~5 分钟)

5.2 可视化浏览

依赖图 / 调用图 / 社区结构图支持交互式浏览(D3.js / Cytoscape 力导向布局),Mermaid / PlantUML 图表嵌入文档展示。

5.3 变更概览与开发简报

基线刷新后,项目概览展示按组件层级组织的变更清单(新增 / 修改 / 删除 / 重命名,可展开至变更文件);「开发简报(驾驶舱)」生成近期变更摘要,条目可深链跳转到基线 diff 或对应会话。

截图待补拍:依赖图 / 社区结构可视化images/zh/graph-view.png
截图待补拍:项目概览(组件变更树 + 开发简报)images/zh/overview-digest.png

六、文档浏览

docs 子项目(独立服务 :3481)提供分析产出文档的浏览:架构概览、组件文档、AI 研讨产物等均持久化存储,经 viewer / web-root 路由访问。

图表渲染统一走 topo 内核(DiagramSchema IR 单一事实源):

  • Mermaid — 浏览器端主线程渲染;服务端无头渲染池(chromium)需 pip install -e "packages/core[diagrams]" + playwright install chromium,未装时 render 接口返回 503
  • PlantUML — 优先本地 sidecar(JVM :3491,jar 放 ~/.topocode/plantuml.jar),未就绪时自动兜底本地 jar → 远程服务
截图待补拍:文档浏览 viewerimages/zh/docs-viewer.png

七、AI 对话

chat 子项目(独立服务 :3483,路由 /chat)提供基于项目上下文的交互式 AI 助手:

  • 会话管理:多会话、技能(prompt 模板)、草稿箱
  • 工具调用:符号搜索、文件读取、图查询等,回答锚定真实代码
  • 流式输出,中英文与界面语言一致

使用前需在「设置 → 模型配置」中添加 LLM(见第十章)。

截图待补拍:AI 对话界面images/zh/ai-chat.png

八、Architect 工作台与 Coding Agent

architect 子项目(独立服务 :3470,路由 /architect)是「从认知到实施」的工作台:语义资产管理、需求分析、设计、以及驱动 Coding Agent 完成实施作业。

8.1 语义资产

以 codegraph 符号索引为符号源,结合 AI 命名与归属分析,形成组件树状语义资产;支持组件改名、合并、未归属文件管理等操作,是需求/设计分析的知识底座。

8.2 Coding Agent 执行器

实施作业经 runner 服务(:3458)在独立 worktree + 分支中执行,支持三类执行器:

执行器会话/多回合审批检查点备注
cline(默认)✓ 常驻多回合✓ 工具白名单 + 越界审批✓ git 快照 restore / compare结构化收口、MCP 注入、会话内换模
opencode✓ serve 重启自动重建无头模式全 allow(协议约束)✗实例空闲自动回收
codex✓ thread 续never + 沙箱✗readOnly 走只读沙箱

作业内省:消息流、token 用量、待审批项、检查点;可注入规约/规则/agent 配置到作业工作区,支持运行中 steer(转向输入)。

截图待补拍:Architect 工作台images/zh/architect-workbench.png
截图待补拍:Coding Agent 实施作业(消息流/审批/检查点)images/zh/coding-agent-run.png

九、知识库

分析文档持久化存储于本地知识库(SQLite + DuckDB)。知识库是迭代重点,目标是成为与用户认知高度契合的外脑知识库:不仅静态存储,还将通过 MCP 等多种对接方式帮助用户指挥驾驭其他 Agent 工具,实现知识的「存储 → 分析 → 使用」闭环。

截图待补拍:知识库浏览与管理images/zh/knowledge-base.png

十、设置与配置

10.1 模型配置

启动应用后,在 设置 → 模型配置 中添加 LLM,支持任何兼容 OpenAI API 格式的提供商。

用途推荐方案说明
架构解析(Agent 工作流)主流云端模型(DeepSeek / GPT / Claude 等,兼容 OpenAI API)解析涉及多轮工具调用与长上下文,对模型能力要求高;本地中小模型适配尚不理想,建议接入主流模型
AI Chat 对话主流云端模型(如 DeepSeek V4 Flash / GPT-4o / Claude)交互式对话对模型能力要求较高

常见地址:DeepSeek https://api.deepseek.com;OpenAI 兼容 https://api.openai.com;本地推理(Ollama http://localhost:11434、LM Studio http://localhost:1234)亦可接入,但效果取决于模型能力。

截图待补拍:模型配置页images/zh/model-config.png

10.2 通用设置

可修改 HTTP 端口(默认 3456)与绑定地址、界面语言(中 / EN)、主题。

10.3 PlantUML 渲染服务

建议自建 PlantUML 服务(数据不出内网):

docker run -d --name plantuml -p 8300:8080 plantuml/plantuml-server:jetty
# 国内镜像:registry.cn-hangzhou.aliyuncs.com/dockerhub-mirror/plantuml/plantuml-server:jetty

设置后端环境变量 PLANTUML_SERVER=http://localhost:8300 并重启生效(默认 http://www.plantuml.com/plantuml,内网环境必须改为自建地址)。

10.4 MCP Server

对外部 Agent/工具提供 MCP(HTTP)接口,独立进程 :3460,topo serve 会随 9 进程自动拉起:

端点说明
GET http://localhost:3460/v1/tools列出可用工具(arch.read / arch.write / arch.invoke / arch.status)
POST http://localhost:3460/v1/tools/{tool}/call执行工具调用(转发至 architect :3470)

十一、FAQ

访问提示 token 无效 / 未登录?

首次启动 topo serve 会在终端输出访问 token,以 http://localhost:3456/#token=<token> 形式访问;URL 中的 #token= 片段登录后即持久化。

:3470 端口被占用 / architect 启动失败?

architect 带实例互斥 pidfile:若存在受监管的旧实例会拒绝双开。请先停止 supervisor(bash scripts/serve.sh stop)再重启,勿手动双开。

分析很慢?

LLM 密集阶段(文件预摘要、组件分析)耗时与模型吞吐、并发配置相关,参见第五章各阶段预估。建议使用吞吐高的主流云端模型,并按配置调高并发。

codegraph 未安装会怎样?

architect 语义资产自动降级为轻量文件扫描(精度下降)。topo doctor 可检测并提示。建议在目标项目先建立 .codegraph/codegraph.db 索引。

图表 render 接口返回 503?

无头渲染池依赖未安装:执行 pip install -e "packages/core[diagrams]" 与 playwright install chromium;或仅使用浏览器端渲染。

生成的代码文件没被分析?

TopoCode 解析磁盘源码,不执行构建。导入前手动跑代码生成命令(如 go generate ./...、protoc)后重新同步。


项目地址:github.com/topocode/topoone-ui · 问题反馈:Issues · 邮箱:topocode@163.com

TopoCode User Guide

Source code architecture analysis platform — an "analysis microscope" for deep code learning

1. Introduction

TopoCode is a source code architecture analysis platform for "deep code learning". Rather than a one-shot prompt-to-diagram tool, it combines static parsing, dependency graph computation, community detection and AI-assisted analysis to help you understand a project's architecture layer by layer and elevate your architectural cognition.

Core Capabilities

  • Project import & management — local directory import, file tree browsing, grouping
  • Multi-language parsing — Tree-sitter based AST parsing, 18+ languages
  • Architecture visualization — dependency / call / community graphs (D3.js / Cytoscape)
  • Community detection — Louvain / Leiden algorithms identify module structure
  • AI architecture analysis — LLM-driven agent workflow generating component docs & overviews
  • Interactive AI assistant — project-context Q&A with tool calling
  • External-brain knowledge base — persistent docs forming a store → analyze → use loop
  • Architect workbench — semantic assets / requirements / design / Coding Agent delivery
  • MCP endpoints — Model Context Protocol (HTTP) access for external agents
Privacy: except for user-configured cloud LLM APIs, parsing, graph computation, analysis and doc serving all run locally. Your source code never leaves the machine.
Form factor: a web app served by a local gateway (:3456); runs on servers, VMs and containers with no desktop/Electron dependency.

2. Installation & Launch

Requirements

  • Node.js >= 20.0.0, Python >= 3.10, npm (or pnpm), pip
  • Recommended: 4+ CPU cores / 16 GB+ RAM / 10 GB+ disk (Linux / macOS / Windows)
  • Analysis mainly relies on frontier cloud models: 4 cores / 8 GB suffices for basic usage; local LLMs require a large-VRAM GPU and a capable model

Install from Source

git clone https://github.com/topocode/topoone-ui
cd topoone-ui
npm run setup   # creates .venv + pip install -e (core + 4 backends) + npm install

Run & Access

npm run serve   # = topo serve: supervisor spawns 9 processes; gateway on :3456
npm run status  # process status (topo status)
bash scripts/serve.sh stop   # stop

The first launch prints an access token. Open in browser:

http://localhost:3456/#token=<token>

Development Mode

npm run dev   # core backend + 4 frontend dev servers concurrently
npm run build # core bundle + portal + 4 sub-app frontends
Screenshot pending: topo serve startup & token outputimages/en/serve-token.png

3. Portal & Layout

TopoCode is a monorepo of sub-apps behind a unified portal, reverse-provided by the local gateway :3456:

URLSub-appDescription
/ · /homePortalUnified home with project & app entries
/appWorkbenchImport, analysis, visualization, knowledge base
/projects · /viewer · /web-rootDocs (:3481)Architecture document browsing & rendering
/chatChat (:3483)Sessions / skills / drafts
/architectArchitect (:3470)Semantic assets / requirements / design / Coding Agent

UI language (中文 / English) is switchable in settings; AI analysis output follows it.

Screenshot pending: portal homeimages/en/portal-home.png
Screenshot pending: workbench overall layoutimages/en/workbench-layout.png

4. Project Management & Baseline

4.1 Import a Project

Import a local source directory (drag & drop) in the workbench; projects support grouping (M:N), file-tree browsing. TopoCode parses source files directly from disk and requires no build environment.

Code-generated projects: if a project generates source (protobuf, graphql-codegen, go generate...), run the generation command before import so generated files are included in analysis.
Screenshot pending: project import (drag directory)images/en/project-import.png
Screenshot pending: project list & groupsimages/en/project-list.png

4.2 Baseline Setup

The overview page shows a "baseline" card that detects three baseline modes and offers matching actions:

  • Git repo — git history as baseline, supports refresh & diff
  • codegraph — external codegraph CLI symbol index (.codegraph/codegraph.db in the target project), the symbol source for architect semantic assets
  • Self-managed — TopoCode-managed snapshots without git

When codegraph is missing it degrades to a lightweight file scan; topo doctor checks environment health. After the baseline is set, AI component naming runs; view progress or re-run it on the overview page.

Screenshot pending: baseline card on overview pageimages/en/baseline-init.png

5. Architecture Analysis

5.1 Pipeline

  1. Parsing — Tree-sitter AST + symbol extraction (pure static, ~2–5 min)
  2. Graph building — call / dependency graphs, file centrality (NetworkX)
  3. Community detection — Louvain / Leiden identify module structure
  4. File pre-summary — LLM batch summarization (optional, ~1 min/file)
  5. Component analysis — LLM multi-turn analysis (1–5 min each)
  6. Architecture overview — consolidated overview document (1–5 min)

5.2 Visualization

Dependency / call / community graphs support interactive browsing (D3.js / Cytoscape force layouts); Mermaid / PlantUML diagrams embed in documents.

5.3 Change Overview & Digest

After a baseline refresh, the project overview lists changes grouped by component hierarchy (added / modified / deleted / renamed, expandable to files). The "development digest (cockpit)" summarizes recent changes with deep links into baseline diffs or sessions.

Screenshot pending: dependency/community graphimages/en/graph-view.png
Screenshot pending: overview (component diff tree + digest)images/en/overview-digest.png

6. Document Viewer

The docs sub-app (service :3481) browses analysis outputs: architecture overviews, component docs, AI discussion artifacts — persisted and served via viewer / web-root routes.

Diagram rendering runs on the unified topo kernel (DiagramSchema IR as single source of truth):

  • Mermaid — client-side main-thread rendering; the server headless pool (chromium) requires pip install -e "packages/core[diagrams]" + playwright install chromium (render endpoints return 503 otherwise)
  • PlantUML — local JVM sidecar (:3491, jar at ~/.topocode/plantuml.jar) preferred, auto-fallback to local jar → remote service
Screenshot pending: docs viewerimages/en/docs-viewer.png

7. AI Chat

The chat sub-app (service :3483, route /chat) provides a project-context interactive assistant:

  • Session management: multiple sessions, skills (prompt templates), drafts
  • Tool calling: symbol search, file reading, graph queries — answers anchored to real code
  • Streaming output; language matches UI setting

Add an LLM under Settings → Model Configuration first (see section 10).

Screenshot pending: AI chat interfaceimages/en/ai-chat.png

8. Architect Workbench & Coding Agent

The architect sub-app (service :3470, route /architect) is the "from cognition to implementation" workbench: semantic assets, requirements, design, and driving Coding Agents through implementation jobs.

8.1 Semantic Assets

Built on the codegraph symbol index plus AI naming & ownership analysis into a component-tree of semantic assets; supports renaming, merging and unassigned-file management — the knowledge foundation for requirement/design analysis.

8.2 Coding Agent Executors

Implementation jobs run via the runner service (:3458) in isolated worktrees + branches, with three executors:

ExecutorSessionsApprovalCheckpointsNotes
cline (default)✓ resident multi-turn✓ tool allowlist + escalation bridge✓ git snapshot restore / comparestructured turn outcome, MCP injection, in-session model switch
opencode✓ auto-rebuild on serve restartheadless full-allow (protocol-bound)✗idle instances auto-recycled
codex✓ thread resumenever + sandbox✗readOnly uses read-only sandbox

Job introspection: message stream, token usage, pending approvals, checkpoints. Specs/rules/agent configs can be injected into the job workspace; steering input supported mid-run.

Screenshot pending: architect workbenchimages/en/architect-workbench.png
Screenshot pending: Coding Agent job (messages/approval/checkpoints)images/en/coding-agent-run.png

9. Knowledge Base

Analysis documents persist in a local knowledge base (SQLite + DuckDB). The KB is the iteration focus: an external-brain aligned with your cognition — not just static storage but, via MCP and other integrations, a base that helps you command other agent tools, closing the store → analyze → use loop.

Screenshot pending: knowledge base browsingimages/en/knowledge-base.png

10. Settings & Configuration

10.1 Model Configuration

Add LLMs under Settings → Model Configuration; any OpenAI-compatible provider works.

PurposeRecommendationNotes
Architecture parsing (agent workflow)Frontier cloud models (DeepSeek / GPT / Claude, OpenAI-compatible)Parsing involves multi-round tool calls with long context; small local models are not yet well-suited — use mainstream models
AI ChatFrontier cloud models (DeepSeek V4 Flash / GPT-4o / Claude)Interactive Q&A demands stronger models

Common endpoints: DeepSeek https://api.deepseek.com; OpenAI https://api.openai.com; local runtimes (Ollama http://localhost:11434, LM Studio http://localhost:1234) also work, with quality depending on the model.

Screenshot pending: model configuration pageimages/en/model-config.png

10.2 General Settings

Change HTTP port (default 3456) and bind address, UI language (中 / EN), and theme.

10.3 PlantUML Rendering Service

Self-hosting PlantUML is recommended (data stays in your network):

docker run -d --name plantuml -p 8300:8080 plantuml/plantuml-server:jetty

Then set backend env PLANTUML_SERVER=http://localhost:8300 and restart (default is http://www.plantuml.com/plantuml; intranet deployments must switch to self-hosted).

10.4 MCP Server

MCP (HTTP) endpoints for external agents run as a separate process on :3460 (auto-started by topo serve):

EndpointDescription
GET http://localhost:3460/v1/toolsList tools (arch.read / arch.write / arch.invoke / arch.status)
POST http://localhost:3460/v1/tools/{tool}/callInvoke a tool (forwarded to architect :3470)

11. FAQ

Token invalid / not logged in?

The first topo serve prints an access token; open http://localhost:3456/#token=<token>. The #token= fragment persists after login.

Port :3470 in use / architect fails to start?

Architect enforces a pidfile mutex: a supervised instance refuses double-launch. Stop the supervisor first (bash scripts/serve.sh stop), then restart.

Analysis is slow?

LLM-heavy stages (file pre-summary, component analysis) depend on model throughput and concurrency — see stage estimates in section 5. Prefer high-throughput frontier cloud models and raise concurrency in settings.

What if codegraph is missing?

Architect semantic assets degrade to a lightweight file scan (lower precision). topo doctor detects it. Prefer building .codegraph/codegraph.db in the target project first.

Render endpoints return 503?

The headless rendering pool isn't installed: run pip install -e "packages/core[diagrams]" and playwright install chromium, or rely on browser-side rendering only.

Generated source files missing from analysis?

TopoCode parses files on disk and never runs builds. Execute codegen (e.g. go generate ./..., protoc) before import, then resync.


Repository: github.com/topocode/topoone-ui · Issues: Issues · Email: topocode@163.com