HashiQube - DevOps Lab
Youtube Channel Medium Posts Riaan Nolan Linkedin Riaan Nolan Hashicorp Ambassador

.

Mermaid

Create diagrams and visualizations using text and code

🚀 Introduction

Mermaid is a JavaScript-based diagramming and charting tool that renders Markdown-inspired text definitions to create and modify diagrams dynamically. It allows you to generate diagrams, flowcharts, and visualizations using simple text syntax, similar to how Markdown works for text formatting.

🛠️ Mermaid Live Editor

You can experiment with Mermaid using the Mermaid Live Editor, which provides real-time preview of your diagrams.

📊 Diagram Examples

Mermaid supports various diagram types. Here are some examples:

State Diagrams

Basic State Diagram

secondthirdThirdSecondFirst

Keyboard State Diagram

NumLockOffNumLockOnCapsLockOffCapsLockOnScrollLockOffScrollLockOnEvNumLockPressedEvNumLockPressedEvCapsLockPressedEvCapsLockPressedEvCapsLockPressedEvCapsLockPressedActive

Sequence Diagrams

Sequence diagrams show how processes operate with one another and in what order.

AliceBobJohnHello Bob, how are you?How about you John?I am good thanks!I am good thanks!Bob thinks a longlong time, so longthat the text doesnot fit on a row.Checking with John...Yes... John, how are you?AliceBobJohn

Pie Charts

Pie charts are useful for representing categorical data.

4%6%90%What Voldemort doesn't have?FRIENDSFAMILYNOSE

Gantt Charts

Gantt charts are useful for project planning and scheduling.

2014-01-072014-01-092014-01-112014-01-132014-01-152014-01-172014-01-192014-01-212014-01-23Completed task Active task Future task Future task2 A sectionAdding GANTT diagram to mermaid

Git Graphs

Git graphs show git branching and merging operations.

master, 8d2a7ab

3db3c28

845a7cd

a333bf9

newbranch, 42bb49b

f60b503

Flowcharts

Flowcharts can represent workflows or processes.

Minor Version
Packer Build
Major Version
Ansible
A9
A9
A4
A72
A4
Azure
OS Vendor
Pen Testing
QA Test
Security Updates
Configuration
Testing
Packer
More
SOE Image Repository

🧩 Diagram Syntax

Basic Syntax Structure

Each diagram type in Mermaid has its own specific syntax, but they all follow a similar pattern:

  1. Start with the diagram type (e.g., graph, sequenceDiagram, gantt)
  2. Follow with the diagram-specific syntax
  3. Wrap in a code block with either:
    • Plain code blocks: </code> and <code>
    • Mermaid code blocks: mermaid</code> and <code>

Common Diagram Types and Their Starting Keywords

  • Flowcharts: graph or flowchart
  • Sequence Diagrams: sequenceDiagram
  • Class Diagrams: classDiagram
  • State Diagrams: stateDiagram
  • Entity Relationship Diagrams: erDiagram
  • User Journey: journey
  • Gantt Charts: gantt
  • Pie Charts: pie
  • Git Graphs: gitGraph

📚 Resources

🔧 Integration

Mermaid can be integrated into various platforms:

  • Markdown: Many Markdown processors support Mermaid
  • Documentation Tools: Like Docusaurus, VuePress, and Jekyll
  • Note-taking Apps: Like Obsidian and Notion
  • Online Editors: Like CodiMD and HackMD
  • Version Control: GitHub, GitLab, and Bitbucket support Mermaid in Markdown

💡 Tips for Using Mermaid

  1. Start Simple: Begin with basic diagrams and gradually add complexity
  2. Use the Live Editor: Test your diagrams in the live editor before embedding them
  3. Check Syntax: Mermaid is sensitive to syntax; ensure proper spacing and indentation
  4. Customize Appearance: Use styling options to enhance your diagrams
  5. Responsive Design: Consider how your diagrams will appear on different screen sizes