mermaid-sequence-diagram-skill

Generates Mermaid-format sequence diagrams from a user-provided interaction flow description. Triggered when the user mentions “sequence diagram” or “generate sequence diagram,” and outputs corresponding Mermaid sequence-diagram code based on the participants and message order in the input.

Installation

Review the source and dependencies with a prompt. A package is available to download.

Install with an AI assistant

Copy the prompt so your assistant can review the pinned revision and dependencies first.

View promptHide prompt
Check whether SkillPI Skill Finder is installed for your current agent. If it is missing, install and enable it using the official instructions at https://github.com/Findskills/skillpi. Then use Skill Finder to locate and install "mermaid-sequence-diagram-skill" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-bbd04083b88b997adf235f607af74c619955bb064b0ca81e852d99fcdf1ffc05. Verify the upstream source and version against https://skillhub.cn/skills/user_6afd4cd8/mermaid-sequence-diagram-skill before installing. If they do not match, stop and report the mismatch. Report the installed path and source version.

Source and setup

skillhub.cn

Setup guidance pending

See the original source for supported tools, dependencies, and permissions.

Installation test pending

Generates Mermaid-format sequence diagrams from a user-provided interaction flow description. Triggered when the user mentions “sequence diagram” or “generate sequence diagram,” and outputs corresponding Mermaid sequence-diagram code based on the participants and message order in the input.

0 Downloads

Introduction source: third_party · user_6afd4cd8 · 1.0.0 Reference

SkillPi interpretation

Tasks
Translation pending; see source documentation.
Limits and differences
Translation pending; see source documentation.
Testing
Not tested

Browse files

Browse files at the source ↗

Original SKILL.md

Open original ↗
Frontmatter
name: mermaid-sequence-diagram-skill
description: 用于生成Mermaid代码格式的时序图。根据用户提供的交互流程描述进行Mermaid格式的时序图生成,或当用户提到“时序图”、“生成时序图”等时触发。
name_zh: Mermaid时序图生成
name_en: mermaid-sequence-diagram-skill
version: 1.0.0
author: duke_xiebo@outlook.com

技能概述

本技能用于根据用户提供的交互流程描述,生成 Mermaid 时序图(Sequence Diagram)代码。时序图是一种交互图,展示各个过程如何相互操作以及操作的顺序 $$TRAE_REF$$。

基础语法

所有时序图以 sequenceDiagram 关键字开头:

sequenceDiagram
Alice->>John: Hello John, how are you?
John-->>Alice: Great!
Alice-)John: See you later!

参与者(Participants)

隐式声明

参与者在消息中首次出现时自动创建,按出现顺序渲染。

显式声明(participant)

使用 participant 关键字声明参与者并按指定顺序显示:

sequenceDiagram
participant Alice
participant Bob
Bob->>Alice: Hi Alice
Alice->>Bob: Hi Bob

角色(actor)

使用 actor 关键字使用参与者符号而非矩形:

sequenceDiagram
actor Alice
actor Bob
Alice->>Bob: Hi Bob
Bob->>Alice: Hi Alice

参与者类型(JSON 配置语法)

Mermaid 支持 7 种参与者类型,使用 @{ "type": "..." } 语法指定:

类型 语法 说明
boundary participant X@{ "type" : "boundary" } 边界符号
control participant X@{ "type" : "control" } 控制符号
entity participant X@{ "type" : "entity" } 实体符号
database participant X@{ "type" : "database" } 数据库符号
collections participant X@{ "type" : "collections" } 集合符号
queue participant X@{ "type" : "queue" } 队列符号
actor actor X 参与者符号(人物图标)
sequenceDiagram
participant Alice@{ "type" : "boundary" }
participant Bob@{ "type" : "database" }
Alice->>Bob: DB query
Bob->>Alice: DB result

别名(Aliases)

外部别名语法:在参与者声明后使用 as 关键字

sequenceDiagram
participant A as Alice
participant J as John
A->>J: Hello John, how are you?
J->>A: Great!

外部别名语法也支持与类型配置结合:

sequenceDiagram
participant API@{ "type": "boundary" } as Public API
actor DB@{ "type": "database" } as User Database
API->>DB: Query user
DB-->>API: User data

内联别名语法:在配置对象中使用 "alias" 字段:

sequenceDiagram
participant API@{ "type": "boundary", "alias": "Public API" }
participant DB@{ "type": "database", "alias": "User Database" }
API->>DB: Login request
DB-->>API: Access token

