← 返回
未分类 中文

PlantUML

Generate UML diagrams (use case, class, sequence, activity, state, component, deployment, object, timing, and more) using PlantUML. Use when the user asks to...
使用 PlantUML 生成 UML、C4、架构、时序、ER、思维导图、WBS和甘特图。
guoxh guoxh 来源
未分类 clawhub v1.1.1 3 版本 100000 Key: 无需
★ 0
Stars
📥 317
下载
💾 0
安装
3
版本
#latest

概述

PlantUML Diagram Generation

One-Liner

java -jar ~/tools/plantuml.jar -tpng -charset UTF-8 file.puml

Prerequisites

  • PlantUML jar: ~/tools/plantuml.jar
  • Graphviz: Required for most diagram types. Verify with dot -V.
  • Java: Required runtime. Verify with java -version.

If Graphviz is missing, sequence diagrams still render (they use the built-in lambda renderer), but other diagram types will fail.

Security & Trust Notes

This skill is a local diagram-generation helper. It does not require credentials, account access, production data access, or background automation. It only documents how to write PlantUML source and render it with local Java/Graphviz tooling.

Rendering PlantUML executes the local PlantUML Java jar and, for most non-sequence diagrams, local Graphviz. Treat .puml files as source code: review diagrams before rendering when they come from untrusted input, and render inside a controlled workspace.

Most examples use PlantUML's local stdlib. A few optional icon examples in references/stdlib-guide.md show external !include URLs for AWS/Azure/devicons; those may fetch resources from GitHub at render time. For sensitive/offline environments, mirror icon libraries locally or avoid URL-based includes.

Quick Start

  1. Write .puml source file (kebab-case filename).
  2. Generate image:

```bash

java -jar ~/tools/plantuml.jar -tpng -charset UTF-8 .puml

```

  1. PlantUML uses the word after @startuml as the output filename (e.g., @startuml MyDiagramMyDiagram.png).
  2. Attach the resulting PNG/SVG in your reply with a MEDIA: directive line — OpenClaw delivers it.

Diagram Types & Syntax

Use Case Diagram

@startuml DiagramName
left to right direction
skinparam packageStyle rectangle
skinparam actorStyle awesome

actor User
actor Admin

rectangle "System Name" {
  usecase "Login" as UC1
  usecase "Do Something" as UC2
}

User --> UC1
User --> UC2
UC2 .> UC1 : <<include>>
@enduml

Class Diagram

@startuml DiagramName
skinparam classAttributeIconSize 0

abstract class Shape {
  + draw(): void
}
class Circle {
  - radius: double
}
Shape <|-- Circle

Circle "1" --> "0..*" Point : contains >
@enduml

Sequence Diagram

@startuml DiagramName
actor User
participant ":System" as SYS

User -> SYS : request()
activate SYS
SYS --> User : response()
deactivate SYS

alt success
  SYS --> User : ok
else failure
  SYS --> User : error
end
@enduml

Activity Diagram

@startuml DiagramName
start
:Step 1;
if (Condition?) then (yes)
  :Step 2a;
else (no)
  :Step 2b;
endif
stop
@enduml

State Diagram

@startuml DiagramName
[*] --> Idle
Idle --> Processing : start
Processing --> Done : complete
Processing --> Error : fail
Done --> [*]
Error --> [*]
@enduml

Component Diagram

@startuml DiagramName
component [Web App] as WA
component [API Server] as API
interface "REST API" as REST

WA -right- REST
REST -right- API
@enduml

Deployment Diagram

@startuml DiagramName
node "Web Server" as WS {
  component [Web App] as WA
}
node "DB Server" as DB {
  database [Database] as D
}
WA ..> D : JDBC
@enduml

C4 Architecture (System Context)

@startuml C4Context
!include <C4/C4_Context>

Person(user, "End User", "Uses the system through web/mobile.")
System(sys, "Order System", "Handles ordering, billing, and fulfilment.")
System_Ext(payment, "Payment Gateway", "Third-party PCI processor.")

Rel(user, sys, "Places orders")
Rel(sys, payment, "Processes payments", "HTTPS/JSON")
@enduml

