PHPackages                             akito-tsukahara/laravel-di-scope - 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. [PSR &amp; Standards](/categories/psr-standards)
4. /
5. akito-tsukahara/laravel-di-scope

ActiveLibrary[PSR &amp; Standards](/categories/psr-standards)

akito-tsukahara/laravel-di-scope
================================

Visualize and validate Laravel DI container bindings

v0.5.0(5mo ago)11MITPHPPHP ^8.2CI passing

Since Jan 18Pushed 5mo agoCompare

[ Source](https://github.com/AkitoTsukahara/laravel-di-scope)[ Packagist](https://packagist.org/packages/akito-tsukahara/laravel-di-scope)[ RSS](/packages/akito-tsukahara-laravel-di-scope/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (5)Versions (6)Used By (0)

Laravel DI Scope
================

[](#laravel-di-scope)

[![Latest Version on Packagist](https://camo.githubusercontent.com/d4925ce8c3cd91bbeb0fd17b05cc9a049e32bac0a867b1961af8bf666ccabf74/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616b69746f2d7473756b61686172612f6c61726176656c2d64692d73636f70652e737667)](https://packagist.org/packages/akito-tsukahara/laravel-di-scope)[![Tests](https://github.com/AkitoTsukahara/laravel-di-scope/actions/workflows/tests.yml/badge.svg)](https://github.com/AkitoTsukahara/laravel-di-scope/actions)[![License](https://camo.githubusercontent.com/5c5d25c8e6bfe397e4256e2043caddb9189a29f65f58fd0c7f5b1e0b0b236c8e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f616b69746f2d7473756b61686172612f6c61726176656c2d64692d73636f70652e737667)](https://packagist.org/packages/akito-tsukahara/laravel-di-scope)

Laravelのサービスコンテナのバインディング情報を解析し、依存関係の可視化とアーキテクチャルールの検証を行うパッケージ。

特徴
--

[](#特徴)

- 🔍 **バインディング可視化**: サービスコンテナに登録された全バインディングを一覧表示
- 📂 **ディレクトリスキャン**: `app/`配下のクラスを自動スキャンして依存関係を解析
- 🎯 **メソッドインジェクション対応**: `__construct`、`__invoke`、`handle`メソッドの依存を解析
- 🌳 **依存ツリー構築**: クラス間の依存関係を再帰的に解決・表示
- ✅ **ルール検証**: 定義したアーキテクチャルールに違反する依存を検出
- 📊 **グラフ出力**: Mermaid形式で依存関係を可視化（違反は赤色でハイライト）
- 🔄 **CI連携**: 違反があればexit code 1を返すためCIパイプラインに組み込み可能

動作要件
----

[](#動作要件)

- PHP 8.2以上
- Laravel 10.x / 11.x / 12.x

インストール
------

[](#インストール)

```
composer require --dev akito-tsukahara/laravel-di-scope
```

設定
--

[](#設定)

設定ファイルをpublish:

```
php artisan vendor:publish --tag=di-scope-config
```

### スキャン設定

[](#スキャン設定)

`config/di-scope.php` でスキャン対象を設定:

```
'scan' => [
    // スキャン対象ディレクトリ（base_path()からの相対パス）
    'paths' => [
        'app/',
        // 'packages/my-package/src/',
    ],

    // 除外ディレクトリ
    'exclude_paths' => [
        // 'app/Providers/',
    ],

    // 除外パターン（名前空間ベース、ワイルドカード対応）
    'exclude_patterns' => [
        'App\\Providers\\*',
    ],
],
```

### 依存解析の除外設定

[](#依存解析の除外設定)

フレームワークの依存など、グラフに含めたくないクラスを除外:

```
'ignore' => [
    'Illuminate\\*',
    'Psr\\*',
    'Symfony\\*',
],
```

### アーキテクチャルール

[](#アーキテクチャルール)

レイヤー間の依存ルールを定義:

```
'rules' => [
    // Domain層はInfrastructure層に依存してはいけない
    'App\\Domain\\*' => [
        'deny' => ['App\\Infrastructure\\*'],
        'allow' => ['App\\Domain\\*', 'App\\Application\\*'],
    ],

    // ControllerはServiceに直接依存してはいけない例
    'App\\Http\\Controllers\\*' => [
        'deny' => ['App\\Services\\*'],
        'allow' => ['App\\Http\\Requests\\*'],
    ],
],
```

使い方
---

[](#使い方)

### バインディング一覧を表示

[](#バインディング一覧を表示)

```
php artisan di:list

# singletonのみ表示
php artisan di:list --type=singleton

# 検索
php artisan di:list --search=Repository
```

### ルール違反を検出

[](#ルール違反を検出)

```
php artisan di:analyze

# 特定の名前空間のみ検証
php artisan di:analyze --focus="App\\Http\\Controllers"
```

出力例:

```
DI Scope Analysis
==================

✓ 24 classes found
✓ 1 rules loaded

✗ 5 violations found

Violations:
-----------
1. PutController cannot depend on TweetService (rule: App\Http\Controllers\*)
   App\Http\Controllers\Tweet\Update\PutController → App\Services\TweetService

2. IndexController cannot depend on TweetService (rule: App\Http\Controllers\*)
   App\Http\Controllers\Tweet\Update\IndexController → App\Services\TweetService

3. DeleteController cannot depend on TweetService (rule: App\Http\Controllers\*)
   App\Http\Controllers\Tweet\DeleteController → App\Services\TweetService
...

```

### 依存グラフを出力

[](#依存グラフを出力)

```
# app/配下をスキャンしてグラフ出力（デフォルト）
php artisan di:graph

# ファイルに保存
php artisan di:graph --output=graph.mmd

# 特定の名前空間にフォーカス
php artisan di:graph --focus="App\\Http\\Controllers"

# 依存の深さを制限
php artisan di:graph --depth=2

# 特定クラスのみ解析
php artisan di:graph --class="App\\Http\\Controllers\\Tweet\\CreateController"

# サービスコンテナのバインディングのみ解析（従来の動作）
php artisan di:graph --bindings
```

### 出力例（Mermaid）

[](#出力例mermaid)

違反エッジは赤色でハイライトされます:

 ```
flowchart TD
    App_Http_Controllers_Tweet_CreateController[CreateController]
    App_Http_Requests_Tweet_CreateRequest[CreateRequest]
    App_Services_TweetService[TweetService]

    App_Http_Controllers_Tweet_CreateController --> App_Http_Requests_Tweet_CreateRequest
    App_Http_Controllers_Tweet_CreateController --> App_Services_TweetService

    linkStyle 1 stroke:#ef4444,stroke-width:2px

    style App_Http_Controllers_Tweet_CreateController fill:#fef2f2,stroke:#ef4444
```

      Loading CI連携
----

[](#ci連携)

### GitHub Actions

[](#github-actions)

```
name: Architecture Check

on: [push, pull_request]

jobs:
  analyze:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Setup PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: '8.2'

      - name: Install dependencies
        run: composer install

      - name: Check DI Architecture Rules
        run: php artisan di:analyze
```

違反があるとexit code 1が返されるため、CIが失敗します。

ユースケース例
-------

[](#ユースケース例)

### クリーンアーキテクチャの検証

[](#クリーンアーキテクチャの検証)

```
'rules' => [
    // Entities（Domain層）は何にも依存しない
    'App\\Domain\\Entities\\*' => [
        'deny' => ['App\\*'],
        'allow' => ['App\\Domain\\Entities\\*'],
    ],

    // UseCases（Application層）はDomain層のみ依存可
    'App\\Domain\\UseCases\\*' => [
        'deny' => ['App\\Infrastructure\\*', 'App\\Http\\*'],
        'allow' => ['App\\Domain\\*'],
    ],

    // Controllers（Interface層）はUseCasesに依存
    'App\\Http\\Controllers\\*' => [
        'deny' => ['App\\Infrastructure\\*', 'App\\Domain\\Entities\\*'],
        'allow' => ['App\\Domain\\UseCases\\*', 'App\\Http\\*'],
    ],
],
```

### レイヤードアーキテクチャの検証

[](#レイヤードアーキテクチャの検証)

```
'rules' => [
    'App\\Domain\\*' => [
        'deny' => ['App\\Infrastructure\\*'],
    ],
    'App\\Application\\*' => [
        'deny' => ['App\\Infrastructure\\*'],
    ],
],
```

ライセンス
-----

[](#ライセンス)

MIT

###  Health Score

32

—

LowBetter than 69% of packages

Maintenance70

Regular maintenance activity

Popularity3

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity41

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

Every ~0 days

Total

5

Last Release

166d ago

### Community

Maintainers

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

---

Top Contributors

[![AkitoTsukahara](https://avatars.githubusercontent.com/u/10906919?v=4)](https://github.com/AkitoTsukahara "AkitoTsukahara (20 commits)")

---

Tags

containerlaraveldependency-injectiondiarchitecture

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/akito-tsukahara-laravel-di-scope/health.svg)

```
[![Health](https://phpackages.com/badges/akito-tsukahara-laravel-di-scope/health.svg)](https://phpackages.com/packages/akito-tsukahara-laravel-di-scope)
```

###  Alternatives

[laravel/ai

The official AI SDK for Laravel.

1.0k3.2M200](/packages/laravel-ai)[laravel/mcp

Rapidly build MCP servers for your Laravel applications.

77022.3M151](/packages/laravel-mcp)[larastan/larastan

Larastan - Discover bugs in your code without running it. A phpstan/phpstan extension for Laravel

6.5k55.4M8.5k](/packages/larastan-larastan)[spatie/laravel-responsecache

Speed up a Laravel application by caching the entire response

2.8k9.0M69](/packages/spatie-laravel-responsecache)[psalm/plugin-laravel

Psalm plugin for Laravel

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

The Illuminate Queue package.

21332.6M1.6k](/packages/illuminate-queue)

PHPackages © 2026

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