Skip to content

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
@staticmethod
def convert(  # noqa: C901
    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.

    Args:
        column_relationships: Set or list of ColumnRelationship objects
        entity_names: Optional mapping of entity_id → display name.
                     Falls back to entity_id if not provided.
        title: Optional diagram title
        trace_from_entity: If provided, trace only the upstream chain
                          from this entity (e.g., a card's dataset ID)
        trace_from_column: If provided alongside trace_from_entity,
                          trace only the upstream chain for this specific
                          column (e.g., a beast mode or dataset column)

    Returns:
        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",
        ... )
    """
    if not column_relationships:
        return MermaidERDiagram(title=title)

    # If tracing, filter to only the upstream chain
    if trace_from_entity:
        column_relationships = _trace_upstream(
            column_relationships,
            start_entity_id=trace_from_entity,
            start_column=trace_from_column,
        )
        if not column_relationships:
            return MermaidERDiagram(title=title)

    entity_names = entity_names or {}

    # Step 1: Collect all entity IDs and their columns
    entity_columns: dict[str, set[str]] = defaultdict(set)
    entity_key_columns: dict[str, dict[str, str]] = defaultdict(
        dict
    )  # entity_id → {col_name → key_type}

    for rel in column_relationships:
        # Track columns on both sides
        if rel.from_column:
            entity_columns[rel.from_entity_id].add(rel.from_column)
        if rel.to_column:
            entity_columns[rel.to_entity_id].add(rel.to_column)

        # Mark FK on columns involved in JOINs
        if rel.transformation_type == ColumnTransformationType.JOIN:
            if rel.from_column:
                entity_key_columns[rel.from_entity_id][rel.from_column] = "FK"
            if rel.to_column:
                entity_key_columns[rel.to_entity_id][rel.to_column] = "FK"

    # Step 2: Build entities
    diagram = MermaidERDiagram(title=title)

    for entity_id, columns in entity_columns.items():
        name = entity_names.get(entity_id, entity_id)
        entity = MermaidEREntity(id=entity_id, name=name)
        for col_name in sorted(columns):
            key = entity_key_columns.get(entity_id, {}).get(col_name)
            entity.add_column(MermaidERColumn(name=col_name, key=key))
        diagram.add_entity(entity)

    # Step 3: Group relationships by entity pair
    pair_rels: dict[tuple[str, str], list[ColumnRelationship]] = defaultdict(list)
    for rel in column_relationships:
        pair_key = (rel.from_entity_id, rel.to_entity_id)
        pair_rels[pair_key].append(rel)

    # Step 4: Build relationships
    for (from_id, to_id), rels in pair_rels.items():
        from_entity = diagram.find_entity(from_id)
        to_entity = diagram.find_entity(to_id)
        if not from_entity or not to_entity:
            continue

        # Determine strongest cardinality from all column relationships
        strongest_card = CARDINALITY_ONE_TO_ONE
        column_labels: list[str] = []

        for rel in rels:
            # Cardinality from transformation type
            type_name = (
                rel.transformation_type.value
                if rel.transformation_type
                else "IDENTITY"
            )
            card = TRANSFORMATION_CARDINALITY.get(type_name, CARDINALITY_ONE_TO_ONE)
            strongest_card = _stronger_cardinality(strongest_card, card)

            # Build column mapping label
            from_col = rel.from_column or "?"
            to_col = rel.to_column or "(new)"
            label_part = from_col if from_col == to_col else f"{from_col}→{to_col}"

            # Add transformation type for non-identity
            if type_name != "IDENTITY":
                label_part += f" [{type_name}]"

            # Add expression if present (beast modes, formulas)
            if rel.expression:
                label_part += f" ({rel.expression})"

            column_labels.append(label_part)

        # Determine if identifying (solid) or non-identifying (dashed)
        # INDIRECT relationships are non-identifying
        has_indirect = any(r.directness == ColumnDirectness.INDIRECT for r in rels)

        # Build label
        label = ", ".join(column_labels) if column_labels else None

        er_rel = MermaidERRelationship(
            from_entity=from_entity,
            to_entity=to_entity,
            cardinality=strongest_card,
            label=label,
            identifying=not has_indirect,
        )
        diagram.add_relationship(er_rel)

    return diagram

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
def __init__(self, graph: LineageGraph | None = None):
    """Initialize MermaidConverter with optional LineageGraph.

    Args:
        graph: Optional LineageGraph to convert
    """
    self.graph = graph

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
def convert(
    self,
    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.

    Args:
        graph: LineageGraph to convert. If None, uses self.graph
        direction: Mermaid flow direction (default: "TD")
        include_entity_ids: Whether to include entity IDs
        title: Title for the diagram
        trace_direction: Direction to trace dependencies
        **options: Additional options

    Returns:
        MermaidDiagram representation of the graph
    """
    _ = include_entity_ids
    _ = options

    target_graph = graph or self.graph
    if not target_graph:
        raise ValueError(
            "No graph provided. Pass graph to convert() or use from_lineage_graph()"
        )

    diagram = MermaidDiagram(
        direction=direction,
        title=title,
    )

    mermaid_nodes: dict[tuple[str, str], MermaidNode] = {}

    for node in target_graph.nodes:
        mermaid_node = MermaidNode.from_lineage_node(node=node)
        diagram.add_node(mermaid_node)
        mermaid_nodes[node.node_key] = mermaid_node

    for edge in target_graph.edges:
        dependent = mermaid_nodes.get(edge.dependent_node.node_key)
        dependency = mermaid_nodes.get(edge.dependency_node.node_key)

        if dependent and dependency:
            rel_type = edge.metadata.get("relationship_type", "DEPENDS_ON")
            if trace_direction == "trace_dependencies":
                relationship = MermaidRelationship(
                    from_node=dependent,
                    to_node=dependency,
                    type=rel_type,
                )
            else:
                relationship = MermaidRelationship(
                    from_node=dependency,
                    to_node=dependent,
                    type=rel_type,
                )
            diagram.add_relationship(relationship)

    return diagram

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
def export(self, **options) -> MermaidDiagram:
    """Convert the stored lineage graph to a MermaidDiagram.

    Args:
        **options: Options to pass to convert()

    Returns:
        MermaidDiagram representation of the graph
    """
    return self.convert(**options)

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
def export_to_file(
    self,
    file_path: str,
    output: MermaidDiagram | None = None,
    footer_text: str | None = None,
    **options,
) -> None:
    """Export Mermaid diagram to markdown file.

    Args:
        file_path: Path to output markdown file
        output: MermaidDiagram to export. If None, converts self.graph
        footer_text: Optional footer text for the markdown
        **options: Additional options to pass to convert()
    """
    if output is None:
        output = self.convert(**options)

    output.export_to_markdown(
        export_file=file_path,
        footer_text=footer_text,
    )

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
@classmethod
def from_lineage_graph(cls, graph: LineageGraph) -> MermaidConverter:
    """Create a MermaidConverter from an existing LineageGraph.

    Args:
        graph: Existing LineageGraph

    Returns:
        MermaidConverter wrapping the graph
    """
    return cls(graph=graph)
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
@classmethod
def from_lineage_links(
    cls,
    links: list[DomoLineage_Link],
) -> MermaidConverter:
    """Create a MermaidConverter from lineage links.

    Args:
        links: List of DomoLineage_Link objects

    Returns:
        MermaidConverter with graph created from links
    """
    graph = LineageGraph.from_lineage_links(links)
    return cls(graph=graph)

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
def add_entity_dependency(
    self,
    from_entity: Any,
    to_entity: Any,
    *,
    relationship_type: str = "dependency",
) -> None:
    """Add a relationship between two Domo entities."""
    if not from_entity or not to_entity:
        return

    from_node = MermaidNode.from_domo_entity(from_entity)
    to_node = MermaidNode.from_domo_entity(to_entity)
    self.add_node(from_node)
    self.add_node(to_node)

    from_ref = self.find_node(from_entity.id, from_entity.entity_type)
    to_ref = self.find_node(to_entity.id, to_entity.entity_type)

    if from_ref and to_ref and from_ref != to_ref:
        self.add_relationship(
            MermaidRelationship(
                from_node=from_ref,
                to_node=to_ref,
                type=relationship_type,
            )
        )

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
def add_federation_node(
    self,
    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."""
    label_parts = []

    name_line = entity.entity_name
    if hasattr(entity, "auth") and entity.auth:
        name_line += f" [{entity.auth.domo_instance}]"
    label_parts.append(name_line)

    if show_entity_id:
        label_parts.append(str(entity.id))

    if show_federation_id:
        label_parts.append(str(show_federation_id))

    label = "<br/>".join(label_parts)

    if custom_type:
        node_type = custom_type
    elif hasattr(entity, "is_federated") and entity.is_federated:
        node_type = f"Federated{entity.entity_type.title()}"
    else:
        if entity.entity_type == "DATA_SOURCE" and hasattr(
            entity, "data_provider_type"
        ):
            provider_type = entity.data_provider_type or None
            if (
                not provider_type
                and hasattr(entity, "stream_id")
                and not entity.stream_id
            ):
                provider_type = "domo"
            node_type = (
                provider_type.replace("-", " ").title()
                if provider_type
                else "Dataset"
            )
        else:
            node_type = entity.entity_type

    node = MermaidNode(
        id=entity.id,
        name=label,
        type=node_type,
    )
    self.add_node(node)
    return node

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
def add_lineage_items(
    self,
    lineage_items: Iterable[Any] | None,
    *,
    recursive: bool = False,
) -> None:
    """Add a collection of lineage items, optionally following dependencies."""
    if not lineage_items:
        return

    visited: set[tuple[str, str]] = set()

    def _add(link: Any) -> None:
        if not link or not getattr(link, "entity", None):
            return

        entity = link.entity
        key = (str(getattr(entity, "id", "")), getattr(entity, "entity_type", ""))
        if key in visited:
            return
        visited.add(key)

        self.add_lineage_link(link)

        if recursive and getattr(link, "dependencies", None):
            for dependency in link.dependencies:
                _add(dependency)

    for root in lineage_items:
        _add(root)
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
def add_lineage_link(self, 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).
    """
    if not lineage_link:
        return

    source_node = MermaidNode.from_lineage_link(lineage_link)
    self.add_node(source_node)

    # Resolve source_node from the diagram (may have been deduplicated)
    source_type = lineage_link.type
    source_id = str(lineage_link.id)
    source_node = self.find_node(source_id, source_type) or source_node

    if lineage_link.dependencies:
        for dependency in lineage_link.dependencies:
            if not dependency:
                continue

            dep_node = MermaidNode.from_lineage_link(dependency)
            self.add_node(dep_node)

            dep_type = dependency.type
            dep_id = str(dependency.id)
            dep_node = self.find_node(dep_id, dep_type) or dep_node

            if source_node != dep_node:
                rel_type = resolve_relationship(source_node.type, dep_node.type)
                rel = MermaidRelationship(
                    from_node=source_node,
                    to_node=dep_node,
                    type=rel_type,
                )
                self.add_relationship(rel)

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
def add_node(self, 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.
    """
    existing = self.find_node(node.id, node.type)
    if existing:
        # Upgrade: hydrated name replaces placeholder UUID
        if node.name != node.id and existing.name == existing.id:
            existing.name = node.name
        # Upgrade: explicit shape replaces None
        if node.shape and not existing.shape:
            existing.shape = node.shape
        # Upgrade: css_class
        if node.css_class and not existing.css_class:
            existing.css_class = node.css_class
        # Upgrade: url
        if node.url and not existing.url:
            existing.url = node.url
        # Upgrade: subtitle
        if node.subtitle and not existing.subtitle:
            existing.subtitle = node.subtitle
        # Upgrade: domo_instance
        if node.domo_instance and not existing.domo_instance:
            existing.domo_instance = node.domo_instance
        return

    if self.use_aliases and node.alias is None:
        node.alias = self._generate_alias(len(self.nodes))
    self.nodes.append(node)

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
def add_relationship(self, relationship: MermaidRelationship) -> None:
    """Add a relationship to the diagram if it doesn't already exist."""
    if relationship not in self.relationships:
        self.relationships.append(relationship)

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
@classmethod
def combine(
    cls,
    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."""
    if not diagrams:
        raise ValueError("No diagrams provided to combine.")

    combined = cls(
        nodes=[],
        relationships=[],
        direction=direction or diagrams[0].direction,
        use_aliases=(
            use_aliases if use_aliases is not None else diagrams[0].use_aliases
        ),
    )

    for diagram in diagrams:
        for node in diagram.nodes:
            combined.add_node(node)
        for relationship in diagram.relationships:
            combined.add_relationship(relationship)

    if combined.use_aliases:
        for idx, node in enumerate(combined.nodes):
            node.alias = combined._generate_alias(idx)

    def _find_node_by_id(node_id: str) -> MermaidNode | None:
        return next((n for n in combined.nodes if str(n.id) == str(node_id)), None)

    start_node = _find_node_by_id(bridge_start_id)
    end_node = _find_node_by_id(bridge_end_id)

    if not start_node or not end_node:
        raise ValueError(
            "Bridge endpoints not found in combined diagram: "
            f"start={bridge_start_id}, end={bridge_end_id}"
        )

    combined.add_relationship(
        MermaidRelationship(
            from_node=start_node,
            to_node=end_node,
            type=bridge_type,
        )
    )

    return combined

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
def export_to_markdown(
    self,
    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.

    Args:
        export_file: Path to write the markdown file
        footer_text: Optional footer text
        show_instance: If True, include domo_instance on node line 3
        show_entity_id: If True, include entity ID on node line 4
    """
    lines = []

    if self.title:
        lines.append(f"# {self.title}")
        lines.append("")

    if self.entity_id and self.entity_type:
        lines.append(f"**Entity Type**: {self.entity_type}")
        lines.append(f"**Entity ID**: {self.entity_id}")
        lines.append("")

    lines.append(f"**Nodes**: {len(self.nodes)}")
    lines.append(f"**Relationships**: {len(self.relationships)}")
    lines.append("")

    lines.append("```mermaid")
    lines.append(
        self.to_string(
            show_instance=show_instance,
            show_entity_id=show_entity_id,
        )
    )
    lines.append("```")

    if footer_text:
        lines.append("")
        lines.append(footer_text.strip())

    markdown_content = "\n".join(lines)

    if export_file:
        output_path = Path(export_file)
        output_path.write_text(markdown_content, encoding="utf-8")

    return markdown_content

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
def find_node(self, node_id: str, node_type: str) -> MermaidNode | None:
    """Find a node by ID and type."""
    return next(
        (n for n in self.nodes if n.id == node_id and n.type == node_type), None
    )

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
@classmethod
def from_entity(
    cls,
    entity: Any,
    direction: str = "TD",
    use_aliases: bool = True,
) -> MermaidDiagram:
    """Create a Mermaid diagram shell for a Domo entity."""
    entity_display_name = _resolve_entity_name(entity)
    diagram = cls(
        nodes=[],
        direction=direction,
        title=f"Lineage Diagram for {entity_display_name}",
        entity_id=str(entity.id),
        entity_type=entity.entity_type,
        use_aliases=use_aliases,
    )
    root_node = MermaidNode.from_domo_entity(entity)
    diagram.add_node(root_node)
    return diagram

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
@classmethod
def from_lineage(
    cls,
    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.

    Args:
        entity: The root Domo entity
        lineage: Pre-fetched lineage items (from entity.Lineage.get())
        direction: Mermaid flow direction
        use_aliases: Whether to use short aliases for node IDs

    Returns:
        MermaidDiagram with all nodes and relationships populated
    """
    diagram = cls.from_entity(entity, direction=direction, use_aliases=use_aliases)
    diagram.add_lineage_items(lineage, recursive=True)
    return diagram

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
def print_lineage_summary(self, lineage: list[Any]) -> None:  # noqa: C901
    """Print a formatted summary of lineage data."""
    if self.nodes:
        parent_name = self.nodes[0].name
    elif self.title:
        parent_name = self.title.replace("Lineage Diagram for ", "")
    else:
        parent_name = self.entity_id or "Unknown"

    print(f"\n{'=' * 60}")
    print(f"Lineage Summary: {parent_name}")
    if self.entity_type:
        print(f"Type: {self.entity_type}, ID: {self.entity_id}")
    print(f"{'=' * 60}")
    print(f"\nTotal lineage items: {len(lineage)}")

    if lineage:
        by_type = {}
        for item in lineage:
            item_type = item.type
            if item_type not in by_type:
                by_type[item_type] = []
            by_type[item_type].append(item)

        print("\nBy Type:")
        for item_type, items in sorted(by_type.items()):
            print(f"  {item_type}: {len(items)}")

        print("\nDetailed Items:")
        for idx, item in enumerate(lineage, 1):
            if (
                hasattr(item, "entity")
                and item.entity
                and hasattr(item.entity, "entity_name")
            ):
                entity_name = item.entity.entity_name
            else:
                if hasattr(item, "entity") and item.entity:
                    entity_name = (
                        getattr(item.entity, "name", None)
                        or getattr(item.entity, "title", None)
                        or getattr(item.entity, "display_name", None)
                        or item.id
                    )
                else:
                    entity_name = item.id
            print(f"\n  {idx}. {item.type}: {item.id}")
            print(f"     Name: {entity_name}")
            if hasattr(item, "dependencies") and item.dependencies:
                print(f"     Dependencies: {len(item.dependencies)}")
            if hasattr(item, "dependents") and item.dependents:
                print(f"     Dependents: {len(item.dependents)}")
    else:
        print("No lineage items found.")

    print(f"\n{'=' * 60}\n")

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
def to_string(
    self,
    *,
    show_instance: bool = False,
    show_entity_id: bool = False,
) -> str:
    """Render the complete Mermaid diagram.

    Args:
        show_instance: If True, include domo_instance on node line 3
        show_entity_id: If True, include entity ID on node line 4
    """
    lines = [f"flowchart {self.direction}"]

    for node in self.nodes:
        lines.append(
            node.to_string(
                use_alias=self.use_aliases,
                show_instance=show_instance,
                show_entity_id=show_entity_id,
            )
        )

    if self.relationships:
        lines.append("")
        for rel in self.relationships:
            lines.append(rel.to_string(use_alias=self.use_aliases))

    classes_added = set()
    for node in self.nodes:
        if node.css_class and node.css_class not in classes_added:
            if self.use_aliases and node.alias:
                node_id = node.alias
            else:
                node_id = f"{node.type}_{node.id}".replace("-", "_").replace(
                    " ", "_"
                )[:50]
            lines.append(f"    class {node_id} {node.css_class}")
            classes_added.add(node.css_class)

    # Click directives — link nodes to their Domo instance URLs
    for node in self.nodes:
        if node.url:
            if self.use_aliases and node.alias:
                node_id = node.alias
            else:
                node_id = f"{node.type}_{node.id}".replace("-", "_").replace(
                    " ", "_"
                )[:50]
            safe_name = node.name.replace('"', "'")
            safe_id = str(node.id).replace('"', "'")
            lines.append(
                f'    click {node_id} "{node.url}" "{safe_name} ({safe_id})"'
            )

    return "\n".join(lines)

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
def to_string(self) -> str:
    """Render as a Mermaid ERD attribute line (inside entity block)."""
    # Mermaid ERD attribute syntax: type name [key] ["comment"]
    parts = [f"        {self.col_type} {self.name}"]
    if self.key:
        parts.append(self.key)
    if self.comment:
        safe = self.comment.replace('"', "'")[:80]
        parts.append(f'"{safe}"')
    return " ".join(parts)

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
def add_entity(self, entity: MermaidEREntity) -> MermaidEREntity:
    """Add an entity to the diagram. Returns the existing entity if found."""
    existing = self.find_entity(entity.id)
    if existing:
        # Merge columns from new entity into existing
        for col in entity.columns:
            existing.add_column(col)
        return existing
    self.entities.append(entity)
    return entity

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
def add_relationship(self, rel: MermaidERRelationship) -> None:
    """Add a relationship if not already present."""
    if rel not in self.relationships:
        self.relationships.append(rel)
    else:
        # Merge label into existing relationship
        existing = next(
            r
            for r in self.relationships
            if r.from_entity.id == rel.from_entity.id
            and r.to_entity.id == rel.to_entity.id
        )
        if rel.label and existing.label:
            # Append new column mapping to existing label
            existing.label = f"{existing.label}, {rel.label}"
        elif rel.label:
            existing.label = rel.label

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
def export_to_markdown(
    self,
    export_file: str | None = None,
    footer_text: str | None = None,
) -> str:
    """Render the diagram as a Markdown document with optional file export."""
    lines = []

    if self.title:
        lines.append(f"# {self.title}")
        lines.append("")

    lines.append(f"**Entities**: {len(self.entities)}")
    lines.append(f"**Relationships**: {len(self.relationships)}")
    lines.append("")

    lines.append("```mermaid")
    lines.append(self.to_string())
    lines.append("```")

    if footer_text:
        lines.append("")
        lines.append(footer_text.strip())

    markdown_content = "\n".join(lines)

    if export_file:
        output_path = Path(export_file)
        output_path.write_text(markdown_content, encoding="utf-8")

    return markdown_content

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
def find_entity(self, entity_id: str) -> MermaidEREntity | None:
    """Find an entity by its ID."""
    return next((e for e in self.entities if e.id == entity_id), None)

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
def to_string(self) -> str:
    """Render the complete Mermaid ER diagram."""
    lines = ["erDiagram"]

    for entity in self.entities:
        lines.append(entity.to_string())

    if self.relationships:
        lines.append("")
        for rel in self.relationships:
            lines.append(rel.to_string())

    return "\n".join(lines)

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

mermaid_name property

mermaid_name: str

Sanitized name for Mermaid ERD output.

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
def add_column(self, column: MermaidERColumn) -> None:
    """Add a column if not already present (by name)."""
    if not any(c.name == column.name for c in self.columns):
        self.columns.append(column)
    else:
        # Upgrade key if the new column has a key and existing doesn't
        existing = next(c for c in self.columns if c.name == column.name)
        if column.key and not existing.key:
            existing.key = column.key

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
def to_string(self) -> str:
    """Render as a Mermaid ERD entity block."""
    lines = [f"    {self.mermaid_name} {{"]
    for col in self.columns:
        lines.append(col.to_string())
    lines.append("    }")
    return "\n".join(lines)

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
def to_string(self) -> str:
    """Render as a Mermaid ERD relationship line."""
    from_name = self.from_entity.mermaid_name
    to_name = self.to_entity.mermaid_name
    separator = "--" if self.identifying else ".."
    # Replace the -- in cardinality with the appropriate separator
    cardinality = self.cardinality.replace("--", separator)
    label_part = f' : "{self.label}"' if self.label else ""
    return f"    {from_name} {cardinality} {to_name}{label_part}"

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

mermaid_id property

mermaid_id: str

Generate a Mermaid-safe node ID.

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
@classmethod
def from_domo_entity(cls, entity: Any) -> MermaidNode:
    """Create a MermaidNode from a Domo entity (DomoPage, DomoDataset, etc.)."""
    name = _resolve_entity_name(entity)
    url = getattr(entity, "display_url", None)
    subtitle = _resolve_subtitle(entity)
    domo_instance = _resolve_domo_instance(entity)

    return cls(
        id=str(entity.id),
        name=name,
        type=entity.entity_type,
        subtitle=subtitle,
        domo_instance=domo_instance,
        url=url,
    )
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
@classmethod
def from_lineage_link(cls, 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)
    """
    if lineage_link.entity:
        entity = lineage_link.entity
        name = _resolve_entity_name(entity)
        url = getattr(entity, "display_url", None)
        subtitle = _resolve_subtitle(entity)
        domo_instance = _resolve_domo_instance(entity)

        return cls(
            id=str(entity.id),
            name=name,
            type=entity.entity_type,
            subtitle=subtitle,
            domo_instance=domo_instance,
            url=url,
        )

    return cls(
        id=str(lineage_link.id),
        name=str(lineage_link.id),
        type=lineage_link.type,
    )

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
@classmethod
def from_lineage_node(
    cls,
    node: LineageNode,
) -> MermaidNode:
    """Create a MermaidNode from a LineageNode with formatted display."""
    entity_name = node.name or str(node.id)

    subtitle = None
    domo_instance = None

    if node.entity:
        domo_instance = _resolve_domo_instance(node.entity)
        subtitle = _resolve_subtitle(node.entity)

    if not subtitle:
        # Fallback: entity_type as title case
        subtitle = node.entity_type.replace("_", " ").title()

    css_class = None
    if node.entity and getattr(node.entity, "is_federated", False):
        clean_type = node.entity_type.replace("_", "").title()
        css_class = f"Federated{clean_type}"
    elif node.entity_type in ("SUBSCRIPTION", "PUBLICATION"):
        css_class = node.entity_type.title()

    return cls(
        id=str(node.id),
        name=entity_name,
        type=node.entity_type,
        subtitle=subtitle,
        domo_instance=domo_instance,
        css_class=css_class,
    )

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
def to_string(
    self,
    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.

    Args:
        use_alias: If True, use the alias instead of full ID
        indentation: Number of spaces to indent
        show_instance: If True, include domo_instance on line 3
        show_entity_id: If True, include entity ID on line 4
    """
    label = self._build_label(
        show_instance=show_instance,
        show_entity_id=show_entity_id,
    )
    safe_label = label.replace('"', "'").replace("\n", " ")

    if use_alias and self.alias:
        node_id = self.alias
    else:
        node_id = f"{self.type}_{self.id}".replace("-", "_").replace(" ", "_")[:50]

    # Resolve shape: explicit > entity-type mapping > default (rect)
    shape = self.shape or self.ENTITY_TYPE_SHAPES.get(self.type)

    if shape:
        return f'{" " * indentation}{node_id}@{{ shape: {shape}, label: "{safe_label}" }}'

    return f'{" " * indentation}{node_id}["{safe_label}"]'

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
def to_string(self, 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.
    """
    if use_alias and self.from_node.alias:
        from_id = self.from_node.alias
    else:
        from_id = f"{self.from_node.type}_{self.from_node.id}".replace(
            "-", "_"
        ).replace(" ", "_")[:50]

    if use_alias and self.to_node.alias:
        to_id = self.to_node.alias
    else:
        to_id = f"{self.to_node.type}_{self.to_node.id}".replace("-", "_").replace(
            " ", "_"
        )[:50]

    rel_type = self.type or "DEPENDS_ON"
    return f"{' ' * indentation}{from_id} -->|{rel_type}| {to_id}"

Modules