Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: update modules chapter in basics #9452

Merged
merged 3 commits into from
Oct 4, 2024

Conversation

shahednasser
Copy link
Member

  • Replace the data models and modules and services chapters in basics with a single modules chapter that covers the three concepts
  • Add redirects from the old chapters to the new one + fix links

@shahednasser shahednasser requested a review from a team as a code owner October 3, 2024 13:56
Copy link

changeset-bot bot commented Oct 3, 2024

⚠️ No Changeset found

Latest commit: dd70fc4

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

vercel bot commented Oct 3, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
api-reference 🔄 Building (Inspect) Visit Preview 💬 Add feedback Oct 4, 2024 9:20am
api-reference-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 4, 2024 9:20am
docs-ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 4, 2024 9:20am
docs-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 4, 2024 9:20am
medusa-dashboard ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 4, 2024 9:20am
resources-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 4, 2024 9:20am
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
medusa-docs ⬜️ Ignored (Inspect) Visit Preview Oct 4, 2024 9:20am

Comment on lines 11 to 21
A module is a package of reusable commerce or architectural functionalities. These functionalities are implemented within the module in a class called a service.

In the module, you can create new tables in the database. Then, you manage their records using the module's service, which connects to the database.

A module is integrated as a building block in your Medusa application, without implications on the existing setup.

<Note title="Tip">

Modules and services have other uses too, which you'll learn about in later chapters.

</Note>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion:

In Medusa, Modules handle business logic and define and manage data models. Out of the box, Medusa comes with multiple pre-built modules for core commerce needs. An example is the Cart module, which holds the data models and business logic for cart operations.

In digital commerce you often need to introduce custom behavior specific to your products, industry, tech stack, or your general ways of working. In other commerce platforms introducing custom business logic and data models requires setting up separate applications to manage these customizations, but Medusa removes the overhead of doing that by enabling you to easily write custom Modules that can interact with the rest of Medusa.

As you learn more about Medusa you will see that Modules are central to customizations and integrations. In this section you will build a module that comprise a data model and a corresponding module service to manage the data model.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this, but how about we use some for this intro section (what is a module), and some in a later section (why use modules)? I just think it could be too much information from the get-go, especially if you haven't seen it in action yet. We'd be jumping 10 steps ahead before the developer had a glimpse of what a module entails.

Copy link
Collaborator

@srindom srindom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some suggestions but otherwise looks good ✅

Comment on lines 25 to 34
## How to Create a Module?

Modules are created in a sub-directory of `src/modules`.

For example, create the directory `src/modules/hello`.

### 1. Create Data Model

A data model represents a table in the database. It's created in a TypeScript or JavaScript file under the module's `models` directory.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thought: feel like there is a need for setting the agenda for the steps that are coming. Just one sentence on the high-level objective here would be helpful.

E.g.: "In the following steps we will create a data model called MyCustom, we will then add a ModuleService to manage that data model, and finally we will use the module in an API route."

Comment on lines 86 to 96
Since the module has data models, its service extends a class generated by the service factory function `MedusaService` imported from `@medusajs/framework/utils`.

<Note title="Tip">

If a module doesn't have data models, it doesn't need to extend `MedusaService`.

</Note>

The service factory function accepts as a parameter an object of data models. It returns a service class with data management methods, such as `createMyCustoms` or `retrieveMyCustoms`.

Your service extends the returned class to benefit from the generated methods.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion:

In the snippet above, your module service extends MedusaService. MedusaService can take a set of data models and will generate a class that has implementations for the CRUD operations on those data models. For example, the HelloModuleService now allows you to do createMyCustoms or retrieveMyCustoms.

Using MedusaService is not required, but it is helpful and recommended when your module has data models.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants