PHPackages                             naokioouchi/laravel-circular-detector - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. naokioouchi/laravel-circular-detector

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

naokioouchi/laravel-circular-detector
=====================================

A Laravel package to detect and visualize circular dependencies in modular monolith architectures

v1.0.0(10mo ago)16MITPHPPHP ^8.1CI passing

Since Aug 21Pushed 10mo agoCompare

[ Source](https://github.com/NaokiOouchi/laravel-circular-dependency-detector)[ Packagist](https://packagist.org/packages/naokioouchi/laravel-circular-detector)[ Docs](https://github.com/NaokiOouchi/laravel-circular-dependency-detector)[ RSS](/packages/naokioouchi-laravel-circular-detector/feed)WikiDiscussions main Synced today

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

Laravel Circular Dependency Detector
====================================

[](#laravel-circular-dependency-detector)

A powerful Laravel package for detecting and visualizing circular dependencies in modular monolith architectures.

Features
--------

[](#features)

- 🔍 **Circular Dependency Detection**: Automatically detect circular dependencies between modules using depth-first search algorithm
- 📊 **Multiple Output Formats**: Console, JSON, DOT (Graphviz), and Mermaid diagram formats
- 📈 **Dependency Visualization**: Generate interactive dependency graphs
- ⚡ **Performance Optimized**: Efficiently analyze large codebases with 100+ modules
- 🎯 **Laravel Integration**: Seamless integration with Laravel's service container and console commands

Installation
------------

[](#installation)

Install the package via Composer:

```
composer require naokioouchi/laravel-circular-detector --dev
```

### Publishing Configuration

[](#publishing-configuration)

After installation, publish the configuration file to customize it for your project:

```
php artisan vendor:publish --provider="LaravelCircularDependencyDetector\ServiceProvider" --tag="config"
```

This will create `config/circular-dependency-detector.php` in your Laravel application where you can customize all settings.

### Alternative: Without Publishing Config

[](#alternative-without-publishing-config)

If you don't want to publish the config, you can also configure it via environment variables or directly in your `config/app.php`:

```
// In your AppServiceProvider or a custom ServiceProvider
public function register()
{
    $this->app->configure('circular-dependency-detector', function() {
        return [
            'modules_path' => base_path('src'), // Your custom path
            'detection_strategy' => 'namespace',
            'namespace_pattern' => 'App\\Domain\\*',
            // ... other settings
        ];
    });
}
```

Configuration
-------------

[](#configuration)

Edit `config/circular-dependency-detector.php` to customize:

```
return [
    'modules_path' => app_path('Modules'),

    // Namespace patterns configuration (NEW)
    // {MODULE} placeholder will be replaced with module name
    'namespace_patterns' => [
        'App\\Modules\\{MODULE}',     // app/Modules/ModuleName
        // 'Packages\\{MODULE}',       // packages/ModuleName
        // 'Domain\\{MODULE}',         // Custom domain structure
    ],

    'scan_patterns' => [
        'controllers' => 'Controllers',
        'services' => 'Services',
        'repositories' => 'Repositories',
        'providers' => 'Providers',
        'models' => 'Models',
        'jobs' => 'Jobs',
        'listeners' => 'Listeners',
        // For DDD patterns
        'domain' => 'Domain',
        'application' => 'Application',
        'infrastructure' => 'Infrastructure',
    ],

    'ignore_patterns' => [
        '*/Tests/*',
        '*/Migrations/*',
        '*/Database/*',
    ],

    'allowed_dependencies' => [
        'Contracts',
        'Events',
        'Exceptions',
        'DTOs',
        'Enums',
    ],
];
```

### Example for packages/ directory structure (DDD/Ports and Adapters)

[](#example-for-packages-directory-structure-dddports-and-adapters)

```
return [
    'modules_path' => base_path('packages'),

    'namespace_patterns' => [
        'Packages\\{MODULE}',
    ],

    'scan_patterns' => [
        'application' => 'Application',
        'domain' => 'Domain',
        'infrastructure' => 'Infrastructure',
    ],
];
```

Usage
-----

[](#usage)

### Detect Circular Dependencies

[](#detect-circular-dependencies)

```
php artisan modules:detect-circular
```

Options:

- `--path=`: Override modules path (e.g., app/Domain, src/Services)
- `--format={console|json|dot|mermaid}`: Output format (default: console)
- `--output=path`: Save output to file

Examples:

```
# Analyze a custom directory structure
php artisan modules:detect-circular --path=app/Domain

# Generate JSON report for DDD structure
php artisan modules:detect-circular --path=src --format=json --output=report.json

# Generate Graphviz DOT file
php artisan modules:detect-circular --format=dot --output=dependencies.dot

# Analyze different project structures without modifying config
php artisan modules:detect-circular --path=packages
php artisan modules:detect-circular --path=src/Bounded
```

### Generate Dependency Graph

[](#generate-dependency-graph)

```
php artisan modules:graph
```

Options:

- `--format={dot|mermaid}`: Graph format (default: dot)
- `--output=path`: Save graph to file

Examples:

```
# Generate DOT graph and convert to PNG
php artisan modules:graph --format=dot --output=graph.dot
dot -Tpng graph.dot -o graph.png

# Generate Mermaid diagram
php artisan modules:graph --format=mermaid --output=graph.md
```

Output Examples
---------------

[](#output-examples)

### Console Output

[](#console-output)

```
=====================================
  Circular Dependency Analysis Report
=====================================

Summary:
--------
  Modules analyzed: 5
  Circular dependencies found: 1
  Status: ❌ Issues Found

Circular Dependencies:
---------------------

1. 🔴 CRITICAL (Length: 2)
   Cycle: ModuleA → ModuleB → ModuleA
   Affected dependencies:
   - ModuleA uses App\Modules\ModuleB\Services\ServiceB
   - ModuleB uses App\Modules\ModuleA\Services\ServiceA

```

### JSON Output

[](#json-output)

```
{
  "analysis_timestamp": "2025-01-01T00:00:00Z",
  "summary": {
    "modules_count": 5,
    "cycles_count": 1,
    "has_issues": true
  },
  "cycles": [
    {
      "cycle": ["ModuleA", "ModuleB", "ModuleA"],
      "length": 2,
      "severity": "critical"
    }
  ],
  "dependencies": {}
}
```

### DOT Graph Output

[](#dot-graph-output)

```
digraph ModuleDependencies {
    rankdir=LR;
    node [shape=box, style=rounded];
    edge [color=gray50];

    "ModuleA" [fillcolor=lightcoral, style="rounded,filled"];
    "ModuleB" [fillcolor=lightcoral, style="rounded,filled"];

    "ModuleA" -> "ModuleB" [color=red, penwidth=2, label="cycle"];
    "ModuleB" -> "ModuleA" [color=red, penwidth=2, label="cycle"];
}
```

### Mermaid Diagram Output

[](#mermaid-diagram-output)

 ```
graph TD
    M0["ModuleA"]
    M1["ModuleB"]

    M0 -->|cycle| M1
    M1 -->|cycle| M0

    classDef cycleNode fill:#ffcccc,stroke:#ff0000,stroke-width:2px
    class M0 cycleNode
    class M1 cycleNode
```

      Loading CI/CD Integration
-----------------

[](#cicd-integration)

### GitHub Actions

[](#github-actions)

```
name: Dependency Check
on: [push, pull_request]
jobs:
  dependency-check:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Setup PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: '8.1'
      - name: Install dependencies
        run: composer install
      - name: Check circular dependencies
        run: php artisan modules:detect-circular --format=json --output=dependencies.json
```

### GitLab CI

[](#gitlab-ci)

```
dependency-check:
  image: php:8.1
  script:
    - composer install
    - php artisan modules:detect-circular --format=json --output=dependencies.json
  artifacts:
    reports:
      junit: dependencies.json
    paths:
      - dependencies.json
```

Performance
-----------

[](#performance)

The package is optimized for performance:

- **100 modules**: Analysis completes in under 30 seconds
- **Memory usage**: Less than 512MB for large projects
- **File limit**: Supports up to 10,000 PHP files

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

[](#requirements)

- PHP ^8.1
- Laravel 10.x, 11.x, or 12.x
- nikic/php-parser ^4.15

Testing
-------

[](#testing)

Run the test suite:

```
composer test
```

Run specific test suites:

```
# Unit tests only
./vendor/bin/phpunit --testsuite=Unit

# Feature tests only
./vendor/bin/phpunit --testsuite=Feature
```

Troubleshooting
---------------

[](#troubleshooting)

### No modules found

[](#no-modules-found)

Check that your `modules_path` in the configuration points to the correct directory:

```
'modules_path' => app_path('Modules'), // Adjust this path
```

### Missing dependencies

[](#missing-dependencies)

Some dependencies might not be detected if they use dynamic class resolution. Consider adding explicit use statements.

### Performance issues

[](#performance-issues)

For large codebases, you can optimize by:

- Adjusting `ignore_patterns` to skip unnecessary directories
- Limiting `scan_patterns` to essential directories only

Contributing
------------

[](#contributing)

Contributions are welcome! Please feel free to submit a Pull Request.

Support
-------

[](#support)

If you encounter any issues or have feature requests, please create an issue on [GitHub](https://github.com/NaokiOouchi/laravel-circular-dependency-detector/issues).

License
-------

[](#license)

MIT

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance54

Moderate activity, may be stable

Popularity6

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity45

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

318d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/45508410?v=4)[OouchiNaoki](/maintainers/NaokiOouchi)[@NaokiOouchi](https://github.com/NaokiOouchi)

---

Top Contributors

[![NaokiOouchi](https://avatars.githubusercontent.com/u/45508410?v=4)](https://github.com/NaokiOouchi "NaokiOouchi (6 commits)")

---

Tags

laravelarchitecturecode analysisdddclean architecturemodular-monolithcircular-dependencydependency-detection

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/naokioouchi-laravel-circular-detector/health.svg)

```
[![Health](https://phpackages.com/badges/naokioouchi-laravel-circular-detector/health.svg)](https://phpackages.com/packages/naokioouchi-laravel-circular-detector)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[laravel/ai

The official AI SDK for Laravel.

1.0k3.2M203](/packages/laravel-ai)[livewire/flux

The official UI component library for Livewire.

9527.8M128](/packages/livewire-flux)[laravel/surveyor

Static analysis tool for Laravel applications.

86121.4k13](/packages/laravel-surveyor)[laravel/mcp

Rapidly build MCP servers for your Laravel applications.

77022.3M151](/packages/laravel-mcp)[zidbih/laravel-deadlock

Make temporary Laravel workarounds expire and fail CI when ignored.

985.4k](/packages/zidbih-laravel-deadlock)

PHPackages © 2026

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