Knowledge Guide
HomeDatabasesNormalization

Designing an E-commerce Platform

An e-commerce platform is a digital marketplace where customers can browse, purchase, and review products. The platform involves multiple entities like users, products, orders, payments, and delivery management. Designing a robust database is critical for handling large-scale operations efficiently.

In this case study, we’ll model an e-commerce platform’s database using Entity-Relationship (ER) diagrams and then map it to a relational schema.

Requirements Analysis

For our case study, let's outline the key functionalities that the HMS should support:

Step-by-Step ER Diagram Creation

We will build the ER diagram for the Hospital Management System through the following four steps.

Step 1: Identify Entities

Entities represent objects or concepts in the system that have data stored about them.

  1. User
  2. Address
  3. Product
  4. Category
  5. Inventory
  6. Order
  7. Order_Item
  8. Payment
  9. Review
  10. Delivery
  11. Coupon
ER Diagram Entities for an Ecommerce Platform
ER Diagram Entities for an Ecommerce Platform

Step 2: Detailing Attributes

1. User

2. Address

3. Product

4. Category

5. Inventory

6. Order

7. Order_Item

8. Payment

9. Review

10. Delivery

11. Coupon

Attributes for an Ecommerce Platform
Attributes for an Ecommerce Platform

Step 3: Defining Relationships

1. User and Address

2. Product and Category

3. Product and Inventory

4. User and Order

5. Order and Order_Item

6. Order and Payment

7. Order and Delivery

8. Product and Review

9. User and Review

10. Order and Coupon

11. Product and Order_Item

Here is the final ER diagram.

ER Diagram for Ecommerce Platform
ER Diagram for Ecommerce Platform

Mapping the ER Diagram to a Relational Schema

When converting the ER diagram into a relational schema for our Ecommerce Platform, we need to carefully handle various components to ensure data integrity and optimal performance. Here are the key considerations:

Here is the final relational model for the Ecommerce Platform.

Relational Model for Ecommerce Platform
Relational Model for Ecommerce Platform

Now, let's translate the ER model into SQL tables.

1. User Table

CREATE TABLE User ( User_ID INT PRIMARY KEY, Full_Name VARCHAR(100), Email VARCHAR(100), Phone_Number VARCHAR(15), Password VARCHAR(50), Date_Joined DATE );

2. Address Table

CREATE TABLE Address ( Address_ID INT PRIMARY KEY, User_ID INT, Street VARCHAR(255), City VARCHAR(50), Country VARCHAR(50), Postal_Code VARCHAR(10), Address_Type VARCHAR(20), FOREIGN KEY (User_ID) REFERENCES User(User_ID) );

3. Product Table

CREATE TABLE Product ( Product_ID INT PRIMARY KEY, Name VARCHAR(100), Description TEXT, Price DECIMAL(10, 2), Category_ID INT, FOREIGN KEY (Category_ID) REFERENCES Category(Category_ID) );

4. Category Table

CREATE TABLE Category ( Category_ID INT PRIMARY KEY, Name VARCHAR(100), Description TEXT );

5. Inventory Table

CREATE TABLE Inventory ( Inventory_ID INT PRIMARY KEY, Product_ID INT, Quantity_In_Stock INT, Reorder_Level INT, FOREIGN KEY (Product_ID) REFERENCES Product(Product_ID) );

6. Order Table

CREATE TABLE Order ( Order_ID INT PRIMARY KEY, Order_Date DATE, User_ID INT, Coupon_ID INT Total_Amount DECIMAL(10, 2), Status VARCHAR(20), FOREIGN KEY (User_ID) REFERENCES User(User_ID), FOREIGN KEY (Coupon_ID) REFERENCES User(Coupon_ID), );

7. Order_Item Table

CREATE TABLE Order_Item ( Order_Item_ID INT PRIMARY KEY, Order_ID INT, Product_ID INT, Quantity INT, Subtotal DECIMAL(10, 2), FOREIGN KEY (Order_ID) REFERENCES Order(Order_ID), FOREIGN KEY (Product_ID) REFERENCES Product(Product_ID) );

8. Payment Table

CREATE TABLE Payment ( Payment_ID INT PRIMARY KEY, Order_ID INT, Payment_Date DATE, Payment_Method VARCHAR(50), Payment_Status VARCHAR(20), FOREIGN KEY (Order_ID) REFERENCES Order(Order_ID) );

9. Review Table

CREATE TABLE Review ( Review_ID INT PRIMARY KEY, User_ID INT, Product_ID INT, Rating INT, Review_Text TEXT, Review_Date DATE, FOREIGN KEY (User_ID) REFERENCES User(User_ID), FOREIGN KEY (Product_ID) REFERENCES Product(Product_ID) );

10. Delivery Table

CREATE TABLE Delivery ( Delivery_ID INT PRIMARY KEY, Order_ID INT, Delivery_Status VARCHAR(20), Delivery_Date DATE, Delivery_Partner VARCHAR(100), FOREIGN KEY (Order_ID) REFERENCES Order(Order_ID) );

11. Coupon Table

CREATE TABLE Coupon ( Coupon_ID INT PRIMARY KEY, Code VARCHAR(50), Discount_Percentage DECIMAL(5, 2), Expiry_Date DATE, Maximum_Usage INT );
🤖 Don't fully get this? Learn it with Claude

Stuck on Designing an E-commerce Platform? Open Claude, copy a block below, and it'll teach you this exact concept — visually and interactively.

🎨 Explain it visually

Build the mental picture, not memorization.

I just read a lesson on **Designing an E-commerce Platform** (Databases) and want to truly understand it. Explain Designing an E-commerce Platform from first principles using ONE vivid real-world analogy and a visual mental model — draw it as ASCII art or a clear step-by-step diagram — with a concrete example using real numbers. Then ask me one question to check I got the mental picture, and wait for my reply. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🤔 Walk me through it (interactive)

Socratic — adapts to where you're stuck.

Teach me **Designing an E-commerce Platform** interactively. Ask me ONE guiding question at a time, wait for my answer, and adapt to my confusion — build the idea with me step by step instead of explaining it all at once. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🧪 Quiz me & fix my gaps

Active recall exposes what you missed.

Quiz me on **Designing an E-commerce Platform** with 5 questions, easy to tricky, ONE at a time. Tell me if each answer is right; at the end, explain clearly what I got wrong and why. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🧠 Make it stick

Intuition + hook + flashcards for long-term memory.

Help me remember **Designing an E-commerce Platform** for the long term: give the one-sentence intuition, a memorable hook/mnemonic, a tiny worked example, and 3 active-recall flashcards (Q -> A). If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.

📝 My notes