Medusa (3/4): Commerce Modules and Features
Tags: webdev, javascript, react, opensource
Published: 2023-05-12 07:01:31

Medusa offers an impressive amount of e-commerce features all available in the medusa package or separately as independent modules. This is the third part of a four part series where the previous parts covered the basics of Medusa and their vision and history. This part will give a an outline of some of the commerce modules and what features they offer. The final part will go into detail on how the Medusa Admin works. 

## Modules and Features

For more technical details on how Medusa’s commerce modules and features work, you can visit the team’s Documentation at: [https://docs.medusajs.com/](https://docs.medusajs.com/)

### Cart & Checkout

Comes with basic cart functionality allowing users to add, update and remove items easily. Developers can choose to integrate any third-party provider of shipping and payment options during checkout, either through existing plug-ins or by creating their own. 

### Orders

Customers place orders to purchase a product. Admins can manage orders, for example capture payment and fulfill items in the order. Admins are also able to edit the order by adding, removing, or updating the order, either by force or by confirmation from the customer. It is also possible to create draft orders as well as returning, swapping and replace orders with new ones. 

### Multi-Warehouse

Medusa recently updated its Multi-Warehouse module that allows merchants to manage inventory and store products in multiple locations within the same commerce application. Through the admin page (see next article), it is also simple to manage from which location to allocate a product to an order or where to return items. 

### Customers

Customers can choose to shop as guests or create an account. They are able to make purchases as guests but can also manage order history and details as account holders. Admins can segment customers into groups, allowing for easily directed marketing and discounts for specific groups. 

### Products

Admins using Medusa can manage an unlimited amount of product variants. Products can be managed through changes in price, inventory, product details etc, and developers are able to implement custom product information as well. Products can also be organized into categories, allowing customers to navigate and filter while browsing. 

### Gift cards

Medusa handles gift cards in a versatile way. Customers can both purchase and use gift cards on the storefront. Developers are able to implement custom logic to send gift cards to specific customers as well as implement shipping profiles that specifically handle the fulfillment of the card. It is also possible to create custom gift cards using the admin page. 

### Price lists

Price lists are special prices applied to products based on a set of conditions. Price lists can be used to add special prices or override current prices for specific products simultaneously. Developers are able to change the default pricing logic and implement custom solutions of how customers view prices this way, which can speed up admin work compared to changing prices on individual products. 

### Regions & Currencies

Regions are handled very flexibly using Medusa. Admins are able to specify an unlimited amount of custom regions. Each region can have a custom set of settings such as currency, payment gateways, tax providers etc. Currencies can be associated with one or many regions, and developers are in full control of the price of a product per currency and per region. A customer within a specific region will automatically get products, prices, shipping options, taxes and more specified for that region. 

### Taxes

Taxes are closely related to regions since they often differ geographically. Medusa provides default tax provider to calculate rates, but developers are able to integrate custom solutions as well. 

### Sales channels

Medusa allows for a large amount of different sales channels, such as the web storefront, mobile apps or selling directly through social media platforms. For each channel, it is possible to choose which products belong to the channel, and products can be made available on multiple channels simultaneously. Each order is associated with a given channel, allowing for easy management and follow-up. 

## The mechanics of Medusa

Within each module described above, Medusa utilizes a set of abstractions in its architecture. This section aims to explain the overall architecture of Medusas commerce modules. 

### Headless architecture

As mentioned earlier, Medusa is a headless backend and is built in Node.js on top of Express. In the Medusa core package, you get access to all commerce modules such as orders, inventory, cart and products. 

### Entities and Services

The backend connects to a database that stores the e-commerce store’s data. Tables in the database are represented by *entities* built on top of Typeorm. An example would be the order-entity which represents the order table in the database. To manipulate e*ntities*, *services* are created as TypeScript or JavaScript classes with utility methods for retrieval and other purposes. The *services* can be accessed throughout the Medusa backend through dependency injection and are a sort of a bundled helper methods that represent a certain *entity* of functionality in Medusa. 

### Endpoints

Rather than having a tightly-coupled frontend which is the case for traditional e-commerce platforms, the Medusa backend provides *endpoints*, which are REST APIs used by frontends like storefront or admin interfaces. Each commerce module contains a set of *endpoints* specific to the functionalities that it provides and are available within the Medusa backend.

### Events

Medusa also uses an event-driven architecture to manage events. When an action occur, such as an order being placed, an *event* is triggered. To handle an *event*, Medusa connects to a *service* that implements a pub/sub model. Messages sent by the pub/sub model are received by *subscribers*. *Subscribers* are TypeScript or JavaScript classes that add their methods as handlers for specific events. These handler methods are then executed only when an *event* is triggered. Using the example of an order being placed, a *service* specific to ordering (the *publisher*) then sends a message to the warehouse (the *subscriber*) that initiate shipping, update the inventory and notify customers. 

### Loaders and plugins

The Medusa backend architecture can be tailored to suit individual requirements, with resources like *entities*, *services* and *endpoints* created without modifying the backend. Loaders are used to load both Medusa and custom resources such as plugins, which can be packaged for reuse in other Medusa backends or published for others to use. Existing plugins can also be installed into a Medusa backend. 

To learn more about the Medusa Admin, read the next article: