paint-brush
ChatGPT: Your Time-Saving Companion for UML Diagram Generationby@nastyakostina
8,963 reads
8,963 reads

ChatGPT: Your Time-Saving Companion for UML Diagram Generation

by Anastasiia KostinaFebruary 7th, 2024
Read on Terminal Reader
Read this story w/o Javascript

Too Long; Didn't Read

Effortlessly create and enhance UML diagrams with ChatGPT, using PlantUML code generation. Save time, streamline processes, and optimize your work, making diagram creation more efficient and enjoyable.
featured image - ChatGPT: Your Time-Saving Companion for UML Diagram Generation
Anastasiia Kostina HackerNoon profile picture

My initial encounter with ChatGPT was driven by sheer curiosity when it was released. I was particularly drawn to articles discussing code generation, even though I don't personally write code. And I initially believed that feature wouldn't be relevant to me.


However, there came a moment when I found myself working on one UML diagram that I wasn't too eager to create.


In my quest to simplify or expedite the process, I turned to various methods. I usually craft UML diagrams using PlantUML code... here, the realization struck me: this is a form of code, and code can be generated.


Thus, ChatGPT evolved into a valuable tool for my diagram creation, and now I'm excited to share my experiences with you.

A Few Words About UML

UML stands for Unified Modeling Language, and it serves as a language for specifying, visualizing, constructing, and documenting artifacts of software systems. UML draws from concepts in object-oriented programming languages; having development knowledge is beneficial for UML modeling but not mandatory.


It is primarily designed to describe aspects of software design, but it also offers a set of behavioral diagrams to model business or user requirements.


In my role, I engage with IT business processes, specifically focusing on modeling them for analysis, optimization, and translating them into a clear format for developers to implement.

When it comes to modeling, I employ various approaches and tools, one of which is UML.


Here's the beauty of it — you don't have to be a software engineer to utilize UML. I use it to navigate through business processes implemented with software, but it goes beyond that — it's remarkably versatile and can be applied by various roles at different stages of development. All in all, give it a try; you might just find yourself loving it.

Draw vs Code

Like any diagram, you can easily draw it — it's simple, convenient, quick, and provides a clear view of the process and the outcome. Numerous graphic tools are available for this purpose, and I do use them. However, more often than not, I choose the "code" approach, thanks to PlantUML.


PlantUML, an open-source modeling language and tool, allows you to generate diagrams based on plain text language. In simpler terms, you can write code in PlantUML to create diagrams.


I enjoy sketching diagrams in my 'creative mode,' but more often than not, I either convert them into code afterward or write the code directly. There are two main reasons for this:

  1. You can insert, move, and delete blocks in your diagrams much more efficiently

    Changing the order of blocks in drawn diagrams often leads to modifications across the entire diagram, affecting other blocks and links. When working with code, you don't need to concern yourself with the visual aspect; you're dealing with a text, and PlantUML takes care of the graphical representation for you.


  2. You can work with and store simple text files instead of dealing with pictures

    This is particularly beneficial when encountering images of diagrams in documentation. The quality may be compromised. It's impossible to continue working with such diagrams, and they can only be redrawn, not edited or extended.


Another significant advantage is that ChatGPT understands PlantUML and can generate code, allowing you to enjoy the benefits of code generation and seamlessly integrate them with UML. I'll share some examples from my personal experience below.


You can use any code editors for PluntUML. I personally prefer Visual Studio Code and PlantUML extension in it. Another way is to use online redactors like https://plantuml.com or others.

ChatGPT, Write PluntUML Code for Me

Example 1 – I Don’t Wanna Start It With a Blank Slate

Let’s create a Use Case diagram for a Taxi application.


First, I use a prompt:

use syntax from https://plantuml.com/ru/use-case-diagram, create a use case diagram for a taxi app


ChatGPT generates a code:

