← Back to Editor All Tutorials
中文

How to Draw Architecture Diagrams in Mermaid

Architecture diagrams visualize system architectures, component relationships, and deployment patterns. They are ideal for system design, architecture reviews, and technical documentation. Mermaid uses architecture-beta keyword for architecture diagrams.

Why Use Architecture Diagrams?

Architecture diagrams are core tools for system design and documentation:

Use Cases

Suitable:

Not Suitable:

Comparison with Other Diagrams

Diagram Type Core Purpose Difference from Architecture
Architecture System components & deployment Emphasizes component hierarchy, external dependencies, deployment patterns
Block Module structure More generic, suitable for network topology, industrial flows
Flowchart Process & decisions Emphasizes step sequence, no component hierarchy concept

Selection Guide:

Declaring a Chart

Use architecture-beta keyword:

architecture-beta
    title System Architecture Diagram

Try in MermZen →

Component Definition

Define system components including services, databases, external systems:

architecture-beta
    title Basic Architecture Components
    container "Frontend Application" {
        component "User Interface"
        component "API Calls"
    }
    container "Backend Services" {
        component "Business Logic"
        component "Data Access"
    }
    database "Database" {
        component "User Data"
        component "Business Data"
    }
    system "External Payment System"

在 MermZen 中试试 →

Connection Relationships

Define connections and dependencies between components:

architecture-beta
    title Component Relationship Diagram
    container "Frontend Application" {
        component "User Interface"
        component "API Calls"
    }
    container "Backend Services" {
        component "Business Logic"
        component "Data Access"
    }
    database "Database" {
        component "User Data"
        component "Business Data"
    }
    system "External Payment System"

    "User Interface" --> "API Calls"
    "API Calls" --> "Business Logic"
    "Business Logic" --> "Data Access"
    "Data Access" --> "User Data"
    "Data Access" --> "Business Data"
    "Business Logic" --> "External Payment System"

在 MermZen 中试试 →

Full Example: Microservices Architecture

architecture-beta
    title E-Commerce System Microservices Architecture
    container "User Interface Layer" {
        component "Web Interface"
        component "Mobile App"
        component "Admin Console"
    }
    container "API Gateway" {
        component "Request Routing"
        component "Authentication"
        component "Rate Limiting & Circuit Breaking"
    }
    container "Business Services Layer" {
        component "User Service"
        component "Product Service"
        component "Order Service"
        component "Payment Service"
        component "Inventory Service"
    }
    database "Data Storage" {
        component "MySQL Primary"
        component "MySQL Replica"
        component "Redis Cache"
    }
    system "External Systems" {
        component "Alipay"
        component "WeChat Pay"
        component "Logistics System"
    }

    "Web Interface" --> "API Gateway"
    "Mobile App" --> "API Gateway"
    "Admin Console" --> "API Gateway"

    "API Gateway" --> "User Service"
    "API Gateway" --> "Product Service"
    "API Gateway" --> "Order Service"
    "API Gateway" --> "Payment Service"
    "API Gateway" --> "Inventory Service"

    "User Service" --> "MySQL Primary"
    "User Service" --> "Redis Cache"
    "Product Service" --> "MySQL Primary"
    "Product Service" --> "Redis Cache"
    "Order Service" --> "MySQL Primary"
    "Inventory Service" --> "MySQL Primary"

    "Payment Service" --> "Alipay"
    "Payment Service" --> "WeChat Pay"
    "Order Service" --> "Logistics System"

Try in MermZen →

Best Practices

Component Organization Principles

Connection Guidelines

Naming Conventions

Element Convention Example
Container Name by function/layer User Interface Layer, API Gateway
Component Name by specific responsibility Request Routing, Authentication
Database Name by storage type MySQL Primary, Redis Cache
System Name by external service Alipay, WeChat Pay

Common Mistakes

Mistake 1: Too Many Connections Creating Clutter

Problem: Drawing connections between all components creates a "spaghetti" diagram

Solution: Only draw major call relationships, document minor ones in text or split into multiple diagrams

Mistake 2: Inconsistent Abstraction Levels

Problem: Mixing "User Service" and "getUser API" at the same level

Solution: Keep components at the same level at the same abstraction level

Mistake 3: Ignoring Data Flow Direction

Problem: Only drawing components without showing data/call flow direction

Solution: Use --> to clearly mark call direction, making the architecture diagram reflect actual system interactions

Quick Reference

Syntax Function
architecture-beta Declare architecture diagram
title Title Set chart title
container "Name" { ... } Define container component
component "Name" Define internal component
database "Name" { ... } Define database component
system "Name" Define external system
"Component1" --> "Component2" Define connection between components
%% comment Line comment

Next Step

After mastering architecture diagrams, continue learning Mermaid Block Diagrams for complex system architecture and process flow visualization.


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