How to generate an AI UML Diagram
Step-by-step guide on generating a UML Diagram
- Determine the type of UML diagram you'd like and specify that in the prompt. For example, start the prompt with "Generate a sequence diagram". UML diagram types include:
- Class Diagram (supported by Eraser)
- Use Case Diagram (supported by Eraser)
- Sequence Diagram (supported by Eraser)
- State Diagram (supported by Eraser)
- Activity Diagram
- Component Diagram
- Deployment Diagram
- Object Diagram
- Package Diagram
- Communication Diagram
- Interaction Overview Diagram
- Timing Diagram
- Describe the content of the diagram. A simple one-liner can work too but the best prompts are usually at least 3-4 sentences long. Here are some helpful prompting frameworks for each UML diagram type:
- Class Diagram: First, write out the entities (i.e. tables). For the entities, you may want to specify attributes (i.e. columns) and their data types. You can also specify primary and foreign keys. Then, write out the relationship between tables including the relationship cardinality.(e.g. "the user entity and the document entity have a one-to-many relationship via the userId attribute")
- Use Case Diagram: Make sure to describe users (e.g. student, teachers) and use cases (e.g. submit homework, view grades). Include the visual requirements of a use case diagram to the prompt: "A use case diagram consists of users and use cases. Users are rectangle shapes and use cases are oval shapes. Connections between users use cases show what users have what use cases, don't add any other connections. Put use cases in a group called use cases. Don't put users in a group and don't group use cases by users. Mention "Use Case Diagram" in the title."
- Sequence Diagram: Write a prompt describing a user flow or a data flow as a sequence of events. Structuring the prompt as a numbered list maps well to a sequence diagram.
- State Diagram: Make sure to describe states (e.g. logged in, logged out) and transitions (e.g. submit credentials, session expiry). Include the visual requirements of a state diagram to the prompt: "States are circle shapes. And connections represent the transition between states. Use icons as appropriate."
- Generate a diagram with the completed prompt.
- Edit the diagram with follow-up prompts (this step requires signing in to Eraser).
- Manually adjust the layout using GUI controls (this step requires signing into Eraser).
Tips on generating a UML diagram
- Instead of writing a prompt from scratch, consider pasting excerpts from existing existing documentation, product code, system output, project description, or uploading image files.
- Working with an LLM to create a fleshed out diagram prompt can be effective. Specify to the LLM the type of UML diagram and system or flow that you're trying to visualize, and ask it to create a list out what should be shown on the diagram.
Example diagrams