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.
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
{
"nodes": {
"orders": {
"type": "data-source",
"name": "Orders",
"dbConfig": {
"service": "UIGraph Adapter",
"database": "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"]
}
}
}
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": {
"service": "UIGraph Adapter",
"database": "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.