Architecture
Mercur follows a layered architecture where each layer has a distinct responsibility:Commerce layer
Medusa provides the core commerce engine — products, pricing, carts, orders, payments, fulfillment, promotions, and inventory. Mercur does not replace any of this. Instead, it builds on top using Medusa’s extension model: custom modules, links, workflows, and API routes.Marketplace layer
This is where Mercur’s code lives. It introduces three custom modules — Seller, Commission, and Payout — along with workflows that coordinate marketplace-specific operations like order splitting and commission calculation. Links connect these modules to Medusa’s core entities (products, orders, customers) without modifying the original models.API layer
Mercur exposes three sets of HTTP endpoints:| API | Path | Purpose |
|---|---|---|
| Admin | /admin/* | Platform administration — manage sellers, configure commission rates, view payouts |
| Vendor | /vendor/* | Seller operations — manage products, orders, fulfillment, shipping, inventory, payouts |
| Store | /store/* | Storefront — browse sellers, manage carts, checkout with order splitting |
Frontend layer
Three interfaces consume the APIs:- Admin Panel — Built with React and Medusa UI components. Operators use it to manage the marketplace: approve sellers, set commission rates, handle disputes.
- Vendor Portal — A React application for sellers to manage their products, orders, fulfillment, and payouts. Uses file-based routing via the Dashboard SDK.
- Storefront — Customer-facing application. Can be built with any frontend technology that consumes the Store API.
Technology stack
| Layer | Technology |
|---|---|
| Runtime | Node.js 20+, TypeScript |
| Framework | MedusaJS v2 |
| Database | PostgreSQL |
| Frontend | React 18, React Router, Vite |
| Data fetching | TanStack React Query |
| UI components | Medusa UI, Radix UI |
| Form handling | React Hook Form, Zod |
| Tables | TanStack React Table |
| Build | Turborepo (monorepo), Bun (package manager), tsup |
| Internationalization | i18next |
Core plugin
The core plugin (@mercurjs/core-plugin) is the main package that contains all marketplace logic. It’s structured as a standard MedusaJS plugin:
Modules
Modules encapsulate data models and business logic for a specific domain. Each module is self-contained with its own models, service, migrations, and repositories. Modules don’t reference each other directly — they communicate through links and workflows.Links
Links define relationships between Mercur modules and Medusa core entities. For example, theproduct-seller-link connects a Medusa Product to a Mercur Seller without modifying either model. There are 17 links that wire the marketplace layer into the commerce layer — connecting sellers to products, orders, customers, shipping options, inventory, promotions, and more.
Workflows
Workflows orchestrate multi-step operations that span multiple modules. They support compensation (automatic rollback on failure) and hooks (extension points for custom logic). The most significant workflow iscompleteCartWithSplitOrdersWorkflow, which handles the entire checkout process — validating items, splitting by seller, creating orders, allocating payments, and calculating commissions.
Subscribers and events
Subscribers listen for events emitted by workflows and trigger asynchronous side effects — sending notifications, updating external systems, or processing webhooks. This keeps the core workflows focused on their primary job while allowing the system to react to changes.How data flows
A typical customer purchase flows through the system like this:- Customer adds items from multiple sellers to their cart (Store API)
- Cart completion triggers the split order workflow (Marketplace Layer)
- Items are grouped by seller, and a separate order is created for each (Commerce + Marketplace Layer)
- Commission lines are calculated for each order based on matching rates (Commission Module)
- Payment is split proportionally across seller orders (Commerce Layer)
- Each seller’s order is credited to their payout account after commission deduction (Payout Module)
- Events are emitted — triggering notifications, webhook calls, and other side effects (Subscribers)
- Sellers manage their orders through the Vendor Portal (Vendor API)
- The admin monitors everything through the Admin Panel (Admin API)
Block-based distribution
Mercur uses a block-based architecture for distribution. Instead of installing an opaque package, the CLI copies source code directly into your project. Each block is a self-contained piece of functionality — a module, a workflow, an API route, or a UI extension. This means:- You own every line of code in your project
- You can modify any block to fit your business requirements
- There are no hidden abstractions or version conflicts
- Updates are explicit — you diff and apply changes from the registry
@mercurjs/cli@latest) manages this process: scaffolding projects, installing blocks, searching the registry, and comparing local changes against upstream versions.