Using ChatGPT to Draw Sequence Diagram

To use ChatGPT to generate a sequence diagram, you can provide a description of the system and the interactions between its components. The description should be written in a clear and concise manner, using plain language and logical ordering of events. Once you have the description, you can use a tool like Mermaid to create the diagram.

In the following example using ChatGPT 3.5 turbo, we have described the process of a user withdrawing cash from an ATM using their bank’s mobile app. We have requested that a sequence diagram be generated using Mermaid syntax. We iterated the prompt approximately 10 times to ensure the best possible result.

write mermaid to generate sequence diagram for a journey of a user to withdraw cash from atm by using his bank mobile app.
user presses “withdraw cash from atm” button from bank app,
user input amount of cash to withdraw
user presses “start to withdraw” button from bank app,
the bank app activatie camera by itself and ready to scan qr code
the user press a button on atm to show moblie cash withdraw qr code
the atm call withdraw token API to request a mobile withdraw token
the withdraw token API generates a token with expiry, store it into database, and then sent the token back to the atm
the atm generates the qr code from the token, and then present the qr code on atm screen
the bank app scans the qr code and sent the token and withdraw amount to withdraw request api
the withdraw request api check if the token exists in the database. bank app shows invalid qr code if it does not exists.
the withdraw request api check if the token expired. bank app shows invalid qr code if it is expired.
if the token exists and is not expired, the withdraw request api invalid the token from database, and then commit the transaction with the token from transaction api. the transaction update transcation status to database
the atm polls “transaction status api” to check if the transcation with the token has been completed. “transaction status api” check status from database and reply status to ATM. once completed present cash to user.
the user pick up cash from atm

ChatGPT generates natural language descriptions of a given prompt, which can be helpful for reviewing whether the prompt is clear and understandable to the model. Below is the script generated by ChatGPT.

  participant BankApp
  participant User
  participant ATM
  participant WithdrawTokenAPI
  participant WithdrawRequestAPI
  participant TransactionAPI
  participant Database
  participant TransactionStatusAPI

  User->>+BankApp: Press 'Withdraw Cash from ATM' button
  User->>+BankApp: Input amount of cash to withdraw
  User->>+BankApp: Press 'Start to Withdraw' button
  BankApp->>+BankApp: Activate camera by itself
  User->>+ATM: Press button to show mobile withdraw QR code
  ATM->>+WithdrawTokenAPI: Call withdraw token API
  WithdrawTokenAPI->>+Database: Store token with expiry
  WithdrawTokenAPI-->>-ATM: Send token
  ATM->>+ATM: Generate QR code from token
  ATM->>+User: Present mobile withdraw QR code
  BankApp->>+WithdrawRequestAPI: Scan QR code and send token and amount
  WithdrawRequestAPI->>+Database: Check if token exists
  Database-->>-WithdrawRequestAPI: Return token existence
  WithdrawRequestAPI->>+Database: Check if token is expired
  Database-->>-WithdrawRequestAPI: Return token expiry
  alt Token exists and is not expired
      WithdrawRequestAPI->>+Database: Invalidate token in database
      WithdrawRequestAPI->>+TransactionAPI: Commit transaction with token
      TransactionAPI->>+Database: Update transaction status to database
      ATM->>+TransactionStatusAPI: Poll transaction status API to check transaction completion
      TransactionStatusAPI->>+Database: Check transaction status from database
      Database-->>-TransactionStatusAPI: Return transaction completion status
      TransactionStatusAPI-->>-ATM: Return transaction completion status
      ATM->>+User: Present cash to user
      User->>+ATM: Pick up cash
  else Token does not exist or is expired
      BankApp->>+User: Show invalid QR code message

In this diagram, each participant is represented as a vertical line. The arrows indicate the flow of messages between the participants.
The journey starts with the user pressing the ‘Withdraw Cash from ATM’ button in the bank app and inputting the amount of cash to withdraw. The user then presses the ‘Start to Withdraw’ button, which activates the camera in the bank app.
The user then presses a button on the ATM to show the mobile withdraw QR code. The ATM calls the Withdraw Token API to request a mobile withdraw token, which is stored in the database and sent back to the ATM.
The ATM generates a QR code from the token and presents it on the ATM screen. The bank app scans the QR code and sends the token and withdraw amount to the Withdraw Request API.
The Withdraw Request API checks if the token exists in the database and if it is expired. If the token exists and is not expired, the Withdraw Request API invalidates the token in the database and commits the transaction with the token from the Transaction API. The Transaction API updates the transaction status to the database.
The ATM polls the Transaction Status API to check for transaction completion, and the Transaction Status API checks the transaction status from the database and returns it to the ATM. Once the transaction is completed, the ATM presents the cash to the user.
Finally, the user picks up the cash from the ATM, completing the withdrawal process. If the token does not exist or is expired, the bank app shows an invalid QR code message to the user.

Below is the result sequence diagram. For the best experience you should view it in mermaid live editor.

BankAppUserATMWithdrawTokenAPIWithdrawRequestAPITransactionAPIDatabaseTransactionStatusAPIalt[Token exists and is not expired][Token does not exist or is expired]Press 'Withdraw Cash from ATM' buttonInput amount of cash to withdrawPress 'Start to Withdraw' buttonActivate camera by itselfPress button to show mobile withdraw QR codeCall withdraw token APIStore token with expirySend tokenGenerate QR code from tokenPresent mobile withdraw QR codeScan QR code and send token and amountCheck if token existsReturn token existenceCheck if token is expiredReturn token expiryInvalidate token in databaseCommit transaction with tokenUpdate transaction status to databasePoll transaction status API to check transaction completionCheck transaction status from databaseReturn transaction completion statusReturn transaction completion statusPresent cash to userPick up cashShow invalid QR code messageBankAppUserATMWithdrawTokenAPIWithdrawRequestAPITransactionAPIDatabaseTransactionStatusAPI