PHPackages                             power-modules/dependency-graph-mermaid - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. power-modules/dependency-graph-mermaid

ActiveLibrary[Framework](/categories/framework)

power-modules/dependency-graph-mermaid
======================================

Mermaid renderer plugin for power-modules/dependency-graph (flowchart, class diagram, timeline)

v0.1.0(7mo ago)02MITPHPPHP ^8.4CI passing

Since Sep 30Pushed 6mo agoCompare

[ Source](https://github.com/power-modules/dependency-graph-mermaid)[ Packagist](https://packagist.org/packages/power-modules/dependency-graph-mermaid)[ RSS](/packages/power-modules-dependency-graph-mermaid/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (6)Versions (2)Used By (0)

Dependency Graph → Mermaid Renderers
====================================

[](#dependency-graph--mermaid-renderers)

[![CI](https://github.com/power-modules/dependency-graph-mermaid/actions/workflows/php.yml/badge.svg)](https://github.com/power-modules/dependency-graph-mermaid/actions/workflows/php.yml)[![Packagist Version](https://camo.githubusercontent.com/798687d145bdfb830457f1cb9fa7b6c73c5127feca551690be9ccffc9a592a11/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f706f7765722d6d6f64756c65732f646570656e64656e63792d67726170682d6d65726d616964)](https://packagist.org/packages/power-modules/dependency-graph-mermaid)[![PHP Version](https://camo.githubusercontent.com/6c8a824a20f716dbfd2a2aee42f8865c04709b87cafc933293c19c5175136694/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f706f7765722d6d6f64756c65732f646570656e64656e63792d67726170682d6d65726d616964)](https://packagist.org/packages/power-modules/dependency-graph-mermaid)[![License: MIT](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)](LICENSE)[![PHPStan](https://camo.githubusercontent.com/1b02b2f6c2946c9b9ad2e14b1c79c5932fdcef4ea31b4d6e79d54af7d7e7a2a7/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d6c6576656c253230382d626c7565)](#)

Mermaid renderer plugin for power-modules/dependency-graph. It adds three renderers (flowchart, class diagram, timeline) and a module that registers them as plugins for discovery in Modular apps.

- Flowchart: `MermaidGraph` → Mermaid `graph LR`
- Class diagram: `MermaidClassDiagram` → Mermaid `classDiagram` (TB) with YAML frontmatter
- Timeline: `MermaidTimeline` → Mermaid `timeline` grouped by phases and sections

Works great with Mermaid Live and VS Code Mermaid preview.

Requirements
------------

[](#requirements)

- PHP 8.4+
- power-modules/dependency-graph ^0.2
- power-modules/framework ^2.1 (when used inside a Modular app)
- power-modules/plugin ^1.0 (for plugin-based discovery)

Install
-------

[](#install)

```
composer require power-modules/dependency-graph-mermaid
```

Quick start
-----------

[](#quick-start)

You can use the renderers through the Plugin Registry inside a Modular app (recommended) or directly (see examples).

```
use Modular\Framework\App\ModularAppBuilder;
use Modular\DependencyGraph\PowerModule\Setup\DependencyGraphSetup;
use Modular\DependencyGraph\Graph\DependencyGraph;
use Modular\DependencyGraph\Renderer\RendererPluginRegistry;
use Modular\DependencyGraph\Renderer\Mermaid\MermaidRendererModule;
use Modular\Plugin\PowerModule\Setup\PluginRegistrySetup; // from power-modules/plugin

$app = (new ModularAppBuilder(__DIR__))
    ->withModules(
        // your app modules ...
        // required to use renderers:
        \Modular\DependencyGraph\Renderer\RendererModule::class,
        // provides Mermaid renderers to the registry
        \Modular\DependencyGraph\Renderer\Mermaid\MermaidRendererModule::class,
    )
    ->withPowerSetup(
        new DependencyGraphSetup(),
        ...PluginRegistrySetup::withDefaults(), // ensures Plugin Registry is available
    )
    ->build();

$graph = $app->get(DependencyGraph::class);
$registry = $app->get(RendererPluginRegistry::class);

// Create any registered renderer on demand
$renderer = $registry->makePlugin(\Modular\DependencyGraph\Renderer\Mermaid\MermaidClassDiagram::class);
$mermaid = $renderer->render($graph);

file_put_contents(__DIR__ . '/../dependency-graph.mmd', $mermaid);
```

Tip: If you don’t need plugin discovery, you can instantiate the renderer classes directly and call `render()`.

Renderers at a glance
---------------------

[](#renderers-at-a-glance)

All renderers implement `Modular\DependencyGraph\Renderer\Renderer` and return Mermaid text (`.mmd`).

### MermaidGraph (flowchart)

[](#mermaidgraph-flowchart)

- Direction: `graph LR`
- Node label: module short name, optionally “exports:” list
- Edge label: imported service short names (namespace stripped) with truncation
- Styling: marks “independent” (no imports) and “unused” (no inbound edges)
    - Uses `class  independent|unused` per node and a single `classDef` set at the end

Constructor options (defaults shown):

```
new MermaidGraph(
    showExports: true,
    showServices: true,
    maxServiceLength: 50,
)
```

### MermaidClassDiagram

[](#mermaidclassdiagram)

- YAML frontmatter is emitted at the top to hide empty member boxes:
    - `config.class.hideEmptyMembersBox: true`
- Direction: `direction TB`
- Modules rendered as classes; exports appear as public members
- Imports shown as dashed dependencies: `A ..> B : Service1, Service2`
- Stereotypes: `` and `` emitted once per class
- Styling: `class X:::independent|unused` plus `classDef` at the end

Constructor options:

```
new MermaidClassDiagram(
    showExports: true,
    showServices: true,
    maxServiceLength: 50,
)
```

### MermaidTimeline

[](#mermaidtimeline)

- Mermaid `timeline` with optional title
- Modules grouped into phases (0..N) using import prerequisites (Kahn-style layering)
- Sections: Infrastructure and Domain, computed via a lightweight heuristic classifier
- Optional counts in labels: `Name (exports:X, imports:Y)`

Constructor options:

```
new MermaidTimeline(
    title: 'Module initialization timeline',
    showCounts: true,
)
```

Examples
--------

[](#examples)

This repo ships runnable examples and a Makefile to generate diagrams.

- E-commerce app: [ecommerce](examples/ecommerce/mermaid/)
- Synthetic microservices: [microservices](examples/microservices/mermaid/)

Generate example diagrams (flowchart, class diagram, timeline) into `examples/**/mermaid/`:

```
make diagrams
```

You can preview the `.mmd` files with:

- Mermaid Live:
- VS Code: “Markdown Preview Mermaid Support” or native Mermaid support

### Example output

[](#example-output)

 ```
classDiagram
direction TB
    class ConfigModule {
        + Loader
    }
    class NotificationModule {
        + EmailService
        + SMSService
        + PushNotificationService
    }
    class DatabaseModule {
        + DatabaseConnection
        + QueryBuilder
    }
    class UserModule {
        + UserService
        + UserRepository
        + UserAuthenticator
    }
    class ProductModule {
        + ProductService
        + ProductRepository
        + ProductSearchService
    }
    class PaymentModule {
        + PaymentProcessor
        + PaymentValidator
    }
    class OrderModule {
        + OrderService
        + OrderRepository
    }

     ConfigModule
     NotificationModule
     DatabaseModule
     ConfigModule
     OrderModule

    UserModule ..> DatabaseModule : DatabaseConnection
    UserModule ..> NotificationModule : EmailService, SMSService
    ProductModule ..> DatabaseModule : DatabaseConnection, QueryBuilder
    PaymentModule ..> DatabaseModule : DatabaseConnection
    PaymentModule ..> NotificationModule : EmailService
    OrderModule ..> UserModule : UserService
    OrderModule ..> ProductModule : ProductService
    OrderModule ..> PaymentModule : PaymentProcessor, PaymentValidator
    OrderModule ..> NotificationModule : EmailService

    class ConfigModule:::independent
    class NotificationModule:::independent
    class DatabaseModule:::independent
    class ConfigModule:::unused
    class OrderModule:::unused

    classDef independent fill:#e1f5fe, stroke:#0277bd, stroke-width:2px;
    classDef unused fill:#fff3e0, stroke:#f57c00, stroke-width:2px, stroke-dasharray: 2;
```

      Loading Notes &amp; conventions
-----------------------

[](#notes--conventions)

- Identifiers are sanitized to `[A-Za-z0-9_]` to avoid Mermaid parse errors
- Service labels show short class names; long labels are truncated by `maxServiceLength`
- Styling/class definitions are emitted once at the end to keep diagrams clean
- Module classification for the timeline is best-effort; adjust names to influence sections

Development
-----------

[](#development)

Helpful targets:

```
make test       # PHPUnit
make phpstan    # Static analysis
make codestyle  # PHP CS Fixer (check)
make diagrams   # Generate example Mermaid files and basic verify
make ci         # Style + static + tests + diagram generation
```

Project layout highlights:

- `src/` — renderers and `MermaidRendererModule`
- `examples/` — end-to-end usage with generated `.mmd` outputs
- `test/` — renderer behavior and formatting expectations

Related packages
----------------

[](#related-packages)

- Framework:
- Plugin system:
- Dependency Graph:

License
-------

[](#license)

MIT License — see `LICENSE`.

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance64

Regular maintenance activity

Popularity2

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

230d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/66858f9b375b50b4206f92195761ceb37e50d2df50317010ca0ad3eaa03f0855?d=identicon)[HomelessCoder](/maintainers/HomelessCoder)

---

Top Contributors

[![HomelessCoder](https://avatars.githubusercontent.com/u/12776808?v=4)](https://github.com/HomelessCoder "HomelessCoder (11 commits)")

---

Tags

phpframeworkanalysisarchitecturemodularmermaidvisualizationdependency-graphpower-modulesencapsulationmodule-dependenciesdependency-visualizer

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/power-modules-dependency-graph-mermaid/health.svg)

```
[![Health](https://phpackages.com/badges/power-modules-dependency-graph-mermaid/health.svg)](https://phpackages.com/packages/power-modules-dependency-graph-mermaid)
```

###  Alternatives

[pestphp/pest-plugin-arch

The Arch plugin for Pest PHP.

3945.8M4.0k](/packages/pestphp-pest-plugin-arch)[gacela-project/gacela

Gacela helps you separate your project into modules

133118.3k9](/packages/gacela-project-gacela)[grazulex/laravel-atlas

Laravel Atlas scans your Laravel project to generate a complete, structured map of its internal components — models, controllers, routes, jobs, observers, events, commands, and more — and exports visual or machine-readable representations in formats like Mermaid, Markdown, JSON, or PDF.

161.7k](/packages/grazulex-laravel-atlas)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
