mmdflux 2.1.0

Render Mermaid diagrams as Unicode text, ASCII, SVG, and MMDS JSON.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://mmdflux.dev/mmds/v1",
  "title": "MMDS — Machine-Mediated Diagram Specification",
  "description": "Structured JSON output for graph-family Mermaid diagrams produced by mmdflux.",
  "type": "object",
  "required": [
    "version",
    "defaults",
    "geometry_level",
    "metadata",
    "nodes",
    "edges"
  ],
  "properties": {
    "version": {
      "const": 1,
      "description": "Integer schema version. Incremented on breaking MMDS changes."
    },
    "profiles": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "default": [],
      "description": "Optional behavior bundles used for profile negotiation (for example 'mmds-core-v1', 'mmdflux-svg-v1', or 'mmdflux-node-style-v1')."
    },
    "extensions": {
      "type": "object",
      "default": {},
      "propertyNames": {
        "pattern": "^[a-z0-9]+(?:[.-][a-z0-9]+)*(?:\\.[a-z0-9]+(?:[.-][a-z0-9]+)*)*\\.v[0-9]+$",
        "description": "Namespaced extension key ending with '.v{number}', for example 'org.mmdflux.render.svg.v1'."
      },
      "properties": {
        "org.mmdflux.node-style.v1": {
          "$ref": "#/$defs/NodeStyleExtension"
        }
      },
      "additionalProperties": {
        "type": "object"
      },
      "description": "Optional namespaced extension payloads keyed by versioned namespace ID."
    },
    "defaults": {
      "$ref": "#/$defs/Defaults",
      "description": "Document-level defaults for omitted node/edge fields."
    },
    "geometry_level": {
      "enum": ["layout", "routed"],
      "description": "Geometry detail level. 'layout' includes node geometry + edge topology only. 'routed' adds edge paths, bounds, and routing metadata."
    },
    "metadata": {
      "$ref": "#/$defs/Metadata"
    },
    "nodes": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/Node"
      },
      "description": "Node inventory, sorted by ID."
    },
    "edges": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/Edge"
      },
      "description": "Edge inventory in declaration order."
    },
    "subgraphs": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/Subgraph"
      },
      "default": [],
      "description": "Subgraph inventory, sorted by ID."
    },
    "participants": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/Participant"
      },
      "description": "Sequence diagram participants (timeline family only)."
    },
    "messages": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/Message"
      },
      "description": "Sequence diagram messages (timeline family only)."
    },
    "notes": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/Note"
      },
      "description": "Sequence diagram notes (timeline family only)."
    },
    "activations": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/Activation"
      },
      "description": "Sequence diagram activation bars (timeline family only)."
    },
    "blocks": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/Block"
      },
      "description": "Sequence diagram interaction frames (timeline family only)."
    },
    "participant_boxes": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/ParticipantBox"
      },
      "description": "Sequence diagram participant groupings (timeline family only)."
    }
  },
  "$defs": {
    "Defaults": {
      "type": "object",
      "required": ["node", "edge"],
      "properties": {
        "node": {
          "$ref": "#/$defs/NodeDefaults"
        },
        "edge": {
          "$ref": "#/$defs/EdgeDefaults"
        }
      }
    },
    "NodeDefaults": {
      "type": "object",
      "required": ["shape"],
      "properties": {
        "shape": {
          "type": "string",
          "description": "Default node shape used when a node omits the shape field."
        }
      }
    },
    "EdgeDefaults": {
      "type": "object",
      "required": ["stroke", "arrow_start", "arrow_end", "minlen"],
      "properties": {
        "stroke": {
          "enum": ["solid", "dotted", "thick", "invisible"],
          "description": "Default edge stroke used when an edge omits stroke."
        },
        "arrow_start": {
          "enum": [
            "none",
            "normal",
            "cross",
            "circle",
            "open_triangle",
            "diamond",
            "open_diamond"
          ],
          "description": "Default source-end marker used when an edge omits arrow_start."
        },
        "arrow_end": {
          "enum": [
            "none",
            "normal",
            "cross",
            "circle",
            "open_triangle",
            "diamond",
            "open_diamond"
          ],
          "description": "Default target-end marker used when an edge omits arrow_end."
        },
        "minlen": {
          "type": "integer",
          "description": "Default minimum rank separation used when an edge omits minlen."
        }
      }
    },
    "Metadata": {
      "type": "object",
      "required": ["diagram_type", "bounds"],
      "properties": {
        "diagram_type": {
          "type": "string",
          "description": "Diagram type identifier (e.g., 'flowchart', 'class')."
        },
        "direction": {
          "enum": ["TD", "BT", "LR", "RL"],
          "description": "Layout direction."
        },
        "bounds": {
          "$ref": "#/$defs/Bounds",
          "description": "Overall diagram canvas extents in unitless MMDS coordinate space. In current mmdflux output, values are SVG-pixel-aligned. Not guaranteed to be a tight content bounding box."
        },
        "engine": {
          "type": "string",
          "description": "Engine+algorithm identifier that produced this output (e.g., 'flux-layered', 'mermaid-layered'). Present when the output was produced via the solve pipeline."
        }
      }
    },
    "Node": {
      "type": "object",
      "required": ["id", "label", "position", "size"],
      "properties": {
        "id": {
          "type": "string",
          "description": "Node identifier from Mermaid source."
        },
        "label": {
          "type": "string",
          "description": "Display label."
        },
        "shape": {
          "type": "string",
          "default": "rectangle",
          "description": "Shape name in snake_case. If omitted, consumers should use defaults.node.shape."
        },
        "parent": {
          "type": "string",
          "description": "Parent subgraph ID, if any."
        },
        "position": {
          "$ref": "#/$defs/Position",
          "description": "Node center position in unitless MMDS coordinate space, not top-left anchor. In current mmdflux output, values are SVG-pixel-aligned."
        },
        "size": {
          "$ref": "#/$defs/Size",
          "description": "Node bounding box dimensions in unitless MMDS coordinate space. In current mmdflux output, values are SVG-pixel-aligned."
        }
      }
    },
    "Edge": {
      "type": "object",
      "required": ["id", "source", "target"],
      "properties": {
        "id": {
          "type": "string",
          "description": "Deterministic edge identifier (e.g., 'e0', 'e1') in declaration order."
        },
        "source": {
          "type": "string",
          "description": "Source node ID."
        },
        "target": {
          "type": "string",
          "description": "Target node ID."
        },
        "from_subgraph": {
          "type": "string",
          "description": "Original source subgraph ID when this edge represented a subgraph-as-source endpoint intent."
        },
        "to_subgraph": {
          "type": "string",
          "description": "Original target subgraph ID when this edge represented a subgraph-as-target endpoint intent."
        },
        "label": {
          "type": "string",
          "description": "Edge label text."
        },
        "stroke": {
          "enum": ["solid", "dotted", "thick", "invisible"],
          "default": "solid",
          "description": "Stroke style. If omitted, consumers should use defaults.edge.stroke."
        },
        "arrow_start": {
          "enum": [
            "none",
            "normal",
            "cross",
            "circle",
            "open_triangle",
            "diamond",
            "open_diamond"
          ],
          "default": "none",
          "description": "Arrow at source end. If omitted, consumers should use defaults.edge.arrow_start."
        },
        "arrow_end": {
          "enum": [
            "none",
            "normal",
            "cross",
            "circle",
            "open_triangle",
            "diamond",
            "open_diamond"
          ],
          "default": "normal",
          "description": "Arrow at target end. If omitted, consumers should use defaults.edge.arrow_end."
        },
        "minlen": {
          "type": "integer",
          "default": 1,
          "description": "Minimum rank separation. If omitted, consumers should use defaults.edge.minlen."
        },
        "path": {
          "type": "array",
          "items": {
            "type": "array",
            "items": {
              "type": "number"
            },
            "minItems": 2,
            "maxItems": 2
          },
          "description": "Routed edge path as [x, y] coordinate pairs in unitless MMDS coordinate space. In current mmdflux output, values are SVG-pixel-aligned. Routed level only."
        },
        "label_position": {
          "$ref": "#/$defs/Position",
          "description": "Label center position in unitless MMDS coordinate space. In current mmdflux output, values are SVG-pixel-aligned. Routed level only."
        },
        "is_backward": {
          "type": "boolean",
          "description": "Whether this edge flows backward in the layout direction. Routed level only."
        },
        "source_port": {
          "$ref": "#/$defs/Port",
          "description": "Source endpoint attachment metadata. Routed level only."
        },
        "target_port": {
          "$ref": "#/$defs/Port",
          "description": "Target endpoint attachment metadata. Routed level only."
        }
      }
    },
    "Subgraph": {
      "type": "object",
      "required": ["id", "title", "children"],
      "properties": {
        "id": {
          "type": "string",
          "description": "Subgraph identifier."
        },
        "title": {
          "type": "string",
          "description": "Display title."
        },
        "children": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "IDs of nodes directly in this subgraph."
        },
        "parent": {
          "type": "string",
          "description": "Parent subgraph ID, if nested."
        },
        "direction": {
          "enum": ["TD", "BT", "LR", "RL"],
          "description": "Subgraph direction override."
        },
        "bounds": {
          "$ref": "#/$defs/Bounds",
          "description": "Subgraph bounding box. Routed level only."
        }
      }
    },
    "Port": {
      "type": "object",
      "required": ["face", "fraction", "position", "group_size"],
      "properties": {
        "face": {
          "enum": ["top", "bottom", "left", "right"],
          "description": "Node boundary face where the edge attaches."
        },
        "fraction": {
          "type": "number",
          "minimum": 0,
          "maximum": 1,
          "description": "Fractional position along the face (0.0 = start, 1.0 = end). For top/bottom faces, 0.0 is left and 1.0 is right. For left/right faces, 0.0 is top and 1.0 is bottom."
        },
        "position": {
          "$ref": "#/$defs/Position",
          "description": "Computed position on the node boundary in MMDS coordinate space."
        },
        "group_size": {
          "type": "integer",
          "minimum": 1,
          "description": "Number of edges attached to this face of this node."
        }
      }
    },
    "NodeStyleExtension": {
      "type": "object",
      "required": ["nodes"],
      "properties": {
        "nodes": {
          "type": "object",
          "description": "Node-ID keyed style overrides replayed into renderer-visible node fill/stroke/text colors.",
          "additionalProperties": {
            "$ref": "#/$defs/NodeStyle"
          }
        }
      }
    },
    "NodeStyle": {
      "type": "object",
      "minProperties": 1,
      "properties": {
        "fill": {
          "type": "string",
          "description": "Raw color token for node fill."
        },
        "stroke": {
          "type": "string",
          "description": "Raw color token for node border stroke."
        },
        "color": {
          "type": "string",
          "description": "Raw color token for node label text."
        }
      },
      "additionalProperties": false
    },
    "Position": {
      "type": "object",
      "required": ["x", "y"],
      "properties": {
        "x": {
          "type": "number",
          "description": "X coordinate in unitless MMDS coordinate space. In current mmdflux output, values are SVG-pixel-aligned."
        },
        "y": {
          "type": "number",
          "description": "Y coordinate in unitless MMDS coordinate space. In current mmdflux output, values are SVG-pixel-aligned."
        }
      }
    },
    "Size": {
      "type": "object",
      "required": ["width", "height"],
      "properties": {
        "width": {
          "type": "number",
          "description": "Width in unitless MMDS coordinate space. In current mmdflux output, values are SVG-pixel-aligned."
        },
        "height": {
          "type": "number",
          "description": "Height in unitless MMDS coordinate space. In current mmdflux output, values are SVG-pixel-aligned."
        }
      }
    },
    "Bounds": {
      "type": "object",
      "required": ["width", "height"],
      "properties": {
        "width": {
          "type": "number",
          "description": "Overall width in unitless MMDS coordinate space. In current mmdflux output, values are SVG-pixel-aligned."
        },
        "height": {
          "type": "number",
          "description": "Overall height in unitless MMDS coordinate space. In current mmdflux output, values are SVG-pixel-aligned. Consumers should preserve width/height aspect ratio when scaling."
        }
      }
    },
    "Rect": {
      "type": "object",
      "required": ["x", "y", "width", "height"],
      "properties": {
        "x": { "type": "number" },
        "y": { "type": "number" },
        "width": { "type": "number" },
        "height": { "type": "number" }
      }
    },
    "Participant": {
      "type": "object",
      "required": ["id", "label", "kind", "position", "size", "lifeline_x"],
      "properties": {
        "id": { "type": "string", "description": "Participant identifier from source." },
        "label": { "type": "string", "description": "Display label (alias if provided, otherwise id)." },
        "kind": { "enum": ["participant", "actor"], "description": "Participant visual kind." },
        "position": { "$ref": "#/$defs/Position", "description": "Top-left of header box." },
        "size": { "$ref": "#/$defs/Size", "description": "Header box dimensions." },
        "lifeline_x": { "type": "number", "description": "Center x of the vertical lifeline." }
      }
    },
    "Message": {
      "type": "object",
      "required": ["id", "from", "to", "line_style", "arrow_head", "text", "y"],
      "properties": {
        "id": { "type": "string", "description": "Deterministic message ID (m0, m1, ...)." },
        "from": { "type": "integer", "minimum": 0, "description": "Source participant index." },
        "to": { "type": "integer", "minimum": 0, "description": "Target participant index." },
        "line_style": { "enum": ["solid", "dashed"], "description": "Line style." },
        "arrow_head": { "enum": ["filled", "open", "cross", "async"], "description": "Arrowhead shape." },
        "text": { "type": "string", "description": "Message label text." },
        "y": { "type": "number", "description": "Vertical position of the arrow." }
      }
    },
    "Note": {
      "type": "object",
      "required": ["placement", "participants", "text", "position", "size"],
      "properties": {
        "placement": { "enum": ["left_of", "right_of", "over"], "description": "Note placement relative to participants." },
        "participants": { "type": "array", "items": { "type": "integer", "minimum": 0 }, "description": "Participant indices the note relates to." },
        "text": { "type": "string", "description": "Note text." },
        "position": { "$ref": "#/$defs/Position", "description": "Top-left of note box." },
        "size": { "$ref": "#/$defs/Size", "description": "Note box dimensions." }
      }
    },
    "Activation": {
      "type": "object",
      "required": ["participant", "y_start", "y_end", "depth"],
      "properties": {
        "participant": { "type": "integer", "minimum": 0, "description": "Participant index." },
        "y_start": { "type": "number", "description": "Top of the activation bar." },
        "y_end": { "type": "number", "description": "Bottom of the activation bar." },
        "depth": { "type": "integer", "minimum": 0, "description": "Nesting depth (0 = outermost)." }
      }
    },
    "BlockDivider": {
      "type": "object",
      "required": ["y", "kind", "label"],
      "properties": {
        "y": { "type": "number", "description": "Vertical position of the divider." },
        "kind": { "enum": ["else", "and", "option"], "description": "Divider kind." },
        "label": { "type": "string", "description": "Divider label." }
      }
    },
    "Block": {
      "type": "object",
      "required": ["kind", "label", "rect"],
      "properties": {
        "kind": { "enum": ["loop", "alt", "opt", "par", "critical", "break", "rect"], "description": "Interaction operator." },
        "label": { "type": "string", "description": "Block header label." },
        "rect": { "$ref": "#/$defs/Rect", "description": "Bounding rectangle." },
        "dividers": { "type": "array", "items": { "$ref": "#/$defs/BlockDivider" }, "default": [], "description": "Interior dividers (else, and, option)." }
      }
    },
    "ParticipantBox": {
      "type": "object",
      "required": ["participants", "rect"],
      "properties": {
        "label": { "type": "string", "description": "Optional grouping label." },
        "color": { "type": "string", "description": "Optional fill color." },
        "participants": { "type": "array", "items": { "type": "integer", "minimum": 0 }, "description": "Participant indices in this grouping." },
        "rect": { "$ref": "#/$defs/Rect", "description": "Bounding rectangle." }
      }
    }
  }
}