E-Commerce Database Schema — Mermaid ER Diagram
ER diagram of a complete e-commerce database with users, products, orders, payments, and reviews.
What this diagram shows
This Mermaid ER diagram is a checkout schema. A user places orders, writes reviews, and stores addresses. An order contains line items, is paid by one payment, and ships to one address. Each line item points at a product and stores the quantity and the unit price captured at purchase. Products belong to a category and collect reviews. Payments store a Stripe id and an amount. Addresses and reviews hang off the user.
Use it when you are reviewing an online store's tables before writing migrations. The unit_price column lives on ORDER_ITEM, not only on PRODUCT, so a later price change does not rewrite history. The address is referenced from the order as well as from the user, because a shipping address is a snapshot of where that order went.
Cardinality is crow's foot. USER to ORDER is one-to-many optional. ORDER to ORDER_ITEM is one-to-many required. ORDER to PAYMENT is one-to-one. PRODUCT to CATEGORY is many-to-one.
Mermaid syntax in this template
The diagram opens with erDiagram. Relationships are declared before or after the entity blocks; Mermaid accepts either order. This template declares the relationship, then the entity with its columns.
USER ||--o{ ORDER : places|| is exactly one on the user side. o{ is zero or more orders. The label places is the verb readers see on the line.
ORDER ||--|{ ORDER_ITEM : contains|{ means one or more. An order in this model cannot exist with zero line items.
uuid user_id FKFK marks a foreign key. PK and UK are the other markers used here (email and category slug are unique).
ORDER }o--|| ADDRESS : "shipped to"Quote the label when it contains a space. }o is zero or more orders per address.
Variations and ways to customize it
Support multiple payments per order
The template is one payment per order. Change the payment relationship to one-to-many if you capture partial captures or retries as separate rows.
ORDER ||--o{ PAYMENT : "paid via"Add a cart that is not yet an order
A cart is a different lifecycle from ORDER. Give it its own entity and line table so you do not overload status on ORDER with 'open cart'.
USER ||--o| CART : "has open"
CART ||--o{ CART_ITEM : contains
CART_ITEM }o--|| PRODUCT : referencesRecord the price book
unit_price is already denormalized onto the line. If finance wants the price list too, add a PRICE row with currency and effective dates, and keep unit_price as the value copied onto the line at checkout.
Diagram type
ER DiagramTags
Frequently asked questions
Why is unit price stored on the order line?
PRODUCT.price can change. ORDER_ITEM.unit_price is the amount charged for that unit on that order. Reviews and catalog pages should read PRODUCT.price. Receipts should read the line.
Is payment one-to-one with the order?
Yes in this template: ORDER ||--|| PAYMENT. Change it to one-to-many if a single order can have several charges. The stripe_id column is the processor reference, not the primary key.
How do I show a guest checkout?
Make user_id optional on ORDER and allow the shipping address to exist without a user. The current USER ||--o{ ORDER edge says every order has a user. Switch the user side to o| if guests are real.
What does UK mean on email and slug?
UK is Mermaid's unique-key marker. email on USER and slug on CATEGORY are unique. PK is the primary key. You can combine markers when a column is both, but this schema keeps them on separate columns.
Related templates and guides
All Database Design templatesInventory Management Schema
ER diagram for warehouse inventory tracking with products, warehouses, stock levels, and transfer orders.
SaaS Multi-Tenant Schema
ER diagram for a multi-tenant SaaS application with organizations, members, roles, and subscription billing.
CMS Content Model
ER diagram for a headless CMS with pages, blocks, media, and versioned content publishing workflow.
Mermaid ER diagram syntax
Crow's-foot markers and PK/FK attributes used on orders and line items.
ER diagram tutorial
How entity blocks and relationship labels work before you add a cart.