- Get Started
- Product
- Resources
- Tools & SDKs
- Framework
- Reference
- Get Started
- Product
- Resources
- Tools & SDKs
- Framework
- Reference
4.1.1. Implement Brand Module
1. Create Module Directory#
Start by creating the directory src/modules/brand
that will hold the Brand Module's files.
2. Create Data Model#
To create a data model that represents a new brand
table in the database, create the file src/modules/brand/models/brand.ts
with the following content:
This creates a Brand
data model which has an id
primary key property, and a name
text property.
3. Create Module Service#
Next, you'll create the module's main service that manages the Brand
data model.
Create the file src/modules/brand/service.ts
with the following content:
The BrandModuleService
extends a MedusaService
function imported from @medusajs/framework/utils
which is a service factory.
The MedusaService
function receives an object of the module's data models as a parameter, and generates methods to manage those data models, such as createBrands
and updateBrands
.
Those methods are now available at the BrandModuleService
class and you'll use them in upcoming steps.
4. Create Module's Definition#
To export the module's definition, create the file src/modules/brand/index.ts
with the following content:
This exposes the module to your application and allows you to resolve the BrandModuleService
, which is its main service.
5. Register Module in Config#
Finally, add the module to Medusa's configurations in medusa-config.ts
:
6. Generate and Run Migrations#
To reflect the data model in the database, generate migrations for the brandModuleService
module and migrate the changes to the database:
Next Step: Create Brand Workflow#
In the next step, you'll create a workflow whose steps use the Brand Module's main service to create a brand.