Git Product home page Git Product logo

Comments (11)

avosalmon avatar avosalmon commented on July 19, 2024 3

@ashourms Thank you for watching the talk!

Basically, a model shouldn't have relationships with models of different modules.
If a module needs to get data from different modules, we need to create a contract and get the required data using the contracts (i.e. interfaces). The contract should return a DTO instead of a related eloquent model to avoid exposing all the properties and methods to different modules. Alternatively, a module can dispatch an event and other modules handle it accordingly, which is a more decoupled approach.

If a module needs to get many different data from other modules, you might want to see if there is a better way to define your domain boundaries.

from modular-monolith-laravel.

avosalmon avatar avosalmon commented on July 19, 2024 2

@robsontenorio Thanks for watching my talk!
I think it's considered a violation since the OrderLine directly accesses the Product model which would expose all the properties and functionalities of the Product model. By accessing the Product model, the order module would be able to trigger whatever actions against the products table. e.g. update, delete
Also, when you test the order module, you won't be able to create a record for the order_lines table without creating a product. However, you shouldn't need to know the details of database tables of the inventory module when you are testing the order module so that the order module can be tested independently.

To deal with this, I would create a contract (i.e. interface) in the inventory module and the order module can get the product by calling the method. This will cause an additional DB query but we can keep the modules decoupled.

from modular-monolith-laravel.

ashourms avatar ashourms commented on July 19, 2024

I really enjoyed your awesome talk during the conference! well done!

I am wondering about the same thing, what if we have a model that is having relationships with many other models in different modules. When using Laravel eager loading "i.e. with method" you will get one collection that have all the related properties of other models.

So using the explained approach in your presentation, does this mean that we need to create a contract in each related module and get the related model information using those services?

from modular-monolith-laravel.

ashourms avatar ashourms commented on July 19, 2024

Noted! Thanks for your feedback!

from modular-monolith-laravel.

Related Issues (5)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.