Skip to main content

Style reference for AI diagram generation

This document is a companion to mxfile.xsd and provides all information needed to programmatically generate valid draw.io (.drawio) files. All data was extracted from the draw.io source code.

See also: Generate and validate draw.io diagrams with AI


1. File Structure Overview

A minimal valid draw.io file:

<mxfile>
<diagram id="page-1" name="Page-1">
<mxGraphModel dx="0" dy="0" grid="1" gridSize="10" guides="1"
tooltips="1" connect="1" arrows="1" fold="1"
page="1" pageScale="1" pageWidth="850" pageHeight="1100"
math="0" shadow="0">
<root>
<!-- Root container (always required, always id="0") -->
<mxCell id="0" />
<!-- Default layer (always required, always id="1", parent="0") -->
<mxCell id="1" parent="0" />
<!-- Diagram elements go here with parent="1" -->
</root>
</mxGraphModel>
</diagram>
</mxfile>

Critical Rules

  1. The first two mxCell elements are mandatory structural cells:
    • id="0" — root container, no parent attribute
    • id="1" with parent="0" — default layer
  2. All diagram elements must have parent="1" (or the id of a group/layer).
  3. IDs must be unique within the diagram. Use any string (e.g. "2", "node-1", "abc123").
  4. Vertices need vertex="1", edges need edge="1"** — these are mutually exclusive.
  5. Edges should reference source and target via cell IDs. Edges without connections need explicit mxPoint sourcePoint/targetPoint.
  6. Always use uncompressed XML (no compressed="true"). AI should not generate compressed content.
  7. Style strings end with semicolon. Example: "rounded=1;whiteSpace=wrap;html=1;"
  8. Coordinates: origin (0,0) is top-left, x increases rightward, y increases downward.

2. Style String Format

The style attribute on mxCell is a semicolon-separated list of key=value pairs:

key1=value1;key2=value2;key3=value3;

A style class name or shape name can appear as a bare token (without =):

ellipse;whiteSpace=wrap;html=1;fillColor=#DAE8FC;

Here ellipse sets the shape. Multiple bare tokens are possible for style class inheritance:

text;html=1;align=left;

Rules

  • Keys and values are case-sensitive
  • No spaces around = or ;
  • Boolean values use 0 and 1 (not true/false)
  • Colors use #RRGGBB hex format (with #), none, or default
  • The trailing ; is conventional but not strictly required
  • Unknown keys are silently ignored

3. Shape Types

3.1 Core mxGraph Shapes

These shapes are defined in the mxGraph core library:

shape= valueDescriptionNotes
rectangleRectangle (default)Also the default if no shape specified
ellipseOval / ellipseUse aspect=fixed for circle
rhombusDiamondUse perimeter=rhombusPerimeter
triangleTriangleUse perimeter=trianglePerimeter
hexagonHexagonUse perimeter=hexagonPerimeter2
cloudCloud
cylinder3D Cylinder
lineHorizontal line
arrowBlock arrow
arrowConnectorArrow-shaped connector
doubleEllipseDouble-bordered ellipse
imageImage containerRequires image=<url>
labelRectangle with icon areaDefault vertex shape
swimlaneContainer with header barUse startSize for header height
actorActor (stick figure outline)
connectorEdge connectorDefault edge shape

3.2 Extended Shapes (draw.io Shapes.js)

These are registered via mxCellRenderer.registerShape():

shape= valueDescription
cube3D cube
isoCubeIsometric cube
isoCube2Isometric cube (variant 2)
isoRectangleIsometric rectangle
cylinder2Cylinder (variant 2, configurable)
cylinder3Cylinder (variant 3)
datastoreCylindrical data store
noteSticky note
note2Note (variant 2)
documentDocument page with curled bottom
folderFolder icon
cardCard with cut corner
tapePunched tape
tapeDataTape data storage
processProcess box (double-sided borders)
process2Same as process
stepStep/chevron arrow
plusPlus sign
extExtended rectangle (supports double=1)
calloutSpeech bubble
parallelogramParallelogram (use perimeter=parallelogramPerimeter)
trapezoidTrapezoid (use perimeter=trapezoidPerimeter)
curlyBracketCurly bracket
switchNetworking switch shape
transparentInvisible shape
messageEnvelope/message
cornerL-shaped corner
crossbarCross bar
teeT-shaped connector
singleArrowSingle arrow
doubleArrowDouble-headed arrow
flexArrowFlexible arrow
wireWire connector
waypointWaypoint marker
manualInputManual input (flowchart)
internalStorageInternal storage (flowchart)
dataStorageData storage (flowchart)
loopLimitLoop limit (flowchart)
offPageConnectorOff-page connector
delayDelay shape
displayDisplay device
orOR gate
orEllipseOR ellipse
xorXOR gate
sumEllipseSum/sigma ellipse
sortShapeSort shape
collateCollate shape
crossCross / X shape
dimensionDimension line
partialRectangleRectangle with configurable borders
lineEllipseLine with ellipse
linkLink / chain shape
pipePipe connector
zigzagZigzag connector
filledEdgeFilled edge connector
tableTable container
tableRowTable row
tableLineTable line
rect2Alternative rectangle

