Mermaid Entity Relationship Diagram

A prompt that asks an AI to generate Mermaid ER diagram code from a set of classes or database entities, showing their relationships and cardinality.

  • 🤖 ChatGPT, Claude, Gemini
  • 🗂️ Coding

Last verified: write-up checked

Prompt by PickleBoxer · Original source (opens in a new tab)

Mermaid Entity Relationship Diagram — prompt preview

The prompt

prompt
Write the Mermaid code for an entity relationship diagram for these classes [INSERT CLASSES]

What it is

Mermaid Entity Relationship Diagram is a prompt for generating ER diagrams in Mermaid syntax from class definitions or database schemas. When you paste in your data models, the AI produces diagram code that shows entities, their attributes, and the relationships between them with proper cardinality notation. This prompt is particularly useful during the design phase of a project, when you need to visualize how your data models relate to each other, or when documenting an existing database schema. Instead of manually drawing boxes and lines in a diagramming tool, you get renderable text that can live in your repository. The prompt works best when you provide complete class or table definitions including fields and any annotations or decorators that indicate relationships. The AI will infer foreign keys, join tables, and cardinality from the code structure and produce a diagram you can preview in any Mermaid-compatible renderer.

Who it's for

  • Developers
  • Database designers and data modelers

Requirements

Requirements

  • Any AI chatbot (ChatGPT, Claude, Gemini)

برومبت يطلب من الذكاء الاصطناعي كتابة كود Mermaid لمخطط علاقات الكيانات من مجموعة فئات أو جداول قاعدة بيانات.

Examples

From the source

Prompt
prompt
Write the Mermaid code for an entity relationship diagram for these classes [INSERT CLASSES]

Expected output: From PickleBoxer's dev-chatgpt-prompts collection on GitHub.

Pros & cons

Pros

  • Pro:Converts code or schema definitions into a visual diagram without switching to a separate tool
  • Pro:ER diagrams in Mermaid format can be version-controlled alongside the codebase

Cons

  • Con:Very large schemas with many entities may produce diagrams that are difficult to read without manual grouping
  • Con:The AI may infer incorrect relationships if class definitions do not clearly show foreign keys or associations

Tips

  • Paste the actual class definitions or table schemas for accurate relationships and data types
  • Ask the AI to include cardinality notation (one-to-many, many-to-many) for precise modeling
  • Use the output in project documentation or wiki pages that support Mermaid rendering