on GitHub" data-tooltip-id=":R1blcldtb:">v2.5.1·Edited Dec 9·
In this chapter, you'll learn how modules are isolated, and what that means for your custom development.
A module is unaware of any resources other than its own, such as services or data models. This means it can't access these resources if they're implemented in another module.
For example, your custom module can't resolve the Product Module's main service or have direct relationships from its data model to the Product Module's data models.
Some of the module isolation's benefits include:
To extend the data model of another module, such as the product
data model of the Product Module, use Medusa's linking concepts as explained in the Module Links chapters.
If you're building a feature that uses functionalities from different modules, use a workflow whose steps resolve the modules' services to perform these functionalities.
Workflows ensure data consistency through their roll-back mechanism and tracking of each execution's status, steps, input, and output.
For example, consider you have two modules:
To sync brands from your application to the third-party system, create the following steps:
1const retrieveBrandsStep = createStep(2 "retrieve-brands",3 async (_, { container }) => {4 const brandModuleService = container.resolve(5 "brandModuleService"6 )7 8 const brands = await brandModuleService.listBrands()9 10 return new StepResponse(brands)11 }12)13 14const createBrandsInCmsStep = createStep(15 "create-brands-in-cms",16 async ({ brands }, { container }) => {17 const cmsModuleService = container.resolve(18 "cmsModuleService"19 )20 21 const cmsBrands = await cmsModuleService.createBrands(brands)22 23 return new StepResponse(cmsBrands, cmsBrands)24 },25 async (brands, { container }) => {26 const cmsModuleService = container.resolve(27 "cmsModuleService"28 )29 30 await cmsModuleService.deleteBrands(31 brands.map((brand) => brand.id)32 )33 }34)
The retrieveBrandsStep
retrieves the brands from a brand module, and the createBrandsInCmsStep
creates the brands in a third-party system using a CMS module.
Then, create the following workflow that uses these steps:
You can then use this workflow in an API route, scheduled job, or other resources that use this functionality.