Back to Cli Anything

Draw.io — CLI Harness Analysis & SOP

drawio/agent-harness/DRAWIO.md

latest5.2 KB
Original Source

Draw.io — CLI Harness Analysis & SOP

Software Overview

Draw.io (diagrams.net) is a free, open-source diagramming tool. The desktop version is built on Electron and supports creating flowcharts, architecture diagrams, ER diagrams, UML, network diagrams, and more.

Architecture

File Format: mxGraph XML (.drawio)

Draw.io uses an XML-based format built on the mxGraph library:

xml
<mxfile host="cli-anything" agent="cli-anything-drawio/1.0.0">
  <diagram id="..." name="Page-1">
    <mxGraphModel dx="1200" dy="800" grid="1" gridSize="10"
                  page="1" pageWidth="850" pageHeight="1100">
      <root>
        <mxCell id="0"/>                              <!-- root container -->
        <mxCell id="1" parent="0"/>                   <!-- default layer -->
        <mxCell id="v_123" value="Server"             <!-- shape (vertex) -->
                style="rounded=1;fillColor=#dae8fc;"
                vertex="1" parent="1">
          <mxGeometry x="100" y="100" width="120" height="60" as="geometry"/>
        </mxCell>
        <mxCell id="e_456" value="query"              <!-- connector (edge) -->
                style="edgeStyle=orthogonalEdgeStyle;"
                edge="1" source="v_123" target="v_789" parent="1">
          <mxGeometry relative="1" as="geometry"/>
        </mxCell>
      </root>
    </mxGraphModel>
  </diagram>
</mxfile>

Key properties:

  • Plain-text XML — fully parseable and writable by the CLI
  • Multi-page support: multiple <diagram> elements under <mxfile>
  • System cells: id="0" (root) and id="1" (default layer) are always present
  • Shapes: <mxCell vertex="1"> with <mxGeometry> for position/size
  • Edges: <mxCell edge="1" source="..." target="...">
  • Styles: semicolon-delimited key=value pairs in the style attribute

Rendering Pipeline

Primary: draw.io desktop CLI

.drawio file → draw.io --export --format png → rendered image

The desktop Electron app supports headless export:

  • draw.io --export input.drawio --output out.png --format png
  • draw.io --export input.drawio --output out.pdf --format pdf
  • draw.io --export input.drawio --output out.svg --format svg

Fallback: direct XML write When draw.io CLI is not installed, the CLI saves the .drawio file directly. Users can open it in draw.io (web or desktop) for manual export.

CLI Strategy

What we manipulate directly (no GUI needed):

  • Project lifecycle: create blank XML, parse existing files, write to disk
  • Shapes: add/remove/move/resize <mxCell vertex="1"> elements
  • Connectors: add/remove <mxCell edge="1"> with source/target references
  • Styles: parse/modify the style attribute string
  • Pages: add/remove/rename <diagram> elements
  • Labels: set the value attribute on any cell

What we delegate to draw.io CLI:

  • Raster export: PNG, PDF rendering (requires the Electron app)
  • SVG export: Vector rendering with proper font/text handling

Shape Registry

CLI NameStyle BaseDescription
rectanglerounded=0;whiteSpace=wrap;html=1Standard rectangle
roundedrounded=1;whiteSpace=wrap;html=1Rounded rectangle
ellipseellipse;whiteSpace=wrap;html=1Circle/oval
diamondrhombus;whiteSpace=wrap;html=1Decision diamond
triangletriangle;whiteSpace=wrap;html=1Triangle
hexagonshape=hexagon;...Hexagon
cylindershape=cylinder3;...Database cylinder
cloudellipse;shape=cloud;...Cloud shape
parallelogramshape=parallelogram;...Parallelogram
processshape=process;...Process box
documentshape=document;...Document shape
calloutshape=callout;...Speech callout
noteshape=note;...Sticky note
actorshape=mxgraph.basic.person;...Person/actor
texttext;html=1;align=center;...Text label

Edge Style Registry

CLI NameStyleDescription
straightedgeStyle=noneStraight line
orthogonaledgeStyle=orthogonalEdgeStyle;rounded=0Right-angle routing
curvededgeStyle=orthogonalEdgeStyle;curved=1;rounded=1Curved routing
entity-relationedgeStyle=entityRelationEdgeStyleER diagram style

Style Properties

Common style keys applicable to shapes and connectors:

KeyValuesDescription
fillColor#rrggbbShape fill color
strokeColor#rrggbbBorder/line color
fontColor#rrggbbText color
fontSizeintegerFont size in points
fontStyle0/1/2/40=normal, 1=bold, 2=italic, 4=underline
opacity0-100Opacity percentage
rounded0/1Rounded corners
shadow0/1Drop shadow
dashed0/1Dashed border/line
strokeWidthnumberBorder/line width
endArrowclassic/block/open/noneArrow head style
startArrowclassic/block/open/noneArrow tail style

Test Coverage

  • Unit tests: XML manipulation, style parsing, all shape/edge presets, session undo/redo, multi-page operations, complex workflows
  • E2E tests: file roundtrip, XML export verification, real draw.io export (PNG/SVG/PDF with magic byte checks), CLI subprocess, real-world diagram scenarios