mermaid_erd
mermaid_erd ¶
MermaidERDiagram — ER diagram rendering using Mermaid erDiagram syntax.
Unlike MermaidDiagram (which renders flowcharts), this module renders entity-relationship diagrams with typed columns and cardinality-annotated relationships. Designed for column-level lineage visualization.
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 | |