medusajs/medusa

The world's most flexible commerce platform.

32,716 stars TypeScript 9 components

Orchestrates modular commerce services through HTTP APIs and admin dashboards

HTTP requests enter through the main API server which routes them to appropriate modules based on resource type (cart, product, payment). Each module processes the request using its own service layer, interacts with its database entities through an ORM, and returns data that gets transformed into standardized API responses. Events flow between modules through an event bus to maintain consistency (e.g., cart updates trigger inventory checks).

Under the hood, the system uses 2 feedback loops, 3 data pools, 3 control points to manage its runtime behavior.

A 9-component fullstack. 10601 files analyzed. Data flows through 5 distinct pipeline stages.

How Data Flows Through the System

HTTP requests enter through the main API server which routes them to appropriate modules based on resource type (cart, product, payment). Each module processes the request using its own service layer, interacts with its database entities through an ORM, and returns data that gets transformed into standardized API responses. Events flow between modules through an event bus to maintain consistency (e.g., cart updates trigger inventory checks).

  1. HTTP request routing — Express.js routes in packages/medusa/src/api parse incoming requests, extract path parameters and query filters, then determine which module should handle the operation [HTTP request → Parsed request data]
  2. Module service invocation — The API layer calls the appropriate module service (CartModuleService.create, ProductModuleService.list) with validated input DTOs, leveraging dependency injection to locate services [CreateCartDTO → Cart entities]
  3. Database entity operations — Module services use MikroORM to persist/retrieve entities from PostgreSQL, with each module managing its own database schema and migrations [Service operations → Database entities]
  4. Response transformation — Functions like buildPriceListResponse transform raw database entities into API response DTOs, applying field selection and data enrichment [Database entities → AdminPriceListRemoteQueryDTO]
  5. Inter-module event propagation — Module operations emit events through the event bus (local or Redis) that other modules can subscribe to, enabling loose coupling between commerce operations [Domain events → Event notifications]

Data Models

The data structures that flow between stages — the contracts that hold the system together.

AdminPriceListRemoteQueryDTO packages/medusa/src/api/admin/price-lists/types
API response object with id: string, title: string, description: string, rules: PriceListRule[], prices: PriceSetPrice[], created_at: Date, updated_at: Date
Created from database price list entities, enriched with rules and prices, then serialized for HTTP response
CreateCartDTO packages/modules/cart/src/types
Input object with optional fields like currency_code: string, region_id: string, customer_id: string, sales_channel_id: string, metadata: Record<string, unknown>
Received from HTTP requests, validated, then passed to CartModuleService.create() to persist as Cart entity
AuthIdentity packages/modules/auth/src/models
Database entity with id: string, provider_identities: ProviderIdentity[], app_metadata: Record<string, unknown>, user_metadata: Record<string, unknown>
Created during user registration, linked to provider identities, persisted in auth database, retrieved during authentication flows
CreateApiKeyDTO packages/modules/api-key/src/types
Input object with title: string, type: ApiKeyType (SECRET|PUBLISHABLE), created_by: string
Created through admin API, generates hashed token, stored in database, used to authenticate API requests
ModuleExports packages/core/types/src
Interface with service: ModuleService, loaders?: ModuleLoader[], models?: Model[]
Defined by each module to export its service and configuration, consumed by framework during module loading

Hidden Assumptions

Things this code relies on but never validates. These are the things that cause silent failures when the system changes.

critical Contract unguarded

The priceLists parameter has properties price_list_rules and prices arrays that can be mutated in-place, and buildPriceListRules/buildPriceSetPricesForCore functions will return compatible array types

If this fails: If price list objects are immutable or lack these properties, the function silently fails to build rules/prices arrays, returning malformed response objects to API clients

packages/medusa/src/api/admin/price-lists/queries/index.ts:buildPriceListResponse
critical Shape unguarded

The apiFields parameter contains valid property paths that exist on the priceList objects being filtered, and the filtering logic can handle nested object structures

If this fails: Invalid field paths in apiFields cause property access errors or return empty objects, breaking API field selection functionality that clients depend on for performance

packages/medusa/src/utils/clean-response-data:cleanResponseData
critical Contract unguarded

Module service classes passed to Module() constructor have a working constructor that can be instantiated by the dependency injection container without throwing errors

If this fails: If a service constructor requires specific parameters or throws during instantiation, the entire application fails to start with unclear error messages about module loading

packages/core/modules-sdk:MedusaModule.bootstrap
warning Environment unguarded

Redis server is accessible at connection parameters specified in RedisCacheModuleOptions, and the Redis instance has sufficient memory for cache operations

If this fails: Application starts successfully but cache operations fail silently or with connection timeouts, causing performance degradation as database queries aren't cached

packages/modules/cache-redis/src/initialize/index.ts:initialize
warning Ordering unguarded

Provider loading happens before AnalyticsService instantiation attempts to use those providers, and provider registration order doesn't matter for analytics functionality

If this fails: If services try to access providers before loader completes, analytics events are dropped silently without error logs, breaking tracking for business metrics

packages/modules/analytics/src/index.ts:loadProviders
warning Scale unguarded

In-memory cache size will not exceed available Node.js heap memory, and cache entries have reasonable TTL values to prevent unbounded growth

If this fails: Large product catalogs or missing TTL configurations cause out-of-memory crashes in production, especially under high concurrent load

packages/modules/cache-inmemory/src/services/inmemory-cache:InMemoryCacheService
warning Contract weakly guarded

The service parameter implements createAuthIdentities method that accepts the userData array format with optional id, required provider_identities array, and optional app_metadata object

