PAGEON Logo

The Ultimate Guide to Automating Diagram Creation with ChatGPT and Mermaid Code

Transform natural language into powerful visual diagrams

Discover how to leverage ChatGPT's capabilities to generate complex Mermaid diagrams without writing a single line of code. This comprehensive guide will take you from understanding the basics to mastering advanced techniques for automated diagram creation.

Understanding Mermaid Diagrams & ChatGPT Integration

What is Mermaid?

Mermaid is a JavaScript-based diagramming and charting tool that renders Markdown-inspired text definitions to create and modify diagrams dynamically. I've found it to be incredibly valuable for technical documentation because it allows diagrams to be version-controlled alongside code and maintained using the same workflows.

Example of Mermaid Code vs. Visual Output

Mermaid Code
flowchart TD
    A[Start] --> B{Is it working?}
    B -->|Yes| C[Great!]
    B -->|No| D[Debug]
    D --> B
                                
Visual Output
flowchart TD
    A[Start] --> B{Is it working?}
    B -->|Yes| C[Great!]
    B -->|No| D[Debug]
    D --> B
                                    

ChatGPT's Role in Diagram Generation

I've discovered that ChatGPT can generate complex Mermaid diagram code through carefully crafted prompts. This powerful capability transforms the way we create technical diagrams by allowing us to describe what we want in natural language and receive functional diagram code in return.

conceptual illustration showing ChatGPT transforming text prompts into Mermaid diagram code with blue to orange gradient

The relationship between natural language instructions and diagram code generation is fascinating. ChatGPT interprets your descriptive intent and translates it into structured Mermaid syntax. This is particularly valuable for those who understand the diagrams they need but lack familiarity with Mermaid's specific syntax requirements.

Benefits of Automated Diagram Creation

When I compare automated diagram generation to manual coding or visual tools, I find several compelling advantages:

  • Speed: Generate complex diagrams in seconds rather than spending hours manually coding or drawing
  • Accessibility: Create professional diagrams without needing to learn Mermaid syntax
  • Iteration: Quickly refine diagrams through conversational prompts
  • Integration: Easily incorporate generated code into documentation workflows
  • Consistency: Maintain uniform diagram styles across documentation

PageOn.ai Integration

I've found ai prompt engineering to be much more effective when I first organize my diagram concepts using PageOn.ai's AI Blocks. This structured approach helps me clarify the relationships and hierarchies I want to visualize before generating the actual Mermaid code, resulting in more accurate and useful diagrams.

Foundational Prompt Engineering for Mermaid Diagrams

Essential Prompt Structures

Through extensive experimentation, I've developed several prompt structures that consistently yield accurate Mermaid code. The key is to be specific about both the diagram type and the relationships you want to illustrate.

Example Prompt Template:

"Generate a Mermaid [DIAGRAM_TYPE] that shows [SPECIFIC_DESCRIPTION]. 
Include the following elements: [ELEMENT1, ELEMENT2, ...] 
with these relationships: [RELATIONSHIP_DESCRIPTIONS].
Use the following styling: [STYLING_PREFERENCES]."
                        

When write effective AI prompts for diagram generation, I always make sure to include clear instructions about the diagram's purpose and audience. This context helps ChatGPT generate more relevant and useful visualizations.

Specifying Diagram Types

flowchart TD
    subgraph "Mermaid Diagram Types"
        flow[Flowchart] 
        seq[Sequence Diagram]
        class[Class Diagram]
        state[State Diagram]
        er[Entity Relationship]
        gantt[Gantt Chart]
        pie[Pie Chart]
        git[Git Graph]
    end
    flow --> direction["Direction: TD, LR, RL, BT"]
    seq --> actors["Actors & Messages"]
    class --> relations["Classes & Relations"]
    state --> transitions["States & Transitions"]
    er --> entities["Entities & Relationships"]
    gantt --> tasks["Tasks & Timeline"]
    pie --> values["Values & Labels"]
    git --> commits["Commits & Branches"]
                        

Each diagram type requires specific terminology in your prompts. I've found it helpful to explicitly state the diagram type at the beginning of my prompt and then use the appropriate vocabulary for that type.

