docs: improvements to intro and basics chapters (#8956)

This commit is contained in:
Shahed Nasser
2024-09-03 17:34:07 +03:00
committed by GitHub
parent 7e278bef76
commit e9fce4c5c2
11 changed files with 53 additions and 29 deletions
@@ -8,9 +8,9 @@ In this chapter, youll learn about modules, their main service, and how to cr
## What is a Module?
A module is a package of reusable functionalities. It can be integrated into your Medusa application without affecting the overall system.
A module is a package of reusable commerce or architectural functionalities. It's integrated as a building block in your Medusa application, without implications on the existing setup.
Use modules to customize or develop commerce and architectural features in your Medusa application.
You create a module to introduce custom features, extend existing ones, or integrate third-party services.
---
@@ -30,7 +30,9 @@ For example, create the directory `src/modules/hello`.
### 1. Create Main Service
A module must define a service. A service is a TypeScript or JavaScript class holding methods related to a business logic or commerce functionality. It must be defined at the root of your module directory under `service.ts` filename.
A module must define a service. A service is a TypeScript or JavaScript class used to perform actions on the database or connect to third-party services.
A service must be defined at the root of your module directory under `service.ts` filename.
For example, create the file `src/modules/hello/service.ts` with the following content:
@@ -81,7 +83,13 @@ module.exports = defineConfig({
})
```
Its key (`helloModuleService`) is the name of the modules main service. It will be registered in the Medusa container with that name. It should also be the same name passed as the first parameter to the `Module` function in the module's definition.
Its key (`helloModuleService`) is the name of the modules main service. It will be registered in the Medusa container with that name.
<Note title="Tip">
It should also be the same name passed as the first parameter to the `Module` function in the module's definition.
</Note>
Its value is an object having the `resolve` property, whose value is either a path to module's directory relative to `src`(it shouldn't include `src` in the path), or an `npm` packages name.
@@ -89,7 +97,13 @@ Its value is an object having the `resolve` property, whose value is either a pa
## Test the Module
Since the module's main service is registered in the Medusa container, you can resolve it in other resources to use its functionalities.
Since the module's main service is registered in the Medusa container, you can resolve it in other resources to use its methods.
<Note title="Tip">
Resolving a module's service is essential to use its methods that perform actions on the database or connect to a third-party service.
</Note>
For example, create the API route `src/api/store/custom/route.ts` with the following content: