Class Diagram for Online Shopping System: Complete UML Example
Table of Contents
E-commerce systems are among the most searched class diagram examples — they combine familiar real-world concepts (cart, checkout, product catalog) with genuine design complexity (polymorphic products, payment strategies, order state machines). This makes them ideal for learning and demonstrating OOP design principles.
This post provides a complete online shopping system class diagram in Mermaid syntax, organized by subsystem.
Product Catalog
classDiagram
class Product {
+String productId
+String name
+String description
+float price
+int stockQuantity
+String sku
+bool isActive
+isInStock() bool
+applyDiscount(pct float) void
+getImages() List
}
class PhysicalProduct {
+float weight
+String dimensions
+String shippingClass
+requiresShipping() bool
}
class DigitalProduct {
+String downloadUrl
+int downloadLimit
+generateDownloadLink() String
}
class Category {
+String categoryId
+String name
+String slug
+Category parent
+getProducts() List
}
class Review {
+String reviewId
+int rating
+String comment
+DateTime createdAt
+bool isVerified
}
Product <|-- PhysicalProduct
Product <|-- DigitalProduct
Product "0..*" --> "1..*" Category : belongs to
Product "1" *-- "0..*" Review : has
Shopping Cart and Checkout
classDiagram
class Cart {
+String cartId
+DateTime createdAt
+DateTime updatedAt
+addItem(product, qty int) void
+removeItem(productId) void
+updateQuantity(productId, qty) void
+getTotal() float
+clear() void
+getItemCount() int
}
class CartItem {
+int quantity
+float unitPrice
+float lineTotal
+getSubtotal() float
}
class Coupon {
+String code
+String discountType
+float discountValue
+Date expiryDate
+int usageLimit
+isValid() bool
+applyTo(cart Cart) float
}
Cart *-- CartItem
CartItem --> Product
Cart "0..1" --> "0..1" Coupon : applies
Sell Custom Apparel — We Handle Printing & Free Shipping
Order Management
classDiagram
class Order {
+String orderId
+DateTime placedAt
+String status
+float subtotal
+float tax
+float shippingCost
+float total
+String notes
+confirm() void
+cancel() void
+getInvoice() Invoice
}
class OrderItem {
+int quantity
+float unitPrice
+float lineTotal
+String productSnapshot
}
class ShippingAddress {
+String recipientName
+String street
+String city
+String state
+String zipCode
+String country
+String phone
}
class Shipment {
+String shipmentId
+String carrier
+String trackingNumber
+DateTime shippedAt
+DateTime estimatedDelivery
+String status
+track() String
}
Order *-- OrderItem
Order *-- ShippingAddress
Order "1" --> "0..1" Shipment : fulfilled by
User "1" --> "0..*" Order : places
Payment System
classDiagram
class Payment {
<<abstract>>
+String paymentId
+float amount
+String currency
+DateTime processedAt
+String status
+process() bool
+refund(amount float) bool
+getReceipt() String
}
class CreditCardPayment {
+String last4Digits
+String cardBrand
+String billingZip
+process() bool
}
class PayPalPayment {
+String paypalEmail
+String transactionId
+process() bool
}
class WalletPayment {
+String walletId
+float walletBalance
+process() bool
}
Payment <|-- CreditCardPayment
Payment <|-- PayPalPayment
Payment <|-- WalletPayment
Order "1" --> "1" Payment : paid via
User and Wishlist
classDiagram
class User {
+String userId
+String email
+String passwordHash
+String firstName
+String lastName
+DateTime createdAt
+bool isEmailVerified
+login(email, pwd) bool
+logout() void
+updateProfile(data) void
}
class Address {
+String addressId
+String label
+String street
+String city
+String country
+bool isDefault
}
class Wishlist {
+String wishlistId
+String name
+bool isPublic
+addProduct(product) void
+removeProduct(productId) void
+moveToCart() void
}
User "1" --> "0..*" Address : has
User "1" --> "0..*" Wishlist : owns
Wishlist "0..*" --> "0..*" Product : contains
User "1" --> "1" Cart : has
Try It Free — No Signup Required
Runs 100% in your browser. No data is collected, stored, or sent anywhere.
Open Free Class Diagram ToolFrequently Asked Questions
Why is Payment shown as abstract in the online shopping diagram?
Because every real payment uses a specific payment method (credit card, PayPal, wallet). There is no generic "Payment" — you always instantiate a concrete subclass. Abstract enforces this design constraint.
Should CartItem use composition or aggregation with Cart?
Composition. A CartItem only exists as part of a Cart — it has no independent lifecycle. When the cart is cleared or abandoned, its items are gone.
What is the difference between CartItem and OrderItem?
CartItem is a live reference to a Product in the cart. OrderItem is a snapshot of the product at purchase time (price, name, SKU locked in). This prevents order history from changing if the product is later modified.
How do I paste this into the free online class diagram tool?
Copy any Mermaid block, open the Badger Class Diagram tool, paste it in, and the diagram renders live. Export PNG or SVG with no signup required.

