@@ -95,13 +95,15 @@ Enforces strict dependency rules for modular hexagonal (Ports and Adapters) arch
9595
9696** What it enforces:**
9797
98- 1 . ** Intra-Module Layer Dependencies** - Within the same module (default configuration):
99- - Domain: Cannot import from Application, Infrastructure, or Presentation
100- - Application: Can import Domain; cannot import Infrastructure or Presentation
101- - Infrastructure: Can import Domain and Application; cannot import Presentation
102- - Presentation: Can import Application and Domain; cannot import Infrastructure
98+ 1 . ** Intra-Module Layer Dependencies** - Within the same module (default Clean Architecture configuration):
99+ - ** Domain** : Cannot import from any other layer (pure business logic)
100+ - ** Application** : Can import Domain only (defines use cases and port interfaces)
101+ - ** Infrastructure** : Can import Domain and Application (implements port interfaces defined in Application)
102+ - ** Presentation** : Can import Application only (calls use cases)
103103 - ** All layers can import from themselves** (e.g., Presentation → Presentation within the same layer)
104104
105+ This follows the ** Dependency Inversion Principle** : Application defines interfaces, Infrastructure implements them.
106+
105107 ** Note:** You can customize these layer dependencies to match your architecture needs (see configuration examples below).
106108
1071092 . ** Cross-Module Dependencies** - Between different modules:
@@ -134,7 +136,7 @@ src/Capability/
134136 class: Phauthentic\PHPStanRules\Architecture\ModularArchitectureRule
135137 arguments:
136138 baseNamespace: 'App\Capability'
137- layerDependencies: null # Uses default layer rules
139+ layerDependencies: null # Uses default Clean Architecture rules
138140 allowedCrossModulePatterns:
139141 - '/Facade$/' # Classes ending with "Facade"
140142 - '/FacadeInterface$/' # Classes ending with "FacadeInterface"
@@ -186,9 +188,13 @@ src/Capability/
186188** Parameters:**
187189
188190- ` baseNamespace ` : The base namespace for your capabilities/modules (e.g., ` App\Capability ` )
189- - ` layerDependencies ` : (Optional) Custom layer dependency rules. If not provided, uses default hexagonal architecture rules.
191+ - ` layerDependencies ` : (Optional) Custom layer dependency rules. If not provided, uses default Clean Architecture rules.
190192 - Format: ` LayerName: [AllowedDependency1, AllowedDependency2, ...] `
191- - Default layers: Domain, Application, Infrastructure, Presentation
193+ - Default layers (following Dependency Inversion Principle):
194+ - ` Domain: [] ` - Pure business logic
195+ - ` Application: [Domain] ` - Use cases and port interfaces
196+ - ` Infrastructure: [Domain, Application] ` - Implements Application interfaces
197+ - ` Presentation: [Application] ` - Controllers, CLI commands
192198 - You can define any custom layer names you need
193199- ` allowedCrossModulePatterns ` : ** Required** - Regex patterns for fully qualified class names that can be imported across modules.
194200 - ** No defaults** - you must explicitly configure which classes can cross module boundaries
@@ -230,13 +236,13 @@ use App\Capability\UserManagement\Domain\Model\User;
230236
231237The rule is flexible and allows you to define your own architectural layers beyond the defaults. Here are some common use cases:
232238
233- 1 . ** Allow Application to depend on Infrastructure ** (for repositories ):
239+ 1 . ** Stricter Isolation ** (Infrastructure cannot see Application ):
234240``` neon
235241layerDependencies:
236242 Domain: []
237- Application: [Domain, Infrastructure] # Application can now use Infrastructure
238- Infrastructure: [Domain]
239- Presentation: [Application, Domain ]
243+ Application: [Domain]
244+ Infrastructure: [Domain] # Infrastructure isolated from Application
245+ Presentation: [Application]
240246```
241247
2422482 . ** Three-Tier Architecture** (instead of hexagonal):
0 commit comments