-
-
Notifications
You must be signed in to change notification settings - Fork 48
Description
| Q | A |
|---|---|
| Library version | 0.5.3.0 |
| PHP version | 8.4.1 |
Support Question
I'm new to phparkitect and would like to know the best way to configure it for my use case. I'm open to creating a PR if something should be added to the codebase 🙌.
Big Ball of Mud into Modular Monolith
I have a legacy application that's essentially a big ball of mud. Everything is coupled to everything else. I want to start adding some separation between modules. To begin, I plan to ensure there's a single point of contact, like through a Module Facade. I tried to define the below rules:
Rule 1: Shop module can only rely on its own or shared classes, and the ProductFacade.
$rules[] = Rule::allClasses()
->that(new ResideInOneOfTheseNamespaces('App\Shop'))
->should(new NotHaveDependencyOutsideNamespace('App\Shop', ['App\Product\ProductFacade', 'App\Shared\*']))
->because('Modules should access other modules only through their public facades');In an ideal situation, this would be enough, but I won't have all the modules defined initially. I will add them gradually, so I also need a rule to ensure that the rest of the codebase doesn't have coupling with the extracted module besides its facade.
Rule 2: Other places should access the Shop module only through ShopFacade
$rules[] = Rule::allClasses()
->that(new ResideInOneOfTheseNamespaces('')) // yes, some classes are not namespaced
->andThat(new NotResideInTheseNamespaces('App\Shop'))
->should(new NotDependsOnTheseNamespaces('App\Shop'))
// how to exclude ShopFacade?
->because('Other modules should only access Shop through ShopFacade');Questions
- How can I exclude
ShopFacadeas a dependency in Rule 2? Should it stay in theApp\Shopnamespace, or should it be moved outside? - Is there a better way to achieve my goal? I have 20+ modules in that repository, which could lead to a messy configuration. I considered creating a
builderto avoid copy-pasting, but perhaps there's a more effective method in phparkitect.