1.3. Medusa's Architecture
In this chapter, you'll learn about the architectural layers in Medusa.
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:
- 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.
- Workflows: API Routes consume workflows that hold the opinionated business logic of your application.
- Modules: Workflows use domain-specific modules for resource management.
- Data store: Modules query the underlying datastore, which is a PostgreSQL database in common cases.
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.
Third-Party Integrations Layer#
Third-party services and systems are integrated through Medusa's Commerce and Architectural modules. You also create custom third-party integrations through a custom module.
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.
Architectural Modules#
Architectural modules integrate third-party services and systems for architectural features. Medusa has the following Architectural modules:
- Workflow Engine Module: Orchestrates workflows that hold the business logic of your application. You can integrate Redis to orchestrate workflows.
- Cache Module: Caches data that require heavy computation. You can integrate a custom module to handle the caching with services like Memcached, or use the existing Redis Cache Module.
- Event Module: A pub/sub system that allows you to subscribe to events and trigger them. You can integrate Redis as the pub/sub system.
- File Module: Manages file uploads and storage, such as upload of product images. You can integrate AWS S3 for file storage.
- Notification Module: Sends notifications to customers and users, such as for order updates or newsletters. You can integrate SendGrid for sending emails.
All of the third-party services mentioned above can be replaced to help you build your preferred architecture and ecosystem.
Full Diagram of Medusa's Architecture#
The following diagram illustrates Medusa's architecture including all its layers.