All posts
MermaidGitHub IntegrationPull RequestsAutomationDocumentation

Mermaid in pull requests: automated diagram comments

6 min readThe MermaidCreator team

Pull requests are where code review happens, but reviewers often lack architectural context: they see a diff but not the system impact. Adding a Mermaid diagram to the PR comment—automatically—gives reviewers the big picture instantly, reduces back-and-forth, and documents the change forever.

Why diagrams belong in pull requests

A diff shows what changed. A diagram shows why it matters. When a reviewer sees a new API endpoint, a database migration, or a microservice boundary shift, a well-placed flowchart or architecture diagram answers the questions that code alone can't:

  • Impact scope — which systems touch this change?
  • Flow changes — does request routing shift?
  • Data model shifts — what does the new schema enable?
  • Integration points — who calls the new code?

Adding diagrams to PR comments:

  • Saves synchronous discussion — reviewers don't ask "what's the architecture here?"
  • Builds institutional memory — merged PRs with diagrams become searchable, reusable docs
  • Prevents regressions — the diagram serves as the golden source for how the system should look
  • Scales teams — new contributors see the full context, not just the delta

Automating diagrams in GitHub

Most teams generate PR diagrams by hand—a screenshot, a manual Mermaid block, or worse, nothing at all. Automation changes the math: once set up, every PR gets a diagram with zero extra work.

GitHub Apps and Actions can:

  1. Detect diagram files in the PR (e.g., files matching *.diagram.mmd)
  2. Render them to images (PNG/SVG)
  3. Post a comment with the diagram, diff links, and a summary

MermaidCreator includes GitHub integration—your team can configure it to auto-generate architecture diagrams from a repository and post them to PRs. Here's how that flow works:

graph LR
    A["PR opened (files changed)"]
    B["GitHub App receives webhook"]
    C["Extract changed files"]
    D["Generate architecture diagram"]
    E["Render to PNG"]
    F["Post PR comment with diagram"]
    G["Reviewer sees context instantly"]
    
    A --> B
    B --> C
    C --> D
    D --> E
    E --> F
    F --> G

Pattern: Embedded diagram blocks

The simplest pattern is to commit Mermaid diagrams alongside your code and let an Action render them on every PR:

src/
  architecture/
    system-flow.mmd
    api-routes.mmd
    database-schema.mmd

A GitHub Action watches for changes to .mmd files and posts rendered images:

✅ Architecture diagrams updated
- system-flow.mmd → [rendered image]
- api-routes.mmd → [rendered image]

Best for: teams already versioning diagrams in git. Keeps the source next to the code, and the comment is generated, not manual.

Pattern: Change-triggered diagrams

For larger teams, generate a diagram only when specific files change. For example, when src/api/** changes, generate an API flow diagram:

sequence diagram
    Client->>API Gateway: POST /orders
    API Gateway->>Auth Service: validate token
    Auth Service-->>API Gateway: valid
    API Gateway->>Order Service: create order
    Order Service->>Database: insert
    Database-->>Order Service: id
    Order Service-->>API Gateway: response
    API Gateway-->>Client: 200 OK

This diagram appears only on PRs touching the API, so reviewers see exactly what changed in context—no noise, no manual refresh.

Pattern: Release notes with diagrams

When a PR merges, extract all its diagrams into a release note template:

## What changed
- New order queue system
- API latency reduced 40%

## Architecture impact
[diagram: order-service-refactor.mmd]

## Reviewers
@alice @bob @charlie

Archive these as team documentation. Over time, you build a visual changelog of how your system evolved.

Workflow: GitHub App + MermaidCreator

If you've connected MermaidCreator to your GitHub account, here's the end-to-end flow:

  1. Push a branch with changes to src/api/ or src/database/
  2. Open a PR — the GitHub App detects the change
  3. MermaidCreator generates an architecture diagram summarizing the diff
  4. Auto-comment posts the diagram to the PR with impact summary
  5. Reviewers see context instantly — they can approve faster and with confidence

This requires:

  • The MermaidCreator GitHub App installed on your repo
  • A DiagramOps plan (GitHub integration is a team feature)
  • Optional: a .mermaidcreator.yml config file in your repo to customize what diagrams are generated

Best practices for PR diagrams

Keep them focused

A diagram in a PR comment should answer one question: "What's the architectural change here?" Long, complex diagrams overwhelm reviewers. If your change spans multiple systems, create separate diagrams per system or per change type (data flow, API endpoints, etc.).

Good: a 3-node flowchart showing the new webhook flow
Bad: a 20-node diagram of the entire system

Label with context

Include a short summary above the diagram:

## Architecture change: Order service split
This PR extracts order fulfillment into a new microservice.
The new service is async and communicates via Kafka.

[diagram]

Version your diagrams

Commit the Mermaid source to git alongside your code:

src/
  diagrams/
    order-service-refactor.mmd  # Versioned, reviewable

This makes the diagram part of the PR and lets reviewers suggest changes (e.g., "move this box to the right").

Link to the merged PR

After merge, add the PR diagram to your internal docs with a link back to the PR:

**Source:** [PR #1234](https://github.com/your-repo/pull/1234)

This creates a two-way link between code history and architecture docs.

Common use cases

Change TypeDiagram TypeExample
New API endpointSequence diagramClient → Gateway → Auth → Service → DB
Database migrationER diagramOld schema side-by-side with new schema
Microservice splitArchitecture diagramBefore/after system boundaries
Async jobFlowchart + SequenceQueue → Worker → Callback
Cache layerBlock diagramRequest path with cache hit/miss

FAQ

Can I customize which files trigger a diagram?
Yes. If you're using MermaidCreator's GitHub App, create a .mermaidcreator.yml in your repo to specify which file patterns trigger auto-generation (e.g., only when src/api/** or src/db/** changes).

Do diagrams show up on every PR or only when certain files change?
Both patterns exist. Some teams auto-generate on every PR; others gate it to specific file patterns (API, database, services) to reduce noise.

How long does it take to render a diagram?
Most diagrams render in under 1 second. Complex diagrams (>50 nodes) may take 2–3 seconds, but the comment still posts within the webhook window.

Can reviewers suggest diagram changes?
Yes. Reviewers can suggest changes to the diagram Mermaid source (if it's committed), and the PR author can update it. Or they can comment on the rendered image.

Start adding diagrams to your PR workflow today. Try the MermaidCreator editor to draft your first architecture diagram, then commit it to git and set up a GitHub Action to render it on your next PR.

Related posts