@startuml
left to right direction
actor "Passenger" as passenger
actor "Driver" as driver
rectangle "Taxi App" {
  usecase "Request Ride" as request
  usecase "Cancel Ride" as cancel
  usecase "Track Ride" as track
  usecase "Payment" as payment

  passenger -- (request)
  passenger -- (cancel)
  passenger -- (track)
  passenger -- (payment)

  driver -- (track)
  driver -- (payment)

  (request) --> (cancel)
  (request) --> (track)
  (track) --> (payment)
}
@enduml

Visual view:


The idea is fine, but having only four cases seems insufficient. I request to add additional cases and enhance it with some syntax examples, as there are none similar in PlantUML. Prompt:

add more cases, you can use different types of links such as include, extends and generalization, syntax:

(case1) .> (case2_includes_case1) : <<include>>

(parent) <|-- (child)

(case1 extends case 2) .> (case2) : <<extends>>


Then I ask multiple times to

add more cases


again and make some specific requests to fix errors.


Here is the final outcome from ChatGPT:

@startuml
left to right direction
actor "Passenger" as passenger
actor "Driver" as driver
rectangle "Taxi App" {
  usecase "Request Ride" as request
  usecase "Cancel Ride" as cancel
  usecase "Track Ride" as track
  usecase "Payment" as payment
  usecase "Rate Driver" as rate
  usecase "View Ride History" as history
  usecase "Select Ride Type" as selectType
  usecase "Provide Feedback" as feedback
  usecase "View Driver Information" as driverInfo
  usecase "Update Profile" as updateProfile
  usecase "Promo Code" as promoCode
  usecase "Emergency Assistance" as emergencyAssistance

  passenger -- (selectType)
  passenger -- (request)
  passenger -- (cancel)
  passenger -- (track)
  passenger -- (payment)
  passenger -- (rate)
  passenger -- (history)
  passenger -- (feedback)
  passenger -- (driverInfo)
  passenger -- (updateProfile)
  passenger -- (promoCode)
  passenger -- (emergencyAssistance)

  driver -- (track)
  driver -- (payment)
  driver -- (rate)

  (request) ---> (cancel)
  (request) ---> (track)
  (track) ---> (payment)
  (track) ---> (rate)
  (history) --> (payment)
  (rate) --> (payment)
  (rate) ---> (track)
  (cancel) --> (request)
  (selectType) --> (request)
  (feedback) --> (rate)
  (driverInfo) ---> (track)
  (updateProfile) --> (track)
  (promoCode) --> (payment)
  (emergencyAssistance) --> (track)
}
@enduml

I like the cases, but not the connections between them. So, I edit that code a bit.


Here is the final result:

@startuml

actor "Passenger" as passenger
actor "Driver" as driver
rectangle "Taxi App" {
  usecase "Request Ride" as request
  usecase "Cancel Ride" as cancel
  usecase "Track Ride" as track
  usecase "Payment" as payment
  usecase "Rate Driver" as rate
  usecase "View Ride History" as history
  usecase "Select Ride Type" as selectType
  usecase "Provide Feedback" as feedback
  usecase "View Driver Information" as driverInfo
  usecase "Update Profile" as updateProfile
  usecase "Promo Code" as promoCode
  usecase "Emergency Assistance" as emergencyAssistance

  passenger -- (selectType)
  passenger - (request)
  passenger -- (track)
  passenger -- (payment)
  passenger -- (history)
  passenger -- (rate)
  passenger -- (updateProfile)
  passenger -- (emergencyAssistance)

  driver - (request)
  driver - (payment)
  driver - (rate)
  (request) --> (track)
  (track) --> (payment)
  (track) --> (rate)

  (selectType) --> (request)
  (cancel) .> (request) : <<extends>>
  (rate) <.. (feedback)  : <<include>>
  (payment) <..(promoCode) : <<include>>
  (driverInfo) .> (track) : <<extends>>
}
@enduml


Certainly, you can incorporate more scenarios. For example, there's no information about user registration and login. Furthermore, you can guide ChatGPT to create a diagram related to your designs. The key is that you have a foundation that you can use.

Example 2 – I Need to Check and Enhance a Diagram

I have a simple version of a sequence diagram for picture storage solution with a reverse proxy:

