power-modules/dependency-graph-mermaid
Composer 安装命令:
composer require power-modules/dependency-graph-mermaid
包简介
Mermaid renderer plugin for power-modules/dependency-graph (flowchart, class diagram, timeline)
关键字:
README 文档
README
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→ Mermaidgraph LR - Class diagram:
MermaidClassDiagram→ MermaidclassDiagram(TB) with YAML frontmatter - Timeline:
MermaidTimeline→ Mermaidtimelinegrouped by phases and sections
Works great with Mermaid Live and VS Code Mermaid preview.
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
composer require power-modules/dependency-graph-mermaid
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
All renderers implement Modular\DependencyGraph\Renderer\Renderer and return Mermaid text (.mmd).
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 <id> independent|unusedper node and a singleclassDefset at the end
- Uses
Constructor options (defaults shown):
new MermaidGraph( showExports: true, showServices: true, maxServiceLength: 50, )
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:
<<independent>>and<<unused>>emitted once per class - Styling:
class X:::independent|unusedplusclassDefat the end
Constructor options:
new MermaidClassDiagram( showExports: true, showServices: true, maxServiceLength: 50, )
MermaidTimeline
- Mermaid
timelinewith 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
This repo ships runnable examples and a Makefile to generate diagrams.
- E-commerce app: ecommerce
- Synthetic microservices: microservices
Generate example diagrams (flowchart, class diagram, timeline) into examples/**/mermaid/:
make diagrams
You can preview the .mmd files with:
- Mermaid Live: https://mermaid.live/
- VS Code: “Markdown Preview Mermaid Support” or native Mermaid support
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
}
<<independent>> ConfigModule
<<independent>> NotificationModule
<<independent>> DatabaseModule
<<unused>> ConfigModule
<<unused>> 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 & 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
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 andMermaidRendererModuleexamples/— end-to-end usage with generated.mmdoutputstest/— renderer behavior and formatting expectations
Related packages
- Framework: https://github.com/power-modules/framework
- Plugin system: https://github.com/power-modules/plugin
- Dependency Graph: https://github.com/power-modules/dependency-graph
License
MIT License — see LICENSE.
power-modules/dependency-graph-mermaid 适用场景与选型建议
power-modules/dependency-graph-mermaid 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 09 月 30 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「framework」 「php」 「modular」 「analysis」 「architecture」 「visualization」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 power-modules/dependency-graph-mermaid 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 power-modules/dependency-graph-mermaid 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 power-modules/dependency-graph-mermaid 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP Framework HLEB2 is the foundation of the web application. Provides ease of development and application performance.
Silverstripe content blocks module
Enterprise-Grade Modular Architecture for Laravel Applications - A powerful Laravel package that revolutionizes application development with robust Service Repository Pattern, Dynamic Module Management, and 50+ Artisan commands for scalable, maintainable applications.
Create laravel modular app using laravel modular plugin
Alfabank REST API integration
Codeurx Modular is simply a package for Laravel to help you create and manage modules.
统计信息
- 总下载量: 2
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 39
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-09-30