plantuml-skill
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePlantUML Diagram Skill
PlantUML 图表生成技能
Overview
概述
Generate PlantUML diagram files and export to PNG/SVG using Kroki — a cloud rendering API that requires no local installation beyond .
.pumlcurlFormat: (PlantUML text)
Renderer: Kroki API () — just , no Java needed
Output: PNG, SVG
Diagram types: sequence, component, class, ER, activity, use case, state, C4, and more
.pumlhttps://kroki.iocurl使用Kroki(一款云渲染API,仅需即可使用,无需额外本地安装)生成格式的PlantUML图表文件,并导出为PNG/SVG格式。
curl.puml格式: (PlantUML文本格式)
渲染器: Kroki API () — 仅需,无需Java环境
输出格式: PNG、SVG
支持的图表类型: 时序图、组件图、类图、ER图、活动图、用例图、状态图、C4架构图等
.pumlhttps://kroki.iocurlWhen to Use
使用场景
Explicit triggers:
- "plantuml diagram", "sequence diagram", "class diagram", "component diagram"
- "UML", "activity diagram", "use case diagram", "state machine"
- "visualize", "draw", "diagram", "flowchart", "architecture chart"
Proactive triggers:
- Explaining a system with 3+ interacting components
- Describing API flows, authentication sequences, message passing
- Showing class hierarchies, database schemas, or ER models
- Illustrating state machines or lifecycle flows
明确触发场景:
- "plantuml diagram", "sequence diagram", "class diagram", "component diagram"
- "UML", "activity diagram", "use case diagram", "state machine"
- "visualize", "draw", "diagram", "flowchart", "architecture chart"
主动触发场景:
- 解释包含3个及以上交互组件的系统
- 描述API流程、认证序列、消息传递机制
- 展示类层级结构、数据库模式或ER模型
- 说明状态机或生命周期流程
Prerequisites
前置条件
Option A: Kroki API (recommended — no install)
bash
undefined选项A:Kroki API(推荐——无需安装)
bash
undefinedJust needs curl (pre-installed on macOS/Linux/Windows Git Bash)
仅需curl(macOS/Linux/Windows Git Bash默认已安装)
curl --version
**Option B: Local Kroki via Docker (for offline use)**
```bash
docker run -d -p 8000:8000 yuzutech/krokicurl --version
**选项B:通过Docker运行本地Kroki(用于离线使用)**
```bash
docker run -d -p 8000:8000 yuzutech/krokiThen replace https://kroki.io with http://localhost:8000 in commands
**Option C: Local PlantUML jar (traditional)**
```bash
**选项C:本地PlantUML jar包(传统方式)**
```bashRequires Java + Graphviz
需要Java + Graphviz
brew install graphviz # macOS
sudo apt install graphviz # Ubuntu
brew install graphviz # macOS系统
sudo apt install graphviz # Ubuntu系统
Download plantuml.jar from https://plantuml.com/download
java -jar plantuml.jar diagram.puml
undefinedjava -jar plantuml.jar diagram.puml
undefinedWorkflow
工作流程
Step 0. Update check (notify, don't pull) — first use per conversation
步骤0. 更新检查(仅通知,不自动拉取)—— 每次会话首次使用时执行
Throttle to one check per 24 hours per installation; never mutate the skill directory without explicit user consent.
-
Ifexists and is less than 24 hours old, skip this step entirely.
<this-skill-dir>/.last_update -
Otherwise, fetch the latest tag from upstream:bash
git -C <this-skill-dir> ls-remote --tags origin 'v*' 2>/dev/null \ | awk '{print $2}' | sed 's|refs/tags/||' \ | sort -V | tail -1 -
Compare with this skill'sfrom the frontmatter. If the upstream tag is strictly newer (semver), tell the user one line and ask:
metadata.version"A newer version of this skill is available: vX.Y.Z → vA.B.C. Want me to?"git pullIf they say yes, run. Refreshgit -C <this-skill-dir> pull --ff-onlyeither way so the prompt doesn't repeat for 24 hours..last_update -
If upstream is the same or older, refreshsilently and continue.
.last_update -
On any failure (offline, not a git checkout — e.g. ClawHub-installed copy, read-only path, no permission), swallow the error silently and continue with the user's task. Do not mention the failure.
限制为每个安装实例24小时检查一次;未经用户明确同意,绝不修改技能目录。
-
如果文件存在且创建时间不超过24小时,直接跳过此步骤。
<this-skill-dir>/.last_update -
否则,从上游仓库获取最新版本标签:bash
git -C <this-skill-dir> ls-remote --tags origin 'v*' 2>/dev/null \ | awk '{print $2}' | sed 's|refs/tags/||' \ | sort -V | tail -1 -
将其与技能前置元数据中的进行比较。如果上游版本标签更新(遵循语义化版本规则),向用户发送一行提示并询问:
metadata.version"此技能有新版本可用:vX.Y.Z → vA.B.C。是否需要执行更新?"git pull如果用户同意,执行。无论用户是否同意,都刷新git -C <this-skill-dir> pull --ff-only文件,确保24小时内不再重复提示。.last_update -
如果上游版本与当前版本相同或更旧,静默刷新文件并继续执行后续步骤。
.last_update -
如果出现任何失败(离线、非Git检出目录——例如ClawHub安装的副本、只读路径、无权限),静默忽略错误并继续执行用户任务,不得提及失败情况。
Step 1: Check Dependencies
步骤1:检查依赖
bash
curl --versioncurl is available on all modern systems. If missing, install via package manager.
bash
curl --versioncurl在所有现代系统中均已预装。如果缺失,可通过包管理器安装。
Step 2: Pick Diagram Type
步骤2:选择图表类型
Choose the most appropriate PlantUML diagram type (see reference below).
选择最适合的PlantUML图表类型(参考下方图表类型列表)。
Step 3: Generate .puml File
步骤3:生成.puml文件
Write the PlantUML source file with / markers.
@startuml@enduml编写包含 / 标记的PlantUML源文件。
@startuml@endumlStep 4: Export via Kroki
步骤4:通过Kroki导出
bash
undefinedbash
undefinedPNG (recommended)
PNG格式(推荐)
curl -s -X POST https://kroki.io/plantuml/png
-H "Content-Type: text/plain"
--data-binary "@diagram.puml"
-o diagram.png
-H "Content-Type: text/plain"
--data-binary "@diagram.puml"
-o diagram.png
curl -s -X POST https://kroki.io/plantuml/png
-H "Content-Type: text/plain"
--data-binary "@diagram.puml"
-o diagram.png
-H "Content-Type: text/plain"
--data-binary "@diagram.puml"
-o diagram.png
SVG
SVG格式
curl -s -X POST https://kroki.io/plantuml/svg
-H "Content-Type: text/plain"
--data-binary "@diagram.puml"
-o diagram.svg
-H "Content-Type: text/plain"
--data-binary "@diagram.puml"
-o diagram.svg
undefinedcurl -s -X POST https://kroki.io/plantuml/svg
-H "Content-Type: text/plain"
--data-binary "@diagram.puml"
-o diagram.svg
-H "Content-Type: text/plain"
--data-binary "@diagram.puml"
-o diagram.svg
undefinedStep 5: Report to User
步骤5:向用户反馈
Tell the user:
- Path to the source file
.puml - Path to the exported PNG/SVG
- Brief description of what was generated
告知用户:
- 源文件的路径
.puml - 导出的PNG/SVG文件的路径
- 生成内容的简要说明
Diagram Types
图表类型
| Type | Keyword | Use for |
|---|---|---|
| Sequence | | API calls, protocol flows, message passing |
| Component | | service architecture, module dependencies |
| Class | | OOP models, data structures |
| ER / Entity | | database schemas |
| Activity | | workflows, business processes |
| Use Case | | system requirements, user stories |
| State | | state machines, lifecycle |
| C4 Context | | high-level system context maps |
| Mind Map | | topic breakdowns, concept maps |
| Gantt | | project timelines, schedules |
| 类型 | 关键字 | 适用场景 |
|---|---|---|
| 时序图 | | API调用、协议流程、消息传递 |
| 组件图 | | 服务架构、模块依赖 |
| 类图 | | 面向对象模型、数据结构 |
| ER/实体图 | | 数据库模式 |
| 活动图 | | 工作流、业务流程 |
| 用例图 | | 系统需求、用户故事 |
| 状态图 | | 状态机、生命周期 |
| C4上下文图 | | 高层系统上下文映射 |
| 思维导图 | | 主题分解、概念图 |
| 甘特图 | | 项目时间线、进度计划 |
Syntax Reference
语法参考
Component / Architecture Diagram
组件/架构图
plantuml
@startuml
!theme plain
title Microservices Architecture
actor "Client" as client
rectangle "API Gateway" as gateway #LightBlue
rectangle "Services" {
component "User Service" as user
component "Order Service" as order
}
database "User DB" as userdb
database "Order DB" as orderdb
queue "Kafka" as kafka
client --> gateway
gateway --> user
gateway --> order
user --> userdb
order --> orderdb
order --> kafka : events
@endumlShape types:
- — stick figure (user, external actor)
actor "Name" as id - — component box with [brackets]
component "Name" as id - — plain rectangle (for groups/layers)
rectangle "Name" as id - — cylinder (database)
database "Name" as id - — queue symbol
queue "Name" as id - — cloud shape (external services)
cloud "Name" as id - — server/node box
node "Name" as id - — frame grouping
frame "Name" as id - — package grouping
package "Name" { }
Arrows:
- — solid arrow
A --> B - — thin arrow
A -> B - — dashed arrow
A ..> B - — labeled arrow
A --> B : label - — bidirectional
A <--> B
Colors:
- ,
#LightBlue,#LightGreen,#LightYellow,#Pink#Violet - (blue),
#AED6F1(green),#A9DFBF(orange),#FAD7A0(red)#F1948A - (purple),
#D7BDE2(yellow),#F9E79F(grey)#D3D3D3
plantuml
@startuml
!theme plain
title Microservices Architecture
actor "Client" as client
rectangle "API Gateway" as gateway #LightBlue
rectangle "Services" {
component "User Service" as user
component "Order Service" as order
}
database "User DB" as userdb
database "Order DB" as orderdb
queue "Kafka" as kafka
client --> gateway
gateway --> user
gateway --> order
user --> userdb
order --> orderdb
order --> kafka : events
@enduml形状类型:
- — 角色人形图(用户、外部参与者)
actor "Name" as id - — 带方括号的组件框
component "Name" as id - — 普通矩形(用于分组/分层)
rectangle "Name" as id - — 圆柱形状(数据库)
database "Name" as id - — 队列符号
queue "Name" as id - — 云形状(外部服务)
cloud "Name" as id - — 服务器/节点框
node "Name" as id - — 框架分组
frame "Name" as id - — 包分组
package "Name" { }
箭头类型:
- — 实心箭头
A --> B - — 细箭头
A -> B - — 虚线箭头
A ..> B - — 带标签的箭头
A --> B : label - — 双向箭头
A <--> B
颜色:
- ,
#LightBlue,#LightGreen,#LightYellow,#Pink#Violet - (蓝色),
#AED6F1(绿色),#A9DFBF(橙色),#FAD7A0(红色)#F1948A - (紫色),
#D7BDE2(黄色),#F9E79F(灰色)#D3D3D3
Sequence Diagram
时序图
plantuml
@startuml
!theme plain
title Login Flow
participant "Client" as C
participant "API Gateway" as G
participant "Auth Service" as A
database "User DB" as D
C -> G : POST /login
G -> A : validateCredentials(user, pass)
A -> D : SELECT * FROM users WHERE email = ?
D --> A : user record
A --> G : 200 OK + JWT token
G --> C : { token: "..." }
@endumlArrow types:
- — synchronous call
A -> B - — return / dashed
A --> B - — async message
A ->> B - — colored arrow
A -[#red]-> B - /
activate A— show activation boxdeactivate A
plantuml
@startuml
!theme plain
title Login Flow
participant "Client" as C
participant "API Gateway" as G
participant "Auth Service" as A
database "User DB" as D
C -> G : POST /login
G -> A : validateCredentials(user, pass)
A -> D : SELECT * FROM users WHERE email = ?
D --> A : user record
A --> G : 200 OK + JWT token
G --> C : { token: "..." }
@enduml箭头类型:
- — 同步调用
A -> B - — 返回/虚线箭头
A --> B - — 异步消息
A ->> B - — 带颜色的箭头
A -[#red]-> B - /
activate A— 显示激活框deactivate A
Class Diagram
类图
plantuml
@startuml
!theme plain
class User {
+int id
+String name
+String email
+login() : bool
+logout()
}
class Order {
+int id
+Date createdAt
+float total
+place()
+cancel()
}
class Product {
+int id
+String name
+float price
}
User "1" --> "*" Order : places
Order "*" --> "*" Product : contains
@endumlRelationships:
- — association
A --> B - — inheritance
A --|> B - — implements interface
A ..|> B - — composition
A *-- B - — aggregation
A o-- B - — with multiplicities
A "1" --> "*" B : label
plantuml
@startuml
!theme plain
class User {
+int id
+String name
+String email
+login() : bool
+logout()
}
class Order {
+int id
+Date createdAt
+float total
+place()
+cancel()
}
class Product {
+int id
+String name
+float price
}
User "1" --> "*" Order : places
Order "*" --> "*" Product : contains
@enduml关系类型:
- — 关联关系
A --> B - — 继承关系
A --|> B - — 接口实现
A ..|> B - — 组合关系
A *-- B - — 聚合关系
A o-- B - — 带多重性的关系
A "1" --> "*" B : label
ER Diagram
ER图
plantuml
@startuml
!theme plain
entity "USER" as user {
* id : int <<PK>>
--
name : varchar
email : varchar
created_at : datetime
}
entity "ORDER" as ord {
* id : int <<PK>>
--
* user_id : int <<FK>>
total : decimal
status : varchar
}
entity "PRODUCT" as prod {
* id : int <<PK>>
--
name : varchar
price : decimal
}
user ||--o{ ord : places
ord }o--|{ prod : contains
@endumlplantuml
@startuml
!theme plain
entity "USER" as user {
* id : int <<PK>>
--
name : varchar
email : varchar
created_at : datetime
}
entity "ORDER" as ord {
* id : int <<PK>>
--
* user_id : int <<FK>>
total : decimal
status : varchar
}
entity "PRODUCT" as prod {
* id : int <<PK>>
--
name : varchar
price : decimal
}
user ||--o{ ord : places
ord }o--|{ prod : contains
@endumlActivity / Flowchart
活动图/流程图
plantuml
@startuml
!theme plain
start
:Receive Order;
if (Payment valid?) then (yes)
:Process Payment;
:Send Confirmation Email;
:Update Inventory;
:Ship Order;
:Mark as Delivered;
else (no)
:Send Payment Failed Email;
:Cancel Order;
endif
stop
@endumlplantuml
@startuml
!theme plain
start
:Receive Order;
if (Payment valid?) then (yes)
:Process Payment;
:Send Confirmation Email;
:Update Inventory;
:Ship Order;
:Mark as Delivered;
else (no)
:Send Payment Failed Email;
:Cancel Order;
endif
stop
@endumlState Diagram
状态图
plantuml
@startuml
!theme plain
[*] --> Pending
Pending --> Processing : payment_received
Processing --> Shipped : packed
Shipped --> Delivered : confirmed
Processing --> Cancelled : cancel
Pending --> Cancelled : cancel
Delivered --> [*]
Cancelled --> [*]
@endumlplantuml
@startuml
!theme plain
[*] --> Pending
Pending --> Processing : payment_received
Processing --> Shipped : packed
Shipped --> Delivered : confirmed
Processing --> Cancelled : cancel
Pending --> Cancelled : cancel
Delivered --> [*]
Cancelled --> [*]
@endumlExport Commands
导出命令
bash
undefinedbash
undefinedPNG via Kroki API (recommended)
通过Kroki API导出PNG(推荐)
curl -s -X POST https://kroki.io/plantuml/png
-H "Content-Type: text/plain"
--data-binary "@diagram.puml"
-o diagram.png
-H "Content-Type: text/plain"
--data-binary "@diagram.puml"
-o diagram.png
curl -s -X POST https://kroki.io/plantuml/png
-H "Content-Type: text/plain"
--data-binary "@diagram.puml"
-o diagram.png
-H "Content-Type: text/plain"
--data-binary "@diagram.puml"
-o diagram.png
SVG via Kroki API
通过Kroki API导出SVG
curl -s -X POST https://kroki.io/plantuml/svg
-H "Content-Type: text/plain"
--data-binary "@diagram.puml"
-o diagram.svg
-H "Content-Type: text/plain"
--data-binary "@diagram.puml"
-o diagram.svg
curl -s -X POST https://kroki.io/plantuml/svg
-H "Content-Type: text/plain"
--data-binary "@diagram.puml"
-o diagram.svg
-H "Content-Type: text/plain"
--data-binary "@diagram.puml"
-o diagram.svg
Via local Kroki Docker (offline)
通过本地Docker运行的Kroki导出(离线)
curl -s -X POST http://localhost:8000/plantuml/png
-H "Content-Type: text/plain"
--data-binary "@diagram.puml"
-o diagram.png
-H "Content-Type: text/plain"
--data-binary "@diagram.puml"
-o diagram.png
curl -s -X POST http://localhost:8000/plantuml/png
-H "Content-Type: text/plain"
--data-binary "@diagram.puml"
-o diagram.png
-H "Content-Type: text/plain"
--data-binary "@diagram.puml"
-o diagram.png
Via local PlantUML jar (if installed)
通过本地PlantUML jar包导出(已安装时)
java -jar plantuml.jar diagram.puml
java -jar plantuml.jar diagram.puml
Output: diagram.png in same directory
输出:同目录下的diagram.png
---
---Themes
主题
plantuml
!theme plain ← clean, minimal (recommended)
!theme cerulean ← blue-tinted
!theme blueprint ← dark blue background
!theme aws-orange ← AWS style
!theme vibrant ← vivid colorsOr use for custom styling:
skinparamplantuml
skinparam backgroundColor #FAFAFA
skinparam componentBorderColor #555555
skinparam ArrowColor #333333
skinparam FontName Arialplantuml
!theme plain ← 简洁极简(推荐)
!theme cerulean ← 蓝色调
!theme blueprint ← 深蓝色背景
!theme aws-orange ← AWS风格
!theme vibrant ← 鲜艳色彩或使用进行自定义样式:
skinparamplantuml
skinparam backgroundColor #FAFAFA
skinparam componentBorderColor #555555
skinparam ArrowColor #333333
skinparam FontName ArialCommon Mistakes
常见错误
| Mistake | Fix |
|---|---|
| Check network; try |
| Kroki returns 400 Bad Request | Validate PlantUML syntax at https://www.plantuml.com/plantuml/uml/ |
| Arrow direction unexpected | Use |
| Diagram too large/crowded | Split into multiple diagrams or use |
Missing | Always wrap diagram in these markers |
| Special chars in labels | Wrap in quotes: |
| C4 includes not found via Kroki | Use Kroki's |
| Component overlap | Use |
| Sequence participants out of order | Declare |
| 错误 | 修复方法 |
|---|---|
| 检查网络连接;使用 |
| Kroki返回400 Bad Request错误 | 在https://www.plantuml.com/plantuml/uml/验证PlantUML语法 |
| 箭头方向不符合预期 | 使用 |
| 图表过大/过于拥挤 | 拆分为多个图表,或使用 |
缺少 | 始终用这些标记包裹图表内容 |
| 标签中包含特殊字符 | 用引号包裹: |
| Kroki无法找到C4引用 | 对于C4图表,使用Kroki的 |
| 组件重叠 | 使用 |
| 时序图参与者顺序混乱 | 在顶部显式声明 |