Mermaid Context
Use contextPath to enrich a Mermaid diagram with node properties, edge properties, and groups.
architectureDiagrams config:
architectureDiagrams:
- name: Checkout Architecture
path: ./diagram.mmd
contextPath: ./context.json
contextPath is optional. Use it when you need custom node types, metadata fields, style, edge labels or markers, or grouping.
When present, the CLI validates that the file exists and sends both the Mermaid source and the context JSON during sync.
Which diagrams you can sync
The first diagram keyword in the file decides how UIGraph reads it:
| Keyword | What syncs |
|---|---|
flowchart, graph | Nodes and the connections between them. This is what the rest of this page shows. |
stateDiagram-v2 | The named states and their transitions. The [*] start and end markers are not nodes, so they have no context key. |
sequenceDiagram | Participants and the messages between them. Participants become the nodes, so the context keys are the participant IDs. |
C4Context, C4Container, C4Component, C4Dynamic, C4Deployment | Elements and relationships. Node IDs are the element aliases, so Person(user, "User") is keyed as user. See C4 Diagrams. |
Each type produces its own node IDs, so write the diagram first and take the IDs from it rather than the other way round. The easiest way to get a matching pair of files is to draw the diagram in UIGraph and use Export To Mermaid, which writes the .mmd and its context file together.
1) How context works
- Mermaid defines structure (nodes and connections).
context.jsonoverlays metadata and presentation.- Context keys must match Mermaid IDs to apply.
2) ID matching rules
nodes.<nodeId>must match Mermaid node IDs exactly.edges["source-target"]must match Mermaid edge direction.groups.<groupId>.nodes[]must contain valid Mermaid node IDs.
Example:
flowchart LR
A[Client] --> B[API]
B --> C[DB]
Matching context keys:
- Node IDs:
A,B,C - Edge IDs:
A-B,B-C
3) Context JSON shape
{
"name": "Checkout context",
"description": "Optional description",
"nodes": {},
"edges": {},
"groups": {}
}
4) Node properties by type
Common node properties:
type: node typename: node display namedata: metadata fieldsstyle: visual style
Supported type values:
shapetextcodetablecommentcloudimagegifcomponentdata-sourcedb-table
Type-specific properties:
shape:shapetextandcode:valuetable:table.columnsandtable.rowscloud:cloud,serviceimage:srcgif:animatedIcon(orsrc)component:componentIddata-sourceanddb-table:dbConfig
Shape node
{
"nodes": {
"P": {
"type": "shape",
"shape": "diamond",
"name": "Decision"
}
}
}
Supported shape values:
rectanglerounded-rectellipsediamondtriangleparallelogramtrapezoidhexagondocumentcylinderdelayoff-page-connectordisplaycollatesortterminatorordatabasemultiple-documentssubroutinemanual-inputsumming-junctioninternal-storage
Text and code nodes
{
"nodes": {
"T": {
"type": "text",
"name": "Label",
"value": "Standard text node"
},
"C": {
"type": "code",
"name": "Snippet",
"value": "function greet(name) { return `Hello, ${name}` }"
}
}
}
Table node
{
"nodes": {
"TableNode": {
"type": "table",
"name": "Task Table",
"table": {
"columns": ["ID", "Name", "Status"],
"rows": [
["1", "Task A", "Done"],
["2", "Task B", "In Progress"]
]
}
}
}
}
Cloud node
{
"nodes": {
"api": {
"type": "cloud",
"name": "API Gateway",
"cloud": "AWS",
"service": "Amazon API Gateway"
}
}
}
Image and GIF nodes
{
"nodes": {
"img1": {
"type": "image",
"name": "Architecture Image",
"src": "https://placehold.co/150x150/6366f1/white?text=1"
},
"g1": {
"type": "gif",
"name": "Authentication",
"animatedIcon": "Authentication"
}
}
}
Component node
{
"nodes": {
"worker": {
"type": "component",
"componentId": "flow_diagram_component_service",
"name": "Order Worker"
}
}
}
Database-linked node
data-source and db-table nodes link a diagram node to a synced database table through dbConfig. All three fields are required and are matched by name, not by ID:
serviceName— the service that owns the databasedatabaseName— the database name, matching adatabases[].nameyou synctableName— the table within that database
{
"nodes": {
"orders": {
"type": "data-source",
"name": "Orders",
"dbConfig": {
"serviceName": "UIGraph Adapter",
"databaseName": "ecommerce",
"tableName": "orders"
}
}
}
}
5) Node style properties
Use under nodes.<id>.style:
fillstrokestrokeWidthborderRadiusstrokeStyle:solid,dashed,dottedborderAnimationEnabled:trueorfalse
Example:
{
"nodes": {
"A": {
"name": "Styled Node",
"style": {
"fill": "#E3F2FD",
"stroke": "#1976D2",
"strokeWidth": 2,
"borderRadius": 8,
"strokeStyle": "dashed",
"borderAnimationEnabled": true
}
}
}
}
6) Data field properties (nodes.<id>.data)
Each field:
"Field Label": { "type": "Text Input", "value": "...", "options": [] }
type: required input type labelvalue: field valueoptions: optional, used by selectable input types
Supported input type labels:
Text InputURL InputNumber InputText EditorDate PickerDropdownMulti SelectBoolean ToggleLink or File UploadRich Text EditorCode EditorKey-Value ListTag InputDate Range PickerColor PickerSliderFile UploadSearch SelectCheckbox Group
Example:
{
"nodes": {
"api": {
"name": "Public API",
"data": {
"Owner": { "type": "Text Input", "value": "Platform Team" },
"Docs": {
"type": "URL Input",
"value": "https://example.com/docs/public-api"
},
"Rate limit (req/s)": { "type": "Number Input", "value": 500 },
"Tags": { "type": "Tag Input", "value": ["edge", "public"] }
}
}
}
}
7) Edge properties
Use under edges["source-target"]:
labelstyle.strokestyle.strokeWidthstyle.strokeStyle(solid,dashed,dotted)style.borderAnimationEnabledmarkerStartmarkerEnd
Marker shape:
{ "type": "arrow", "color": "#1976D2" }
Edge example:
{
"edges": {
"A-B": {
"label": "HTTPS",
"style": {
"stroke": "#2563eb",
"strokeWidth": 2,
"strokeStyle": "dashed",
"borderAnimationEnabled": false
},
"markerStart": { "type": "arrow", "color": "#2563eb" },
"markerEnd": { "type": "arrow", "color": "#2563eb" }
}
}
}
8) Group properties
Use under groups.<groupId>:
namenodes: array of Mermaid node IDs
Example:
{
"groups": {
"core-backend": {
"name": "Core backend",
"nodes": ["api", "worker", "queue", "db", "cache"]
}
}
}
Once the diagram is in UIGraph, a group can be collapsed with the button in its top-right corner. Hide details folds the group down to its name and hides the nodes inside it, and any connection that crossed the boundary now points at the group itself. Connections between two nodes inside the group disappear with them. Show details puts everything back exactly as it was.
Collapsing is a good way to read a large diagram, so use it on a group that holds more detail than a reviewer needs at first glance.
9) Complete minimal working example
Mermaid:
flowchart LR
Client --> API
API --> DB
Context:
{
"name": "checkout-context",
"nodes": {
"Client": {
"type": "text",
"name": "Client",
"data": {
"Channel": { "type": "Dropdown", "value": "Web" }
}
},
"API": {
"type": "cloud",
"name": "Checkout API",
"cloud": "AWS",
"service": "Amazon API Gateway",
"data": {
"Owner": { "type": "Text Input", "value": "Payments Team" }
}
},
"DB": {
"type": "data-source",
"name": "Orders DB",
"dbConfig": {
"serviceName": "UIGraph Adapter",
"databaseName": "ecommerce",
"tableName": "orders"
}
}
},
"edges": {
"Client-API": {
"label": "POST /checkout",
"style": { "stroke": "#111827", "strokeWidth": 2, "strokeStyle": "solid" },
"markerEnd": { "type": "arrow" }
},
"API-DB": {
"label": "save order",
"style": { "stroke": "#111827", "strokeWidth": 2, "strokeStyle": "dashed" },
"markerEnd": { "type": "arrow" }
}
},
"groups": {
"backend": {
"name": "Backend services",
"nodes": ["API", "DB"]
}
}
}
10) Common mistakes
- Node ID mismatch: context key
Apidoes not match Mermaid nodeAPI. - Edge key direction mismatch: Mermaid has
A --> B, but context usesB-A. - Invalid JSON: trailing commas, comments, or unquoted keys.
- Input type typo:
TextInputinstead ofText Input. - Group references unknown node IDs.