@startuml
participant Client
boundary "Reverse Proxy" as Proxy
participant Back
participant FileStorage
participant Admin
actor Editor

Editor -> Admin: Add picture
Admin -> FileStorage: Add picture

Client -> Proxy: Get picture
Proxy -> Proxy: Check cache

alt cash is not empty
Proxy -->> Client: Return picture
else cash is empty
Proxy -> FileStorage: Recieve picture
FileStorage --> Proxy: Picture
Proxy -> Proxy: Save to cache
Proxy -->> Client: Return picture
end
@enduml


Let’s improve it. My prompt:

I'm designing a solution for storing and using images, check this diagram and edit it if necessary


ChatGPT suggestion:

1. **Participant Name Clarification:**
    - Consider renaming "Back" to something more descriptive, like "Application Server" or a similar term that better represents the functionality.
2. **Actor Placement:**
    - Move the "Editor" actor to a more standard position, usually at the top.

@startuml
participant Client
actor Editor
boundary "Reverse Proxy" as Proxy
participant ApplicationServer
participant FileStorage
participant Admin

Editor -> Admin: Add picture
Admin -> FileStorage: Add picture

Client -> Proxy: Get picture
Proxy -> Proxy: Check cache

alt cache is not empty
    Proxy -->> Client: Return picture
else cache is empty
    Proxy -> ApplicationServer: Receive picture
    ApplicationServer --> Proxy: Picture
    Proxy -> Proxy: Save to cache
    Proxy -->> Client: Return picture
end
@enduml


I don’t like the point about actor placement, so I put it back; everything else is fine.


Then I repeated several times a prompt:

check this diagram and enhance it if needed


and write prompts:

show how ApplicationServer get pic from database


add focus of control


add some corner cases


To finalize it, I adjust the focus of control and make some changes to the naming. Here's the final result:

@startuml
participant Client
boundary "Reverse Proxy" as Proxy
participant ApplicationServer
database FileStorage
participant Admin
actor Editor

Editor -> Admin: Add picture
activate Admin
deactivate Admin
Admin -> FileStorage: Add picture
activate FileStorage
deactivate FileStorage
Admin -> ApplicationServer: Store metadata
activate ApplicationServer

Client -> Proxy: Get picture
activate Proxy
Proxy -> Proxy: Check cache

alt cache is not empty
  Proxy -->> Client: Return picture
else cache is empty
  Proxy -> ApplicationServer: Receive picture request
  activate FileStorage
  ApplicationServer -> FileStorage: Retrieve picture from database
  alt picture not found in database
    FileStorage --> ApplicationServer: Picture not found
    deactivate FileStorage
    ApplicationServer -> Proxy: Notify picture not found
    Proxy -->> Client: Picture not found
  else
    FileStorage --> ApplicationServer: Picture data
    deactivate FileStorage
    ApplicationServer -> Proxy: Send picture to Proxy
    Proxy -> Proxy: Save to cache
    Proxy -->> Client: Return picture
  end
end

deactivate Proxy
deactivate ApplicationServer
deactivate Admin
deactivate Editor
@enduml

Drawbacks

First of all, you have to check everything because "ChatGPT can make mistakes." It is not meant to be a replacement for you but rather a tool to streamline and optimize your work.


The most common errors are related to PlantUML syntax. Sometimes, it happens in the middle of a conversation, and I have to fix it and get ChatGPT back on the right track.


Second, I use a free version of ChatGPT 3.5, and it has ups and downs. Sometimes, it works worse and gives some random answers for the same prompt.


Third, ChatGPT understands some diagrams better than others. For example, it does much better with sequence diagrams than use case diagrams.


However, despite these limitations, ChatGPT remains a valuable tool and an excellent assistant capable of increasing your efficiency and saving you time.

Conclusion

I use ChatGPT on a permanent basis in my work. If you're a manager, analyst, developer, tester, or in any other role, you can make use of UML. If that's the case, consider writing and generating PlantUML code — it will save you time and boost your efficiency.


I hope my experience will be useful and inspire you. Thank you!