PlantUML  is probably the most popular  textual UML tool   with over 15  millions UML models rendered. Textual UML tools enable you to define your models with some kind of textual language / notation and let the tool render the corresponding UML model for you. They typicall support class, sequence and use case diagrams but some, like PlantUML, cover almost all diagrams.

We recently caught up with Arnaud Roques (the person behind the tool) to chat about the past, present and future of PlantUML. You can read the interview here. Still, since the tool development is advancing non-stop, I thought it deserved a closer look to some of its latest ones. PlantUML supports all

PlantUML supports all important UML diagrams (class, use case, activity, sequence, component, deployment and object diagrams, see the language reference guide for details on the syntax) but, to me, the strong point of this tool is the variety of scenarios in which can be used.

Core PlantUML features

As part of the “core” tool you can:

  • Generate .png files for your textual UML diagrams from the command line
  • Use it as a web service to generate images on the fly (the service generates a URL that you can use in to display the generated image in your web pages or inside a tweet)
  • Create UML models from your annotated java source code
  • Document your java classes with a textual UML design model of that part of the code and visualize the corresponding graphical model within the Eclipse IDE itself
  • Integrate and call this tool from your other tools
  • or you can even use it to draw UML diagrams in Word. There is a Visual Basic Macro that parses the word document and replaces the PlantUML text with the corresponding images (see below)

but even more interesting than these core features is the growing ecosystem of tools that extend PlantUML and let you do a whole bunch of amazing things with it. Let’s review some of them (and let me know if you know about others! ).

UML to Latex

Some brave colleagues (I´m looking at you, Robert) have managed to draw class diagrams in LaTeX using the TikZ package. The results are really nice but it’s a lot of work.

Fortunately, PlantUML has come to the rescue and now offers the option to automatically generate the LaTeX/TikZ files for you, thanks to this new feature (still in beta, report your bugs here) you can go from this textual description of a UML class diagram:

@startuml
class Subscriber {
  subscriberId
}
class AccumUsage {
  subscriberId
}
class IpSession {
  ipAddress
  specificData
  sapcOriginStateId
  apnId
}
Subscriber "1" --> "1..*" IpSession
Subscriber "1" --> "0..1" AccumUsage
@enduml

to this TikZ description and rendered image (see it online here)

uml to latex transformation

With this and this LaTeX package to simplify the writing of OCL expressions, life of researchers on UML/OCL topics is now easier than ever!

UML to SQL

The tool plantuml2mysql offers a script to generate SQL DDL commands from your PlantUML model.

Class diagram to SQL DDL generation (i.e. generating a script to create in your relational database the tables implementing your UML class diagram design) is the most typical (and for many people the only useful one) code-generation scenario. There are plenty of tools able to do this but this one benefits from the simplicity of PlantUML to provide a limited but easy-to-use database generation functionality.

You can see below an example (the symbol ‘#’ is an added annotation to indicate the UML attributes that should be regarded as primary keys).

@startuml
 
class dummy {
  Sample table.
  ==
  #id int(10) -- A comment
  field1 int(10)
  .. Comment line, ignored ..
  field2 varchar(128)
}
 
@enduml
will be converted to SQL:
 
CREATE TABLE IF NOT EXISTS `dummy` (
  id               INT(10) COMMENT 'A comment',
  field1           INT(10),
  field2           VARCHAR(128),
  PRIMARY KEY (id));

 

SQL to UML

And you can also go the other way round. You can use PlantUML to generate a UML class diagram depicting the structure of your database. All database management systems use an internal data dictionary, i.e. a set of tables in the database that store information about the database itself, including the list of tables, the columns in each table, the indexes,… Therefore, writing a SQL query on those tables will return the information you need to draw the database structure in UML. All you need to do is to tweak a little bit the return of the query so that what you actually return is compliant with what PlantUML expects.

Phil Factor shows how to generate UML from SQL Server. As a quick reference, see below the query he used:

DECLARE @object_ID INT
SELECT @Object_ID=object_id('HumanResources.vEmployeeDepartmentHistory')
SELECT COALESCE(object_schema_name(referencing_ID)+'.','')
     + object_name(referencing_ID) +' --|> '
        + referenced_schema_name+'.'+Referenced_Entity_name
        + ':References' 
           --AS reference
FROM sys.sql_expression_dependencies
    WHERE (referencing_id =@object_ID
        OR referenced_ID = @object_ID)
      AND is_schema_bound_reference =0 
        AND referenced_ID IS NOT NULL
UNION ALL
SELECT COALESCE(object_schema_name(parent_object_ID)+'.','') 
    + object_name(parent_object_ID) + ' --|> '
       + COALESCE(object_schema_name(referenced_object_ID)+'.','')
       + object_name(referenced_object_ID)+':FK' 
FROM sys.foreign_keys
    WHERE parent_object_ID = @object_ID
      OR referenced_object_ID = @object_ID

UML in Jekyll

This PlantUML plugin for Jekyll enables you to embed UML diagrams in your Jekyll blog posts. Simply write something like

{% plantuml %}
[First] - [Second]
{% endplantuml %}

to get it working seamlessly with your blog text.

UML in Google Docs

PlantUML Gizmo is a google docs add-on that enables the definition of textual UML models in your Google docs. The PlantUML source text is encoded within the link of the image in Google Docs, so you can edit it later and re-insert the diagram using PlantUML Gizmo. Btw, the author uses this extension to create the teaching material for his Software Engineering courses

Integration of PlantUML in Google Docs

Integration of PlantUML in Google Docs

Visual Studio Code PlantUML plugin

An experimental extension to Visual Studio, available in the VS marketplace to preview UML diagrams in Visual Studio.

See it working in the following animated GIF.

Previewing UML diagrams in Visual Studio

Previewing UML diagrams in Visual Studio

Want to build better software faster?

Want to build better software faster?

Read about the latest trends on software modeling and low-code development

You have Successfully Subscribed!

Pin It on Pinterest

Share This