← Back to Editor All Tutorials
中文

How to Draw Block Diagrams in Mermaid

Block diagrams visualize complex system component structures, hierarchical relationships, and connections. They are ideal for system architecture design, network topology, and industrial flow diagrams. Mermaid uses block-beta keyword for block diagrams.

Why Use Block Diagrams?

Block diagrams are essential tools for visualizing complex systems:

Use Cases

Suitable:

Not Suitable:

Comparison with Other Diagrams

Diagram Type Core Purpose Difference from Block
Block Module nesting structure Emphasizes hierarchy and containment
Architecture System components & deployment More specific to software architecture
Flowchart Process & decisions Emphasizes flow, not structure

Selection Guide:

Declaring a Chart

Use block-beta keyword:

block-beta
    title Block Diagram Title

Try in MermZen →

Basic Block Definition

Create simple blocks and connections:

block-beta
    title Basic Block Diagram
    block "Block A"
    block "Block B"
    block "Block C"

    "Block A" --> "Block B"
    "Block A" --> "Block C"
    "Block B" --> "Block C"

在 MermZen 中试试 →

Nested Block Structures

Create complex nested structures with sub-blocks:

block-beta
    title Nested Block Diagram
    block "System" {
        block "Subsystem 1" {
            block "Component A"
            block "Component B"
        }
        block "Subsystem 2" {
            block "Component C"
            block "Component D"
        }
    }

    "Component A" --> "Component C"
    "Component B" --> "Component D"
    "Subsystem 1" --> "Subsystem 2"

在 MermZen 中试试 →

Full Example: Network Topology

block-beta
    title Company Network Topology
    block "Headquarters Network" {
        block "Core Switch"
        block "Server Cluster" {
            block "Web Server"
            block "Database Server"
            block "Application Server"
        }
        block "Office Network" {
            block "Employee Computers"
            block "Printers"
        }
    }
    block "Branch Office" {
        block "Branch Switch"
        block "Local Server"
        block "Employee Devices"
    }
    block "Internet"

    "Core Switch" --> "Web Server"
    "Core Switch" --> "Database Server"
    "Core Switch" --> "Application Server"
    "Core Switch" --> "Employee Computers"
    "Core Switch" --> "Printers"
    "Core Switch" --> "Internet"
    "Branch Switch" --> "Local Server"
    "Branch Switch" --> "Employee Devices"
    "Branch Switch" --> "Internet"

Try in MermZen →

Best Practices

Nesting Depth Guidelines

Connection Guidelines

Naming Conventions

Element Convention Example
Top-level block System/Domain name Headquarters Network
Mid-level block Subsystem name Server Cluster
Leaf block Specific component Web Server

Common Mistakes

Mistake 1: Overly Deep Nesting

Problem: Nesting 5+ levels deep creates unreadable diagrams

Solution: Keep to 2-4 levels, split complex systems into multiple diagrams

Mistake 2: Too Many Connections

Problem: Connecting every block to every other block creates visual clutter

Solution: Only show important relationships, document others separately

Mistake 3: Inconsistent Abstraction Levels

Problem: Mixing high-level concepts with low-level details in same diagram

Solution: Keep all blocks at the same level of abstraction

Quick Reference

Syntax Function
block-beta Declare block diagram
title Title Set chart title
block "Name" Define block
block "Name" { ... } Define block with sub-blocks
"Block1" --> "Block2" Define connection between blocks
%% comment Line comment

Next Step

After mastering block diagrams, continue learning Mermaid Requirement Diagrams for project requirements management and analysis.


To try the above code in MermZen, click Open Editor and paste the code there.