3.3 UML Shapes

shape= valueDescription
umlActorUML stick figure
umlBoundaryUML boundary
umlEntityUML entity
umlDestroyUML destruction mark
umlControlUML control
umlLifelineUML lifeline
umlFrameUML frame
umlStateUML state (use perimeter=mxPerimeter.StatePerimeter)
lollipopUML provided interface
requiresUML required interface
requiredInterfaceUML required interface (arc)
providedRequiredInterfaceUML assembly connector
moduleUML module
componentUML component
associativeEntityER associative entity
endStateState diagram end state
startStateState diagram start state

3.4 Stencil Libraries

Additional shapes are available via stencil libraries in the stencils/ directory. Use with: shape=stencil(<library>.<shape>) or shape=mxgraph.<library>.<shape>.

Major libraries:

  • mxgraph.flowchart.* — Flowchart shapes
  • mxgraph.bpmn.* — BPMN shapes
  • mxgraph.aws4.* — AWS architecture icons
  • mxgraph.azure.* — Azure architecture icons
  • mxgraph.gcp.* / mxgraph.gcp2.* — Google Cloud icons
  • mxgraph.cisco.* / mxgraph.cisco19.* — Cisco networking
  • mxgraph.kubernetes.* — Kubernetes icons
  • mxgraph.uml.* — UML shapes
  • mxgraph.er.* — Entity-relationship shapes
  • mxgraph.electrical.* — Electrical engineering symbols
  • mxgraph.pid.* — Piping and instrumentation
  • mxgraph.mockup.* — UI wireframe components
  • mxgraph.lean_mapping.* — Lean mapping
  • mxgraph.eip.* — Enterprise integration patterns

4. Style Properties Reference

4.1 Fill and Stroke

PropertyValuesDefaultDescription
fillColor#RRGGBB, none, defaultdefaultShape fill color
gradientColor#RRGGBB, nonenoneGradient end color (gradient from fillColor to gradientColor)
gradientDirectionnorth, south, east, westsouthGradient direction
strokeColor#RRGGBB, none, defaultdefaultBorder/stroke color
strokeWidthnumber1Border width in pixels
dashed0, 10Dashed stroke
dashPatternstringDash pattern, e.g. "1 3" (1px dash, 3px gap), "8 8"
opacity0100100Overall opacity (0=transparent, 100=opaque)
fillOpacity0100100Fill opacity only
strokeOpacity0100100Stroke opacity only
glass0, 10Glass/shine overlay effect
shadow0, 10Drop shadow (also controlled globally on mxGraphModel)

4.2 Shape Geometry

PropertyValuesDefaultDescription
shapesee Shape Types abovelabelShape type
perimetersee Perimeters belowrectanglePerimeterConnection point calculation
rounded0, 10Round rectangle corners
arcSizenumberCorner radius for rounded shapes (0–50, as percentage)
aspectvariable, fixedvariablefixed preserves width/height ratio
directionnorth, south, east, westRotate shape by 90° increments
flipH0, 10Flip horizontally
flipV0, 10Flip vertically
rotationnumber (degrees)0Free rotation angle (0–360)
fixedSize0, 10Shape keeps size independent of label

4.3 Text and Labels

