تخطَّ إلى المحتوى

PlantUML Cheat Sheet

Overview

PlantUML is an open-source tool that generates UML diagrams from plain text descriptions. It supports sequence, class, activity, component, state, object, deployment, and timing diagrams, plus non-UML diagrams like mind maps, Gantt charts, and JSON/YAML visualization. PlantUML uses a simple, intuitive text syntax that makes diagrams easy to create and version control.

PlantUML requires Java to run and can be used via command line, integrated into IDEs (VS Code, IntelliJ, Eclipse), embedded in documentation tools (Confluence, GitLab), or accessed through the online server at plantuml.com. It outputs PNG, SVG, EPS, and ASCII art formats.

Installation

# Prerequisites: Java Runtime Environment
java -version

# Download PlantUML JAR
wget https://github.com/plantuml/plantuml/releases/latest/download/plantuml.jar

# Generate a diagram
java -jar plantuml.jar diagram.puml

# Generate SVG output
java -jar plantuml.jar -tsvg diagram.puml

# macOS via Homebrew
brew install plantuml

# Linux via package manager
sudo apt install plantuml

# Docker
docker run -v $(pwd):/data plantuml/plantuml diagram.puml

CLI Options

OptionDescription
-tpngOutput as PNG (default)
-tsvgOutput as SVG
-tepsOutput as EPS
-ttxtOutput as ASCII art
-tpdfOutput as PDF
-o <dir>Output directory
-dpi <num>Set DPI for raster output
-charset utf-8Set character encoding
-pipeRead from stdin, write to stdout
-config <file>Load configuration file
-checkonlyValidate syntax without generating
-nbthread autoUse multiple threads

Sequence Diagrams

@startuml
title Authentication Flow

actor User
participant "Web App" as App
participant "Auth Server" as Auth
database "User DB" as DB

User -> App : Login request
activate App

App -> Auth : POST /oauth/token
activate Auth

Auth -> DB : Validate credentials
DB --> Auth : User record

alt Valid credentials
    Auth --> App : Access token
else Invalid credentials
    Auth --> App : 401 Unauthorized
end

deactivate Auth
deactivate App

note right of Auth : Tokens expire after 1 hour

@enduml

Arrow Types

SyntaxDescription
->Solid line with arrow
-->Dotted line with arrow
->>Thin arrow
-->>Thin dotted arrow
->xLost message
<->Bidirectional

Class Diagrams

@startuml
abstract class Shape {
    # color: String
    + {abstract} area(): double
    + {abstract} perimeter(): double
}

class Circle {
    - radius: double
    + area(): double
}

class Rectangle {
    - width: double
    - height: double
    + area(): double
}

interface Drawable {
    + draw(canvas: Canvas): void
}

Shape <|-- Circle
Shape <|-- Rectangle
Drawable <|.. Circle
Drawable <|.. Rectangle

@enduml

Visibility Markers

MarkerVisibility
+Public
-Private
#Protected
~Package-private
{static}Static member
{abstract}Abstract member

Activity Diagrams

@startuml
start
:Receive order;

if (Payment valid?) then (yes)
    :Process payment;
    fork
        :Pack items;
    fork again
        :Send confirmation email;
    end fork
    :Ship order;
else (no)
    :Notify customer;
    stop
endif

:Deliver to customer;
stop
@enduml

Component Diagrams

@startuml
package "Frontend" {
    [React App] as react
    [State Manager] as state
}

package "Backend" {
    [API Gateway] as gateway
    [Auth Service] as auth
    [User Service] as users
}

database "PostgreSQL" as pg
database "Redis" as redis

react --> gateway : HTTPS
gateway --> auth
gateway --> users
users --> pg
auth --> redis
@enduml

State Diagrams

@startuml
[*] --> Draft

Draft --> Review : Submit
Review --> Approved : Approve
Review --> Draft : Request changes
Approved --> Published : Publish
Published --> Archived : Archive

state Review {
    [*] --> PeerReview
    PeerReview --> TechReview
    TechReview --> [*]
}
@enduml

Configuration and Theming

@startuml
skinparam backgroundColor #FEFEFE

skinparam class {
    BackgroundColor #E8F5E9
    BorderColor #2E7D32
    ArrowColor #1B5E20
    FontSize 14
}

skinparam sequence {
    ArrowColor #1565C0
    ParticipantBackgroundColor #E3F2FD
}
@enduml

Themes

@startuml
!theme cerulean
' Available: amiga, aws-orange, cerulean, cyborg,
' mars, materia, metal, minty, plain, sketchy-outline
@enduml

Advanced Usage

Mind Maps

@startmindmap
* Project
** Planning
*** Requirements
*** Timeline
** Development
*** Frontend
*** Backend
** Testing
*** Unit Tests
*** Integration
@endmindmap

JSON Visualization

@startjson
{
  "name": "API Config",
  "version": "2.0",
  "endpoints": [
    { "path": "/users", "method": "GET" },
    { "path": "/orders", "method": "POST" }
  ]
}
@endjson

Include Files and Preprocessor

@startuml
!include common-styles.puml
!define PRIMARY_COLOR #1a73e8

!procedure $service($name, $desc)
    rectangle "$name\n<size:10>$desc</size>" as $name
!endprocedure

$service("API", "REST Gateway")
$service("DB", "PostgreSQL")
API --> DB
@enduml

Troubleshooting

IssueSolution
Java not foundInstall JDK 8+ and ensure java is in PATH
Graphviz requiredInstall Graphviz: apt install graphviz
Diagram too largeAdd scale 0.7 or split into multiple diagrams
Encoding issuesUse -charset utf-8 flag
VS Code preview not workingInstall PlantUML extension; configure jar path
Slow renderingUse -nbthread auto for parallel processing
Font missing in outputInstall the font or use skinparam fontName
SVG text not selectableEnsure -tsvg is used