Choreo.Render.Mermaid (Choreo v0.9.0)

Copy Markdown View Source

Mermaid.js rendering for Choreo architecture diagrams.

This module translates a Choreo struct into Mermaid flowchart syntax, suitable for embedding in Markdown, GitHub, GitLab, Notion, and other platforms that support Mermaid natively.

Node shapes

Infrastructure types map to Mermaid flowchart shapes:

TypeMermaid shapeSyntax
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.

Renders a Choreo struct to a Mermaid flowchart string.

Functions

theme(name \\ :default, overrides \\ [])

@spec theme(
  atom(),
  keyword()
) :: map()

Returns a theme for Choreo infrastructure Mermaid diagrams.

See also Choreo.theme/2.

to_mermaid(system, opts \\ [])

@spec to_mermaid(
  Choreo.t(),
  keyword()
) :: String.t()

Renders a Choreo struct to a Mermaid flowchart string.

Options

  • :theme - :default, :dark, :minimal, :warm, :forest, :ocean or a Choreo.Theme struct
  • :direction - :td (default), :lr, :bt, :rl
  • :highlighted_nodes - list of node IDs to highlight
  • :highlighted_edges - list of edge IDs or {from, to} tuples to highlight
  • 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