Mermaid.js rendering for Choreo architecture diagrams.
This module translates a Choreo struct into Mermaid syntax. The default
output is a flowchart, but the native architecture-beta diagram type is
also supported via the :syntax option.
Node shapes
Infrastructure types map to Mermaid flowchart shapes:
| Type | Mermaid shape | Syntax |
|---|---|---|
database | :cylinder | [(label)] |
cache | :hexagon | {{label}} |
service | :subroutine | [[label]] |
network | :rounded_rect | [label] |
user | :circle | ((label)) |
load_balancer | :hexagon | {{label}} |
queue | :stadium | ([label]) |
storage | :rounded_rect | [label] |
generic | :rounded_rect | [label] |
Edges are styled according to their semantic type (:connection or
:dataflow). Dataflow edges use a dashed purple stroke; virtual
edges (from transitive filtering) use a light-grey stroke.
Themes
All built-in themes (:default, :dark, :minimal, :warm, :forest,
:ocean) are supported. Per-type colours and shapes are resolved from
Choreo.Theme and translated into Mermaid style declarations.
Examples
mermaid = Choreo.Render.Mermaid.to_mermaid(system)
mermaid = Choreo.Render.Mermaid.to_mermaid(system, theme: :dark)
theme = Choreo.Theme.custom(colors: [database: "#ff0000"])
mermaid = Choreo.Render.Mermaid.to_mermaid(system, theme: theme)The output can be wrapped in a Markdown code block:
```mermaid
<%= mermaid %>
```
Summary
Functions
Returns a theme for Choreo infrastructure Mermaid diagrams.
See also Choreo.theme/2.
Renders a Choreo struct to a Mermaid string.
Options
:syntax-:flowchart(default) or:architecture(nativearchitecture-betadiagram type):theme-:default,:dark,:minimal,:warm,:forest,:oceanor aChoreo.Themestruct (only applies to:flowchart):direction-:td(default),:lr,:bt,:rl(only applies to:flowchart):highlighted_nodes- list of node IDs to highlight (only applies to:flowchart):highlighted_edges- list of edge IDs or{from, to}tuples to highlight (only applies to:flowchart)- Any other option accepted by
Yog.Multi.Mermaid.to_mermaid/2
Examples
iex> system = Choreo.new() |> Choreo.add_service(:api)
iex> mermaid = Choreo.Render.Mermaid.to_mermaid(system)
iex> String.contains?(mermaid, "graph TD")
true
iex> String.contains?(mermaid, "api")
true