Diagram Type Key Terminology Example Prompt Snippet
Flowchart Nodes, edges, direction, decision points "Generate a Mermaid flowchart with decision points for user authentication"
Sequence Diagram Actors, messages, activations, notes "Create a sequence diagram showing interaction between user, server, and database"
Class Diagram Classes, methods, properties, relationships "Design a class diagram for a library management system"
Entity Relationship Entities, relationships, cardinality "Create an ER diagram for an e-commerce database"

Common Pitfalls and Solutions

Common Pitfalls

  • Ambiguous relationship descriptions
  • Incorrect syntax for specific diagram types
  • Overly complex diagrams that become unreadable
  • Missing node definitions
  • Inconsistent naming conventions

Solutions

  • Use precise directional terms (A leads to B)
  • Specify diagram type explicitly
  • Break complex diagrams into smaller components
  • List all nodes before describing relationships
  • Define naming convention in your prompt

PageOn.ai's Deep Search functionality has been invaluable in my work with Mermaid diagrams. I use it to find relevant diagram examples and patterns that I can reference in my prompts to ChatGPT, which significantly improves the quality and accuracy of the generated code.

Advanced Techniques for Complex Diagram Generation

Creating Multi-level Flowcharts

For complex systems, I often need to create multi-level flowcharts that clearly show hierarchies and relationships. I've found that using subgraphs in Mermaid is the key to organizing these complex diagrams.

Example: Multi-level System Architecture

flowchart TD
    subgraph "Client Layer"
        A[Web Browser]
        B[Mobile App]
    end
    subgraph "API Layer"
        C[API Gateway]
        D[Authentication]
        E[Rate Limiting]
    end
    subgraph "Service Layer"
        F[User Service]
        G[Content Service]
        H[Analytics Service]
    end
    subgraph "Data Layer"
        I[(User DB)]
        J[(Content DB)]
        K[(Analytics DB)]
    end
    A --> C
    B --> C
    C --> D
    C --> E
    D --> F
    E --> F
    E --> G
    E --> H
    F --> I
    G --> J
    H --> K
                            

Prompt used to generate this diagram:

"Create a Mermaid flowchart with top-down direction showing a multi-layer system architecture. Include these layers as subgraphs: Client Layer (with Web Browser and Mobile App), API Layer (with API Gateway, Authentication, Rate Limiting), Service Layer (with User Service, Content Service, Analytics Service), and Data Layer (with User DB, Content DB, Analytics DB). Show the flow of requests from clients through the API layer to services and finally to databases."

Designing Sequence Diagrams

Sequence diagrams are excellent for visualizing interactions between different components over time. I've developed specific prompting techniques to ensure these diagrams accurately capture the temporal flow of operations.

sequenceDiagram
    participant User
    participant App
    participant API
    participant DB
    User->>App: Opens application
    App->>API: Request user data
    API->>DB: Query user information
    DB-->>API: Return user data
    API-->>App: Send user profile
    App-->>User: Display dashboard
    User->>App: Create new item
    App->>API: Send item data
    API->>DB: Insert new record
    DB-->>API: Confirm success
    API-->>App: Return item ID
    App-->>User: Show confirmation
                        

When prompting for sequence diagrams, I've found it helpful to explicitly list all actors first, then describe each interaction step-by-step in chronological order. This approach helps ChatGPT generate more accurate sequence flows.

Entity-Relationship Diagrams

For database design visualization, entity-relationship diagrams are invaluable. I use specific terminology in my prompts to ensure the relationships are correctly represented.