PropertyValuesDefaultDescription
html0, 11Enable HTML label rendering
whiteSpacewrap, nowrapText wrapping mode. Use wrap for most shapes
fontSizenumber12Font size in pixels
fontFamilystringHelveticaFont family name
fontColor#RRGGBB, defaultdefaultText color
fontStylebitmask0Font style: 0=normal, 1=bold, 2=italic, 4=underline (combine by adding: 3=bold+italic)
alignleft, center, rightcenterHorizontal text alignment
verticalAligntop, middle, bottommiddleVertical text alignment
labelPositionleft, center, rightcenterHorizontal label position relative to shape
verticalLabelPositiontop, middle, bottommiddleVertical label position relative to shape
overflowvisible, hidden, fill, widthText overflow handling
spacingnumber2General padding in pixels
spacingTopnumber0Top padding
spacingBottomnumber0Bottom padding
spacingLeftnumber0Left padding
spacingRightnumber0Right padding
textOpacity0100100Text opacity
labelBackgroundColor#RRGGBB, none, defaultBackground behind text (useful for edge labels)
labelBorderColor#RRGGBB, noneBorder around label
labelWidthnumberFixed label width
textDirectiondefault, ltr, rtldefaultText direction
horizontal0, 110 for vertical text

4.4 Edge / Connector Properties

PropertyValuesDefaultDescription
edgeStylesee Edge Styles belowRouting algorithm
curved0, 10Curved edge path
rounded0, 11Round edge corners (for orthogonal)
jettySizeauto, numberautoSpacing from port for orthogonal edges
sourceJettySizenumberSource-side jetty override
targetJettySizenumberTarget-side jetty override
orthogonalLoop0, 11Self-loop routing style
elbowhorizontal, verticalElbow edge direction
jumpStylearc, gap, sharpLine crossing visualization
jumpSizenumber6Jump width at crossings

4.5 Arrow Markers

PropertyValuesDefaultDescription
startArrowarrow typenoneMarker at edge start
endArrowarrow typeclassicMarker at edge end
startSizenumberStart marker size
endSizenumberEnd marker size
startFill0, 11Fill start marker
endFill0, 11Fill end marker

Arrow type values:

