Skip to main content

Group nodes in a Mermaid flowchart by putting them in a subgraph

I was drawing a flowchart with Mermaid, and I wanted to draw a box around several items to group them together.

I found a suggestion by Stack Overflow user KZiovas to use a subgraph. Here’s an example:

flowchart LR
  subgraph sources["my sources"]

    SRC1[source 1]
    SRC2[source 2]
    SRC3[source 3]
  end
  DST[destination]

  SRC1 --> DST
  SRC2 --> DST
  SRC3 --> DST

and here’s what the rendered graph looks like:

my sources

source 1

source 2

source 3

destination