modular-monolith-laravel icon indicating copy to clipboard operation
modular-monolith-laravel copied to clipboard

[Question] Module Encapsulation / Dependency

Open boxxroom opened this issue 2 years ago • 1 comments

Thanks very much for your talk on Laracon, it was insightful and couldn't have come at a more fitting time.

I am a big fan of the Actions paradigm and already using this on a Domain level, more inline with Brents, Laravel Beyond Crud (https://laravel-beyond-crud.com/) from Spatie but will now be adding a contract to Actions as shown from Luke Downing's Laracon talk. To incorporate incapsulated domain level Actions within Modules (for me) would be the icing on the cake.

My question:

Isn't the Orders module dependant on the Inventory module or at the very least a skinny version of the Inventory module in order to work correctly. (Reasoning below)

Exploring this repo's codebase, I really like the structure and how everything belongs to that module, but I couldn't help but notice (please correct me if I am wrong) there was a dependency required from another module in order for a given module to work correctly. The module I refer to is the Orders module, specifically the Order Model requiring a ProductDto contract (interface) from the Inventory module. https://github.com/avosalmon/modular-monolith-laravel/blob/291dc78d0d6128c24b82acc451f4d858852553d5/src/Order/Domain/Models/Order.php#L11 https://github.com/avosalmon/modular-monolith-laravel/blob/291dc78d0d6128c24b82acc451f4d858852553d5/src/Order/Domain/Models/Order.php#L44

"Thinking out allowed"

I'm not entirely sure if there is an alternative approach/way of dealing with this either, it seems as though module knowledge has to be shared but it does feel as if it's breaking the self contained, workable module structure.

Thoughts welcome.....

boxxroom avatar Mar 06 '22 16:03 boxxroom

@boxxroom Thank you for watching the talk! I also got inspired by Luke's talk about actions and I think contracts in my talk can be implemented as actions as well.

To answer your question, yes, the order module is dependent on the inventory module. However, you can change the inventory module's implementation without having to change the order module since the order module only depends on the contracts (i.e. interface and DTO) of the inventory module. The idea is that modules are "loosely" coupled so that we can independently change the module's implementation as long as the contract remains the same.

An alternative approach is dispatching an event from a module and another module handles the event. This way, a module wouldn't need to depend on the interfaces and DTOs.

avosalmon avatar Mar 13 '22 03:03 avosalmon