The Problem
Architecture diagrams are typically hand‑crafted and quickly become stale as code evolves. Likec4 automates this by letting you describe a C4‑style model in a domain‑specific language and then generating live, always‑up‑to‑date diagrams from the source code itself.
What This Does
Likec4 is not a single monolith but a portfolio of six self‑contained projects (see the directory breakdown). The packages layer (6702 files, 6458 code files) houses the core modeling logic:
packages/core/src/model/DeploymentElementModel.ts– definesstyle,name,shape,color,iconand is called from 28 other files.packages/core/src/model/LikeC4Model.ts– exposesfromParsed,create,fromDump,constructor,getOrCreateFolder; 16 callers reference it.packages/core/src/utils/invariant.ts– exportsinvariant,nonNullable,nonexhaustive;invariantitself is invoked from 80 call sites, making it a central consistency guard.
The apps layer (243 files) provides a playground and documentation UI; apps/playground/src/examples/ contains demo models (bigbank, rank, deployment, dynamic) that illustrate the language. Dockerfile at the root builds a container image, and package.json files use pnpm as the package manager. The repo also includes e2e tests, styled‑system utilities, and a .agents skill set for agent orchestration.
How It Is Wired
Execution starts from a handful of entry points identified by the call‑graph analysis:
| Entry point | File (reaches) | Calls |
|---|---|---|
| init | packages/create-likec4/src/index.ts:38 | reaches 4 functions, called from 1 place |
| run | devops/commands/clean.ts:18 | reaches 12 functions, called by nothing else in the repo |
| write | packages/create-likec4/src/index.ts:58 | reaches 2 functions, called from 1 place |
| copy | packages/create-likec4/src/index.ts:9 | reaches 1 function, called from 3 places |
| copyDir | packages/create-likec4/src/index.ts:18 | reaches 1 function, called from 1 place |
Tracing the shortest paths shows two concrete side‑effects:
init → write→ filesystem viafs.writeFileSync(creates/overwrites generated diagram files).run → loadPrepackGitignore→ filesystem viafs.readFile(reads the gitignore prepacked for the container).
The internal call graph also highlights high‑impact hubs: invariant (80 callers), includes (38), nonNullable (36), and isString (31). Changing any of these ripples through many modules, so they should be treated as stability anchors.
How To Use It
- Install –
pnpm install(the rootpackage.jsonand allapps/*/package.jsonfiles use pnpm). - Build / run – The CLI is exposed via
npx likec4 start(as documented in the README). This launches the development server that watches source files and refreshes diagrams automatically. - Configuration – No environment variables are required for basic operation; the model is defined in
.likec4DSL files placed alongside your code. The Dockerfile (Dockerfile) builds a container image (node:22.22.3-bookworm/-slim) that can be deployed if you prefer an isolated runtime. - Custom notation – Override or extend element types in
packages/core/src/model/or add new shapes via the skilladd-new-element-shapeunder.agents/skills/.
Missing evidence – The repo does not expose apyproject.tomlorMakefile; all build‑time steps are covered by the Node‑based tooling and Docker.
Real‑World Use
A development team wanting to keep their C4 diagrams in sync can add a .likec4 model describing containers, components, and relations. Running npx likec4 start starts a Vite dev server (configured in apps/playground/vite.config.ts) that parses the model, invokes packages/core/src/compute-view/ to compute views, and streams the resulting SVG/PNG to the browser. When a service class is renamed or a new API endpoint is added, the diagram updates on the next refresh, eliminating the “drift” problem entirely.
Code Health & Issues
The static analysis produced seven hygiene findings (ranked by severity/confidence):
- [CRITICAL] Keep secrets out of workflows a fork can trigger –
.github/workflows/prepare-release.yamlcontainsBOT_APP_PRIVATE_KEY,BOT_APP_ID. A PR could exfiltrate these publish tokens. Fix: move secret‑using steps into aworkflow_runjob that never checks out PR code, or gate on an environment with required reviewers. - [HIGH] Pin third‑party GitHub Actions to a commit SHA –
pnpm/action-setup@v6,cloudflare/wrangler-action@v4,docker/setup-docker-action@v4,docker/login-action@v3use mutable version tags. Fix: replace each@vNwith the 40‑character commit SHA and let Dependabot bump the SHAs. - [MEDIUM] Pin the container base image by digest –
Dockerfileusesnode:22.22.3-bookwormandnode:22.22.3-bookworm-slimwithout a digest. Fix: usenode:22.22.3-bookworm@sha256:<digest>and enable Dependabot’s docker ecosystem. - [MEDIUM] Gate pull requests on a dependency vulnerability scan – CI has no dependency‑scan step. Fix: add
dependency-review-actiononpull_requestor runosv-scanneron push and a schedule. - [MEDIUM] Set
persist-credentials: falseon checkout –checkoutkeeps the token, allowing later steps to read pushable credentials. Fix: addwith: persist-credentials: falseand pass an explicit token only to the push step. - [MEDIUM] Add a non‑root USER to the image –
Dockerfilehas noUSERdirective; the process runs as root. Fix: create an unprivileged user,chownneeded paths, and end the Dockerfile withUSER. - [LOW] Set
timeout-minuteson workflow jobs –docker.yamldeclares no job timeout, risking overlapping runs on a two‑hourly schedule. Fix: add a realistictimeout-minutesto each job.
The Bottom Line
Likec4 delivers a pragmatic way to keep architecture diagrams live and code‑driven, with a clear modeling language and a modest set of entry points that make the system easy to understand and extend. The codebase is well‑structured (6 self‑contained projects) and has CI, Docker, and test coverage in place. However, several SDLC hygiene items—especially secrets in workflows, mutable action versions, and an untagged Docker base image—need attention before the project can be considered production‑ready at scale. Teams that value up‑to‑date visual architecture and are willing to address the listed security/configuration gaps will find Likec4 a valuable addition to their tooling stack.