Skip to content

E-Segments/modular-architecture-graph

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Esegments Modular Architecture Graph

Module dependency graph visualization for Laravel modular architecture. An optional add-on that provides visual dependency analysis for your modules.

Features

  • Module Dependency Visualization: See how your modules depend on each other
  • Multiple Output Formats: ASCII, DOT/Graphviz, Mermaid, JSON
  • Status Indicators: Color-coded nodes (green = enabled, gray = disabled)
  • Protected Module Markers: Special shapes for protected modules
  • Enabled-Only Filtering: Focus on active modules only

Requirements

  • PHP 8.2+
  • Laravel 11.0+ or 12.0+
  • esegments/modular-architecture
  • esegments/dependency-graph

Installation

composer require esegments/modular-architecture-graph

The package auto-registers its service provider in Laravel.

Quick Start

# View module dependencies as ASCII tree
php artisan modular:graph

# View as Mermaid diagram
php artisan modular:graph --format=mermaid

# View as DOT/Graphviz
php artisan modular:graph --format=dot

# View as JSON
php artisan modular:graph --format=json

# Show only enabled modules
php artisan modular:graph --enabled

Command Options

Option Description
--format=ascii ASCII tree output (default)
--format=mermaid Mermaid diagram output
--format=dot DOT/Graphviz output
--format=json JSON output
--enabled Only show enabled modules

Example Output

ASCII (Default)

Blog v1.0.0
├── Core v1.0.0
└── Users v1.0.0
    └── Core v1.0.0

Products v1.0.0
└── Core v1.0.0

Core v1.0.0

Mermaid

graph TD
    Blog[Blog v1.0.0]
    Core[Core v1.0.0]
    Users[Users v1.0.0]
    Products[Products v1.0.0]
    Blog --> Core
    Blog --> Users
    Users --> Core
    Products --> Core
    style Core fill:#90EE90
    style Blog fill:#90EE90
    style Users fill:#90EE90
    style Products fill:#D3D3D3
Loading

JSON

{
    "nodes": [
        {
            "id": "Blog",
            "label": "Blog v1.0.0",
            "dependencies": ["Core", "Users"],
            "metadata": {
                "enabled": true,
                "protected": false,
                "version": "1.0.0",
                "color": "#90EE90"
            }
        }
    ],
    "edges": [
        {"from": "Blog", "to": "Core"},
        {"from": "Blog", "to": "Users"}
    ]
}

Programmatic Usage

Building a Module Graph

use Esegments\ModularArchitecture\Modular;
use Esegments\ModularArchitectureGraph\Graph\ModuleGraphBuilder;

$modular = app(Modular::class);
$builder = new ModuleGraphBuilder($modular);

// Build graph of all modules
$graph = $builder->build();

// Build graph of enabled modules only
$graph = $builder->enabledOnly()->build();

// Output in various formats
echo $graph->toAscii();
echo $graph->toMermaid();
echo $graph->toDot();
echo $graph->toJson();

Analyzing Dependencies

$graph = $builder->build();

// Get all nodes that depend on Core
$dependents = $graph->getDependents('Core');
// Returns: ['Blog', 'Users', 'Products']

// Get transitive dependency chain
$chain = $graph->getDependencyChain('Blog');
// Returns: ['Core', 'Users', 'Blog']

// Check for circular dependencies
if ($graph->hasCycles()) {
    $cycles = $graph->detectCycles();
    // Handle circular dependencies
}

// Topological sort (load order)
$loadOrder = $graph->topologicalSort();
// Returns: ['Core', 'Users', 'Products', 'Blog']

Node Metadata

Each module node includes rich metadata:

$node = $graph->getNode('Blog');

$node->getMeta('enabled');    // true/false
$node->getMeta('protected');  // true/false
$node->getMeta('version');    // "1.0.0"
$node->getMeta('color');      // "#90EE90" (green) or "#D3D3D3" (gray)
$node->getMeta('shape');      // "subroutine" (protected) or "default"

Color Scheme

Status Color Hex
Enabled Green #90EE90
Disabled Gray #D3D3D3

Shapes

Type Shape
Regular Module default
Protected Module subroutine

Integration with Graphviz

Generate a PNG image from the DOT output:

php artisan modular:graph --format=dot > modules.dot
dot -Tpng modules.dot -o modules.png

Integration with Mermaid Live

  1. Run php artisan modular:graph --format=mermaid
  2. Copy the output
  3. Paste into Mermaid Live Editor

Package Architecture

This package is an optional add-on that bridges:

┌─────────────────────────────────────┐
│  esegments/modular-architecture-graph │
└───────────────┬─────────────────────┘
                │ depends on
        ┌───────┴───────┐
        ▼               ▼
┌───────────────┐ ┌─────────────────────┐
│ dependency-graph │ │ modular-architecture │
└───────────────┘ └─────────────────────┘

Install modular-architecture alone for the module system without graph commands. Install modular-architecture-graph to add visualization capabilities.

Testing

composer test

Dependencies

License

MIT License. See LICENSE for details.

About

Visualization add-on for modular-architecture - Generate dependency graphs in DOT, Mermaid, and ASCII formats

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages