一套模型,两张图
一份系统总览图,加一份服务内部的依赖图。数据库拆出去之后,两张都得改,漏改一张,下次新人照着旧图找服务。LikeC4 是个用文本描述软件架构的开源工具:把服务和调用关系写进 .c4 文件,再从同一份模型生成不同层级的图。
比如总览图只画「用户 → 订单系统」,细节图再展开网页、API 和数据库。用户实际访问的是系统里的网页,这条关系只写一次,LikeC4 就能在总览图里把它归到「用户 → 订单系统」。图交给工具布局,架构怎么变,用 Git diff 看模型改了哪几行。
从一个 .c4 文件开始
把下面这段存成 orders.c4。model 写服务和关系,views 决定每张图看哪一层。
specification {
element actor
element system
element component
}
model {
buyer = actor '买家'
orders = system '订单系统' {
component web '下单页面'
component api '订单 API'
component db '数据库'
web -> api '提交订单'
api -> db '保存订单'
}
buyer -> web '打开页面'
}
views {
view index {
include *
}
view of orders {
include *
}
}
在文件所在目录启动预览。这里固定用 1.61.1,该版本需要 Node.js 22.23.3 或更高版本。
npx [email protected] start
默认打开 http://localhost:5173 看图,保存模型文件后浏览器会刷新图。想把架构图放到团队内部站点,可以生成静态网页:
npx [email protected] build -o ./dist
LikeC4 不会扫描业务代码替你补关系。它适合本来就要维护多张架构图、希望把模型改动和代码放在同一个 PR 里审的团队。如果只是临时画一张图,没必要先建模型。
项目信息
- 主要语言:TypeScript
- 许可证:MIT
- GitHub Star:截至 2026-12-04 约 6,400
- GitHub:GitHub - likec4/likec4: Visualize, collaborate, and evolve the software architecture with always actual and live diagrams from your code · GitHub
- 官网:https://likec4.dev/
- 在线试玩:LikeC4 Playground
- 演示:https://template.likec4.dev/view/index