For Container, Component, Dynamic, and Deployment views, see references/stdlib-guide.md.

Themes & Shared Style

PlantUML supports built-in themes (set near the top, after @startuml):

!theme cerulean-outline   ' clean blue/white
!theme materia            ' material design
!theme plain              ' minimal black/white
!theme spacelab           ' light, professional

For consistent styling across diagrams, prefer the shared include:

@startuml MyDiagram
!include /home/guoxh/.openclaw/skills/plantuml/references/default-style.iuml
...
@enduml

The include sets sensible defaults: dpi 150, no shadows, professional fonts, consistent colors. Override per-diagram as needed.

Key Conventions

  • File naming: Use kebab-case for .puml filenames (e.g., order-system-class.puml).
  • Diagram label: Always name @startuml — this becomes the output filename.
  • Charset: Always pass -charset UTF-8 for CJK content.
  • Format: Default to -tpng. Use -tsvg for vector output (zoomable, smaller for line art).
  • Batch: Pass multiple .puml files in one command for efficiency.
  • Output directory: Default is same directory as source. Use -o to specify a different output directory.
  • Style consistency: !include the shared default-style.iuml for professional output.

Rendering & Delivery Workflow

  1. Write the .puml file to the workspace.
  2. Render:

```bash

java -jar ~/tools/plantuml.jar -tpng -charset UTF-8 .puml

```

Or use the wrapper:

```bash

python3 ~/.openclaw/skills/plantuml/scripts/render.py .puml

```

  1. Verify the output file exists and is non-zero size:

```bash

ls -la .png

```

  1. Attach in your reply by adding a line like:

```

MEDIA:/absolute/path/to/DiagramName.png

```

The directive must start the line as plain text (no markdown wrappers, not inside code fences). OpenClaw delivers the file via the active channel.

Smoke Test

Verify the toolchain end-to-end after install or update:

cd ~/.openclaw/skills/plantuml/examples
java -jar ~/tools/plantuml.jar -tpng -charset UTF-8 sequence-sample.puml
ls -la SequenceSample.png   # should exist, non-zero

Troubleshooting

ProblemSolution
-------------------
Cannot run program "dot"Graphviz not installed. Sequence diagrams still work; others need apt install graphviz.
Empty output file (0 bytes)Likely a syntax error. Run with -v flag to see detailed error output.
Smetana UnsupportedOperationExceptionAvoid -Playout=smetana; use Graphviz instead.
CJK garbled textEnsure -charset UTF-8 flag is set and source file is UTF-8.
Image too large/smallAdd -DPLANTUML_LIMIT_SIZE=16384 before the jar, or set skinparam dpi in source.
C4 stdlib not foundRequires PlantUML ≥ 1.2020.x. Verify with java -jar ~/tools/plantuml.jar -version.
!include file not foundUse absolute path or path relative to the .puml file.

Advanced: Output Size Control

# Increase max image size (default 4096)
java -DPLANTUML_LIMIT_SIZE=16384 -jar ~/tools/plantuml.jar -tpng -charset UTF-8 file.puml

Within the diagram:

skinparam dpi 150

版本历史

共 3 个版本

  • v1.1.1 当前
    2026-06-14 23:47
  • v1.1.0
    2026-06-14 19:54
  • v1.0.1
    2026-05-13 06:53 安全 安全

安全检测

腾讯云安全 (Keen)

队列中

腾讯云安全 (Sanbu)

队列中

🔗 相关推荐

Baidu Speech Synthesis

guoxh
百度智能云语音合成(TTS),支持多角色对话音频生成,SSML/段合并双模式,语速/音调可调。
★ 0 📥 687

Gemini Citation

guoxh
利用Gemini API的“科学引用”(Google Search grounding)功能进行基于证据的精确APA引用研究,适用于X场景。
★ 1 📥 570

Zotero Enhanced

guoxh
Zotero 文献库管理,支持 PDF 元数据自动获取(Crossref/arXiv)、文献检索、文件读取与笔记管理,兼容云存储与 WebDAV。
★ 1 📥 662