Over a million developers have joined DZone.

PlantUML Pleasantness: Keeping Elements Together

DZone's Guide to

PlantUML Pleasantness: Keeping Elements Together

PlantUML automatically lays out UML diagrams from a description. It's designed to avoid laying out the diagram manually, but it helps to know how to make it look nice.

Free Resource

Modernize your application architectures with microservices and APIs with best practices from this free virtual summit series. Brought to you in partnership with CA Technologies.

When we write a PlantUML definition, the generated graphical diagram is laid out by PlantUML. In a previous post, we learned how to move elements using the length of the connection. But we can also use a together block with all the elements that should be at the same level. PlantUML will try to keep the elements together when the diagram is drawn. 

In the following sample PlantUML definition, we want the PostgresDB and Mail elements to be at the same level, so we group them using a together block:


actor User
[Third party application] as ThirdPartyApp

/' Try to keep PostgresDB and Mail together,
   so they are at the same level in the diagram. '/
together {
    [PostgreSQL database] as PostgresDB <<Database>>
    [Mail server] as Mail <<Mail server>>

package "Spring Boot Application" {
    [Controllers] <<Spring REST controllers>>
    [DataStoreService] <<Spring service>>
    [Repository] <<Spring repository>>

User --> Controllers
ThirdPartyApp --> Controllers

Controllers --> DataStoreService

DataStoreService --> Repository
DataStoreService --> Mail

Repository --> PostgresDB


Let's create the diagram. We see that the elements are aligned nicely:

Written with PlantUML 8086.

The Integration Zone is proudly sponsored by CA Technologies. Learn from expert microservices and API presentations at the Modernizing Application Architectures Virtual Summit Series.

integration ,uml ,diagrams

Published at DZone with permission of Hubert Klein Ikkink, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.


Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.


{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}