mermaid
mermaid ¶
Mermaid diagram components for lineage graphs.
ColumnRelationshipERConverter
dataclass
¶
ColumnRelationshipERConverter()
Convert ColumnRelationships to a Mermaid ER diagram.
Groups column relationships by entity pair, builds entities with columns, and creates relationships with cardinality derived from transformation types.
Supports tracing a specific column upstream through the relationship graph — enabling the "where does this column come from?" use case.
Example
from crew_dcs.classes.subentity import ColumnRelationship rels = { ... ColumnRelationship(from_entity_id="ds-1", from_column="ID", ... to_entity_id="meta-1", to_column="ID"), ... ColumnRelationship(from_entity_id="meta-1", from_column="ID", ... to_entity_id="gb-1", to_column="ID", ... transformation_type=ColumnTransformationType.AGGREGATION), ... } diagram = ColumnRelationshipERConverter.convert(rels, entity_names={"ds-1": "Source", "meta-1": "Metadata", "gb-1": "GroupBy"}) print(diagram.to_string())
convert
staticmethod
¶
convert(
column_relationships: (
set[ColumnRelationship] | list[ColumnRelationship]
),
*,
entity_names: dict[str, str] | None = None,
title: str | None = None,
trace_from_entity: str | None = None,
trace_from_column: str | None = None
) -> MermaidERDiagram
Convert column relationships to a Mermaid ER diagram.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
column_relationships
|
set[ColumnRelationship] | list[ColumnRelationship]
|
Set or list of ColumnRelationship objects |
required |
entity_names
|
dict[str, str] | None
|
Optional mapping of entity_id → display name. Falls back to entity_id if not provided. |
None
|
title
|
str | None
|
Optional diagram title |
None
|
trace_from_entity
|
str | None
|
If provided, trace only the upstream chain from this entity (e.g., a card's dataset ID) |
None
|
trace_from_column
|
str | None
|
If provided alongside trace_from_entity, trace only the upstream chain for this specific column (e.g., a beast mode or dataset column) |
None
|
Returns:
| Type | Description |
|---|---|
MermaidERDiagram
|
MermaidERDiagram with entities and relationships |
Example — trace a specific column: >>> # "Where does the 'Revenue' column in this card come from?" >>> diagram = ColumnRelationshipERConverter.convert( ... all_rels, ... entity_names=names, ... trace_from_entity="card-dataset-id", ... trace_from_column="Revenue", ... )
Source code in src/crew_dcs/integrations/graphs/mermaid/column_relationship_erd_converter.py
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 | |
MermaidConverter ¶
MermaidConverter(graph: LineageGraph | None = None)
Bases: GraphConverter
Convert lineage graph to Mermaid diagram.
Initialize MermaidConverter with optional LineageGraph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
LineageGraph | None
|
Optional LineageGraph to convert |
None
|
Source code in src/crew_dcs/integrations/graphs/mermaid/mermaid_converter.py
20 21 22 23 24 25 26 | |
convert ¶
convert(
graph: LineageGraph | None = None,
direction: str = "TD",
include_entity_ids: bool = True,
title: str | None = None,
trace_direction: Literal[
"trace_dependencies", "trace_dependents"
] = "trace_dependencies",
**options
) -> MermaidDiagram
Convert LineageGraph to MermaidDiagram.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
LineageGraph | None
|
LineageGraph to convert. If None, uses self.graph |
None
|
direction
|
str
|
Mermaid flow direction (default: "TD") |
'TD'
|
include_entity_ids
|
bool
|
Whether to include entity IDs |
True
|
title
|
str | None
|
Title for the diagram |
None
|
trace_direction
|
Literal['trace_dependencies', 'trace_dependents']
|
Direction to trace dependencies |
'trace_dependencies'
|
**options
|
Additional options |
{}
|
Returns:
| Type | Description |
|---|---|
MermaidDiagram
|
MermaidDiagram representation of the graph |
Source code in src/crew_dcs/integrations/graphs/mermaid/mermaid_converter.py
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 | |
export ¶
export(**options) -> MermaidDiagram
Convert the stored lineage graph to a MermaidDiagram.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**options
|
Options to pass to convert() |
{}
|
Returns:
| Type | Description |
|---|---|
MermaidDiagram
|
MermaidDiagram representation of the graph |
Source code in src/crew_dcs/integrations/graphs/mermaid/mermaid_converter.py
123 124 125 126 127 128 129 130 131 132 | |
export_to_file ¶
export_to_file(
file_path: str,
output: MermaidDiagram | None = None,
footer_text: str | None = None,
**options
) -> None
Export Mermaid diagram to markdown file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
str
|
Path to output markdown file |
required |
output
|
MermaidDiagram | None
|
MermaidDiagram to export. If None, converts self.graph |
None
|
footer_text
|
str | None
|
Optional footer text for the markdown |
None
|
**options
|
Additional options to pass to convert() |
{}
|
Source code in src/crew_dcs/integrations/graphs/mermaid/mermaid_converter.py
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | |
from_lineage_graph
classmethod
¶
from_lineage_graph(graph: LineageGraph) -> MermaidConverter
Create a MermaidConverter from an existing LineageGraph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
LineageGraph
|
Existing LineageGraph |
required |
Returns:
| Type | Description |
|---|---|
MermaidConverter
|
MermaidConverter wrapping the graph |
Source code in src/crew_dcs/integrations/graphs/mermaid/mermaid_converter.py
44 45 46 47 48 49 50 51 52 53 54 | |
from_lineage_links
classmethod
¶
from_lineage_links(
links: list[DomoLineage_Link],
) -> MermaidConverter
Create a MermaidConverter from lineage links.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
links
|
list[DomoLineage_Link]
|
List of DomoLineage_Link objects |
required |
Returns:
| Type | Description |
|---|---|
MermaidConverter
|
MermaidConverter with graph created from links |
Source code in src/crew_dcs/integrations/graphs/mermaid/mermaid_converter.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | |
MermaidDiagram
dataclass
¶
MermaidDiagram(
nodes: list[MermaidNode] = list(),
relationships: list[MermaidRelationship] = list(),
direction: str = "TD",
title: str | None = None,
entity_id: str | None = None,
entity_type: str | None = None,
use_aliases: bool = True,
)
Complete Mermaid diagram with nodes and relationships.
add_entity_dependency ¶
add_entity_dependency(
from_entity: Any,
to_entity: Any,
*,
relationship_type: str = "dependency"
) -> None
Add a relationship between two Domo entities.
Source code in src/crew_dcs/integrations/graphs/mermaid/mermaid_diagram.py
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 | |
add_federation_node ¶
add_federation_node(
entity: Any,
*,
custom_type: str | None = None,
show_entity_id: bool = False,
show_federation_id: str | None = None
) -> MermaidNode
Add a node with federation-aware type label.
Source code in src/crew_dcs/integrations/graphs/mermaid/mermaid_diagram.py
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 | |
add_lineage_items ¶
add_lineage_items(
lineage_items: Iterable[Any] | None,
*,
recursive: bool = False
) -> None
Add a collection of lineage items, optionally following dependencies.
Source code in src/crew_dcs/integrations/graphs/mermaid/mermaid_diagram.py
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 | |
add_lineage_link ¶
add_lineage_link(lineage_link: Any) -> None
Add a lineage link's node and relationships to the diagram.
Handles both fully-hydrated links (with entity objects) and placeholder links (ID + type only, entity=None). Relationship types are derived from entity types via resolve_relationship (e.g., DATA_SOURCE→DATAFLOW becomes CREATED_BY, PAGE→CARD becomes CONTAINS).
Source code in src/crew_dcs/integrations/graphs/mermaid/mermaid_diagram.py
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 | |
add_node ¶
add_node(node: MermaidNode) -> None
Add a node to the diagram if it doesn't already exist.
If a node with the same id+type already exists, the new node's data is merged into the existing one — specifically, a hydrated name replaces a placeholder UUID name, and an explicit shape replaces None.
Source code in src/crew_dcs/integrations/graphs/mermaid/mermaid_diagram.py
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 | |
add_relationship ¶
add_relationship(relationship: MermaidRelationship) -> None
Add a relationship to the diagram if it doesn't already exist.
Source code in src/crew_dcs/integrations/graphs/mermaid/mermaid_diagram.py
76 77 78 79 | |
combine
classmethod
¶
combine(
diagrams: list[MermaidDiagram],
*,
bridge_start_id: str,
bridge_end_id: str,
bridge_type: str = "published",
direction: str | None = None,
use_aliases: bool | None = None
) -> MermaidDiagram
Merge multiple diagrams and add a bridge edge between two nodes.
Source code in src/crew_dcs/integrations/graphs/mermaid/mermaid_diagram.py
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 | |
export_to_markdown ¶
export_to_markdown(
export_file: str | None = None,
footer_text: str | None = None,
*,
show_instance: bool = False,
show_entity_id: bool = False
) -> str
Render the diagram as a Markdown document with optional file export.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
export_file
|
str | None
|
Path to write the markdown file |
None
|
footer_text
|
str | None
|
Optional footer text |
None
|
show_instance
|
bool
|
If True, include domo_instance on node line 3 |
False
|
show_entity_id
|
bool
|
If True, include entity ID on node line 4 |
False
|
Source code in src/crew_dcs/integrations/graphs/mermaid/mermaid_diagram.py
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 | |
find_node ¶
find_node(
node_id: str, node_type: str
) -> MermaidNode | None
Find a node by ID and type.
Source code in src/crew_dcs/integrations/graphs/mermaid/mermaid_diagram.py
29 30 31 32 33 | |
from_entity
classmethod
¶
from_entity(
entity: Any,
direction: str = "TD",
use_aliases: bool = True,
) -> MermaidDiagram
Create a Mermaid diagram shell for a Domo entity.
Source code in src/crew_dcs/integrations/graphs/mermaid/mermaid_diagram.py
457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 | |
from_lineage
classmethod
¶
from_lineage(
entity: Any,
lineage: list[Any],
direction: str = "TD",
use_aliases: bool = True,
) -> MermaidDiagram
Create a fully populated MermaidDiagram from an entity and its lineage.
Combines from_entity + add_lineage_items into a single call. Relationship types are derived from entity types via resolve_relationship.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entity
|
Any
|
The root Domo entity |
required |
lineage
|
list[Any]
|
Pre-fetched lineage items (from entity.Lineage.get()) |
required |
direction
|
str
|
Mermaid flow direction |
'TD'
|
use_aliases
|
bool
|
Whether to use short aliases for node IDs |
True
|
Returns:
| Type | Description |
|---|---|
MermaidDiagram
|
MermaidDiagram with all nodes and relationships populated |
Source code in src/crew_dcs/integrations/graphs/mermaid/mermaid_diagram.py
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 | |
print_lineage_summary ¶
print_lineage_summary(lineage: list[Any]) -> None
Print a formatted summary of lineage data.
Source code in src/crew_dcs/integrations/graphs/mermaid/mermaid_diagram.py
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 | |
to_string ¶
to_string(
*,
show_instance: bool = False,
show_entity_id: bool = False
) -> str
Render the complete Mermaid diagram.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
show_instance
|
bool
|
If True, include domo_instance on node line 3 |
False
|
show_entity_id
|
bool
|
If True, include entity ID on node line 4 |
False
|
Source code in src/crew_dcs/integrations/graphs/mermaid/mermaid_diagram.py
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 | |
MermaidERColumn
dataclass
¶
MermaidERColumn(
name: str,
col_type: str = "string",
key: str | None = None,
comment: str | None = None,
)
A column in an ER entity.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Column name |
col_type |
str
|
Mermaid ERD attribute type (string, int, timestamp, etc.) |
key |
str | None
|
Optional key marker (PK, FK, UK, or combinations like "PK, FK") |
comment |
str | None
|
Optional inline comment shown in the diagram (double-quoted) |
to_string ¶
to_string() -> str
Render as a Mermaid ERD attribute line (inside entity block).
Source code in src/crew_dcs/integrations/graphs/mermaid/mermaid_erd.py
57 58 59 60 61 62 63 64 65 66 | |
MermaidERDiagram
dataclass
¶
MermaidERDiagram(
entities: list[MermaidEREntity] = list(),
relationships: list[MermaidERRelationship] = list(),
title: str | None = None,
)
Complete Mermaid ER diagram with entities and relationships.
Unlike MermaidDiagram (which renders flowcharts), this renders entity-relationship diagrams with typed columns and cardinality relationships using the Mermaid erDiagram syntax.
add_entity ¶
add_entity(entity: MermaidEREntity) -> MermaidEREntity
Add an entity to the diagram. Returns the existing entity if found.
Source code in src/crew_dcs/integrations/graphs/mermaid/mermaid_erd.py
208 209 210 211 212 213 214 215 216 217 | |
add_relationship ¶
add_relationship(rel: MermaidERRelationship) -> None
Add a relationship if not already present.
Source code in src/crew_dcs/integrations/graphs/mermaid/mermaid_erd.py
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 | |
export_to_markdown ¶
export_to_markdown(
export_file: str | None = None,
footer_text: str | None = None,
) -> str
Render the diagram as a Markdown document with optional file export.
Source code in src/crew_dcs/integrations/graphs/mermaid/mermaid_erd.py
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 | |
find_entity ¶
find_entity(entity_id: str) -> MermaidEREntity | None
Find an entity by its ID.
Source code in src/crew_dcs/integrations/graphs/mermaid/mermaid_erd.py
204 205 206 | |
to_string ¶
to_string() -> str
Render the complete Mermaid ER diagram.
Source code in src/crew_dcs/integrations/graphs/mermaid/mermaid_erd.py
237 238 239 240 241 242 243 244 245 246 247 248 249 | |
MermaidEREntity
dataclass
¶
MermaidEREntity(
id: str,
name: str,
columns: list[MermaidERColumn] = list(),
)
An entity in an ER diagram with typed columns.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str
|
Unique identifier (used for deduplication and relationship references) |
name |
str
|
Display name (sanitized for Mermaid output) |
columns |
list[MermaidERColumn]
|
List of columns belonging to this entity |
add_column ¶
add_column(column: MermaidERColumn) -> None
Add a column if not already present (by name).
Source code in src/crew_dcs/integrations/graphs/mermaid/mermaid_erd.py
101 102 103 104 105 106 107 108 109 | |
to_string ¶
to_string() -> str
Render as a Mermaid ERD entity block.
Source code in src/crew_dcs/integrations/graphs/mermaid/mermaid_erd.py
111 112 113 114 115 116 117 | |
MermaidERRelationship
dataclass
¶
MermaidERRelationship(
from_entity: MermaidEREntity,
to_entity: MermaidEREntity,
cardinality: str = CARDINALITY_ONE_TO_ONE,
label: str | None = None,
identifying: bool = True,
)
A relationship between two ER entities.
Attributes:
| Name | Type | Description |
|---|---|---|
from_entity |
MermaidEREntity
|
Source entity |
to_entity |
MermaidEREntity
|
Target entity |
cardinality |
str
|
Crow's-foot cardinality string (e.g., "||--|{") |
label |
str | None
|
Relationship label (column mapping summary) |
identifying |
bool
|
True = solid line, False = dashed line |
to_string ¶
to_string() -> str
Render as a Mermaid ERD relationship line.
Source code in src/crew_dcs/integrations/graphs/mermaid/mermaid_erd.py
175 176 177 178 179 180 181 182 183 | |
MermaidNode
dataclass
¶
MermaidNode(
id: str,
name: str,
type: str,
subtitle: str | None = None,
domo_instance: str | None = None,
alias: str | None = None,
css_class: str | None = None,
shape: str | None = None,
url: str | None = None,
)
Represents a node in a Mermaid diagram.
Structured label (rendered at to_string time): Line 1: name (entity title) Line 2: subtitle (chart_type, data_provider_type, or class name) Line 3: domo_instance (if show_instance=True) Line 4: id (if show_entity_id=True)
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str
|
Unique identifier for the node |
name |
str
|
Display name for the entity (title only — no metadata baked in) |
type |
str
|
Entity type (e.g., PAGE, CARD, DATA_SOURCE) |
subtitle |
str | None
|
Second line — chart_type, data_provider_type, or class name |
domo_instance |
str | None
|
Domo instance name (for federated/multi-instance diagrams) |
alias |
str | None
|
Short alias for the node (e.g., "A", "B", "C") - auto-generated |
css_class |
str | None
|
Optional CSS class for styling (e.g., "FederatedDataset") |
shape |
str | None
|
Mermaid shape name (e.g., "cyl", "notch-rect", "fr-rect") |
url |
str | None
|
Optional URL for click directive linking to the entity in Domo |
from_domo_entity
classmethod
¶
from_domo_entity(entity: Any) -> MermaidNode
Create a MermaidNode from a Domo entity (DomoPage, DomoDataset, etc.).
Source code in src/crew_dcs/integrations/graphs/mermaid/mermaid_node.py
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 | |
from_lineage_link
classmethod
¶
from_lineage_link(lineage_link: Any) -> MermaidNode
Create a MermaidNode from a lineage link item.
Structured label: - Line 1: entity name - Line 2: chart_type / data_provider_type / class name - Line 3: domo_instance (stored but only shown if flag is set)
Source code in src/crew_dcs/integrations/graphs/mermaid/mermaid_node.py
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 | |
from_lineage_node
classmethod
¶
from_lineage_node(node: LineageNode) -> MermaidNode
Create a MermaidNode from a LineageNode with formatted display.
Source code in src/crew_dcs/integrations/graphs/mermaid/mermaid_node.py
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 | |
to_string ¶
to_string(
use_alias: bool = False,
indentation: int = 4,
*,
show_instance: bool = False,
show_entity_id: bool = False
) -> str
Render the node as a Mermaid node definition.
Uses the v11.3.0+ @{ shape: <name> } syntax when a shape is set,
falling back to the bracket syntax (["name"]) otherwise.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
use_alias
|
bool
|
If True, use the alias instead of full ID |
False
|
indentation
|
int
|
Number of spaces to indent |
4
|
show_instance
|
bool
|
If True, include domo_instance on line 3 |
False
|
show_entity_id
|
bool
|
If True, include entity ID on line 4 |
False
|
Source code in src/crew_dcs/integrations/graphs/mermaid/mermaid_node.py
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 | |
MermaidRelationship
dataclass
¶
MermaidRelationship(
from_node: MermaidNode,
to_node: MermaidNode,
type: str = "DEPENDS_ON",
)
Represents a relationship between two nodes in a Mermaid diagram.
to_string ¶
to_string(
use_alias: bool = False, indentation: int = 4
) -> str
Render the relationship as a Mermaid arrow with type label.
All relationships render as A -->|TYPE| B including DEPENDS_ON.
Source code in src/crew_dcs/integrations/graphs/mermaid/mermaid_relationship.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | |