Mermaid を用いたマークダウンにおける UML 記述の基礎

UML をコードベースで記述する方法の覚え書き

検証環境

そもそも Mermaid とは?

環境構築

実行方法

共通基礎文法

コメントアウト

A --> B
%% this is a comment
        
A --> B %% this comment cause error
        

グラフの成長方向

TB: Top to Bottom
BT: Bottom to Top
LR: Left to Right
RL: Right to REFT

direction TB
        

各種グラフの基礎

以下は各種グラフの書き方についての説明

フローチャート

flowchart
    START --> END
        

start diagram

flowchart LR
A --> B
C --> D
D --> A
B --> C
        

random flowchart

flowchart LR
A[test-A] --> B[(test-B)]
B --> C(test-C)
D([test-D]) --> E[[test-E]]
E --> F((test-F))
G[\test-G\] --> H[/test-H\]
H --> I>test-I]
        

flow shape

グラフ

graph TD
graph TD
  A[app.py] --> B[utils.py]
  A --> C[models/user.py]
  C --> D[database/db.py]
  D --> E[(PostgreSQL)]
  B --> E
  C --> B
  %% comment
  A --> C
        

complex graph

シーケンス図

sequenceDiagram
  A ->> B: normal arrow
  B --> A: dot dot dot
  B -->> A: dot with arrow
  actor C
  participant D as testD
  C <<-->> D: test
  activate D
  D --x C: activated!
  deactivate D
        

sequence img

アーキテクチャ (システム構成)

architecture-beta
 group api1(cloud)[test cloud]
 group api2(cloud)[test 2]
 
 service db1(database)[db hoge] in api1
 service disk1(disk)[disk hoge] in api1
 service server1(server)[server hoge] in api1

 db1:L -- R:disk1
 server1:T -- B:disk1

 service net1(internet)[local net] in api2
 service net2(internet)[private net] in api2

 net1:B -- B:net2
        

arch