@diagc/cli

中文文档
1.9.0发布于 2026/11/02AGPL-3.0-onlyTypeScriptES Module构建来源已验证近 30 天下载 2521

Author software-architecture diagrams as code, compile them to a validated model, edit them in a local studio, and publish pages and images.

原始使用文档
文档目录5 节
  1. Quickstart
  2. Commands
  3. Two ways to author, one model
  4. Documentation
  5. License

diagc

Diagrams as code, with a local studio. diagc turns diagram sources that live in your repository into things other people can open.

  • Pages and pictures. diagc publish writes one self-contained HTML page per diagram, and a PNG. The page folds, zooms and switches views in the browser, with no server behind it. Host the pages on GitHub Pages, GitLab Pages or any static host, and put the PNG in a README.
  • Diffs in pull requests. A GitHub Action comments on a pull request that changes a diagram: the list of changes, and the before and after pictures.
  • A local studio. diagc studio opens a browser app against your repository. Draw a diagram there and the studio saves it as a file in the repository. diagc eject turns a drawn diagram into TypeScript.
  • In the terminal. diagc show prints a diagram as text, for a pipe or a coding agent. diagc tui browses the diagrams full-screen and redraws as you edit.

Diagrams are plain files in your repository, so they diff, review and refactor like the rest of it.

npm i -g @diagc/cli   # or: npx @diagc/cli studio

Needs Node ≥ 22.

Quickstart

diagc init shop    # a starter diagram in .diagrams/src/, the .gitignore lines, compiled
diagc studio       # opens the editor, recompiling as you edit

npm i -D @diagc/core as well if you want types and completion on .diagram.ts files — the CLI compiles them either way.

Commands

CommandWhat it does
diagc initSet a repository up: a starter diagram (--type c4 for a C4 one), the .gitignore lines, and with --agents a pointer to the guide for coding agents (AGENTS.md / CLAUDE.md, and a Claude Code skill).
diagc compileCompile .diagrams/src/**/*.diagram.{ts,json} into validated artifacts under .diagrams/.artifacts/. The default command.
diagc lintReport what compiles but is probably a mistake — typos, duplicates, unused or undrawn parts. --json for a script or an agent; exit 1 until clean.
diagc watchCompile, then again on every change.
diagc publishWrite self-contained HTML pages to .diagrams/html/ and PNGs to .diagrams/static/.
diagc showPrint a diagram as text: boxes, lines and labels in box-drawing characters, coloured on a terminal and plain in a pipe. --plane, --layers, --depth and --root choose the view, --ascii the characters.
diagc studioServe the visual editor against the current directory (default http://127.0.0.1:5173). Diagrams drawn here are saved back as .diagram.json.
diagc tuiBrowse the diagrams full-screen in the terminal: fold and unfold, go into a group, switch planes and layers, search. Redraws as the sources change.
diagc ejectReplace a drawn .diagram.json with a generated .diagram.ts, checked first to rebuild the same model.
diagc diffDraw what changed in the diagrams between two git refs, or a ref and the working tree: before and after pages and PNGs, and a summary.
diagc guidePrint how to write a diagram: the DSL, then one topic per diagram type (diagc guide c4). Written for a coding agent as much as for a person.

diagc --help lists every command and flag, and the CLI reference has the details.

PNG export drives headless Chrome. Without one, publish writes HTML and says so; npx playwright-core install chromium gets a browser it finds, or point CHROME_PATH at one.

Two ways to author, one model

Write a .diagram.ts with the builder DSL, or draw one in the studio and it writes a .diagram.json for you. Both compile to the same validated model, so a diagram is never trapped in the tool that made it. Positions live in a separate <name>.layout.json, which keeps meaning and coordinates in different diffs.

Commit .diagrams/src/. .diagrams/.artifacts/, .diagrams/html/ and .diagrams/diff/ are build output — diagc init gitignores them.

Documentation

Website and live examples: https://ferroman.github.io/diagc/

Full docs, tutorials, and the model reference: https://github.com/Ferroman/diagc

License

AGPL-3.0-only, with additional permissions under section 7: diagrams you author, and the pages and images built from them, are yours to license however you like. A commercial license is available. See the project README.

版本与发布记录

@diagc/cli 共发布 37 个版本,首次发布于 2026/09/26;过去 12 个月发布了 37 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.9.0latest2026/11/0210 天前
1.8.02026/11/0111 天前
1.7.02026/10/1825 天前
1.6.02026/10/1825 天前
1.5.02026/10/1726 天前
1.4.02026/10/1528 天前

关于 @diagc/cli 的常见问题

@diagc/cli 是什么?

Author software-architecture diagrams as code, compile them to a validated model, edit them in a local studio, and publish pages and images.

如何安装 @diagc/cli?

在项目目录运行 npm install @diagc/cli,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 diagc,可以用 npx diagc 直接运行。

@diagc/cli 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@diagc/cli 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@diagc/cli 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@diagc/cli 可以商用吗?

@diagc/cli 使用 AGPL-3.0-only 许可。最严格的 Copyleft:除分发外,通过网络向用户提供基于它的服务也需要开源对应源码。闭源 SaaS 使用前务必评估。以上为概括,不构成法律意见,请以许可原文为准。

@diagc/cli 的下载量有多少?

根据 npm 官方下载统计,@diagc/cli 在 2026/10/12 – 2026/11/10 这 30 天内被下载 2,521 次,日均约 84 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@diagc/cli 还在维护吗?

最新版本 1.9.0 发布于 2026/11/02(10 天前);至今共发布 37 个版本,其中过去 12 个月发布了 37 个;首次发布于 2026/09/26。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。