If this fails: If IAuthModuleService interface changes or service implementation expects different data shape, test fixtures fail with method not found or validation errors

packages/modules/auth/integration-tests/__fixtures__/auth-identity/index.ts:createAuthIdentities
info Domain weakly guarded

API key types SECRET and PUBLISHABLE map to specific authentication behaviors, and 'created_by' field accepts arbitrary string identifiers without validation

If this fails: If ApiKeyType enum values change or created_by requires valid user IDs, API key creation fails in production with cryptic validation errors

packages/modules/api-key/integration-tests/__fixtures__/index.ts:createSecretKeyFixture
warning Temporal unguarded

Module loading order is deterministic and modules don't have circular dependencies that require specific initialization sequencing

If this fails: Race conditions during startup cause some modules to initialize before their dependencies are ready, leading to intermittent startup failures that are hard to reproduce

packages/core/modules-sdk:MedusaModule.bootstrap
warning Resource unguarded

Redis connection pool can handle concurrent cache operations from multiple request threads without connection exhaustion or timeout issues

If this fails: Under high load, cache operations queue up behind exhausted connections, causing API response times to degrade as requests wait for cache access

packages/modules/cache-redis/src/services:RedisCacheService

System Behavior

How the system operates at runtime — where data accumulates, what loops, what waits, and what controls what.

Data Pools

Module databases (database)
Each commerce module maintains its own PostgreSQL schema with entities like Cart, Product, Order — providing data isolation and independent scaling
Event bus queue (queue)
Queues domain events between modules to ensure eventual consistency and enable reactive business logic
Cache layer (cache)
Stores frequently accessed data like product catalogs, price lists, and computed totals to reduce database load

Feedback Loops

Delays

Control Points

Technology Stack

TypeScript (runtime)
Primary language for type-safe commerce logic across all modules
Node.js (runtime)
JavaScript runtime environment for server-side execution
Express.js (framework)
HTTP server framework providing REST API endpoints for admin and store operations
MikroORM (database)
Database ORM for managing PostgreSQL schemas and entity relationships within each module
PostgreSQL (database)
Primary database for persisting commerce entities like products, orders, customers
Redis (infra)
Distributed caching and event bus implementation for multi-instance deployments
Awilix (framework)
Dependency injection container for managing module services and their dependencies
React (framework)
Frontend framework for building the admin dashboard interface
Jest (testing)
Testing framework for unit and integration tests across all packages
Turbo (build)
Monorepo build system for managing dependencies and parallel builds across 85+ packages

Key Components

Package Structure

medusa-core (app)
The main commerce platform API server that orchestrates all commerce operations through HTTP endpoints
commerce-modules (library)
Modular commerce services (cart, product, payment, etc.) that implement core business logic
core-framework (library)
Framework utilities, SDKs, orchestration, and type definitions that power the entire system
admin-dashboard (app)
React-based administrative interface for managing the commerce platform
design-system (library)
UI components, icons, and design tokens used across admin interfaces
cli-tools (tooling)
Command-line tools for project creation, development, and OpenAPI spec generation
test-utils (tooling)
Testing utilities and fixtures for integration tests across the platform
plugins (library)
Optional commerce extensions like draft orders and loyalty programs

Explore the interactive analysis

See the full architecture map, data flow, and code patterns visualization.

Analyze on CodeSea

Compare medusa

Related Fullstack Repositories

Frequently Asked Questions

What is medusa used for?

Orchestrates modular commerce services through HTTP APIs and admin dashboards medusajs/medusa is a 9-component fullstack written in TypeScript. Data flows through 5 distinct pipeline stages. The codebase contains 10601 files.

How is medusa architected?

medusa is organized into 4 architecture layers: API Gateway, Commerce Modules, Framework Layer, Provider Ecosystem. Data flows through 5 distinct pipeline stages. This layered structure keeps concerns separated and modules independent.

How does data flow through medusa?

Data moves through 5 stages: HTTP request routing → Module service invocation → Database entity operations → Response transformation → Inter-module event propagation. HTTP requests enter through the main API server which routes them to appropriate modules based on resource type (cart, product, payment). Each module processes the request using its own service layer, interacts with its database entities through an ORM, and returns data that gets transformed into standardized API responses. Events flow between modules through an event bus to maintain consistency (e.g., cart updates trigger inventory checks). This pipeline design reflects a complex multi-stage processing system.

What technologies does medusa use?

The core stack includes TypeScript (Primary language for type-safe commerce logic across all modules), Node.js (JavaScript runtime environment for server-side execution), Express.js (HTTP server framework providing REST API endpoints for admin and store operations), MikroORM (Database ORM for managing PostgreSQL schemas and entity relationships within each module), PostgreSQL (Primary database for persisting commerce entities like products, orders, customers), Redis (Distributed caching and event bus implementation for multi-instance deployments), and 4 more. This broad technology surface reflects a mature project with many integration points.

What system dynamics does medusa have?

medusa exhibits 3 data pools (Module databases, Event bus queue), 2 feedback loops, 3 control points, 2 delays. The feedback loops handle recursive and self-correction. These runtime behaviors shape how the system responds to load, failures, and configuration changes.

What design patterns does medusa use?

4 design patterns detected: Modular Service Architecture, Provider Plugin System, Event-Driven Architecture, API Response Transformation.

How does medusa compare to alternatives?

CodeSea has side-by-side architecture comparisons of medusa with commerce. These comparisons show tech stack differences, pipeline design, system behavior, and code patterns. See the comparison pages above for detailed analysis.

Analyzed on April 20, 2026 by CodeSea. Written by .