Guide

Mermaid Tutorial: Flowchart & Sequence Diagram

Build your first Mermaid flowchart and sequence diagram, preview the source, fix syntax errors and choose an image format for your document.

Pele Editor guide · Published

Start with one question

A useful diagram answers one question: what happens after a request arrives, which components communicate, or who owns a record. Name the start and end before adding detail. Keep the source beside the document it explains.

Write a small flow

Begin with a direction, two nodes and an arrow. Square brackets create process steps; braces create a decision. Use short identifiers in the source and human-readable labels on the diagram.

flowchart LR
  A[Receive request] --> B{Valid?}
  B -->|Yes| C[Process]
  B -->|No| D[Explain error]
YesNoReceive requestValid?ProcessExplain error

Describe a conversation

Sequence diagrams put participants across the page and messages in time order. Use solid arrows for requests and dashed arrows for responses. An alt block makes alternate paths explicit.

sequenceDiagram
  participant App
  participant API
  App->>API: Request
  API-->>App: Response
RequestResponseAppAPIAppAPI

Review and export

Check the preview after each change. Choose a light or dark diagram theme and export SVG for scalable documentation or PNG for a fixed image. The export includes the complete diagram, even when the preview is zoomed. Save the .mmd source so the diagram remains editable.

Separate identifiers from labels

Use a short identifier such as A for a node and a descriptive label such as Receive request for the reader. Reusing A later refers to the same node. This makes source edits easier to follow than inventing a new identifier whenever a sentence changes. Keep one declaration at the top of the source so the renderer knows which diagram grammar to use.

flowchart TD
  Request[Receive request] --> Check{Required fields present?}
  Check -->|Yes| Save[Save record]
  Check -->|No| Explain[Explain missing fields]
YesNoReceive requestRequired fields present?Save recordExplain missing fields

Debug one change at a time

Begin with a small working diagram. Add a node or message, check the preview, and only then add another structural change. When a parse error appears, inspect the last edit for missing brackets, quotes, or a block ending. Reducing the input to the smallest failing example is often faster than trying several unrelated syntax changes at once.

Choose the handoff your reader needs

Share source when the recipient needs to edit the model, and export an image when the document needs a fixed visual result. A host that accepts Mermaid syntax still controls its own renderer and version. Preview the source in the final destination, especially when using newer diagram types or styling. Keep the editable source next to exported assets so a later correction does not require reconstructing the diagram from an image.

Choose the handoff your reader needs
NeedStarting point
A decision processFlowchart
A conversation between servicesSequence diagram
Entities and their data relationshipsER diagram
A lifecycle with allowed transitionsState diagram
Try it in the editor ↗