Grocery Cart Checkout
Problem Statement
Designing the Low-Level Design (LLD) for a Grocery Cart Checkout System, similar to what’s used in online grocery platforms like BigBasket, Blinkit, Amazon Fresh, or Instacart.
The system allows customers to add grocery items to their cart, apply offers or coupons, calculate the total bill (including taxes and discounts), and finally proceed to checkout and payment.
The focus is on the object-oriented design — defining entities, relationships, and workflows between components.
🎯 Goal
Design a system that can:
✅ Functional Requirements
1. Cart Management
Operations:
2. Product Details
3. Discounts and Coupons
Flat discount
Percentage discount
BOGO (Buy One Get One) (optional)
4. Tax Calculation
5. Checkout and Payment
6. Invoice / Receipt
⚙️ Non-Functional Requirements
🧱 Key Classes to Design
ClassResponsibility
Product
Represents grocery items with attributes like name, price, and tax rate.
CartItem
Represents an item and its quantity inside a cart.
Cart
Holds list of CartItems and handles add/remove/update operations.
Discount
Abstract class/interface for different discount types.
FlatDiscount, PercentageDiscount, CouponDiscount
Implement discount logic.
TaxCalculator
Calculates applicable tax on items.
CartCalculator
Computes subtotal, discount total, tax, and final total.
Payment
Represents payment transaction details.
CheckoutService
Handles final checkout, applies discounts/taxes, triggers payment.
InvoiceGenerator
Generates the final bill/receipt.
🧩 Suggested Class Structure
1
2Customer
3 ├── String id
4 ├── String name
5 ├── Cart cart
6
7Cart
8 ├── List<CartItem> items
9 ├── void addItem(Product, quantity)
10 ├── void removeItem(Product)
11 ├── void updateQuantity(Product, newQuantity)
12 ├── double getTotalBeforeDiscount()
13 ├── double getTotalAfterDiscountAndTax()
14
15CartItem
16 ├── Product product
17 ├── int quantity
18 ├── double getItemTotal()
19
20Product
21 ├── String id
22 ├── String name
23 ├── double pricePerUnit
24 ├── double taxRate
25 ├── String category
26 ├── int availableQuantity
27
28Discount (interface)
29 ├── double apply(Cart cart)
30
31FlatDiscount, PercentageDiscount, CouponDiscount
32 ├── override apply()
33
34TaxCalculator
35 ├── double calculateTax(CartItem)
36
37CheckoutService
38 ├── CartCalculator cartCalculator
39 ├── Payment processCheckout(Cart)
40
41Payment
42 ├── PaymentType type (CASH, CARD, WALLET)
43 ├── double amountPaid
44 ├── PaymentStatus status (SUCCESS, FAILED)
45
46InvoiceGenerator
47 ├── String generateInvoice(Cart, Payment)🔄 Example Flow
Add Items to Cart
Payment
Invoice Generated
1
2------------------------------
3Grocery Cart Receipt
4------------------------------
5Milk (2) ₹100
6Apple (3) ₹90
7Discount (10%) -₹19
8Tax (5%) ₹8.55
9------------------------------
10Total: ₹179.55
11Paid via: UPI
12------------------------------🧠 Design Patterns
⚡ Possible Extensions
✅ Final Summary:
Design a Grocery Cart Checkout System (LLD) that: