A brand new way to create sequence diagrams with ChatGPT

Peng Xiao
Contributor
April 27, 2023

The concept of generating sequence diagrams from text or code is far from novel. In fact, a plethora of tools, including ZenUML, Mermaid, and PlantUML, have long since provided this functionality.

However, the advent of ChatGPT has revolutionized this process by empowering users to create diagrams using natural language. For instance, the diagram displayed on the right has been crafted from the paragraphs on the left.

Screenshot 2023-04-27 at 9.31.59 pm.png

Experience this groundbreaking technology firsthand by giving it a try yourself.

Step 1: Open https://chat.openai.com

We suggest utilizing GPT-4, as GPT-3.5 may not consistently deliver the same level of response quality.

Step 2: Past the following prompt to ChatGPT

Here is a DSL example. Lines starts with '//' are comments.
Write a DSL for a new scenario. Do not explain the DSL you generate.
Do not generate classes. We do not have 'class' keyword. Whenever possible put the whole process together instead of split it into multiple processes.

----Example:----
```
BookLibService.Borrow(id) {
User = Session.GetUser() {
loadUserProfile()
}
if(User.isActive) {
BookRepository.“Update the table by id etc.”
receipt = new Receipt(id, dueDate)
}
return receipt
}
```
# Message types
1. Sync message: Represents a synchronous message between participants. Syntax: `Participant.Method`
2. Creation message: Represents the creation of a new instance of a class. Syntax: `new ClassName()`
**Special Structures:**
1. Loop: Represents a loop in the sequence. Examples: for(condition) { other messages }
2. Alt: Represents conditional branching in the sequence. Example: `if (condition1) {} else if (condition2) {} else {}`

----New scenario----
There is an Order Service which is a RESTFul service served at the endpoint called `/orders`. Client will call this service with order details such as list of products, prices and relevant promotions. Once the service receives the order details, it will first validate the order. If it is valid it will create an order object and save it into database.

----Instruction----
Please generate the DSL and put it in a code block.

Chat GPT should produce something like this.

bd116aea-4d30-45f4-8d9b-25e64090a77e.png

OrderService.CreateOrder(orderDetails) {
isValid = OrderValidator.Validate(orderDetails) {
checkProductAvailability()
checkPromotionsValidity()
}
if (isValid) {
order = new Order(orderDetails)
OrderRepository.Save(order) {
insertOrderToDatabase()
}
} else {
return "Invalid order"
}
return order
}

Step 3: Generate Sequence Diagram with ZenUML

If you have installed ZenUML Diagrams for Confluence(FREEMIUM) | Atlassian Marketplace , you can incorporate a Diagram Macro to your confluence page and paste the above Code to the editor. Otherwise, simply paste the code to https://app.zenuml.com to generate the sequence diagram shown above.

 

1 comment

Comment

Log in or Sign up to comment
Roman Stoffel
Contributor
April 27, 2023

Interesting =). Its not quite doing yet what I want, but it is getting somewhere.

I'm not sure yet about the 'fluff' and boiler plate code it added (promo codes, availability checks, validation services etc).
When I write sequence diagrams, its often to show a difficult control flow, so I do not want fluff to be added in that case.
Or I want to use help me to think about a work flow. There, it is interesting that it can add stuff. However, I kind of would want to have it generate the 'bare minimum' no fluff. And maybe add 'suggested' things explicitly. There the 'promo codes and availability' checks would make sense. As a reminder that we might have something in the system like that.

 

Anyway, we will see. I can see a version of this helping us to 'visualize' our text and might find obvious flaws in a text based requirement.

Peng Xiao
Contributor
April 27, 2023

I get your point and totally agree with you.

It seems to be a common issue with modern AI technologies. They struggle to differentiate between 'superfluous information' and 'essential data' or 'solely what has been instructed.'

Although adjusting the prompt may yield improvements, it is ultimately necessary to enhance the underlying structure to address the fundamental issue.

Peng Xiao
Contributor
April 27, 2023

I added one line in the prompt - "do not make up logic that is not described in the scenario". It gave me the following code:

OrderService.CreateOrder(orderDetails) {
Validation = new Validation(orderDetails) {
validateOrder()
}
if(Validation.isValid) {
Order = new Order(orderDetails) {
createOrder()
saveToDatabase()
}
Response = new Response(Order) {
sendResponse()
}
} else {
ErrorResponse = new ErrorResponse(Validation.errors) {
sendErrorResponse()
}
}
}

I don't really know if that mattered :)  

Like Roman Stoffel likes this
TAGS
AUG Leaders

Atlassian Community Events