erDiagram
    CUSTOMER ||--o{ ORDER : places
    CUSTOMER {
        string name
        string email
        string address
    }
    ORDER ||--|{ ORDER_ITEM : contains
    ORDER {
        int order_id
        date created_at
        string status
    }
    PRODUCT ||--o{ ORDER_ITEM : "ordered in"
    PRODUCT {
        int product_id
        string name
        float price
        string category
    }
    ORDER_ITEM {
        int quantity
        float price
    }
                        

For ER diagrams, I make sure to specify cardinality relationships (one-to-many, many-to-many, etc.) and include the attributes for each entity. This level of detail helps ChatGPT generate more useful and accurate database diagrams.

Using PageOn.ai's Vibe Creation

screenshot of PageOn.ai interface showing Vibe Creation tool transforming abstract concepts into visual diagrams with orange highlights

I've enhanced my diagram creation process by using PageOn.ai's Vibe Creation feature to transform abstract concepts into clear visual instructions. This has been particularly helpful when working with AI Image Creation with ChatGPT for more complex diagrams. The tool helps me articulate the visual style and organization I want before I even start crafting my ChatGPT prompt.

Optimizing Prompts for Diagram Customization

Specifying Styling Preferences

One of the most powerful aspects of Mermaid diagrams is the ability to customize their appearance. I've developed specific prompt techniques to control colors, shapes, and styles.

Style Specification Examples

Basic Prompt
"Create a flowchart showing the user registration process with steps: Start, Fill Form, Validate, Success/Error."
Style-Enhanced Prompt
"Create a flowchart showing the user registration process with steps: Start, Fill Form, Validate, Success/Error. Style Start with green rounded box, Error with red hexagon, and Success with green hexagon. Use blue arrows for normal flow and red dashed arrows for error paths."
flowchart TD
    classDef start fill:#d4edda,stroke:#28a745,stroke-width:2px,color:#28a745,rx:10,ry:10
    classDef process fill:#f8f9fa,stroke:#6c757d,stroke-width:1px
    classDef success fill:#d4edda,stroke:#28a745,stroke-width:2px,color:#28a745,shape:hexagon
    classDef error fill:#f8d7da,stroke:#dc3545,stroke-width:2px,color:#dc3545,shape:hexagon
    A[Start] --> B[Fill Registration Form]
    B --> C{Validate Input}
    C -->|Valid| D[Create Account]
    C -->|Invalid| E[Show Error Message]
    D --> F[Success: Account Created]
    E --> B
    A:::start
    B:::process
    C:::process
    D:::process
    E:::error
    F:::success
                        

I've found that being specific about colors (using named colors or hex codes), shapes, and line styles in my prompts leads to much more visually appealing and informative diagrams.

Controlling Node Shapes and Relationships

Node Shape Reference

flowchart TD
    A[Rectangle]
    B(Rounded Rectangle)
    C([Stadium shape])
    D[[Subroutine shape]]
    E[(Database)]
    F((Circle))
    G>Asymmetric]
    H{Diamond}
    I{{Hexagon}}
    J[/Parallelogram/]
    K[\Parallelogram alt\]
    L[/Trapezoid\]
    M[\Trapezoid alt/]
                                

Relationship Types

flowchart LR
    A1[Normal] --> B1[Arrow]
    A2[Open] --- B2[Link]
    A3[Bold] ==> B3[Arrow]
    A4[Dotted] -.-> B4[Arrow]
    A5[Dotted] -.- B5[Link]
    A6[Text] -->|Yes| B6[On Link]
    A7[Two-way] <--> B7[Arrow]
                                

When creating diagrams for technical documentation, I use specific node shapes to represent different types of components. For example, I use database shapes for data stores, diamonds for decision points, and rectangles for processes. This visual language makes the diagrams more intuitive.

I've found that integrating these styling requirements with ChatGPT generate AI images capabilities creates a powerful workflow for generating both diagrams and supporting visuals that share a consistent visual language.

Maintaining Visual Consistency

For documentation that includes multiple diagrams, maintaining visual consistency is crucial. I use PageOn.ai's visual building blocks to create a consistent style guide for my diagrams.

Style Guide Template for Prompts

"Please apply the following style guide to the diagram:
- User interfaces: rounded rectangles with #e6f7ff background
- APIs/Services: rectangles with #fff2e8 background
- Databases: cylinder shape with #f6ffed background
- Decision points: diamonds with #fff1f0 background
- Normal flow: solid blue arrows
- Alternative flow: dashed orange arrows
- Error flow: dotted red arrows"
                        

Workflow Integration Strategies

Documentation Platform Integration

I've developed specific prompting techniques for generating Mermaid code that integrates seamlessly with various documentation platforms.

GitHub/GitLab Markdown

```mermaid
flowchart TD
    A[Start] --> B[Process]
    B --> C[End]
```
                            

Confluence

<ac:structured-macro ac:name="mermaid">
<ac:plain-text-body><![CDATA[
flowchart TD
    A[Start] --> B[Process]
    B --> C[End]
]]></ac:plain-text-body>
</ac:structured-macro>
                            

When generating diagrams for specific platforms, I include the platform name in my prompt: "Generate a Mermaid flowchart for GitHub markdown that shows..." This ensures ChatGPT produces code in the correct format.

Iterative Refinement Techniques

iterative diagram refinement process visualization showing feedback loop between prompt and output with orange highlights

I've found that diagram creation is rarely a one-shot process. Instead, I use an iterative approach with ChatGPT:

  1. Start with a basic prompt describing the diagram's purpose and key elements
  2. Review the generated code and identify areas for improvement
  3. Ask for specific modifications: "Please update the diagram to add a new node for payment processing between the Order and Confirmation steps"
  4. Request styling enhancements once the structure is correct
  5. Finally, ask for the code in the format needed for your documentation platform

Creating Prompt Templates

To ensure consistency across my team, I've created a set of prompt templates for different diagram types. These templates include placeholders for specific content while maintaining a consistent structure and style.

System Architecture Template

"Generate a Mermaid flowchart with top-down direction showing the system architecture for [SYSTEM_NAME]. 
Include these components:
- Frontend: [LIST_FRONTEND_COMPONENTS]
- Backend: [LIST_BACKEND_SERVICES]
- Databases: [LIST_DATABASES]
- External Services: [LIST_EXTERNAL_SERVICES]
Show the data flow between components with these key interactions:
[LIST_KEY_INTERACTIONS]
Use the following styling:
- Frontend components: rounded rectangles with light blue background
- Backend services: regular rectangles with light green background
- Databases: cylinder shape with light yellow background
- External services: hexagons with light purple background
- Arrows should indicate data flow direction"
                        

Using AI chat tools for coding in combination with these templates has dramatically improved my team's efficiency in creating technical documentation.

Using PageOn.ai's Agentic Capabilities

I've found tremendous value in using PageOn.ai's agentic capabilities to transform complex technical requirements into diagram instructions. The platform helps me organize my thoughts and create structured prompts that result in more accurate and useful Mermaid diagrams.

Case Studies: From Concept to Visualization

System Architecture Visualization

I recently needed to create a comprehensive system architecture diagram for a microservice-based application. Here's how I approached it:

The Prompt

"Generate a Mermaid flowchart with left-to-right direction showing a microservice architecture for an e-commerce platform. Include these components: Web Client, Mobile App, API Gateway, User Service, Product Service, Order Service, Payment Service, Notification Service, User Database, Product Database, Order Database, and External Payment Provider. Show the request flow between components, highlighting the path of placing an order. Style client applications with rounded rectangles, services with regular rectangles, databases as cylinders, and external systems with hexagons."

The Result

flowchart LR
    %% Client Applications
    WebClient([Web Client]):::client
    MobileApp([Mobile App]):::client
    %% API Layer
    Gateway[API Gateway]:::service
    %% Microservices
    UserService[User Service]:::service
    ProductService[Product Service]:::service
    OrderService[Order Service]:::service
    PaymentService[Payment Service]:::service
    NotificationService[Notification Service]:::service
    %% Databases
    UserDB[(User DB)]:::database
    ProductDB[(Product DB)]:::database
    OrderDB[(Order DB)]:::database
    %% External Systems
    PaymentProvider{{Payment Provider}}:::external
    %% Connections
    WebClient --> Gateway
    MobileApp --> Gateway
    Gateway --> UserService
    Gateway --> ProductService
    Gateway --> OrderService
    UserService --> UserDB
    ProductService --> ProductDB
    OrderService --> OrderDB
    OrderService --> PaymentService
    OrderService --> NotificationService
    PaymentService --> PaymentProvider
    NotificationService --> UserService
    %% Highlight Order Flow
    WebClient -.-> |1. Browse Products| Gateway
    Gateway -.-> |2. Get Products| ProductService
    ProductService -.-> |3. Fetch Products| ProductDB
    WebClient -.-> |4. Place Order| Gateway
    Gateway -.-> |5. Create Order| OrderService
    OrderService -.-> |6. Save Order| OrderDB
    OrderService -.-> |7. Process Payment| PaymentService
    PaymentService -.-> |8. External Payment| PaymentProvider
    OrderService -.-> |9. Send Notification| NotificationService
    %% Styles
    classDef client fill:#d4f1f9,stroke:#05a5d1,stroke-width:2px,rx:10,ry:10
    classDef service fill:#d5f5e3,stroke:#2ecc71,stroke-width:1px
    classDef database fill:#fef9e7,stroke:#f1c40f,stroke-width:1px
    classDef external fill:#ebdef0,stroke:#8e44ad,stroke-width:1px
                            

This case demonstrates how a well-structured prompt can generate a complex system architecture diagram that clearly shows both the overall structure and a specific flow (in this case, the order placement process).

User Journey Visualization

Converting user journey narratives into visual flowcharts helps product teams understand the user experience. Here's an example:

flowchart TD
    Start([User starts]) --> Discover[Discovers product]
    Discover --> Research[Researches features]
    Research --> Compare{Compare alternatives?}
    Compare -->|Yes| Competitors[Views competitors]
    Competitors --> Decision
    Compare -->|No| Decision{Make decision}
    Decision -->|Purchase| Checkout[Proceeds to checkout]
    Decision -->|Abandon| Exit([Exits journey])
    Checkout --> Payment[Completes payment]
    Payment --> Confirmation[Receives confirmation]
    Confirmation --> Onboarding[Completes onboarding]
    Onboarding --> Usage[Regular usage]
    Usage --> Feedback[Provides feedback]
    classDef start fill:#d4edda,stroke:#28a745,stroke-width:2px,color:#212529,rx:10,ry:10
    classDef process fill:#f8f9fa,stroke:#6c757d,stroke-width:1px,color:#212529
    classDef decision fill:#e2f0fd,stroke:#0d6efd,stroke-width:1px,color:#212529,shape:diamond
    classDef end fill:#f8d7da,stroke:#dc3545,stroke-width:2px,color:#212529,rx:10,ry:10
    Start:::start
    Discover:::process
    Research:::process
    Compare:::decision
    Competitors:::process
    Decision:::decision
    Checkout:::process
    Payment:::process
    Confirmation:::process
    Onboarding:::process
    Usage:::process
    Feedback:::process
    Exit:::end
                        

To create this diagram, I provided ChatGPT with a narrative description of the user journey and asked it to visualize the flow with decision points and possible paths. The prompt included specific instructions for color-coding different types of steps in the journey.

Database Schema Visualization

Visualizing database schemas helps developers understand data relationships. Here's how I converted a textual schema description into a visual diagram:

erDiagram
    USERS ||--o{ ORDERS : places
    USERS {
        int user_id PK
        string username
        string email
        string password_hash
        date created_at
        boolean is_active
    }
    ORDERS ||--|{ ORDER_ITEMS : contains
    ORDERS {
        int order_id PK
        int user_id FK
        date order_date
        string status
        float total_amount
        string shipping_address
    }
    PRODUCTS ||--o{ ORDER_ITEMS : "included in"
    PRODUCTS {
        int product_id PK
        string name
        string description
        float price
        int inventory_count
        int category_id FK
    }
    ORDER_ITEMS {
        int order_item_id PK
        int order_id FK
        int product_id FK
        int quantity
        float unit_price
    }
    CATEGORIES ||--o{ PRODUCTS : categorizes
    CATEGORIES {
        int category_id PK
        string name
        string description
    }
                        

Troubleshooting & Optimization

Common Errors and Solutions

Common Error Cause Solution
Syntax errors in generated code Incorrect or outdated syntax patterns in prompt Ask ChatGPT to fix the specific error or provide an example of the correct syntax
Missing node definitions References to nodes that aren't defined Request a complete list of all nodes before relationships
Overlapping nodes or poor layout Complex diagram without layout guidance Specify direction (TD, LR) and use subgraphs to organize
Styling not applied correctly Incorrect class definitions or applications Ask for explicit classDef statements and class assignments

I've found that most errors in generated Mermaid code can be fixed by providing more specific instructions or examples of the correct syntax in follow-up prompts.

Breaking Down Complex Diagrams

When dealing with complex systems, I've found it's much more effective to break them down into multiple connected diagrams rather than trying to create one massive visualization. This approach has several benefits:

  • Improved readability and focus on specific aspects of the system
  • Higher success rate in generating correct code
  • Better rendering performance in documentation platforms
  • Easier maintenance and updates
  • More accurate representation of specific components

For example, instead of creating one massive system architecture diagram, I might create separate diagrams for the frontend architecture, backend services, data flow, and deployment infrastructure, with clear references between them.

Using PageOn.ai for Refinement

When ChatGPT's generated diagrams need improvement, I turn to PageOn.ai to refine and clarify the diagram structures. The platform's visual thinking tools help me identify what's missing or unclear in the initial diagram, which I can then communicate back to ChatGPT in a more structured way.

Future-Proofing Your Diagram Generation Workflow

Staying Updated with Mermaid

Mermaid is an actively developed tool with regular updates and new features. To keep my diagram generation prompts effective, I follow these practices:

  • Subscribe to the Mermaid.js GitHub repository for release notifications
  • Periodically review the documentation for syntax changes
  • Test existing prompt templates with new Mermaid versions
  • Explore new diagram types as they become available

When a new Mermaid feature is released, I explicitly mention it in my prompts to ensure ChatGPT incorporates it correctly: "Generate a Mermaid diagram using the new journey chart type introduced in version X.X..."

Adapting Prompts for Different AI Models

Different AI models have varying capabilities when it comes to generating Mermaid code. I've developed strategies for adapting my prompts based on the model I'm using:

For Advanced Models (GPT-4)

  • Use more abstract descriptions
  • Request complex styling and layouts
  • Ask for optimizations and best practices
  • Provide high-level goals rather than specific steps

For Earlier Models

  • Be more explicit about syntax
  • Break requests into smaller chunks
  • Provide examples of desired output
  • Focus on one aspect at a time (structure first, then styling)

Building a Prompt Library

One of the most valuable practices I've developed is maintaining a library of successful prompting patterns. This includes:

  • Template prompts for each diagram type
  • Successful examples with both the prompt and resulting code
  • Styling patterns that work well for different contexts
  • Troubleshooting prompts for common errors

This library serves as a valuable resource for my team and helps maintain consistency across our documentation.

Combining PageOn.ai with ChatGPT

workflow diagram showing integration between PageOn.ai visual tools and ChatGPT code generation with bidirectional arrows

My most effective workflow combines PageOn.ai's visual thinking tools with ChatGPT's code generation capabilities. I use PageOn.ai to organize concepts, create visual structures, and establish relationships between elements. Then I use these visual insights to craft precise prompts for ChatGPT, resulting in more accurate and useful Mermaid diagrams.

Transform Your Visual Expressions with PageOn.ai

Ready to take your diagram creation to the next level? PageOn.ai's powerful visualization tools work seamlessly with ChatGPT to help you create stunning, accurate diagrams that communicate complex ideas clearly.

Start Creating with PageOn.ai Today

Conclusion: The Future of Automated Diagram Creation

Throughout this guide, I've shared my experience and techniques for mastering ChatGPT prompts to generate Mermaid diagrams. From understanding the basics to implementing advanced customizations and workflows, these methods can dramatically improve your technical documentation and communication.

The combination of natural language processing and diagram generation represents a significant shift in how we approach technical visualization. As AI models continue to improve, I expect even more sophisticated diagram generation capabilities to emerge.

By integrating PageOn.ai's visual thinking tools with ChatGPT's code generation capabilities, you can create a powerful workflow that transforms complex ideas into clear, compelling diagrams. This approach not only saves time but also improves the quality and consistency of your visual communication.

Back to top