Documentation

9.1. Cheat sheet

This chapter provides a cheat sheet for Medusa's resources on when to use or not use them.

NameUse ifDon't use if
API Routes
  • You're exposing custom functionality to be used in the admin dashboard or an external application, such as a storefront.

-

Modules
  • You're implementing a custom commerce feature. For example, you're implementing digital products.
  • You want to extend data models in other commerce modules, such as adding a field or a relation to the Product model.
  • You want to re-use your custom commerce functionalities across Medusa applications or use them in other environments, such as Edge functions and Next.js apps.

-

Module Links
  • You want to create a relation between data models from different modules.
  • You want to create a relationship between data models in the same module. Use data model relationships instead.
Data Models
  • You want to store data related to your customization in the database.
  • You want to store simple key-value pairs related to a Medusa data model. Instead, use the metadata field that models have, which is an object of custom key-value pairs.
Data Model Relationships
  • You want to create a relation between data models in the same module.
  • You want to create a relationship between data models in different modules. Use module links instead.
Loaders
  • You're performing an action at application start-up.
  • You're establishing a one-time connection with an external system.
  • You want to perform an action continuously or at a set time pattern in the application. Use scheduled jobs instead.
Subscribers
  • You want to perform an action everytime a specific event is emitted in the Medusa application.

-

Scheduled Jobs
  • You're executing an action at a specified time interval during application runtime.
  • The action must be executed automatically.
  • You want the action to execute at a specified time interval while the Medusa application isn't running. Instead, use the operating system's equivalent of a cron job.
  • You want to execute the action once. Use loaders instead.
  • You want to execute the action if an event occurs. Use subscribers instead.
Workflows
  • You're defining a flow with interactions across multiple systems and services.
  • You're defining flows to be used across different resources. For example, if you want to invoke the flow manually through an API Router, but also want to automate its running through a scheduled job.
  • You want to define how the series of actions are rolled-back when an error occurs.

-

Middlewares
  • You want to protect API routes by a custom condition.
  • You're modifying the request body.

-

Was this chapter helpful?
Edit this page