1.3. Medusa's Architecture - Medusa Documentation (original) (raw)

In this chapter, you'll learn about the architectural layers in Medusa.

Tip: Find the full architectural diagram at the end of this chapter.

HTTP, Workflow, and Module Layers#

Medusa is a headless commerce platform. So, storefronts, admin dashboards, and other clients consume Medusa's functionalities through its API routes.

In a common Medusa application, requests go through four layers in the stack. In order of entry, those are:

  1. API Routes (HTTP): Our API Routes are the typical entry point. The Medusa server is based on Express.js, which handles incoming requests. It can also connect to a Redis database that stores the server session data.
  2. Workflows: API Routes consume workflows that hold the opinionated business logic of your application.
  3. Modules: Workflows use domain-specific modules for resource management.
  4. Data store: Modules query the underlying datastore, which is a PostgreSQL database in common cases.

Note: These layers of stack can be implemented within plugins.

This diagram illustrates the entry point of requests into the Medusa application through API routes. It shows a storefront and an admin that can send a request to the HTTP layer. The HTTP layer then uses workflows to handle the business logic. Finally, the workflows use modules to query and manipulate data in the data stores.


Database Layer#

The Medusa application injects into each module, including your custom modules, a connection to the configured PostgreSQL database. Modules use that connection to read and write data to the database.

Note: Modules can be implemented within plugins.

This diagram illustrates how modules connect to the database.


Third-Party Integrations Layer#

Third-party services and systems are integrated through Medusa's Commerce and Infrastructure Modules. You also create custom third-party integrations through a custom module.

Note: Modules can be implemented within plugins.

Commerce Modules#

Commerce Modules integrate third-party services relevant for commerce or user-facing features. For example, you can integrate Stripe through a Payment Module Provider, or ShipStation through a Fulfillment Module Provider.

You can also integrate third-party services for custom functionalities. For example, you can integrate Sanity for rich CMS capabilities, or Odoo to sync your Medusa application with your ERP system.

You can replace any of the third-party services mentioned above to build your preferred commerce ecosystem.

Diagram illustrating the Commerce Modules integration to third-party services

Infrastructure Modules#

Infrastructure Modules integrate third-party services and systems that customize Medusa's infrastructure. Medusa has the following Infrastructure Modules:

All of the third-party services mentioned above can be replaced to help you build your preferred architecture and ecosystem.

Diagram illustrating the Infrastructure Modules integration to third-party services and systems


Full Diagram of Medusa's Architecture#

The following diagram illustrates Medusa's architecture including all its layers.

Full diagram illustrating Medusa's architecture combining all the different layers.

Was this chapter helpful?