iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
📊

Streamline Diagramming with Markdown & AI: A Collection of Copy-Paste Mermaid Prompts

に公開2件

Introduction

While creating documentation, I sometimes think, "It might be easier to understand if I had a diagram...", but drawing diagrams is really tedious, isn't it? (Or is it just me?)

Opening a drawing tool, placing boxes, drawing lines, adjusting positions... before you know it, "I've spent 30 minutes just making a diagram!" 😫

For such tiresome tasks, you'd want to leave it to someone else and focus on other tasks, wouldn't you?

By simply telling Chat AIs you use for development, such as GitHub Copilot, Cursor, ClaudeCode, or Gemini CLI, "I want a diagram like this," Mermaid diagrams are generated in a flash. Creating diagrams in Mermaid syntax yourself can be quite difficult, but leaving it to AI gets the diagram finished in no time.

Even for me, who isn't great at documentation, I've recently started to enjoy creating documentation, so I wrote this article hoping it would be helpful for others with similar struggles! ✨

https://mermaid.js.org/

What is Mermaid?

Mermaid is a tool that allows you to draw diagrams using text.

With regular drawing software, you need to click around with a mouse to place shapes and draw lines, but with Mermaid, the diagram is complete just by writing text!

For example, if you write it like this...

graph TD
    A[Start] --> B[Process] --> C[End]

This diagram is created!

Benefits of Mermaid

✨ Manageable via code: Can be version-controlled with Git
✨ Lightweight: No image files required, can be embedded directly into Markdown
✨ Easy to modify: Diagrams can be updated just by changing the text

Where can it be used?

  • GitHub: Diagrams can be displayed in READMEs and Issues
  • Zenn, Qiita: Diagrams can be displayed within articles
  • Notion, Obsidian: Can be embedded into notes and documents

Setting up an environment for writing Mermaid

If you use editors like Visual Studio Code or Cursor, you can enable previews by installing an extension. The Markdown Preview Mermaid Support extension is, in my opinion, the simplest and easiest to use.

  1. Search for and install the "Markdown Preview Mermaid Support" extension.
  2. Open an .md file, then press Cmd + Shift + V (Mac) / Ctrl + Shift + V (Win) or click the preview button in the top right.
  3. The Mermaid diagram will be displayed in the preview.

Editing the .md file will update the preview.

https://marketplace.visualstudio.com/items?itemName=bierner.markdown-mermaid

Types of diagrams you can create

1. Flowchart

Final image

Prompt example

Create a flowchart in Mermaid for a web application troubleshooting process.
Start point: Problem Occurs
Decision point: Cause Analysis (three branches: Code, Environment, Data)
End point: Problem Resolved
Include a loop back to the start in case of failure.

Output example

```mermaid
flowchart TD
    A[Problem Occurs] --> B{Cause Analysis}
    B -->|Code| C[Debug Execution]
    B -->|Environment| D[Check Settings]
    B -->|Data| E[Check Logs]
    C --> F[Fix Implementation]
    D --> F
    E --> F
    F --> G[Run Test]
    G --> H{Result OK?}
    H -->|Yes| I[Complete]
    H -->|No| A
```

2. Sequence Diagram

Final image

Prompt example

Create a sequence diagram in Mermaid for a user login system.
Participants: User, Frontend, API, Database
Flow: Login request -> Authentication -> DB check -> Token issuance -> Success response

Output example

```mermaid
sequenceDiagram
    participant U as User
    participant F as Frontend
    participant A as API
    participant D as Database
    
    U->>F: Login request
    F->>A: Authentication request
    A->>D: Get user info
    D-->>A: User data
    A-->>F: JWT token
    F-->>U: Login success
```

3. Gantt Chart

Final image

Prompt example

Create a Gantt chart in Mermaid for a 3-month web app development project.
Phases: Design (Requirements, UI/UX), Development (Frontend, Backend), Testing (Unit, Integration)
Period: July - September 2025
Include dependencies.

Output example

```mermaid
gantt
    title Web App Development Schedule
    dateFormat  YYYY-MM-DD
    section Design
    Requirements Definition           :done, req, 2025-07-01, 2025-07-15
    UI/UX Design         :done, design, after req, 10d
    section Development
    Frontend Development  :active, frontend, 2025-07-25, 25d
    Backend Development    :backend, 2025-07-30, 20d
    section Testing
    Unit Testing         :testing, after frontend, 5d
    Integration Testing         :integration, after backend, 5d
```

4. Class Diagram

Final image

Prompt example

Create a class diagram in Mermaid for an e-commerce site's product class.
Parent class: Product
Child classes: Book, Electronics
Include inheritance relationships, and include unique properties and methods for each child class.

Output example

```mermaid
classDiagram
    Product <|-- Book
    Product <|-- Electronics

    class Product {
        +int id
        +string name
        +float price
        +getDetails()
    }

    class Book {
        +string author
        +string ISBN
        +getSummary()
    }

    class Electronics {
        +string brand
        +int warrantyMonths
        +getWarrantyInfo()
    }
```

