Draw.io integration
LikeC4 can export views to Draw.io (.drawio) so you can edit diagrams in Draw.io or reuse them in tools that support the format.
CLI: likec4 export drawio — see CLI — Export to Draw.io.
This page describes what is mapped on export, export profiles, re-export with round-trip comment blocks, and limitations.
Export (LikeC4 → Draw.io)
Section titled “Export (LikeC4 → Draw.io)”By default, one .drawio file is produced per view (the view becomes one diagram tab in that file).
Use the CLI option --all-in-one to write all views as tabs of a single .drawio file.
Export profiles
Section titled “Export profiles”Export can use two profiles:
| Profile | Description |
|---|---|
default |
Standard round-trip; layout, stroke, waypoints, and existing style attributes (see Mapped to Draw.io below). |
leanix |
Adds bridge-managed metadata on vertices, edges, and diagram root so diagrams can be used with the LeanIX bridge or LeanIX tooling. |
When using leanix profile:
- Vertices and root cell:
bridgeManaged=true,likec4Id,likec4Kind,likec4ViewId, and (if provided)likec4ProjectId. OptionallyleanixFactSheetTypeper element kind whenleanixFactSheetTypeByKindis set (e.g. via custom generator). - Edges:
likec4RelationId,bridgeManaged.
CLI: likec4 export drawio --profile leanix -o ./diagrams
Programmatic: Pass profile: 'leanix' (and optionally projectId, leanixFactSheetTypeByKind) in GenerateDrawioOptions, see Generators API. See @likec4/leanix-bridge for sync and round-trip mapping.
Mapped to Draw.io
Section titled “Mapped to Draw.io”| LikeC4 | Draw.io |
|---|---|
| View (view id) | Diagram tab name and id; view title/description in root cell as likec4ViewTitle, likec4ViewDescription |
| Element id | mxCell id (internal); hierarchy via parent |
| Element title, description | mxCell value (title; description in HTML or in style likec4Description) |
| Element: technology, notes, tags, navigateTo, icon | Style likec4Technology, likec4Notes, likec4Tags, likec4NavigateTo, likec4Icon (URI-encoded). navigateTo is also written as a Draw.io cell link so the element opens the view tab when clicked (see below). |
| Element: summary, links | Style likec4Summary, likec4Links (JSON array) |
| Element: notation | Style likec4Notation |
| Element: shape | Style shape (rectangle, umlActor, cylinder3, document, etc.) |
| Element: color | Style fillColor, strokeColor, fontColor (hex); theme/custom name in likec4ColorName; stroke in likec4StrokeColor for round-trip |
| Element: border, opacity | Style strokeWidth, likec4Border, likec4StrokeWidth (round-trip); opacity |
| Element: size, padding, textSize, iconPosition | Style likec4Size, likec4Padding, likec4TextSize, likec4IconPosition |
| View notation | Root cell likec4ViewNotation (round-trip) |
| Element position/size | mxGeometry x, y, width, height (from layout; overridable via options) |
| Element/edge custom data | mxUserObject <data key="k">v</data> (round-trip) |
| Edge waypoints | mxGeometry relative="0" with <Array> of <mxPoint> (when viewmodel has points) |
| Relationship: source, target, label | mxCell edge source, target, value |
| Relationship: description, technology, notes, navigateTo | Style likec4Description, likec4Technology, likec4Notes, likec4NavigateTo |
| Relationship: kind, notation | Style likec4RelationshipKind, likec4Notation |
| Relationship: links, metadata | Style likec4Links (JSON array), likec4Metadata (JSON object) |
| Relationship: head/tail, line style, color | Style endArrow, startArrow, dashed/dashPattern, strokeColor; label uses theme relationships.label for font color |
Navigability (elements with their own view): If an element has navigateTo set (in the model) to a view id, the exported Draw.io cell gets a link that opens the diagram tab with id likec4-<viewId>. So when you export all views (--all-in-one), clicking that element in the first diagram jumps to the tab of the view that shows the element’s internals. Set navigateTo <viewId> on the element in your LikeC4 model so the viewmodel provides it; the exporter then adds the link automatically.
Export uses the project theme (or LikeC4 default) for element and relationship colors; containers (bounded contexts) are drawn behind their children as a wrapping rectangle; edge connection points are derived from layout so arrows attach on the correct sides of nodes.
The Playground writes uncompressed diagram XML by default, for maximum compatibility.
The CLI compresses it by default; use --uncompressed to write it raw.
Not preserved on export
Section titled “Not preserved on export”- View rules (include/exclude, style rules) — only the resulting nodes and edges are exported.
- Layout drifts / fine position tweaks — only final node position is written (or the provided
layoutOverride). - Theme color names — stored as hex in Draw.io;
likec4ColorNamekeeps the name for round-trip.
Re-export using comment blocks
Section titled “Re-export using comment blocks”The exporter can take layout, vertex stroke color/width, and edge waypoints from round-trip comment blocks in the .c4 source,
so the generated .drawio file matches a previously edited diagram.
The blocks are written by parseDrawioToLikeC4, or by hand:
| Block | Content |
|---|---|
// <likec4.layout.drawio> … // </likec4.layout.drawio> |
JSON with node positions and sizes per view: { "<viewId>": { "nodes": { "<fqn>": { "x", "y", "width", "height" } } } } |
// <likec4.strokeColor.vertices> … // </likec4.strokeColor.vertices> |
One // <fqn>=<hex> line per element |
// <likec4.strokeWidth.vertices> … // </likec4.strokeWidth.vertices> |
One // <fqn>=<width> line per element |
// <likec4.edge.waypoints> … // </likec4.edge.waypoints> |
One // <source>|<target> [[x,y],…] line per edge; the key can end with |<edgeId> for parallel edges |
- CLI:
likec4 export drawio --roundtripreads all.c4and.likec4files of the workspace and applies the blocks. With--all-in-one, they are applied per view in that file. - Playground: export applies the blocks found in the current workspace source.
Generators API
Section titled “Generators API”The @likec4/generators package exports the functions the CLI and the Playground use, for custom tooling:
import { buildDrawioExportOptionsFromSource, generateDrawio, generateDrawioMulti, parseDrawioRoundtripComments, type GenerateDrawioOptions,} from '@likec4/generators'
// One view, one diagramconst xml = generateDrawio(viewmodel, { compressed: false })
// Several views as tabs of one file, options per view idconst multiXml = generateDrawioMulti(viewmodels, { [viewId]: { profile: 'leanix', projectId } })
// Options from round-trip comment blocks in the .c4 sourceconst options = buildDrawioExportOptionsFromSource(viewId, c4Source)viewmodel is a layouted view from the model API (e.g. model.view('index')).
GenerateDrawioOptions include layoutOverride (per-node bbox { x, y, width, height }, same shape as @likec4/core BBox),
strokeColorByNodeId, strokeWidthByNodeId, edgeWaypoints, compressed (generateDrawio compresses unless it is false)
and profile (default or leanix; with leanix, optionally projectId and leanixFactSheetTypeByKind).
Troubleshooting
Section titled “Troubleshooting”The exported .drawio file does not open in Draw.io (e.g. “Could not add object Array”, blank diagram, or Draw.io desktop / Open file / Import does nothing):
- Playground: Exports are uncompressed by default so the file opens in Draw.io desktop and via Open file / Import. Refresh the app and export again.
- CLI: Use
--uncompressedso the diagram XML is written raw (no compression):likec4 export drawio --uncompressed -o ./out. This produces a larger file that opens reliably in Draw.io desktop. - If you still use compressed export, update to the latest release (older versions used an invalid XML structure for edge waypoints):
pnpm update likec4ornpm update likec4, then export again.
The diagram shows fewer elements than expected:
- Each view exports exactly what you see in that view. A top-level view (e.g.
view index { include * }) typically shows only top-level elements (e.g. Customer and Our SaaS). Nested elements (e.g. Frontend, Backend inside the system) appear in the element view of that system (e.g.view saas of saas { include * }). To get all elements in Draw.io in one file, use Export all views (CLI:--all-in-one) and open the tab for the nested view, or switch to that view in the Playground before exporting.