If you've ever tried to review someone's diagram in a pull request or wanted to leave structured feedback on a flowchart, you know how frustrating it can be when the diagram is just an image file. You can't easily spot errors, suggest changes, or track revisions. That's where Mermaid diagram code syntax for reviews becomes genuinely useful. Mermaid lets you write diagrams as plain text code, which means reviewers can read, comment on, and version-control diagrams the same way they handle source code. This changes how teams collaborate on visual documentation.
What Is Mermaid Diagram Code Syntax?
Mermaid is a JavaScript-based diagramming tool that renders diagrams from a text-based syntax. Instead of dragging shapes in a GUI editor, you write simple code that describes your diagram's structure. A flowchart, sequence diagram, Gantt chart, or class diagram can all be defined in a few lines of readable text.
For example, a basic flowchart looks like this:
graph TD
A[Start] --> B{Decision}
B -->|Yes| C[Action 1]
B -->|No| D[Action 2]
When rendered, this produces a top-down flowchart with a decision node and two outcomes. The syntax is close enough to pseudocode that most developers can understand it without training.
Why Do Teams Use Mermaid Syntax Specifically for Reviews?
The main reason teams adopt Mermaid for review workflows is that text-based diagrams fit naturally into code review processes. When a diagram lives in a .md or .mmd file inside a Git repository, reviewers can:
- Comment on specific lines of diagram code during pull request reviews
- Track changes over time with standard Git diff and blame
- Suggest corrections by proposing line-level edits, just like with any other file
- Avoid binary file headaches that come with reviewing PNG or SVG exports
This matters in architecture reviews, API flow discussions, onboarding documentation audits, and any process where accuracy in diagrams directly affects team understanding. If you're evaluating how well different tools handle code-based diagramming, our comparison of Mermaid diagram syntax across diagramming tools covers this in more depth.
What Does the Core Syntax Actually Look Like?
Mermaid supports several diagram types, each with its own keyword to start the block. Here are the most commonly used ones in review contexts:
Flowcharts
Use graph or flowchart as the opening keyword. Directions include TD (top-down), LR (left-right), and RL. Shapes are defined by bracket style: [] for rectangles, {} for diamonds, (()) for circles, and [[]] for subroutines.
Sequence Diagrams
These show interactions between actors over time. The syntax uses sequenceDiagram as the keyword, with ->> for arrows between participants. Alt blocks, loops, and notes make these popular for API and service interaction reviews.
Class Diagrams
Defined with classDiagram, these use UML-like notation to show classes, attributes, methods, and relationships. Arrows like -->, --|>, and -- express association, inheritance, and composition. Teams doing object-oriented design reviews rely on these heavily. If your review work extends into broader UML territory, our guide on UML diagram code for system reviews covers syntax patterns across multiple UML diagram types.
State Diagrams
Use stateDiagram-v2 to define state machines. States and transitions are written plainly: Idle --> Processing : submit. These are useful for reviewing workflow logic, especially in backend systems and protocol designs.
Gantt Charts and ER Diagrams
gantt diagrams use a date-based syntax for project timelines. erDiagram defines entity-relationship models with a simple card notation. Both are less common in code reviews but useful for project planning and database design reviews respectively.
How Do You Review Mermaid Diagrams in a Pull Request?
The review process for Mermaid code follows the same pattern as reviewing any text file in a repository:
- The author commits a
.mdor.mmdfile containing the Mermaid syntax. - The reviewer opens the pull request and reads the diff. Changed nodes, arrows, and labels show up as line changes.
- Comments are left on specific lines. For example: "This arrow should point to the error handler, not the success path."
- The author updates the code, commits again, and the reviewer confirms the rendered output looks correct.
- Rendered preview is checked either in GitHub/GitLab's built-in Mermaid rendering or in an external previewer.
GitHub renders Mermaid blocks inside Markdown files natively, so reviewers can see both the raw code and the visual output without leaving the platform.
What Are Common Mistakes When Writing Mermaid for Reviews?
Teams new to code-based diagramming often hit the same issues:
- Missing or wrong indentation inside nested blocks like
subgraphoralt/loopin sequence diagrams. Mermaid is sensitive to whitespace in certain contexts. - Special characters in labels. Characters like parentheses, pipes, and quotes inside node labels need to be wrapped in quotes:
A["Label with (parens)"]. - Arrow syntax confusion. Using
-->where---oor--xis needed, or mixing up solid and dotted lines for different relationship types in class diagrams. - Overly long diagrams that try to capture an entire system in one file. These become hard to review and hard to render. Breaking large diagrams into focused, smaller files improves both review quality and readability.
- No preview check before submitting. A diagram that parses correctly in syntax may render with overlapping labels or misaligned nodes. Always preview before requesting a review.
How Do You Test That Mermaid Code Actually Renders Correctly?
Checking that your Mermaid syntax is valid and renders as expected is a key part of the review workflow. You can use the official Mermaid Live Editor to paste code and get an instant preview. For automated checks, some CI pipelines use the Mermaid CLI to render diagrams to SVG and fail the build if parsing errors occur.
Accuracy in rendering matters for reviews because a diagram that looks wrong can lead to incorrect feedback. If your team needs to validate that diagrams match intended structures, our article on diagram code generation accuracy testing covers approaches for catching rendering issues before they reach reviewers.
What Tips Help When Reviewing Mermaid Diagrams as a Team?
A few practices make team-based diagram reviews smoother:
- Keep one diagram per file with a descriptive filename like
payment-flow.mmdoruser-auth-sequence.md. - Add a comment block at the top of the file explaining what the diagram covers, who maintains it, and when it was last updated.
- Use subgraphs in flowcharts to group related logic visually. This also makes it easier to comment on sections during reviews.
- Establish a style guide for your team: arrow types, naming conventions for nodes, color themes. Consistency reduces review friction.
- Link diagrams to specs. If a sequence diagram represents an API contract, link to the OpenAPI spec or requirement doc in a comment above the diagram code.
- Version your diagrams alongside the code they describe. A diagram in a separate, unrelated repository will drift out of date fast.
Should You Review Diagrams Manually or Automate the Process?
For small teams with a few diagrams, manual review in pull requests works fine. The reviewer reads the code, checks the preview, and leaves comments. For larger teams or organizations with dozens of diagrams across multiple services, automation adds real value.
Automated approaches include:
- CI rendering checks that generate SVGs from Mermaid code and compare them against a baseline
- Syntax linting with custom rules for naming conventions and structure
- Automated diff images that show visual before/after comparisons in pull request comments
The right approach depends on how many diagrams your team maintains and how often they change.
Practical Checklist Before Submitting Mermaid Diagrams for Review
- Paste your code into Mermaid Live Editor and confirm it renders without errors
- Check that all labels are readable and nothing overlaps in the rendered output
- Verify arrow directions and types match the actual relationship or flow you intend
- Wrap any label containing special characters in double quotes
- Use descriptive node names, not generic ones like "A" and "B," unless the diagram is trivial
- Add a title or comment block explaining the diagram's purpose
- Commit the file alongside related code changes so the reviewer sees context
- If the diagram is large, split it into smaller files grouped by function or module
Diagram Codes Explained: Diagramming Tool Reviews Guide
Top Diagram Tools for Software Architecture Review Diagrams and Code Mapping
Top Diagramming Tools for Code Generation Accuracy Tested and Compared
Keyword: Uml Diagram Code for System Reviews
C4 Model Architecture Diagram Notation Explained Simply
Uml Sequence Diagram Notation Explained: Symbols and Syntax Guide