# Plantuml

> 使用 PlantUML 创建各种 UML 图表，自动配置中文字体支持。适用于创建流程图、时序图、类图、活动图、用例图、状态图、组件图等。当用户需要绘制 UML 图、流程图、架构图时使用此 skill。

- Skill: `otamot93/plantuml` (Agent Skill)
- Install (CLI): `npx skillmds@latest add otamot93/plantuml`
- Raw SKILL.md: https://api.skillmd.com/api/skills/otamot93/plantuml/raw
- Safety review: pending (external: skill-scanner PASS, skillspector PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: otamot93 (https://skillmd.com/u/otamot93)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/otamot93/plantuml

---


# PlantUML 中文绘图 Skill

当用户请求创建 PlantUML 图表时，使用此指南确保中文正确显示并生成高质量的图表。

## 基础模板

所有 PlantUML 图表必须以以下配置开头，确保中文字体正确渲染：

```plantuml
@startuml
!theme plain
skinparam defaultFontName "SimHei"
skinparam backgroundColor #FEFEFE
```

## 图表类型及配置

### 1. 活动图（流程图）

适用于：业务流程、算法流程、工作流程

```plantuml
@startuml
!theme plain
skinparam defaultFontName "SimHei"
skinparam backgroundColor #FEFEFE
skinparam ActivityBackgroundColor #E8F4FD
skinparam ActivityBorderColor #2196F3
skinparam ActivityDiamondBackgroundColor #FFF3E0
skinparam ActivityDiamondBorderColor #FF9800

start
:步骤一;
if (条件判断?) then (是)
  :执行操作A;
else (否)
  :执行操作B;
endif
stop
@enduml
```

### 2. 时序图

适用于：接口调用、系统交互、消息传递

```plantuml
@startuml
!theme plain
skinparam defaultFontName "SimHei"
skinparam backgroundColor #FEFEFE
skinparam SequenceParticipantBackgroundColor #E3F2FD
skinparam SequenceParticipantBorderColor #1976D2
skinparam SequenceArrowColor #1976D2
skinparam SequenceLifeLineBorderColor #90CAF9

participant "客户端" as Client
participant "服务器" as Server
participant "数据库" as DB

Client -> Server: 发送请求
Server -> DB: 查询数据
DB --> Server: 返回结果
Server --> Client: 响应数据
@enduml
```

### 3. 类图

适用于：类结构、对象关系、数据模型

```plantuml
@startuml
!theme plain
skinparam defaultFontName "SimHei"
skinparam backgroundColor #FEFEFE
skinparam ClassBackgroundColor #E8F5E9
skinparam ClassBorderColor #4CAF50
skinparam ClassArrowColor #388E3C

class "用户" as User {
  +姓名: String
  +邮箱: String
  +登录(): boolean
}

class "订单" as Order {
  +订单号: String
  +金额: decimal
  +创建订单(): void
}

User "1" --> "*" Order: 下单
@enduml
```

### 4. 用例图

适用于：需求分析、功能规划

```plantuml
@startuml
!theme plain
skinparam defaultFontName "SimHei"
skinparam backgroundColor #FEFEFE
skinparam ActorBackgroundColor #FFF3E0
skinparam ActorBorderColor #FF9800
skinparam UsecaseBackgroundColor #E3F2FD
skinparam UsecaseBorderColor #1976D2

actor "用户" as user
actor "管理员" as admin

rectangle "系统" {
  usecase "登录" as UC1
  usecase "查看数据" as UC2
  usecase "管理用户" as UC3
}

user --> UC1
user --> UC2
admin --> UC1
admin --> UC3
@enduml
```

### 5. 状态图

适用于：状态机、生命周期、状态转换

```plantuml
@startuml
!theme plain
skinparam defaultFontName "SimHei"
skinparam backgroundColor #FEFEFE
skinparam StateBackgroundColor #E8EAF6
skinparam StateBorderColor #3F51B5
skinparam StateArrowColor #303F9F

[*] --> 待处理
待处理 --> 处理中 : 开始处理
处理中 --> 已完成 : 处理成功
处理中 --> 已失败 : 处理失败
已完成 --> [*]
已失败 --> 待处理 : 重试
@enduml
```

### 6. 组件图

适用于：系统架构、模块划分

```plantuml
@startuml
!theme plain
skinparam defaultFontName "SimHei"
skinparam backgroundColor #FEFEFE
skinparam ComponentBackgroundColor #FCE4EC
skinparam ComponentBorderColor #E91E63
skinparam InterfaceBackgroundColor #F3E5F5
skinparam InterfaceBorderColor #9C27B0

package "前端" {
  [Web应用] as web
  [移动端] as mobile
}

package "后端" {
  [API网关] as gateway
  [业务服务] as service
  [数据服务] as data
}

database "数据库" as db

web --> gateway
mobile --> gateway
gateway --> service
service --> data
data --> db
@enduml
```

### 7. 思维导图

适用于：知识整理、头脑风暴

```plantuml
@startmindmap
!theme plain
skinparam defaultFontName "SimHei"

* 项目管理
** 计划阶段
*** 需求分析
*** 可行性研究
** 执行阶段
*** 开发
*** 测试
** 收尾阶段
*** 部署上线
*** 项目总结
@endmindmap
```

### 8. 甘特图

适用于：项目计划、进度管理

```plantuml
@startgantt
!theme plain
skinparam defaultFontName "SimHei"

Project starts 2024-01-01
[需求分析] lasts 10 days
[系统设计] lasts 15 days
[系统设计] starts at [需求分析]'s end
[开发实现] lasts 30 days
[开发实现] starts at [系统设计]'s end
[测试验收] lasts 10 days
[测试验收] starts at [开发实现]'s end
@endgantt
```

## 高级技巧

### 分区与分组 (partition)

用于将流程分组，提高可读性：

```plantuml
partition "模块A" {
  :操作1;
  :操作2;
}

partition "模块B" #E8FFE8 {
  :操作3;
  :操作4;
}
```

### 注释 (note)

添加说明性注释：

```plantuml
:执行操作;
note right
  这里是注释说明
  可以多行
end note

note left #FFFFCC
  带颜色的注释
end note
```

### 图例 (legend)

添加图例说明：

```plantuml
legend right
  |= 颜色 |= 说明 |
  | <#90EE90> | 新增功能 |
  | <#E8F4FD> | 现有功能 |
endlegend
```

### 自定义颜色

活动图节点着色：

```plantuml
#90EE90:==绿色高亮节点==;
#FFB6C1:粉色节点;
```

### 循环与条件

```plantuml
while (条件) is (满足)
  :执行操作;
endwhile (不满足)

if (判断条件?) then (是)
  :分支A;
elseif (其他条件?) then (是)
  :分支B;
else (否)
  :分支C;
endif
```

## 输出要求

1. **文件格式**: 将 PlantUML 代码保存为 `.puml` 或 `.plantuml` 文件
2. **中文支持**: 始终在开头包含 `skinparam defaultFontName "SimHei"`
3. **配色方案**: 使用协调的颜色方案，保持视觉一致性
4. **清晰布局**: 合理使用分区、注释、图例提高图表可读性

## 渲染方式

用户可以通过以下方式渲染 PlantUML 图表：

1. **VS Code 插件**: PlantUML 扩展
2. **在线工具**: https://www.plantuml.com/plantuml/
3. **本地安装**: 安装 PlantUML JAR 包配合 Graphviz
4. **命令行**: `java -jar plantuml.jar diagram.puml`

## 注意事项

- 确保所有中文文本使用 UTF-8 编码
- 复杂图表建议分模块绘制
- 使用有意义的别名（as）提高代码可读性
- 颜色使用十六进制格式（如 #E8F4FD）或标准颜色名称

