Create sequence diagrams with PlantUML

Recently I came across PlantUML as a tool for building UML diagrams. It can be considered as a standard of making UML, because the output is auto-generated and thus unified.
The idea is to describe the content of your diagrams using a simple language and then PlantUML will create the visual representation for you.
You can create all kinds of diagrams with it, but today I am going to illustrate this component by focusing only on the sequence diagrams. The reason I choose exactly this type of diagrams is that we will only need the plantuml.jar file for that purpose. For the other types of diagrams we will also require a software called Graphiz.

First of all you will need to download the plantuml.jar from here:
http://plantuml.com/download

When you open it it will display the following window:

From here you can set the directory, where the plantuml description file will be positioned.
I am going to create a txt file for that purpose in the selected directory.

Let me give you an example of plantUML format in order to clear the process and the idea.
Imagine a scenario where a user tries to access a restricted area in a web site. If the user is already authenticated he will be allowed to just open the restricted page, otherwise he is redirected to a login page where he enters his credentials. There are two possible situations here – one is to authenticate the user and redirect him back to the restricted page, and the other is to fail his authentication due to invalid username or password and show him a message.

Let’s give it a try and describe that with the plantUML language:

@startuml

actor User
User -> "Restricted Page": Try to open

alt authenticated user

	"Restricted Page" -> "Restricted Page": Open page
	
else unauthenticated user

	"Restricted Page" -> "Login Page": Redirect
	"Login Page" -> DB: Check auth details
	DB -> "Login Page": Auth response
	
	alt unsuccessful authentication
	
		"Login Page" -> "Login Page": Show error \nmessage
	
	else successful authentication
	
		"Login Page" -> "Restricted Page": Redirect to the \nrestricted page
		
	end	
end

@enduml

When you save the text file the plantuml application will generate a png image for you.
The above code will result in the following sequence diagram:

You have variety of options about the colors, arrows (the type of requests, responses), you can add Activation sections, different interaction fragments, comments and everything you will potentially need from a sequence diagram.

Check out the plantuml website for the details:
http://plantuml.com/sequence-diagram

I wish you a happy “drawing”.

One thought on “Create sequence diagrams with PlantUML

  1. Excellent post. The tool(standard) is not that bad. You can draw uml sequence diagrams really fast once you get used to it.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s