注意:当同时提供内联别名和外部别名时,外部别名优先。

角色创建与销毁(v10.3.0+)

使用 create participant / create actor 和 destroy 关键字:

sequenceDiagram
Alice->>Bob: Hello Bob, how are you ?
Bob->>Alice: Fine, thank you. And you?
create participant Carl
Alice->>Carl: Hi Carl!
create actor D as Donald
Carl->>D: Hi!
destroy Carl
Alice-xCarl: We are too many
destroy Bob
Bob->>Alice: I agree

消息的发送者或接收者可以被销毁,但只有接收者可以被创建。

分组 / 框(Box)

参与者可以分组在垂直框中,支持颜色和标签:

sequenceDiagram
box Purple Alice & John
participant A
participant J
end
box Another Group
participant B
participant C
end
A->>J: Hello John, how are you?
J->>A: Great!

Box 颜色支持的格式:

  • 命名颜色:box Aqua Description
  • RGB:box rgb(33,66,99)
  • RGBA:box rgba(33,66,99,0.5)
  • HSL:box hsl(10, 40%, 90%)
  • HSLA:box hsla(10, 40%, 90%, 0.5)
  • 透明:box transparent

注意:十六进制颜色(如 #ff0000)不支持,因为 # 被解析为注释语法。

消息(Messages)

消息格式:[Actor][Arrow][Actor]:Message text

标准箭头类型

类型 描述
-> 无箭头实线
--> 无箭头虚线
->> 带箭头实线
-->> 带箭头虚线
<<->> 双向箭头实线(v11.0.0+)
<<-->> 双向箭头虚线(v11.0.0+)
-x 末端带叉号实线
--x 末端带叉号虚线
-) 末端带开放箭头实线(异步)
--) 末端带开放箭头虚线(异步)

半箭头类型(v11.12.3+)

类型 描述
-\| 带顶部半箭头实线
--\| 带顶部半箭头虚线
-\|/ 带底部半箭头实线
--\|/ 带底部半箭头虚线
/\|- 带反向顶部半箭头实线
/\|-- 带反向顶部半箭头虚线
\\- 带反向底部半箭头实线
\\-- 带反向底部半箭头虚线
-\\ 带顶部棒形半箭头实线
--\\ 带顶部棒形半箭头虚线
-// 带底部棒形半箭头实线
--// 带底部棒形半箭头虚线
//- 带反向顶部棒形半箭头实线
//-- 带反向顶部棒形半箭头虚线

半箭头的实线和虚线变体通过增加破折号数量切换(- → --)。

中央连接(Central Connections,v11.12.3+)

使用 () 表示连接到中心点的消息:

sequenceDiagram
participant Alice
participant John
Alice->()John: Hello John
Alice()->>John: How are you?
John()->()Alice: Great!

激活(Activations)

激活和停用角色,表示方法调用持续时间:

专用声明方式:

sequenceDiagram
Alice->>John: Hello John, how are you?
activate John
John-->>Alice: Great!
deactivate John

快捷方式:在消息箭头后添加 +/- 后缀

sequenceDiagram
Alice->>+John: Hello John, how are you?
John-->>-Alice: Great!

叠加激活:

sequenceDiagram
Alice->>+John: Hello John, how are you?
Alice->>+John: John, can you hear me?
John-->>-Alice: Hi Alice, I can hear you!
John-->>-Alice: I feel great!

注释(Notes)

添加注释到参与者:

sequenceDiagram
participant John
Note right of John: Text in note
Note left of John: Left side note
Note over John: Over note

跨参与者注释:

sequenceDiagram
Alice->John: Hello John, how are you?
Note over Alice,John: A typical interaction

换行

在备注和消息中添加换行:

sequenceDiagram
Alice->John: Hello John,<br/>how are you?
Note over Alice,John: A typical interaction<br/>But now in two lines

参与者名称中的换行需要别名:

sequenceDiagram
participant Alice as Alice<br/>Johnson
Alice->John: Hello John, how are you?

循环(Loops)

sequenceDiagram
Alice->John: Hello John, how are you?
loop Every minute
  John-->Alice: Great!
end

条件分支(Alt / Opt)

Alt(if-else 替代路径):