5. State Diagram

Final image

Prompt example

Create a state diagram in Mermaid for a user authentication system.
States: Not logged in, Logging in, Logged in, Session expired
Transitions: Login attempt, Authentication success/failure, Logout, Timeout

Output example

```mermaid
stateDiagram-v2
    [*] --> 未ログイン
    未ログイン --> ログイン中 : ログイン試行
    ログイン中 --> ログイン済み : 認証成功
    ログイン中 --> 未ログイン : 認証失敗
    ログイン済み --> 未ログイン : ログアウト
    ログイン済み --> セッション期限切れ : タイムアウト
    セッション期限切れ --> 未ログイン : 自動ログアウト
```

6. ER Diagram

Final image

Prompt example

Create an ER diagram for an e-commerce site database in Mermaid.
Tables: Customer, Order, Product, OrderItem
Relationships: A customer places multiple orders, an order contains multiple items; please include many-to-many relationships.

Output example

```mermaid
erDiagram
    CUSTOMER ||--o{ ORDER : places
    ORDER ||--|{ ORDER-ITEM : contains
    PRODUCT ||--o{ ORDER-ITEM : "ordered in"
    
    CUSTOMER {
        string customer_id
        string name
        string email
    }
    ORDER {
        string order_id
        string customer_id
        date order_date
    }
    PRODUCT {
        string product_id
        string name
        float price
    }
```

7. Mind Map

Final image

Prompt example

Create a mind map of the tech stack required for Web development in Mermaid.
Center: Web Development
Categories: Frontend, Backend, Database
Please organize major technologies and frameworks hierarchically under each category.

Output example

```mermaid
mindmap
  root((Web Development))
    Frontend
      React
        Components
        Hooks
      Vue.js
        Composition API
        Vuex
    Backend
      Node.js
        Express
        NestJS
      PHP
        Laravel
        Symfony
    Database
      MySQL
      PostgreSQL
      MongoDB
```

8. Pie Chart

Final image

Prompt example

Create a pie chart showing the time allocation for a software development project.
Items: Coding (40%), Debugging (25%), Design (20%), Testing (10%), Documentation (5%)

Output example

```mermaid
pie title Allocation of Development Time
    "Coding" : 40
    "Debugging" : 25
    "Design" : 20
    "Testing" : 10
    "Documentation" : 5
```

Modifying Created Diagrams

When you want to change something after creating a diagram, let the AI handle the modifications as well.

Steps

  1. Select the code range of mermaid …
  2. Send the modification details via a prompt

How to select

  • GitHub Copilot (Visual Studio Code): Select range → Cmd + I (Mac) / Ctrl + I (Win)
  • Cursor: Select range → Cmd + L (Mac) / Ctrl + L (Win)
  • ClaudeCode: Copy range → Paste normally
  • Gemini CLI: Copy range → Paste normally

Prompt example

Please add a failed authentication attempt limit and account lock feature.
If it fails 3 times, it should go into an account locked state and require manual unlocking by an administrator.

Before modification

After modification

Changes

stateDiagram-v2
    [*] --> 未ログイン
    未ログイン --> ログイン中 : ログイン試行
    ログイン中 --> ログイン済み : 認証成功
-   ログイン中 --> 未ログイン : 認証失敗
+   ログイン中 --> 認証失敗1回 : 1回目失敗
+   ログイン中 --> 認証失敗2回 : 2回目失敗
+   ログイン中 --> アカウントロック : 3回目失敗
+   認証失敗1回 --> ログイン中 : 再試行
+   認証失敗2回 --> ログイン中 : 再試行
+   認証失敗1回 --> ログイン済み : 認証成功
+   認証失敗2回 --> ログイン済み : 認証成功
+   アカウントロック --> 未ログイン : 管理者解除
    ログイン済み --> 未ログイン : ログアウト
    ログイン済み --> セッション期限切れ : タイムアウト
    セッション期限切れ --> 未ログイン : 自動ログアウト

As shown above, by telling the AI the modification details, you can easily update your diagrams.

Conclusion

Diagramming used to be a time-consuming task, but being able to generate Mermaid diagrams instantly just by feeding prompts to an AI is truly convenient!

The time that used to take 30 minutes to draw a diagram can now be completed in just a few seconds by leaving it to AI. The biggest benefit is being able to concentrate on other important tasks with the saved time!

Furthermore, since modifications can also be handled with natural language, I feel that the barrier to entry for creating documentation has lowered significantly.

I encourage you all to try this with the AI tools you use daily. It will surely make documentation creation enjoyable!

AUN Tech Blog

Discussion

せとぅせとぅ

Mermaidでこのレベルのガントチャートが作れるのですね!
初めて知りました。わかりやすいまとめありがとうございます。

1