Interactive Mermaid Diagrams Integration Guide

Last updated on May 29, 2026 12:45

Introduction

In modern technical documentation and web publishing, a picture is worth a thousand lines of text. Visualizing complex workflows, system architectures, and lifecycle states helps readers digest technical details rapidly.

Rather than relying on heavy, non-searchable static image files or slow third-party CDNs that increase page latency and degrade privacy, PolyCMS integrates a native Self-Hosted Mermaid.js rendering pipeline. This guide covers how diagrams are compiled dynamically, introduces the interactive visual TipTap editor element, and demonstrates four chart examples ranging from simple flows to the overall architecture of PolyCMS.


Technical Architecture & Self-Hosted Strategy

PolyCMS is built for speed and absolute sovereignty. The core renderer parses raw block elements dynamically. When a block is marked as a diagram:

  1. Parser Detection: The PHP dynamic engine (helpers.php) scans for standard Markdown blocks starting with <pre><code class="language-mermaid">.
  2. Safe Entity Decoding: It decodes HTML entities safely (e.g. converting --&gt; back to the raw parser-ready --> syntax).
  3. Offline Assets: Instead of requesting jsDelivr or cdnjs, PolyCMS resolves the script locally via the Laravel asset('assets/vendor/mermaid-10.x/mermaid.min.js') helper.
  4. Vercel-Inspired Theme Variables: Both the admin visual editor and public frontend render the diagrams with custom Vercel-like base variables, delivering high-contrast, clean minimalist aesthetics in both Light and Dark modes.

Diagram Presets & Examples

Below are four classic diagram implementations running natively in PolyCMS.

1. Simple Flowchart: User Authentication Lifecycle (Horizontal - LR)

A simple left-to-right flow chart displaying how standard client-side inputs are parsed and authenticated by the session guard.

graph LR A[Enter Credentials] --> B{Is Fields Empty?} B -->|Yes| C[Show Validation Error] B -->|No| D[Authenticate via Sanctum] D --> E{Success?} E -->|Yes| F[Redirect to Admin Panel] E -->|No| G[Show Bad Credentials]

2. State Diagram: E-Commerce Transaction Lifecycle (StateDiagram-v2)

A state diagram depicting the possible state transitions of an online purchase transaction through PayPal or SePay payment gateways.

stateDiagram-v2 [*] --> New New --> Pending : Customer Checkouts Pending --> Completed : Payment Confirmed Pending --> Failed : Payment Timeout / Failed Failed --> Pending : Customer Retries Completed --> [*]

3. Intermediate Sequence Diagram: Secure REST API Request Flow

A sequence diagram showcasing the secure back-and-forth interactions between a Customer, the Web Client, the API Gateway, and the Database to serve token-authenticated content.

sequenceDiagram participant User as Developer or User participant App as API Client participant Auth as API Gateway participant DB as Core Database User->>App: Send API request with Bearer Token App->>Auth: GET /api/v1/posts (Auth Header) Auth->>Auth: Validate token signature & scopes Auth->>DB: Query posts (filtered by taxonomy) DB-->>Auth: Eloquent collection retrieved Auth-->>App: JSON Response (200 OK + Data) App-->>User: Present formatted data array

PolyCMS Core Architectural Workflow (Complex - TD)

To demonstrate a complex vertical layout, here is the complete technical architectural pipeline of PolyCMS. It outlines how a post travels from the Database, passes through the dynamic block compiler, parses the shortcode/Mermaid tags, applies WordPress-inspired hook/filter hooks, and finally outputs premium Vercel-styled HTML views.

graph TD %% Define Node Shapes DB[(MySQL or PostgreSQL Database)] Engine[ContentRenderer Core Engine] JsonParser{Parse block JSON content_raw?} HtmlFallback[Fallback to content_html] TiptapParse[TipTap NodeView Reconstitution] Helper[app/helpers.php Processing Pipeline] HookAction[Phase 1: Filter content.render.html] ModalOverlay[Phase 2: Extract Modal Links & YT Sliders] MermaidParse[Phase 3: Decode Mermaid Graph syntax] AssetLoader[Inject Dynamic Self-Hosted Assets] VercelTheme[Apply Premium Vercel CSS themeVariables] FinalView[Final Web View Rendered HTML] %% Flow lines DB -->|Fetch post payload| Engine Engine --> JsonParser JsonParser -->|Yes - Not Null| TiptapParse JsonParser -->|No - Null| HtmlFallback TiptapParse --> Helper HtmlFallback --> Helper Helper --> HookAction HookAction --> ModalOverlay ModalOverlay --> MermaidParse MermaidParse --> AssetLoader AssetLoader --> VercelTheme VercelTheme --> FinalView %% Style highlights style DB fill:#0a0a0a,stroke:#333333,stroke-width:2px,color:#ffffff style Engine fill:#000000,stroke:#333333,stroke-width:2px,color:#ffffff style Helper fill:#000000,stroke:#10b981,stroke-width:2px,color:#ffffff style FinalView fill:#111111,stroke:#10b981,stroke-width:3px,color:#ffffff

Interactive TipTap Diagram Block Editor

As an author in the PolyCMS Admin Panel, you do not need to memorise Mermaid syntax to create these beautiful graphics. In the block editor:

  1. Click the Mermaid Diagram button on the editor toolbar.
  2. An elegant visual container will instantly render inline.
  3. Switch to the Edit Code tab to write syntax with helper buttons (--> Arrow, [Node], {Decision}).
  4. Use the Templates dropdown to instantly load standard presets (Flowcharts, Sequences, States) and modify them on the fly.
  5. If your syntax is incorrect, the built-in compiler highlights the line and shows a helpful error banner without interrupting your drafting process!

PolyCMS is an open-source content management system for modern web applications, inspired by the WordPress plugin and theme ecosystem but built on top of the Laravel framework. It is designed to provide a complete foundation for content publishing, e-commerce, multi-language support, and extensible module architecture — powered by a Vue 3 admin panel with data served entirely through RESTful APIs.

Whether you're building a blog, a documentation site, an online store, or a multi-tenant SaaS platform, PolyCMS aims to give you a comprehensive starting scaffold so you can ship quickly and extend easily through integrated modules and themes. In particular, themes in PolyCMS follow a multi-theme architecture — one Main theme and an unlimited number of Sub themes can run side by side on the same installation.

We hope this ready-made foundation proves useful for building your next website, blog, or web app, saving you from having to start completely from scratch.