项目简介
LikeC4 是一种受 C4 模型启发的建模语言和工具集,能够从代码直接生成始终最新的架构图,支持协作和架构演进。提供 CLI、VS Code 扩展和实时预览服务器。
README 预览
# Architecture as a code\n\nVisualize, collaborate on, and evolve your software architecture with always up-to-date, live diagrams generated from your code.\n\n[docs](https://likec4.dev/) - [playground](https://playground.likec4.dev/) - [demo](https://template.likec4.dev/view/index)\n\n \n\n\n\n\n\n\n## What is LikeC4? Why "like"?\n\nLikeC4 is a modeling language for describing software architecture and tools to generate diagrams from the model.\n\nLikeC4 is inspired by [C4 Model](https://c4model.com/) and [Structurizr DSL](https://github.com/structurizr/dsl), but provides some flexibility.\nYou customize or define your own notation, element types, and any number of nested levels in architecture model.\\nPerfectly tailored to your needs.\n\n## What does LikeC4 look like?\n\nLikeC4 source:\n\n\n \n\n\nRun [CLI](./packages/likec4/README.md) to preview:\n\n```sh\nnpx likec4 start\n```\n\nAnd result:\n\n\n \n\n\nTemplate repository - [likec4/template](https://github.com/likec4/template)\\nDeployed - [https://template.likec4.dev](https://template.likec4.dev/view/index)\n\n[](https://stackblitz.com/~/github.com/likec4/template)\n\nCheck [Tutorial](https://likec4.dev/tutorial/) - for a quick overview of LikeC4.\n\n## Getting help\n\nWe are always happy to help you get started:\n\n- [Join Discord community](https://discord.gg/86ZSpjKAdA) – it is the easiest way to get help\n- [GitHub Discussions](https://github.com/likec4/likec4/discussions) – ask anything about the project or give feedback\n\n## Contributors\n\n\n \n\n\n[Become a contributor](./CONTRIBUTING.md)\n\n## Support development\n\nLikeC4 is a MIT-licensed open source project with its ongoing development made possible entirely by your support.\\nIf you like the project, please consider contributing financially to help grow and improve it.\\nYou can support us via [OpenCollective](https://opencollective.com/likec4) or [GitHub Sponsors](https://github.com/sponsors/likec4).\n\n## License\n\nThis project is release
常见问题 (5)
故障排除如何修复在两个已导入的同级元素之间建立关系时出现的 LikeC4 错误 "Layout validation failed: Element @owner not found"?
此问题影响 LikeC4 CLI 1.59.3 和 1.59.4。当连接诸如 @owner.a 和 @owner.b 这样的导入元素时,commonAncestor() 会错误地将项目命名空间 @owner 视为模型元素。
临时解决方法:将这两个元素放在一个真实的父元素下,然后导入该父元素。
在 owner/model.c4 中:
model {
system platform {
system a
system b
}
}
在 consumer/model.c4 中:
import { platform } from 'owner'
model {
platform.a -> platform.b "Example relationship"
}
views {
view example {
include platform.a, platform.b
}
}
永久修复:在 packages/core/src/utils/fqn.ts 中,更新 commonAncestor(),使单个 @namespace 段不会被作为祖先返回:
if (
ancestor.length === 0 ||
(ancestor.length === 1 && ancestor[0]!.startsWith('@'))
) {
return null
}使用打过补丁的构建版本,或升级到包含 PR "fix(core): ignore project namespace in commonAncestor of imported elements" 的发布版本。使用以下命令验证:
npx likec4 validate --project consumer . --json故障排除如何修复 LikeC4 可视化编辑器在 dynamic view 之外插入重复样式规则的问题?
升级到 LikeC4 v1.59.4 或更高版本;该 bug 已在 language-server 中修复,修复方式是将样式更改插入到视图的右大括号之前。升级后,删除外层 views 块中重复的 style 块,仅保留所编辑动态视图内的规则,例如:
dynamic view example {
user -> app
style app {
shape mobile
}
}
在 v1.59.3 上的临时解决方法是:在使用可视化编辑器之前,先在动态视图内添加任意本地样式规则,例如 style user {},这样后续的样式插入就会保留在视图内部。
故障排除为什么 LikeC4 元素详情对话框中的长元数据值未被截断,且缺少显示完整值的工具提示(tooltip)?
值所在的网格列使用了 1fr,它会解析为 minmax(auto, 1fr)。在 white-space: nowrap 的作用下,其最小宽度会变成完整文本的宽度,因此该列会扩展而不是截断值。修复 packages/diagram/src/overlays/element-details/ElementDetailsCard.tsx 中的网格,将值列改为 minmax(0, 1fr):
gridTemplateColumns: 'min-content minmax(0, 1fr)'
同时在 packages/diagram/src/overlays/element-details/MetadataValue.tsx 中为元数据值的包装元素添加 minWidth: 0,并保留截断样式:
{
minWidth: 0,
overflow: 'hidden',
textOverflow: 'ellipsis',
whiteSpace: 'nowrap'
}
这样可以让该列收缩到低于其内容宽度,使长值满足 scrollWidth > clientWidth,从而启用悬停提示框(tooltip)。短值保持不变。如果修复后提示框显示在对话框背板(backdrop)后面,还需要将 portal 提示框的 z-index 提高到 <dialog> 和背板之上(与 #3256 相关)。
故障排除为什么 LikeC4 动态视图步骤中缺少关系类型的默认标题?
这是 LikeC4 1.59.3 中的一个 bug:关系类型的默认 technology 会被应用到动态视图步骤,但其默认 title 却不会。请升级到包含修复 fix(core): apply relationship kind default title to dynamic view steps 的版本。作为临时解决方案,可以在步骤中显式地重复标题:
gatewayService2 -[discover]-> discoveryServer ':8761'
如果不添加显式的 ':8761',标题将无法渲染,直到使用修复后的版本。
故障排除如何修复 LikeC4 HTML 导出忽略动态视图的 "variant: sequence" 属性而显示图表视图的问题?
出现这种情况是因为导出的 SPA 在初始渲染时将 URL 的 dynamic 参数默认设置为 diagram,从而覆盖了视图中配置的 variant: sequence。
临时解决方法:使用显式查询参数打开导出的 HTML:
index.html?dynamic=sequence
如果 URL 已经包含查询字符串,则使用:
index.html?...&dynamic=sequence
对于本地单文件导出,可以按如下方式打开,例如:
file:///absolute/path/to/index.html?dynamic=sequence
永久修复:升级到包含"在初始渲染时遵循动态视图 variant"修复的 LikeC4 版本,然后重新构建:
npx -y likec4@latest build -o "./html" --output-single-file