Complete systematic analysis and reference guide for AI assistants working with PlantUML
- Universal Syntax Fundamentals
- Diagram Types Reference
- Advanced Features
- LLM Best Practices
- Common Patterns & Templates
- Troubleshooting Guide
@startuml [optional_diagram_name]
' Your diagram content here
@enduml- Comments:
'(single line) or/' ... '/(multi-line block) - String handling: Use
"quotes"for names with spaces/special chars - Aliases:
askeyword creates short references - Colors:
#hexcode,colorname, or gradients#color1|color2 - Styling: Inline
#coloror globalskinparam
' Variable naming (preprocessing)
!$variable = "value"
' Color application
element #color
element #back:color;line:color;text:color
' Multiline text
"First line\nSecond line"
' Aliases for complex names
component "Complex System Name" as CSNCore Syntax:
@startuml
participant Alice
actor Bob
database "Database" as DB
Alice -> Bob: Request
Bob --> Alice: Response
Alice -> DB: Store data
note right of Alice: This is a note
@endumlKey Features:
- Participants:
participant,actor,boundary,control,entity,database,collections,queue - Arrows:
->(solid),-->(dashed),<-(reverse) - Arrow styles:
->x(lost),->>(thin),->o(circle),<->(bidirectional) - Activation:
activate/deactivateor++/-- - Grouping:
alt/else/end,opt,loop,par,group,critical - Auto-numbering:
autonumber [start] [increment] ["format"] - Notes:
note left/right/over : text
Advanced Patterns:
' Message alignment
skinparam sequenceMessageAlign right
' Participant ordering
participant Last order 30
participant First order 10
' Multiline participants
participant Participant [
=Title
----
""SubTitle""
]
' Colored arrows
Alice -[#red]> Bob: colored messageCore Syntax:
@startuml
class User {
+name: string
-password: string
#email: string
~id: int
--
+login()
+logout()
-validatePassword()
}
class Admin extends User
User ||--o{ Order : places
@endumlKey Relationships:
| Symbol | Meaning | Usage |
|---|---|---|
<|-- |
Inheritance | Child <|-- Parent |
<|.. |
Implementation | Class <|.. Interface |
*-- |
Composition | Whole *-- Part |
o-- |
Aggregation | Container o-- Item |
--> |
Dependency | Client --> Service |
..> |
Weak dependency | A ..> B |
Visibility Modifiers:
+Public-Private#Protected~Package
Advanced Features:
' Association classes
class Student
class Course
(Student, Course) .. Enrollment
' Package organization
package "com.example" {
class MyClass
}
' Stereotypes and spots
class System << (S,#FF7700) Singleton >>Core Syntax:
@startuml
start
:Initialize system;
if (System ready?) then (yes)
:Process request;
if (Valid input?) then (yes)
:Execute action;
else (no)
:Show error;
stop
endif
else (no)
:Wait for system;
endif
:Send response;
end
@endumlControl Structures:
- Conditionals:
if/then/else/endif - Switches:
switch/case/endswitch - Loops:
repeat/repeatwhile,while/endwhile - Parallel:
fork/fork again/end fork - Partitions:
partition "Name" { ... } - Swimlanes:
|Actor| :action;
Advanced Patterns:
' Colored activities
#HotPink:Critical process;
' SDL shapes (Specification Description Language)
:Input<
:Output>
:Procedure|
:Save/
:Load\
' Kill/Detach
:Process data;
kill
' Connectors
start
:Activity;
(A)
detach
(A)
:Other activity;@startuml
left to right direction
:User: --> (Login)
:Admin: --> (Manage Users)
package System {
(Login) .> (Validate Credentials) : include
(Manage Users) .> (Login) : include
}
:User: --> (Browse Products)
@endumlKey Elements:
- Actors:
:Actor Name: - Use Cases:
(Use Case) - Relationships:
-->(association),.>(include/extend) - Packages:
package Name { ... }
@startuml
package "Web Layer" {
component [Web Controller] as WC
component [Web Service] as WS
}
package "Business Layer" {
component [Business Logic] as BL
component [Data Access] as DA
}
database "Database" as DB
WC --> WS
WS --> BL
BL --> DA
DA --> DB
@enduml@startuml
[*] --> Idle
Idle --> Processing : start
Processing --> Idle : complete
Processing --> Error : failure
Error --> Idle : reset
Idle --> [*] : shutdown
state Processing {
[*] --> Loading
Loading --> Executing
Executing --> Validating
Validating --> [*]
}
@enduml@startgantt
Project starts 2024-01-01
[Design Phase] requires 2 weeks
[Implementation] requires 3 weeks
[Testing] requires 1 week
[Implementation] starts at [Design Phase]'s end
[Testing] starts at [Implementation]'s end
[Design Phase] is colored in lightblue
[Implementation] is colored in lightgreen
[Testing] is colored in orange
@endgantt@startmindmap
* Central Topic
** Right Branch 1
*** Sub-item 1
*** Sub-item 2
** Right Branch 2
left side
** Left Branch 1
*** Left Sub-item
** Left Branch 2
@endmindmap@startuml
nwdiag {
network internet {
web01 [shape = cloud];
}
network internal {
web01;
db01 [shape = database];
app01;
}
}
@endumlPlantUML includes a powerful preprocessing system for dynamic content generation:
@startuml
!$company = "Acme Corp"
!$version = 1.2
!function $header($title)
!return $title + " v" + $version + " - " + $company
!endfunction
title $header("System Architecture")
' Rest of diagram...
@enduml@startuml
!$environment = "production"
!if $environment == "production"
skinparam backgroundColor lightgreen
!else
skinparam backgroundColor lightcoral
!endif
' Conditional elements
!if $environment == "production"
database "Production DB" as ProdDB
!else
database "Test DB" as TestDB
!endif
@enduml@startuml
!procedure $createServers($count)
!$i = 1
!while $i <= $count
component "Server $i" as S$i
!$i = $i + 1
!endwhile
!endprocedure
$createServers(3)
S1 --> S2
S2 --> S3
@enduml@startuml
skinparam {
backgroundColor #E8F4FD
defaultFontSize 12
defaultFontName Arial
class {
BackgroundColor lightblue
BorderColor darkblue
ArrowColor black
}
sequence {
ParticipantBorderColor black
ParticipantBackgroundColor #EEEEEE
MessageAlign center
}
}
' Your diagram content...
@enduml@startuml
' Color syntax: #[background];line:color;line.style;text:color
class Important #red;line:black;line.bold;text:white
component Service #lightblue;line:blue;line.dashed
@enduml@startuml
<style>
classDiagram {
class {
BackgroundColor #E1F5FE
BorderColor #0277BD
FontSize 14
FontStyle bold
}
.important {
BackgroundColor #FFCDD2
BorderColor #D32F2F
}
}
</style>
class NormalClass
class ImportantClass <<important>>
@enduml@startjson
{
"name": "John Doe",
"age": 30,
"skills": ["Java", "Python", "PlantUML"],
"address": {
"city": "New York",
"country": "USA"
}
}
@endjson@startyaml
name: John Doe
age: 30
skills:
- Java
- Python
- PlantUML
address:
city: New York
country: USA
@endyaml@startuml
!include <aws/AWSCommon>
!include <aws/Compute/AmazonEC2/AmazonEC2>
!include <aws/Database/AmazonRDS/AmazonRDS>
!include <aws/Storage/AmazonS3/AmazonS3>
AmazonEC2(ec2, "Web Server", "")
AmazonRDS(rds, "Database", "")
AmazonS3(s3, "File Storage", "")
ec2 --> rds
ec2 --> s3
@endumlStart Simple, Add Complexity:
' Phase 1: Basic structure
@startuml
A -> B
@enduml
' Phase 2: Add details
@startuml
participant "System A" as A
participant "System B" as B
A -> B: Request
B --> A: Response
@enduml
' Phase 3: Add styling and notes
@startuml
participant "System A" as A #lightblue
participant "System B" as B #lightgreen
A -> B: Request
note right: Important interaction
B --> A: Response
@endumlSafe Naming:
' Good: Use aliases for complex names
component "Complex-System_Name (v2.1)" as CSN
database "User Database Server" as UDB
' Avoid: Special characters in direct references
' component Complex-System_Name (v2.1) // This could cause issuesQuote Management:
' Safe approach for special characters
participant "User with spaces" as User
actor "Admin (Super)" as Admin
note over User, Admin: "Quoted text with ""nested"" quotes"@startuml
' Control diagram direction
left to right direction
' Group related elements
together {
class A
class B
}
' Force layout with hidden connections
A -[hidden]-> C
B -[hidden]-> D
' Use packages for organization
package "Layer 1" {
class Service1
}
package "Layer 2" {
class Service2
}
@enduml@startuml
' Set appropriate scaling
scale 1.2
' Control text wrapping
skinparam maxMessageSize 100
skinparam wrapWidth 200
' Use meaningful short names
participant "Long Service Name" as LSN
@enduml@startuml
!define SYSTEM(name, desc) rectangle name as "==name\n\n desc"
!define EXTERNAL(name, desc) rectangle name as "==name\n\n desc" #lightgray
title System Architecture Overview
SYSTEM(WebApp, "Main Web Application")
SYSTEM(API, "REST API Gateway")
SYSTEM(Auth, "Authentication Service")
EXTERNAL(Database, "PostgreSQL Database")
EXTERNAL(Cache, "Redis Cache")
WebApp --> API: HTTP Requests
API --> Auth: Validate Token
API --> Database: Query Data
API --> Cache: Cache Results
@enduml@startuml
!procedure $decision($condition, $yes, $no)
if ($condition) then (yes)
:$yes;
else (no)
:$no;
endif
!endprocedure
start
:Receive Request;
$decision("Valid Input?", "Process Request", "Return Error")
:Send Response;
stop
@enduml@startuml
abstract class Animal {
#name: String
#age: int
--
+getName(): String
{abstract} +makeSound(): String
}
class Dog extends Animal {
-breed: String
--
+makeSound(): String
}
class Cat extends Animal {
-indoor: boolean
--
+makeSound(): String
}
interface Pet {
+play(): void
+feed(): void
}
Dog ..|> Pet
Cat ..|> Pet
@enduml@startuml
!include <aws/AWSCommon>
!include <kubernetes/k8s-sprites-unlabeled-25pct>
package "Kubernetes Cluster" {
rectangle "<$k8s-pod>\nWeb Pods" as WebPods
rectangle "<$k8s-svc>\nLoad Balancer" as LB
}
package "AWS Services" {
rectangle "<$aws-rds>\nDatabase" as DB
rectangle "<$aws-s3>\nFile Storage" as Storage
}
LB --> WebPods
WebPods --> DB
WebPods --> Storage
@endumlIssue: Parsing Errors
' Problem: Unclosed quotes or brackets
participant "User Name // Missing closing quote
' Solution: Properly close all quotes
participant "User Name" as UserIssue: Invalid Characters
' Problem: Special characters in names
class User-Profile // Hyphen can cause issues
' Solution: Use quotes or aliases
class "User-Profile" as UPIssue: Poor Automatic Layout
' Solution: Use layout hints
@startuml
left to right direction
skinparam nodesep 50
skinparam ranksep 50
@endumlIssue: Text Overflow
' Solution: Control text wrapping
@startuml
skinparam maxMessageSize 50
skinparam wrapWidth 150
@endumlUse Logging:
@startuml
!log "Starting diagram generation"
!$counter = 0
!while $counter < 3
!log "Creating component " + $counter
component "Service $counter" as S$counter
!$counter = $counter + 1
!endwhile
!log "Completed diagram with " + $counter + " components"
@endumlMemory Debugging:
@startuml
!$debug = true
!if $debug
!dump_memory Debug checkpoint
!endif
' Your diagram content
@endumlFor Large Diagrams:
@startuml
' Split large diagrams
page 2x2
' Use appropriate scale
scale 0.8
' Minimize complex styling
skinparam shadowing false
skinparam linetype ortho
@enduml| Diagram Type | Solid | Dashed | Notes |
|---|---|---|---|
| Sequence | -> |
--> |
Use <- for reverse |
| Class | -- |
.. |
Add heads: `< |
| Activity | -> |
N/A | Use within flow |
| Use Case | --> |
..> |
For associations |
| Method | Example | Usage |
|---|---|---|
| Hex | #FF0000 |
Precise colors |
| Named | red, lightblue |
Common colors |
| Gradient | #red|blue |
Background gradients |
| Inline | #back:color;line:color |
Complex styling |
| Type | Start | End | Purpose |
|---|---|---|---|
| UML | @startuml |
@enduml |
General UML diagrams |
| Gantt | @startgantt |
@endgantt |
Project schedules |
| MindMap | @startmindmap |
@endmindmap |
Mind mapping |
| JSON | @startjson |
@endjson |
Data display |
| YAML | @startyaml |
@endyaml |
Data display |
This comprehensive cheat sheet covers the essential patterns and advanced features needed for effective PlantUML usage by LLM systems. Always start with simple structures and progressively add complexity as needed.