toContain('Shared', 'Customers'); }); foreach ($modules as $module) { $root = 'App\\Modules\\'.$module; arch("{$module}: domain does not depend on Laravel or outer layers") ->expect($root.'\\Domain') ->not->toUse([ 'Illuminate', 'Livewire', 'App\\Models', $root.'\\Application', $root.'\\Infrastructure', $root.'\\Presentation', ]); arch("{$module}: application does not use the database, facades, HTTP or outer layers") ->expect($root.'\\Application') ->not->toUse([ 'Illuminate\\Database', 'Illuminate\\Support\\Facades', 'Illuminate\\Http', 'Livewire', 'App\\Models', $root.'\\Infrastructure', $root.'\\Presentation', ]); // Service providers are the module's composition root: they may register its commands and middleware. arch("{$module}: infrastructure does not depend on presentation") ->expect($root.'\\Infrastructure') ->not->toUse($root.'\\Presentation') ->ignoring($root.'\\Infrastructure\\Providers'); $otherModules = array_values(array_diff($modules, [$module])); if ($otherModules !== []) { arch("{$module}: does not use the infrastructure or presentation of other modules") ->expect($root) ->not->toUse(array_merge(...array_map( fn (string $other): array => [ 'App\\Modules\\'.$other.'\\Infrastructure', 'App\\Modules\\'.$other.'\\Presentation', ], $otherModules, ))); } arch("{$module}: domain and application use strict types") ->expect([$root.'\\Domain', $root.'\\Application']) ->toUseStrictTypes(); arch("{$module}: DTOs are readonly") ->expect($root.'\\Application\\DTOs') ->toBeReadonly(); }