Taco Steemers

A personal blog.

PlantUML notes

Running PlantUML

Is PlantUML installed as a package? Then we can run it like this: plantuml input.puml .

If we have the jar file we can run the jar file like normal: java -jar plantuml.jar input.puml .

Any file extension can be used. Using .txt probably makes it easier for people to open the text files. On the other hand, when we use .puml it is immediately clear what the file contains. We can call PlantUML with any number of file and directory paths as argument.

PlantUML.com has a good command-line options page . It also explains how to get the source from an output PNG. It is embedded there as text. That can also be used as a way to only regenerate a file if it is necessary.

Integrated with Pelican

We can integrate PlantUML with Pelican using the plugin called plantuml. If you already have the entire plugin repository locally all you need to do is add plantuml to your plugin list. We can embed the PlantUML diagram specification inside our content and it will be processed and replaced with the image file.

This is the opening text:

&colon&colonuml&colon&colon format="png" alt="describe the diagram here"

Then we add the UML specification here, and close with:

&colon&colonend-uml&colon&colon

Horizontal instead of vertical

To get a horizontal diagram we can add left to right direction at the top, like this:

@startuml
left to right direction

Lines and arrows going both ways

We can't specify lines and arrows twice in separate directions. We must specify them both in one go. Like this: A <--> B

I find it to be the least error prone to do all of them at the end, rather than some in between.

Mixing UML concepts in one graph

allowmixing can be added to allow mixing UML concepts that are not supposed to be mixed. In the diagram below I am mixing components with classes.

System diagram example

Here is an example system diagram specification:

@startuml
left to right direction
allowmixing
'This line is only a comment

title
  Example system / component diagram for discussing a simple fail-over design
end title

cloud "Internal" as IN

node "Load Balancer" as ILB

package "App Nodes" as NODES {
  node "Node 1" as N1
  node "Node 2" as N2
  node "..." as NE
  node "Node n" as NN
}

database "MySql" {
  frame "Main database" {
    class "activity" as AT <<T, white>> {
      node_identifier VARCHAR
      timestamp DATETIME
    }
  }
}

node "Load Balancer" as ELB

cloud "External" as EX

IN <--> ILB
ILB <--> NODES
N1 <--> AT
N2 <--> AT
NN <--> AT
NODES <--> ELB
ELB <--> EX

@enduml

It leads to the following diagram:

uml diagram