ValueDescription
noneNo arrow
classicStandard filled triangle
classicThinThin triangle
blockFilled block
blockThinThin block
openOpen (unfilled) triangle
openThinThin open triangle
ovalCircle/oval
diamondDiamond
diamondThinThin diamond
boxSquare box
halfCircleHalf circle
circleCircle
circlePlusCircle with plus
crossCross mark
baseDashPerpendicular dash
doubleBlockDouble filled block
dashShort dash
asyncAsynchronous (half-arrow)
openAsyncOpen asynchronous arrow
manyOptionalER many-optional (crow's foot)

Fill behavior: startFill=0/endFill=0 renders the marker as an outline only. This is important for UML and ER diagram conventions (e.g., open diamond = aggregation, filled diamond = composition).

4.6 Connection Points

PropertyValuesDefaultDescription
exitX0.01.0Relative x of exit point (0=left, 0.5=center, 1=right)
exitY0.01.0Relative y of exit point (0=top, 0.5=middle, 1=bottom)
exitDxnumberAbsolute x offset from exit point
exitDynumberAbsolute y offset from exit point
exitPerimeter0, 11Use perimeter for exit point
entryX0.01.0Relative x of entry point
entryY0.01.0Relative y of entry point
entryDxnumberAbsolute x offset from entry point
entryDynumberAbsolute y offset from entry point
entryPerimeter0, 11Use perimeter for entry point
portConstrainteastwest, northsouth, perimeter, fixedPort constraint

4.7 Container / Swimlane Properties

PropertyValuesDefaultDescription
container0, 10Cell is a container (children can be placed inside)
collapsible0, 11Container can be collapsed
recursiveResize0, 11Resize children when container resizes
swimlaneFillColor#RRGGBBSwimlane header fill color
startSizenumber23Swimlane header height in pixels
horizontal0, 11Swimlane orientation (1=header on top, 0=header on left)
childLayoutstackLayout, treeLayout, flowLayoutAuto-layout for children
resizeParent0, 1Parent resizes to fit children
resizeParentMax0, 1Limit parent resize
resizeLast0, 1Last child fills remaining space
horizontalStack0, 1Stack direction (1=horizontal, 0=vertical)
marginBottomnumberBottom margin for stack layout

4.8 Image Properties

PropertyValuesDefaultDescription
imageURL stringImage URL (data: URIs also supported)
imageWidthnumber42Image width
imageHeightnumber42Image height
imageAlignleft, center, rightImage horizontal alignment
imageVerticalAligntop, middle, bottomImage vertical alignment
imageAspect0, 11Preserve image aspect ratio

4.9 Sketch / Hand-Drawn Style

PropertyValuesDefaultDescription
sketch0, 10Enable hand-drawn/sketch style (uses rough.js)
comic0, 10Comic book style
fillStylesolid, hachure, cross-hatch, dotsFill pattern for sketch mode
fillWeightnumberHatch line weight (negative = thinner)
hachureGapnumberGap between hatch lines in pixels
hachureAnglenumber (degrees)Angle of hatch lines
jigglenumberHand-drawn jiggle amount
curveFitting01Curve fitting quality
simplification01Path simplification
disableMultiStroke0, 1Disable double-stroke effect
disableMultiStrokeFill0, 1Disable double-stroke fill

4.10 Behavior Properties

PropertyValuesDefaultDescription
movable0, 11Allow moving
resizable0, 11Allow resizing
rotatable0, 11Allow rotation
bendable0, 11Allow bending edges
editable0, 11Allow label editing
deletable0, 11Allow deletion
cloneable0, 11Allow cloning
foldable0, 1Allow fold/collapse
connectable0, 11Allow connections
pointerEvents0, 11Enable mouse events
autosize0, 10Auto-size to fit content

5. Edge Styles (Routing Algorithms)

edgeStyle= valueDescription
orthogonalEdgeStyleRoutes with right-angle turns (most common)
segmentEdgeStyleManual segments with horizontal/vertical segments
elbowEdgeStyleSingle elbow (one bend). Combine with elbow=horizontal or elbow=vertical
entityRelationEdgeStyleEntity-relationship style (perpendicular exits)
isometricEdgeStyleIsometric diagram routing
loopEdgeStyleSelf-referencing loop
sideToSideEdgeStyleSide-to-side connection
topToBottomEdgeStyleTop-to-bottom connection
(empty/none)Straight line, no routing

Common edge style combinations:

edgeStyle=orthogonalEdgeStyle;rounded=1;         # Rounded orthogonal (default-like)
edgeStyle=orthogonalEdgeStyle;curved=1; # Curved orthogonal
edgeStyle=elbowEdgeStyle;elbow=horizontal; # Horizontal elbow
edgeStyle=entityRelationEdgeStyle; # ER-style connections
edgeStyle=none; # Straight line

6. Perimeter Types

The perimeter determines how connection points are calculated on a shape's border:

perimeter= valueUse with
rectanglePerimeterRectangles (default)
ellipsePerimeterEllipses, circles
rhombusPerimeterDiamond shapes
trianglePerimeterTriangles
hexagonPerimeter2Hexagons
parallelogramPerimeterParallelograms
trapezoidPerimeterTrapezoids
calloutPerimeterCallout/speech bubbles
backbonePerimeterBackbone/bus shapes
centerPerimeterSingle center point
stepPerimeterStep/chevron shapes

Important: When using non-rectangular shapes, always set the matching perimeter. Otherwise edges will connect to the rectangular bounding box instead of the visible shape border.


7. Predefined Style Classes

These class names can be used as bare tokens in the style string. They set multiple style properties at once:

ClassSets
textNo fill, no stroke, left-aligned, top-aligned
edgeLabelExtends text, adds label background, font size 11
labelBold, left-aligned, with image area (42x42), rounded
iconExtends label, centered image above text
swimlaneSwimlane shape, bold, header size 23
groupNo fill, no stroke, transparent container
ellipseEllipse shape with ellipsePerimeter
rhombusDiamond shape with rhombusPerimeter
triangleTriangle shape with trianglePerimeter
lineLine shape, strokeWidth=4
imageImage shape with label below
arrowArrow shape, no edge routing

Color Theme Classes

Each sets fillColor, gradientColor, strokeColor, plus shadow=1 and glass=1:

ClassfillColorgradientColorstrokeColor
blue#DAE8FC#7EA6E0#6C8EBF
green#D5E8D4#97D077#82B366
yellow#FFF2CC#FFD966#D6B656
orange#FFCD28#FFA500#D79B00
red#F8CECC#EA6B66#B85450
pink#E6D0DE#B5739D#996185
purple#E1D5E7#8C6C9C#9673A6
gray#F5F5F5#B3B3B3#666666
turquoise#D5E8D4#67AB9F#6A9153

plain-* variants (e.g. plain-blue) set the same colors without shadow and glass.


8. Common Color Palettes

Standard draw.io Colors

These are commonly used in the draw.io UI:

Fill colors (light):

  • #DAE8FC (light blue)
  • #D5E8D4 (light green)
  • #FFF2CC (light yellow)
  • #F8CECC (light red)
  • #E1D5E7 (light purple)
  • #E6D0DE (light pink)
  • #F5F5F5 (light gray)
  • #FFCD28 (orange)
  • #FFE6CC (light orange)

Stroke colors (matching):

  • #6C8EBF (blue)
  • #82B366 (green)
  • #D6B656 (yellow/gold)
  • #B85450 (red)
  • #9673A6 (purple)
  • #996185 (pink)
  • #666666 (gray)
  • #D79B00 (orange)

Font/accent colors:

  • #000000 (black)
  • #FFFFFF (white)
  • #333333 (dark gray)
  • #0000EE (link blue)

Special Color Values

  • none — transparent / no color (removes fill or stroke)
  • default — uses the current theme's default (resolves at render time)

9. HTML Labels

When html=1 is set in the style, the cell's value attribute can contain HTML:

Supported HTML Elements

  • <b>, <i>, <u>, <s> — text formatting
  • <br> / <br/> — line break
  • <p>, <div>, <span> — block/inline containers
  • <font> — font attributes (face, size, color)
  • <table>, <tr>, <td>, <th> — tables
  • <ul>, <ol>, <li> — lists
  • <hr> — horizontal rule
  • <img> — inline images (with src attribute)
  • <a> — links (href attribute)
  • <sub>, <sup> — subscript/superscript

HTML in Attributes

HTML in the value attribute must be XML-escaped:

  • <&lt;
  • >&gt;
  • &&amp;
  • "&quot;

Example:

<mxCell value="&lt;b&gt;Title&lt;/b&gt;&lt;br&gt;Description"
style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">

Common HTML Patterns

Bold title with description:

&lt;b&gt;Title&lt;/b&gt;&lt;br&gt;Description text

UML class box (within table container):

&lt;p style=&quot;margin:0px;margin-top:4px;text-align:center;&quot;&gt;&lt;b&gt;ClassName&lt;/b&gt;&lt;/p&gt;
&lt;hr size=&quot;1&quot;/&gt;
&lt;p style=&quot;margin:0px;margin-left:4px;&quot;&gt;+ field: Type&lt;/p&gt;
&lt;hr size=&quot;1&quot;/&gt;
&lt;p style=&quot;margin:0px;margin-left:4px;&quot;&gt;+ method(): ReturnType&lt;/p&gt;

Colored text:

&lt;font color=&quot;#FF0000&quot;&gt;Red text&lt;/font&gt;

10. Layers

Layers are additional mxCell elements with parent="0":

<root>
<mxCell id="0" />
<mxCell id="1" parent="0" /> <!-- Default layer -->
<mxCell id="layer2" value="Background" parent="0" /> <!-- Additional layer -->

<!-- Elements on default layer -->
<mxCell id="2" ... parent="1" />

<!-- Elements on "Background" layer -->
<mxCell id="3" ... parent="layer2" />
</root>

To hide a layer: add visible="0" to the layer cell.


11. Groups and Containers

A group/container is a vertex that other cells reference as their parent:

<!-- Group container -->
<mxCell id="group1" value="Group" style="group;" vertex="1" parent="1">
<mxGeometry x="100" y="100" width="300" height="200" as="geometry" />
</mxCell>

<!-- Children reference the group as parent -->
<mxCell id="child1" value="Inside" style="rounded=1;html=1;" vertex="1" parent="group1">
<mxGeometry x="10" y="10" width="100" height="40" as="geometry" />
</mxCell>

Key points:

  • Child coordinates are relative to the parent container
  • Use style="group;" for invisible containers
  • Use style="swimlane;startSize=30;" for containers with a visible header
  • Add container=1; to any style to make it act as a container
  • collapsible=0; prevents the collapse/expand button

Collapsible Containers and Alternate Bounds

When a container (e.g. swimlane) is collapsible, draw.io stores alternate bounds in an mxRectangle child element inside mxGeometry. When the container is collapsed/expanded, the geometry swaps between the normal and alternate bounds:

<mxCell id="class1" value="ClassName" style="swimlane;fontStyle=1;childLayout=stackLayout;startSize=26;collapsible=1;" vertex="1" parent="1">
<mxGeometry x="100" y="100" width="200" height="150" as="geometry">
<mxRectangle x="100" y="100" width="200" height="26" as="alternateBounds" />
</mxGeometry>
</mxCell>

The alternateBounds typically has the same x/y but a smaller height (just the header). AI generators generally do not need to produce mxRectangle elements — draw.io adds them automatically when the user collapses a container.


12. Edge Geometry and Labels

Basic Connected Edge

<mxCell id="e1" value="" style="endArrow=classic;html=1;"
edge="1" parent="1" source="v1" target="v2">
<mxGeometry relative="1" as="geometry" />
</mxCell>

Edge with Waypoints

<mxCell id="e2" value="" style="edgeStyle=orthogonalEdgeStyle;html=1;"
edge="1" parent="1" source="v1" target="v2">
<mxGeometry relative="1" as="geometry">
<Array as="points">
<mxPoint x="300" y="150" />
<mxPoint x="300" y="250" />
</Array>
</mxGeometry>
</mxCell>

Edge with Label

Edge labels are usually encoded in the edge cell's value. The label position is controlled by the geometry:

<mxCell id="e3" value="label text" style="endArrow=classic;html=1;"
edge="1" parent="1" source="v1" target="v2">
<mxGeometry x="-0.5" y="0" relative="1" as="geometry">
<mxPoint as="offset" />
</mxGeometry>
</mxCell>
  • x on geometry: position along edge (-1 to 1, where 0 = center, -1 = near source, 1 = near target)
  • y on geometry: perpendicular offset in pixels

Unconnected Edge (Floating)

<mxCell id="e4" value="" style="endArrow=classic;html=1;"
edge="1" parent="1">
<mxGeometry relative="1" as="geometry">
<mxPoint x="100" y="200" as="sourcePoint" />
<mxPoint x="300" y="100" as="targetPoint" />
</mxGeometry>
</mxCell>

13. Complete Examples

Example 1: Simple Flowchart

<mxfile>
<diagram id="flowchart" name="Flowchart">
<mxGraphModel dx="0" dy="0" grid="1" gridSize="10" guides="1"
tooltips="1" connect="1" arrows="1" fold="1"
page="1" pageScale="1" pageWidth="850" pageHeight="1100">
<root>
<mxCell id="0" />
<mxCell id="1" parent="0" />

<!-- Start -->
<mxCell id="start" value="Start" style="ellipse;whiteSpace=wrap;html=1;fillColor=#D5E8D4;strokeColor=#82B366;" vertex="1" parent="1">
<mxGeometry x="340" y="40" width="120" height="60" as="geometry" />
</mxCell>

<!-- Decision -->
<mxCell id="decision" value="Condition?" style="rhombus;whiteSpace=wrap;html=1;fillColor=#FFF2CC;strokeColor=#D6B656;" vertex="1" parent="1">
<mxGeometry x="320" y="150" width="160" height="80" as="geometry" />
</mxCell>

<!-- Process A -->
<mxCell id="procA" value="Process A" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#DAE8FC;strokeColor=#6C8EBF;" vertex="1" parent="1">
<mxGeometry x="160" y="290" width="120" height="60" as="geometry" />
</mxCell>

<!-- Process B -->
<mxCell id="procB" value="Process B" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#DAE8FC;strokeColor=#6C8EBF;" vertex="1" parent="1">
<mxGeometry x="520" y="290" width="120" height="60" as="geometry" />
</mxCell>

<!-- End -->
<mxCell id="end" value="End" style="ellipse;whiteSpace=wrap;html=1;fillColor=#F8CECC;strokeColor=#B85450;" vertex="1" parent="1">
<mxGeometry x="340" y="420" width="120" height="60" as="geometry" />
</mxCell>

<!-- Edges -->
<mxCell id="e1" style="endArrow=classic;html=1;" edge="1" parent="1" source="start" target="decision">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="e2" value="Yes" style="endArrow=classic;html=1;" edge="1" parent="1" source="decision" target="procA">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="e3" value="No" style="endArrow=classic;html=1;" edge="1" parent="1" source="decision" target="procB">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="e4" style="endArrow=classic;html=1;" edge="1" parent="1" source="procA" target="end">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="e5" style="endArrow=classic;html=1;" edge="1" parent="1" source="procB" target="end">
<mxGeometry relative="1" as="geometry" />
</mxCell>
</root>
</mxGraphModel>
</diagram>
</mxfile>

Example 2: UML Class Diagram

<mxfile>
<diagram id="uml" name="Classes">
<mxGraphModel dx="0" dy="0" grid="1" gridSize="10" guides="1"
tooltips="1" connect="1" arrows="1" fold="1"
page="1" pageScale="1" pageWidth="850" pageHeight="1100">
<root>
<mxCell id="0" />
<mxCell id="1" parent="0" />

<!-- Class: Animal -->
<mxCell id="animal" value="&lt;p style=&quot;margin:0px;margin-top:4px;text-align:center;&quot;&gt;&lt;i&gt;&amp;lt;&amp;lt;abstract&amp;gt;&amp;gt;&lt;/i&gt;&lt;br&gt;&lt;b&gt;Animal&lt;/b&gt;&lt;/p&gt;&lt;hr size=&quot;1&quot;/&gt;&lt;p style=&quot;margin:0px;margin-left:4px;&quot;&gt;+ name: String&lt;br&gt;+ age: int&lt;/p&gt;&lt;hr size=&quot;1&quot;/&gt;&lt;p style=&quot;margin:0px;margin-left:4px;&quot;&gt;+ speak(): void&lt;br&gt;+ move(): void&lt;/p&gt;" style="verticalAlign=top;align=left;overflow=fill;fontSize=12;fontFamily=Helvetica;html=1;whiteSpace=wrap;" vertex="1" parent="1">
<mxGeometry x="300" y="40" width="200" height="140" as="geometry" />
</mxCell>

<!-- Class: Dog -->
<mxCell id="dog" value="&lt;p style=&quot;margin:0px;margin-top:4px;text-align:center;&quot;&gt;&lt;b&gt;Dog&lt;/b&gt;&lt;/p&gt;&lt;hr size=&quot;1&quot;/&gt;&lt;p style=&quot;margin:0px;margin-left:4px;&quot;&gt;+ breed: String&lt;/p&gt;&lt;hr size=&quot;1&quot;/&gt;&lt;p style=&quot;margin:0px;margin-left:4px;&quot;&gt;+ fetch(): void&lt;/p&gt;" style="verticalAlign=top;align=left;overflow=fill;fontSize=12;fontFamily=Helvetica;html=1;whiteSpace=wrap;" vertex="1" parent="1">
<mxGeometry x="180" y="260" width="160" height="120" as="geometry" />
</mxCell>

<!-- Class: Cat -->
<mxCell id="cat" value="&lt;p style=&quot;margin:0px;margin-top:4px;text-align:center;&quot;&gt;&lt;b&gt;Cat&lt;/b&gt;&lt;/p&gt;&lt;hr size=&quot;1&quot;/&gt;&lt;p style=&quot;margin:0px;margin-left:4px;&quot;&gt;+ indoor: boolean&lt;/p&gt;&lt;hr size=&quot;1&quot;/&gt;&lt;p style=&quot;margin:0px;margin-left:4px;&quot;&gt;+ purr(): void&lt;/p&gt;" style="verticalAlign=top;align=left;overflow=fill;fontSize=12;fontFamily=Helvetica;html=1;whiteSpace=wrap;" vertex="1" parent="1">
<mxGeometry x="460" y="260" width="160" height="120" as="geometry" />
</mxCell>

<!-- Inheritance: Dog extends Animal -->
<mxCell id="e1" style="endArrow=block;endFill=0;html=1;" edge="1" parent="1" source="dog" target="animal">
<mxGeometry relative="1" as="geometry" />
</mxCell>

<!-- Inheritance: Cat extends Animal -->
<mxCell id="e2" style="endArrow=block;endFill=0;html=1;" edge="1" parent="1" source="cat" target="animal">
<mxGeometry relative="1" as="geometry" />
</mxCell>
</root>
</mxGraphModel>
</diagram>
</mxfile>

Example 3: Network Diagram with Groups

<mxfile>
<diagram id="network" name="Network">
<mxGraphModel dx="0" dy="0" grid="1" gridSize="10" guides="1"
tooltips="1" connect="1" arrows="1" fold="1"
page="1" pageScale="1" pageWidth="850" pageHeight="1100">
<root>
<mxCell id="0" />
<mxCell id="1" parent="0" />

<!-- DMZ Group -->
<mxCell id="dmz" value="DMZ" style="swimlane;startSize=25;fillColor=#F5F5F5;strokeColor=#666666;fontStyle=1;html=1;" vertex="1" parent="1">
<mxGeometry x="50" y="50" width="300" height="200" as="geometry" />
</mxCell>

<!-- Firewall inside DMZ -->
<mxCell id="fw" value="Firewall" style="shape=mxgraph.cisco.firewalls.firewall;sketch=0;html=1;whiteSpace=wrap;" vertex="1" parent="dmz">
<mxGeometry x="100" y="60" width="80" height="60" as="geometry" />
</mxCell>

<!-- Internal Group -->
<mxCell id="internal" value="Internal Network" style="swimlane;startSize=25;fillColor=#DAE8FC;strokeColor=#6C8EBF;fontStyle=1;html=1;" vertex="1" parent="1">
<mxGeometry x="450" y="50" width="300" height="200" as="geometry" />
</mxCell>

<!-- Server -->
<mxCell id="srv" value="App Server" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#D5E8D4;strokeColor=#82B366;" vertex="1" parent="internal">
<mxGeometry x="90" y="60" width="120" height="60" as="geometry" />
</mxCell>

<!-- Connection -->
<mxCell id="conn" style="endArrow=classic;startArrow=classic;html=1;strokeWidth=2;" edge="1" parent="1" source="fw" target="srv">
<mxGeometry relative="1" as="geometry" />
</mxCell>
</root>
</mxGraphModel>
</diagram>
</mxfile>

Example 4: Custom Metadata with UserObject

<mxfile>
<diagram id="metadata" name="Servers">
<mxGraphModel dx="0" dy="0" grid="1" gridSize="10" guides="1"
tooltips="1" connect="1" arrows="1" fold="1"
page="1" pageScale="1" pageWidth="850" pageHeight="1100">
<root>
<mxCell id="0" />
<mxCell id="1" parent="0" />

<!-- Server with custom attributes -->
<UserObject id="srv1" label="Web Server" tooltip="Production web server"
ip="10.0.1.10" environment="production" owner="ops-team">
<mxCell style="rounded=1;whiteSpace=wrap;html=1;fillColor=#D5E8D4;strokeColor=#82B366;" vertex="1" parent="1">
<mxGeometry x="100" y="100" width="140" height="70" as="geometry" />
</mxCell>
</UserObject>

<!-- Database with custom attributes -->
<object id="db1" label="PostgreSQL" ip="10.0.2.20"
environment="production" port="5432">
<mxCell style="shape=cylinder3;whiteSpace=wrap;html=1;boundedLbl=1;backgroundOutline=1;size=15;fillColor=#DAE8FC;strokeColor=#6C8EBF;" vertex="1" parent="1">
<mxGeometry x="350" y="90" width="100" height="90" as="geometry" />
</mxCell>
</object>

<mxCell id="conn1" style="endArrow=classic;html=1;" edge="1" parent="1" source="srv1" target="db1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
</root>
</mxGraphModel>
</diagram>
</mxfile>

14. Additional mxGraphModel Attributes

These optional attributes on <mxGraphModel> are less commonly used but appear in real-world files:

AttributeValuesDescription
adaptiveColorsauto, simple, none, defaultControls color adaptation for light/dark mode viewing

adaptiveColors example:

<mxGraphModel dx="0" dy="0" grid="1" ... adaptiveColors="auto">

AI generators typically do not need to set this attribute.


15. Validation Checklist for AI-Generated Files

Use this checklist to verify generated draw.io files:

  1. Valid XML: File is well-formed XML with proper escaping
  2. Root element: <mxfile> as root, contains at least one <diagram>
  3. Diagram IDs: Each diagram has a unique id attribute
  4. Structural cells: Root contains <mxCell id="0"/> and <mxCell id="1" parent="0"/>
  5. Unique IDs: All cell IDs are unique within the diagram
  6. Parent references: Every cell (except id="0") has a valid parent referencing an existing cell
  7. Type flags: Each content cell has either vertex="1" or edge="1" (not both)
  8. Edge references: Edge source and target reference existing vertex IDs
  9. Geometry: Vertices have mxGeometry with x, y, width, height; edges have relative="1"
  10. Style format: Style strings use key=value; format, valid keys and values
  11. Perimeter match: Non-rectangular shapes have matching perimeter in style
  12. HTML escaping: HTML in value attributes is properly XML-escaped
  13. Coordinate system: x increases right, y increases down, no negative dimensions
  14. Group hierarchy: Children of groups have coordinates relative to the group