Cairn, a specialized Software Architecture Diagram as Code tool
Just as a mountain trail is marked by cairns, software architecture is understood through a series of views, each revealing a different part of the landscape.
In short,
Cairn is an Elkjs (Eclipse Layout Kernel) based diagram-as-code tool specialised in these three software architecture views : logical, application and infrastructure, with the aim to follow the requirements of the methodology. This tool comes with a CLI and a browser playground, both providing template initializing for each type of diagram, validation, live previous, and export to SVG and PNG format.
Table of contents
Used by
Projects that integrate cairn:
Using cairn in your project? Feel free to open a PR to add it here.
Why cairn?
A large majority of the diagrams (logical, application, infrastructure view) in existing Software Architecture Documents I've worked are made with graphical diagramming softwares such as Drawio and the like. However, modifying diagrams manually in a GUI despite providing more control on the display, take time and migrating to diagram as code has proven complicated since most diagrams are rich and it's hard to preserve the same level of information with other solutions like C4.
Furthermore, complexe software architecture with many flows and component generated with existing diagram-as-code tools end up very large or with overlapping flow labels making them unreadable and therefore not possible to integrate in a techical architecture document that requires specifically a logical view, application, physical & infrastructure view and Cairn is made specially to answer this need by provided the following features :
| Features | Description |
|---|
| Readability through overlap-checked layout. | Label space is reserved during layout; overlaps are measured on every build, which reports how many are left, and Cairn's own CI keeps them at 0 across all its examples. Each flow stays a distinct arrow with its own label. Labels can also be numbered, with the full labels displayed in the legend. |
| Configurable dispositions | Four dispositions suit different presentation requirements: wide and tall set the reading direction, slide fits a 16:9 slide and page a portrait page |
| Spacial optimization | Cairn aims to optimize space as much as possible (Still working on improving this functionnality) |
| Typed diagrams with validation. | Each view defines its element kinds and rules; cairn validate reports syntax, schema, and completeness issues as source-located, coded diagnostics, with a JSON mode for CI. |
| Flow matrix. | cairn matrix exports the flow matrix as CSV, Markdown, or SVG — from any view, with the columns that view can fill. In infrastructure it splits protocol from port and annotates endpoints that sit in a network zone; headers localise via style { lang: fr }. The same table is available to embedders through compile(source, { matrix: true }). |
| Author-controlled positioning. | Layout is automatic, with opt-in overrides for when it gets a diagram wrong. The main ones: order: 2 sequences a top-level element along the disposition's own reading direction (left to right in wide, top to bottom in tall) and sorts siblings inside a container, A.right -> B.left pins which side of an element a flow leaves and arrives on, and the arrow glyph carries the line style (-> solid, --> dashed, ..> dotted). Finer placement uses the positioning controls: offset:, label-offset:, segment-offset:, size:. |
| Playground drag-to-adjust. | When the automatic layout needs a correction, the playground lets you drag elements, flow labels, a single route segment, or a flow's endpoint onto another side. Every drag is written back into the source as the matching hint — offset:, label-offset:, segment-offset:, ID.side — so the adjustment stays versionable text and re-renders identically from the CLI. A hovered flow label also offers a wrap button, which writes that flow's own flow-label-wrap:. |
| Enterprise-view extras. | Business objects on flows, an auto-generated legend, and a numbered-flow table via flow-text: numbered. |