LikeC4 CLI
The likec4 CLI is a tool for various operations and automation tasks, such as:
- Start development server to preview diagrams (with hot-reload)
- Build a static website for sharing and embedding diagrams
- Export to PNG, JSON, Mermaid, Dot, D2, DrawIO
- Import from DrawIO (.drawio → LikeC4)
- Generate source code artifacts:
- React components
- Web Components
- Typed data
Install
Section titled “Install”Local installation
Section titled “Local installation”If you’re using it in an npm project, install it as a development dependency:
npm i -D likec4pnpm add -D likec4yarn add -D likec4bun add -d likec4You can reference it directly in the package.json#scripts object:
{ scripts: { dev: 'likec4 dev ...', build: 'likec4 build ...' }}Global installation
Section titled “Global installation”To fetch and execute a package binary, without installing it as a dependency:
npx likec4 startpnpx likec4 startyarn dlx likec4 startbunx likec4 startTo use it in any project without npx, install it globally:
npm install --global likec4
# Then, you can call `likec4` directly:likec4 [command]Almost all commands have a --help option and provide usage examples.
likec4 build -hlikec4 gen react -hPreview diagrams
Section titled “Preview diagrams”In a folder with LikeC4 sources:
likec4 serve# Aliases:likec4 startlikec4 devThis recursively searches for *.c4 and *.likec4 files in the current folder, parses them, and serves diagrams via a local web server.
Any change in the source files triggers a hot update in the browser immediately.
Build static website
Section titled “Build static website”CLI can build a website with the diagrams, ready to be deployed or embedded.
When you deployed the website, you can use “Share” button and get a link to a specific diagram.
The resulting website is strictly bound to the given base path (/ by default).
A relocatable app can be built with --base "./".
likec4 build -o ./dist| Option | Description |
|---|---|
--output | Output directory |
--base, --base-url | Base URL from which the app is being served, e.g., ”/”, “/pages/”, or ”./” for a relocatable app |
--use-hash-history | Hash-based navigation, e.g. ”/#/view” instead of “/view” |
--use-dot | Use local binaries of Graphviz (“dot”) instead of bundled WASM |
--webcomponent-prefix | Prefix for web components, e.g. “c4” generates <c4-view ../> |
--title | Base title of the app pages (default is “LikeC4”) |
--output-single-file | Generates a single self-contained HTML file |
There is also a supplementary command to preview the build:
likec4 preview -o ./distFor example, this command can be used in CI to compare diagrams with ones from the previous or main build.
Export to PNG
Section titled “Export to PNG”likec4 export png -o ./assetsThis command starts local web server and uses Playwright to take screenshots.
If you plan to use it in CI, refer to the Playwright documentation for details
or consider LikeC4 GitHub Actions
| Option | Description |
|---|---|
--output, --outdir | output directory, if not specified, images are saved next to sources |
--project | select LikeC4 project to export from by name (e.g. “my-project”) or by path If not specified, exports all |
--theme | color-scheme to use, “light” (default), “dark” |
--dark | use dark theme, shortcut for —theme=dark |
--light | use light theme, shortcut for —theme=light |
--use-dot | Use local binaries of Graphviz (“dot”) instead of bundled WASM |
--seq, --sequence | use sequence layout for dynamic views |
--flat, --flatten | flatten all images in output directory ignoring sources structure |
-f, --filter | include views with ids matching given patterns (multiple patterns are combined with OR) |
-i, --ignore | continue if export fails for some views |
-t, --timeout | timeout for playwright in seconds, default is 15 |
--max-attempts | max attempts to export failing view, 1 means no retry (default is 3) |
--server-url | use this url instead of starting new likec4 server |
--chromium-sandbox | enable chromium sandbox (see Playwright docs) |
Export to JSON
Section titled “Export to JSON”likec4 export json -o dump.jsonExport to DrawIO
Section titled “Export to DrawIO”Export views to DrawIO (.drawio) so you can edit diagrams in draw.io or reuse them in tools that support the format. One .drawio file is generated per view.
likec4 export drawiolikec4 export drawio -o ./diagramslikec4 export drawio -o ./diagrams src/| Option | Description |
|---|---|
path | Path to project (default: current directory) |
--outdir, -o | Output directory for .drawio files (default: current directory or path) |
--project | Select LikeC4 project by name or path; if not set, exports all |
--use-dot | Use local Graphviz (dot) for layout instead of bundled WASM |
Import from DrawIO
Section titled “Import from DrawIO”Convert an existing DrawIO diagram to LikeC4 source (.c4) so you can adopt LikeC4 from DrawIO assets or round-trip between the two.
likec4 import drawio diagram.drawiolikec4 import drawio diagram.drawio -o src/model.c4| Option | Description |
|---|---|
input | Path to .drawio or .drawio.xml file |
--outfile, -o | Output .c4 file (default: same name as input with .c4) |
Elements (actors, systems, containers) and relationships are inferred from shapes and edges; colors and custom properties (e.g. description, technology) are preserved when present in the DrawIO file.
Generate Mermaid, Dot, D2, PlantUml
Section titled “Generate Mermaid, Dot, D2, PlantUml”Via codegen:
likec4 gen mmdlikec4 gen mermaidlikec4 gen dotlikec4 gen d2likec4 gen plantumlTogether with Export to DrawIO and Import from DrawIO, this allows teams to reuse diagrams in Mermaid, Dot, D2, PlantUML, or DrawIO.
Validate
Section titled “Validate”likec4 validateThis command checks for:
- Syntax errors
- Layout drift (outdated manual layout)
If any errors are found, the command exits with a non-zero return code.