PHPackages                             drmovi/phpstan-laravel-module-boundaries - 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. [Validation &amp; Sanitization](/categories/validation)
4. /
5. drmovi/phpstan-laravel-module-boundaries

ActivePhpstan-extension[Validation &amp; Sanitization](/categories/validation)

drmovi/phpstan-laravel-module-boundaries
========================================

PHPStan extension to enforce Laravel module boundaries and prevent cross-module imports

1.0.0(10mo ago)11MITPHPPHP ^8.4

Since Aug 31Pushed 6mo agoCompare

[ Source](https://github.com/drmovi/phpstan-laravel-module-boundaries)[ Packagist](https://packagist.org/packages/drmovi/phpstan-laravel-module-boundaries)[ RSS](/packages/drmovi-phpstan-laravel-module-boundaries/feed)WikiDiscussions master Synced today

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

PHPStan Laravel Module Boundaries
=================================

[](#phpstan-laravel-module-boundaries)

A PHPStan extension that enforces module boundaries in Laravel applications to maintain bounded contexts and prevent unwanted cross-module dependencies.

Features
--------

[](#features)

- Detects and prevents cross-module imports between Laravel modules
- Supports shared modules that can be imported by any module
- Configurable via Laravel project's `composer.json`
- Works with PHPStan 2.0+

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

[](#installation)

Install the extension via Composer:

```
composer require --dev drmovi/phpstan-laravel-module-boundaries
```

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

[](#configuration)

### 1. Laravel Project Configuration

[](#1-laravel-project-configuration)

In your Laravel project's `composer.json`, add the following configuration:

```
{
    "extra": {
        "modules": {
            "path": "app/Modules"
        },
        "phpstan-laravel-module-boundaries": {
            "shared": ["shared", "auth"]
        }
    }
}
```

- `laravel-module.path`: The path to your modules directory relative to the project root
- `phpstan-laravel-module-boundaries.shared`: Array of module names that are considered "shared" and can be imported by any module

### 2. PHPStan Configuration

[](#2-phpstan-configuration)

The extension is automatically loaded when installed. No additional PHPStan configuration is required.

Rules
-----

[](#rules)

### Module Boundary Rule

[](#module-boundary-rule)

This rule enforces the following boundaries:

1. **Same Module**: Files within a module can import from the same module ✅
2. **Shared Modules**: Any module can import from modules listed in the `shared` configuration ✅
3. **Shared to Shared**: Shared modules can import from other shared modules ✅
4. **Cross-Module**: Non-shared modules cannot import from other non-shared modules ❌

Example
-------

[](#example)

Given the following module structure:

```
app/Modules/
├── User/
│   └── UserService.php
├── Order/
│   └── OrderService.php
├── shared/
│   └── SharedHelper.php
└── auth/
    └── AuthService.php

```

With configuration:

```
{
    "extra": {
        "modules": {
            "path": "app/Modules"
        },
        "phpstan-laravel-module-boundaries": {
            "shared": ["shared", "auth"]
        }
    }
}
```

### Allowed Imports ✅

[](#allowed-imports-)

```
// In User/UserService.php
use App\Modules\User\UserRepository;     // Same module
use App\Modules\shared\SharedHelper;     // From shared module
use App\Modules\auth\AuthService;        // From shared module
```

```
// In shared/SharedHelper.php
use App\Modules\auth\AuthService;        // Shared to shared
```

### Forbidden Imports ❌

[](#forbidden-imports-)

```
// In User/UserService.php
use App\Modules\Order\OrderService;      // Cross-module import
```

```
// In Order/OrderService.php
use App\Modules\User\UserService;        // Cross-module import
```

Error Messages
--------------

[](#error-messages)

When a boundary violation is detected, PHPStan will report an error like:

```
Module "User" cannot import "App\Modules\Order\OrderService" from module "Order".
Cross-module imports are only allowed from shared modules (shared, auth).

```

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

[](#requirements)

- PHP 8.4+
- PHPStan 2.0+
- Laravel project with modular structure

License
-------

[](#license)

MIT License. See LICENSE file for details.

###  Health Score

33

—

LowBetter than 72% of packages

Maintenance62

Regular maintenance activity

Popularity3

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

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

309d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/8846428?v=4)[Mostafa Darwish](/maintainers/drmovi)[@drmovi](https://github.com/drmovi)

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/drmovi-phpstan-laravel-module-boundaries/health.svg)

```
[![Health](https://phpackages.com/badges/drmovi-phpstan-laravel-module-boundaries/health.svg)](https://phpackages.com/packages/drmovi-phpstan-laravel-module-boundaries)
```

###  Alternatives

[rector/rector

Instant Upgrade and Automated Refactoring of any PHP code

10.4k139.2M9.4k](/packages/rector-rector)[larastan/larastan

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

6.5k55.4M8.6k](/packages/larastan-larastan)[phpstan/phpstan-symfony

Symfony Framework extensions and rules for PHPStan

79475.7M2.2k](/packages/phpstan-phpstan-symfony)[phpstan/phpstan-doctrine

Doctrine extensions for PHPStan

67272.8M1.4k](/packages/phpstan-phpstan-doctrine)[shipmonk/dead-code-detector

Dead code detector to find unused PHP code via PHPStan extension. Can automatically remove dead PHP code. Supports libraries like Symfony, Doctrine, PHPUnit etc. Detects dead cycles. Can detect dead code that is tested.

4853.5M93](/packages/shipmonk-dead-code-detector)[tomasvotruba/cognitive-complexity

PHPStan rules to measure cognitive complexity of your classes and methods

1635.6M291](/packages/tomasvotruba-cognitive-complexity)

PHPackages © 2026

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