jonaspardon/mermaid-php
Generate Mermaid diagrams from PHP with a fluent API. Build flowcharts, sequence diagrams, and more as strings for docs, dashboards, or Markdown—no JavaScript required.
Package: jonaspardon/mermaid-php — a PHP library that builds Mermaid.js diagram definitions via a fluent, object-oriented API, with optional rendering to image/SVG through the Mermaid CLI (mmdc).
Architecture fit: Reasonable for server-side, deterministic diagram generation where diagrams are derived from application data (ER diagrams from schema introspection, flowcharts from workflow state machines, sequence diagrams from job pipelines, Gantt output for delivery reporting). It fits Laravel cleanly: service provider with package auto-discovery, a facade for the builder, and a publishable config file. It is a poor fit for user-authored or free-form diagrams — that workload belongs in a front-end editor (mermaid.live, Mermaid + a JS bundle), not in PHP.
Integration feasibility: Low-effort to adopt in "syntax generation only" mode — a composer require, auto-discovered provider, and the fluent builder returns a Mermaid string that any renderer (including the front end) can consume. Rendering to PNG/SVG server-side raises the effort: it requires Node.js plus @mermaid-js/mermaid-cli (and therefore Chromium/Puppeteer) in the runtime image or a sidecar container. That dependency, not the package, is the real integration cost.
Technical risk:
--no-sandbox in production) is a security consideration that must be owned explicitly.composer.json constraint widening only or includes Testbench/CI coverage for 11.Key questions:
Stack fit: Laravel 10/11, PHP 8.1+. Composer-installed, auto-discovered provider, optional config publish. No database, queue, or cache requirements of its own — it is a pure library, which is exactly what we want from a dependency of this size.
Migration path: Greenfield — no migration required. If we have ad-hoc Mermaid strings scattered in Blade templates, docs generators, or markdown, treat this as a consolidation opportunity: move those strings behind the package's builder in a single DiagramService, which gives us one place to escape labels and one place to swap the library out later.
Compatibility: v1.0.1 adds Laravel 11 support (contributed PR), which is the entire substance of this release — safe to adopt on 11, and it does not disturb 10. Verify on our matrix: PHP version floor, Laravel 11 Testbench coverage, and that composer update does not drag an unexpected transitive change. Since the constraint widening is the only change, pin ^1.0.1 and let CI prove it.
Sequencing:
Maintenance: Minimal for source-only usage — a composer constraint and a semver-major watch. Rendering adds ongoing ownership: Node LTS, Mermaid CLI, and Chromium patching on our cadence, independent of the package's. Budget that as a standing line item, not a one-off setup cost.
Support: Community-only. GitHub issues, no SLA, no commercial backing. Acceptable for internal tooling and documentation output; not acceptable as a hard dependency of a revenue-path feature without the internal abstraction layer described above.
Scaling: Source generation is pure CPU-cheap string building — negligible. Rendering is the bottleneck: headless Chromium is memory-hungry (~hundreds of MB per process) and slow (seconds per diagram, worse on cold start). Required posture: render asynchronously on a queue with a dedicated pool, cache aggressively by hash(mermaid_source + mermaid_version + theme), cap concurrent renderers, and never render inline in a web request.
Failure modes:
mmdc binary or Chromium missing/misconfigured → runtime exception; fails at deploy, not at build, unless we smoke-test it in CI.Ramp-up: Low. The fluent builder is discoverable and the mental model is just Mermaid syntax, which most engineers already recognise from Markdown tooling — roughly half a day to productive for a mid-level PHP developer, with the real learning curve being diagram design (which diagram type for which question), not the API. Document one internal example per diagram type and the escaping rule; that is enough. The rendering infrastructure, if adopted, is a separate and much steeper ramp — assign it to whoever already owns container builds.
How can I help you explore Laravel packages today?