sequenceDiagram
Alice->>Bob: Hello Bob, how are you?
alt is sick
  Bob->>Alice: Not so good :(
else is well
  Bob->>Alice: Feeling fresh like a daisy
end

Opt(可选路径):

sequenceDiagram
Alice->>Bob: Hello Bob, how are you?
Bob->>Alice: Not so good :(
opt Extra response
  Bob->>Alice: Thanks for asking
end

并行(Parallel)

sequenceDiagram
par Alice to Bob
  Alice->>Bob: Hello guys!
and Alice to John
  Alice->>John: Hello guys!
end
Bob-->>Alice: Hi Alice!
John-->>Alice: Hi Alice!

支持嵌套并行块:

sequenceDiagram
par Alice to Bob
  Alice->>Bob: Go help John
  and Alice to John
  Alice->>John: I want this done today
  par John to Charlie
    John->>Charlie: Can we do this today?
  and John to Diana
    John->>Diana: Can you help us today?
  end
end

临界区(Critical Region)

sequenceDiagram
critical Establish a connection to the DB
  Service-->DB: connect
  option Network timeout
    Service-->Service: Log error
  option Credentials rejected
    Service-->Service: Log different error
end

中断(Break)

sequenceDiagram
Consumer-->API: Book something
API-->BookingService: Start booking process
break when the booking process fails
  API-->Consumer: show failure
end
API-->BillingService: Start billing process

背景强调(Background Highlighting)

使用彩色矩形高亮流程:

sequenceDiagram
participant Alice
participant John

rect rgb(191, 223, 255)
  note right of Alice: Alice calls John.
  Alice->>+John: Hello John, how are you?
  rect rgb(200, 150, 255)
    Alice->>+John: John, can you hear me?
    John-->>-Alice: Hi Alice, I can hear you!
  end
  John-->>-Alice: I feel great!
end
Alice ->>+ John: Did you want to go to the game tonight?
John -->>- Alice: Yeah! See you there.

颜色支持格式:rgb()、rgba()

注释(Comments)

使用 %% 添加注释,注释会被解析器忽略:

sequenceDiagram
Alice->>John: Hello John, how are you?
%% this is a comment
John-->>Alice: Great!

实体编码转义字符

使用 # 后跟十进制编码转义字符:

sequenceDiagram
A->>B: I #9829; you!
B->>A: I #9829; you #infin; times more!
  • # 可编码为 #35;
  • 支持 HTML 字符名称
  • 分号需编码为 #59;

序列号(sequenceNumbers)

在每个箭头上附加序列号:

%%{init: { 'sequence': { 'showSequenceNumbers': true } } }%%
sequenceDiagram
Alice->>John: Hello John, how are you?
John-->>Alice: Great!

起始值和递增值(v11.15.0+)

sequenceDiagram
autonumber 1 1
Alice->>John: Hello John, how are you?
John-->>Alice: Great!

autonumber <start> <increment> — 可包含小数,精确到百分位。

角色菜单(Actor Menus)

为角色添加带链接的弹出菜单:

sequenceDiagram
participant Alice
participant John
link Alice: Dashboard @ https://dashboard.example.com
link Alice: Wiki @ https://wiki.example.com
Alice->>John: Hello John, how are you?
John-->>Alice: Great!

高级 JSON 语法:

sequenceDiagram
participant Alice
participant John
links Alice: {"健康看板": "https://dashboard.example.com", "Wiki": "https://wiki.example.com"}
Alice->>John: Hello John, how are you?
John-->>Alice: Great!

配置选项

样式类

CSS 类 描述
.actor 角色框样式
.actor-top 图表顶部角色图形/框样式
.actor-bottom 图表底部角色图形/框样式
text.actor 所有角色文本样式
text.actor-box 角色框文本样式
text.actor-man 角色图形文本样式
.actor-line 角色垂直线样式
.messageLine0 实线消息线样式
.messageLine1 虚线消息线样式
.messageText 消息箭头文本样式
.labelBox 循环左侧标签样式
.labelText 循环标签文本样式
.loopText 循环框中文本样式
.loopLine 循环框中线条样式
.note 备注框样式
.noteText 备注框中文本样式

渲染配置参数

可通过 mermaid.sequenceConfig 或 %%{init}%% 指令配置:

mermaid.sequenceConfig = {
  diagramMarginX: 50,
  diagramMarginY: 10,
  boxTextMargin: 5,
  noteMargin: 10,
  messageMargin: 35,
  mirrorActors: true,
};
参数 描述 默认值
mirrorActors 是否在图表下方也渲染角色 false
bottomMarginAdj 调整图表结束位置下移距离 1
actorFontSize 角色描述字体大小 14
actorFontFamily 角色描述字体系列 "Open Sans", sans-serif
actorFontWeight 角色描述字体粗细 -
noteFontSize 备注字体大小 14
noteFontFamily 备注字体系列 "trebuchet ms", verdana, arial
noteFontWeight 备注字体粗细 -
noteAlign 备注文本对齐方式 center
messageFontSize 消息字体大小 16
messageFontFamily 消息字体系列 "trebuchet ms", verdana, arial
messageFontWeight 消息字体粗细 -
showSequenceNumbers 显示序列号 false

技能工作流程

步骤 1:理解用户需求

  • 确认用户想要展示的交互流程和参与者
  • 明确消息的类型(同步/异步/回复)
  • 梳理控制流逻辑(循环/条件/并行/异常)

步骤 2:选择合适的语法

  • 简单对话:使用隐式参与者 + 基础箭头语法
  • 系统架构交互:使用参与者类型(boundary/control/database)和分组
  • 方法调用生命周期:使用激活(activate/deactivate)机制
  • 复杂控制流:使用 loop/alt/opt/par/break/rect 等结构

步骤 3:组装完整代码块

将生成的代码包裹在 ``mermaid \`\`\ 代码块中。

步骤 4:验证

  • 确认所有参与者在图中正确出现
  • 检查 end 关键字是否被正确闭合(如有必要用引号或括号包裹)
  • 确认消息箭头方向正确
  • 验证括号 {}、end 等结构完整匹配

最佳实践

  1. 遵循 32 位习惯:每行显示约 32 位,符合 RFC 文档惯例
  2. 使用参与者类型:用 @{ "type": "database" } 等类型使图表更具表现力
  3. 善用别名:长名称用别名保持代码简洁
  4. 激活标记:用 +/- 后缀标记方法调用生命周期
  5. 控制流结构:用 loop/alt/par 等表达复杂业务流程
  6. 配色标注:用 rect 和 box 为不同流程区域着色
  7. 避免 "end" 歧义:如果必须使用 "end" 一词,用括号或引号包裹
  8. 注释说明:用 %% 注释关键交互的意图

重要注意事项

  • "end" 关键字可能破坏图表,如果不可避免,使用 (end)、[end] 或 {end} 包裹
  • 十六进制颜色(#ff0000)在 box 中不支持,请使用 RGB/RGBA/HSL/HSLA
  • create participant 只能创建接收者(不能创建发送者)
  • 分号用于替代换行符定义标记,消息文本中的分号需编码为 #59;

参考资料

Current listing version

1.0.0

Verify the source revision ↗

Safety and assessment details

Quality assessment

Out of 100 · Assessment report from SkillPi LAB.

Scenario Value78/100

Highlights

  • 面向开发者、架构师等有流程图绘制需求的群体,实用价值明确
  • 功能定位清晰,解决将交互流程描述转换为标准 Mermaid 代码的痛点
Trigger Precision85/100

Highlights

  • 触发词覆盖完整,包含“时序图”、“生成时序图”等核心表达
  • 边界清晰,不易与其他 Skill 重叠
Structure and Standards92/100

Highlights

  • 技能工作流程分步骤清晰,含验证出口条件
  • 提供大量端到端代码示例,frontmatter 完整
Execution Reliability88/100

Highlights

  • 基于 Mermaid.js 官方语法,参数准确
  • 重要注意事项覆盖常见陷阱,提升执行成功率
Evidence Verifiability (mean of the first four)86/100

The arithmetic mean of the first four original scores, rounded to a whole number.

Static text checks

100 / 100 · skillpi-20261123-no-r3-v1

No current rules matched the text.

This score reflects rule matches in the text and is provided for reference before use. It excludes attachments and runtime behavior.

Permissions and checks before use

Automatically summarized from this main document. Matches may be examples or defensive advice; they are not actual permission declarations. Attachments, external dependencies and runtime behavior are not covered.

Domains or addresses referenced in the document

These addresses may be documentation links or examples, not an approved network allowlist. Verify actual destinations and outgoing data before use.

  • dashboard.example.com
  • mermaid.js.org
  • mermaid.nodejs.cn
  • wiki.example.com

These notices grant no permissions. Your host tool must still confirm file changes, secrets, external transfers or costs as needed.

Security rating and access scope

safe · Static evidence review; not a runtime safety guarantee.

Before use, confirm and authorize actual file access, external services and network destinations in your host. This review grants no runtime permissions.