PlantUML is awesome
Tags: productivity, design
Published: 2019-09-08 09:37:14

This post is all about why I felt PlantUML is awesome.

[PlantUML](https://github.com/plantuml/plantuml) is an open-source tool allowing users to create UML diagrams from a plain text language.

You can just write few lines of code to draw your UML diagram. UML diagrams are very important in communicating design implementation, doing these digrams in draw.io or something drawing tool is a time taking task. Playing with touchpad/mouse for long time is less effective.

I have used similar tools in past, like [mermaid](https://github.com/knsv/mermaid) and [graphviz](https://graphviz.org/).

Following are the things that made PlantUML different

* Readability
* Maintainable
* Flexible
* Powerful
* Customable

Once the UML is designed with plantUML the end result can be extracted out into PNG or SVG. There are plugins that can be easily intergated into IDE's, such as [PlantUML for VS Code](https://marketplace.visualstudio.com/items?itemName=jebbs.plantuml) and [PlantUML for IntelliJ](https://plugins.jetbrains.com/plugin/7017-plantuml-integration).

Also available for [Confluence](https://www.atlassian.com/software/confluence)(document manager of Atlassian suite) where the history of the change in design implementation can be tracked easily [PlantUML for Confluence](https://marketplace.atlassian.com/apps/41025/plantuml-for-confluence?hosting=server&tab=overview)

*PS: PlantUML is written is java with graphviz underhood :)*

PlantUML is a component that allows to quickly write :

1. Sequence diagram
2. Usecase diagram
* Class diagram
* Activity diagram (here is the legacy syntax)
* Component diagram
* State diagram
* Object diagram
* Deployment diagram `beta`
* Timing diagram `beta`

You can find the details [documentation](http://plantuml.com/) of how and what is plantUML.

Here I took a random sequence diagram from internet and tried to replicate the same in PlantUML with few tweeks, the end result was wow!

## Sample Sequence diagram
![sample sequnce](https://i.postimg.cc/PqvRnKNP/sequence-example-facebook-authentication.png)


## Sequence diagram with PlantUML
![PlantUML sequnce](https://i.postimg.cc/4NtvGM1C/facebook.png)

It's not just a replica, but a much better one.

Here the code that did the `magic` for us.

```
@startuml
header Facebook Authentication System
title Facebook Authentication System
footer Page no %page% of %lastpage%

actor user #3c5a99
participant WebBrowser as "Web Browser"
box "Facebook server"
    participant App as "Application"
    participant AuthZ as "Authorization System"
    database FCS as "Facebook Content System"
end box

== Basic flow ==

activate user
user -> WebBrowser : get FB resource
    activate WebBrowser
        WebBrowser -> App : request FB access
        WebBrowser <-- App : <<http redirect>>
        WebBrowser -[#red]> AuthZ : authorize
        WebBrowser <-- AuthZ : permission form
        user <-- WebBrowser : permission form
    deactivate WebBrowser

    user -> WebBrowser : user permission
    activate WebBrowser
        WebBrowser -> AuthZ : process permission
        ... 5 minutes alter ...
        WebBrowser <-- AuthZ : <<http redirect>>

        == Authorization ==
        alt permission granted
            activate App
                group
                WebBrowser -> App : FB authorization code
                        activate AuthZ
                            App ->  AuthZ : FB authorization code
                            App <--  AuthZ : FB authorization code
                        deactivate AuthZ

                        activate FCS
                            App -> FCS : access FB user protected resource
                            App <-- FCS : user protected resource
                            note left FCS: Check with content system
                        deactivate FCS
                 end
            deactivate App

            WebBrowser <-- App : user protected resource
            deactivate WebBrowser

            user <-- WebBrowser  : user protected resource
        else permission not granted
            activate WebBrowser
                activate App
                    WebBrowser -> App : no authorization
                    WebBrowser <-- App : FB resource not available
                deactivate App
            deactivate WebBrowser

            user <-- WebBrowser  : FB resource not available
        end
    deactivate WebBrowser

deactivate user
@enduml
```

Thanks for reading!!!
:)