Skip to content

Conversation

@adityacosmos24
Copy link
Contributor

Zepto Clone Quick Commerce Delivery System (C++)

Overview

This PR introduces a comprehensive C++ implementation of a Zepto Clone (quick commerce delivery system) that demonstrates multiple design patterns working together in a real-world e-commerce scenario. The implementation showcases a complete order fulfillment system with inventory management, multi-store routing, and intelligent delivery partner assignment.

Design Patterns Demonstrated

1. Factory Pattern

  • ProductFactory: Centralized product creation based on SKU
  • Encapsulates product instantiation logic
  • Supports easy addition of new product types

2. Strategy Pattern

  • ReplenishStrategy: Abstract base for inventory replenishment algorithms
  • ThresholdReplenishStrategy: Replenishes when stock falls below a threshold
  • WeeklyReplenishStrategy: Weekly scheduled replenishment
  • Allows runtime strategy selection without modifying client code

3. Singleton Pattern

  • DarkStoreManager: Single instance managing all dark stores in the system
  • OrderManager: Single instance handling all order operations
  • Ensures centralized management and consistent state

4. Abstraction & Interface Segregation

  • InventoryStore: Abstract interface for inventory storage
  • DbInventoryStore: Concrete implementation using in-memory maps
  • Enables easy swapping of storage backends (database, cache, etc.)

Architecture & Components

Core Entities

  1. Product Management

    • Product: Represents a product with SKU, name, and price
    • ProductFactory: Creates products based on SKU lookup
  2. Inventory System

    • InventoryStore: Abstract interface for inventory operations
    • DbInventoryStore: In-memory inventory storage with stock tracking
    • InventoryManager: Facade for inventory operations
  3. Dark Store System

    • DarkStore: Represents a warehouse with location coordinates (x, y)
    • Manages inventory per store
    • Supports configurable replenishment strategies
    • Calculates distance to users for proximity-based routing
  4. Store Management

    • DarkStoreManager: Singleton managing all dark stores
    • Finds nearby stores within specified radius (default: 5 KM)
    • Sorts stores by distance using Euclidean distance calculation
  5. Order Management

    • Order: Represents a customer order with items and delivery partners
    • OrderManager: Singleton handling order placement and fulfillment
    • Supports both single-store and multi-store order fulfillment
  6. User & Shopping

    • User: Represents a customer with location coordinates
    • Cart: Shopping cart managing product items and quantities
    • Calculates total order value
  7. Delivery System

    • DeliveryPartner: Represents delivery personnel
    • Automatically assigned based on store distribution

Key Features

Intelligent Order Fulfillment

Single Store Fulfillment:

  • When all requested items are available in the nearest store
  • Single delivery partner assigned
  • Efficient and cost-effective

Multi-Store Fulfillment:

  • Automatically splits orders across multiple stores when needed
  • Assigns delivery partners for each store involved
  • Handles partial fulfillment scenarios gracefully
  • Reports unfulfillable items with detailed information

Location-Based Routing

  • Finds dark stores within 5 KM radius of user location
  • Uses Euclidean distance formula: √((x₁-x₂)² + (y₁-y₂)²)
  • Sorts stores by proximity (nearest first)
  • Optimizes delivery time and cost

Inventory Operations

  • Add Stock: Add products to store inventory
  • Remove Stock: Deduct inventory on order fulfillment
  • Check Stock: Query available quantity for a SKU
  • List Products: Get all available products in a store
  • Automatic stock deduction on successful order placement

Replenishment Strategies

  • Threshold-based: Replenishes when stock falls below configured threshold
  • Weekly: Scheduled weekly replenishment
  • Easily extensible for new strategies (demand-based, seasonal, etc.)

Implementation Highlights

Order Placement Flow

  1. User adds items to cart → Products created via Factory
  2. Find nearby stores → DarkStoreManager queries stores within 5 KM
  3. Check availability → Verify if nearest store has all items
  4. Fulfillment decision:
    • If all items available → Single store fulfillment
    • If items split → Multi-store fulfillment with partner assignment
  5. Stock deduction → Remove items from store inventories
  6. Order creation → Generate order with summary and partner assignments

Multi-Store Fulfillment Algorithm

// Pseudo-code for multi-store fulfillment
for each nearby store (sorted by distance):
    for each SKU in order:
        if store has SKU in stock:
            take min(available, needed)
            assign delivery partner
            update remaining quantities
    if all items fulfilled: break

Example Usage

// 1. Initialize system with dark stores
ZeptoHelper::initialize();

// 2. Create user at location (1.0, 1.0)
User* user = new User("Aditya", 1.0, 1.0);

// 3. Show available products within 5 KM
ZeptoHelper::showAllItems(user);

// 4. Add items to cart
Cart* cart = user->getCart();
cart->addItem(101, 4);  // Apple x4
cart->addItem(102, 3);  // Banana x3
cart->addItem(103, 2);  // Chocolate x2

// 5. Place order (handles multi-store fulfillment automatically)
OrderManager::getInstance()->placeOrder(user, cart);

Sample Output

  • Lists all available products within 5 KM radius
  • Shows order placement process with store selection
  • Displays stock allocation across stores
  • Shows delivery partner assignments
  • Provides complete order summary with items and total

Build Instructions

The project includes a compile.bat script for Windows that:

  • Compiles the C++ code using g++ with C++11 standard
  • Automatically runs the executable upon successful compilation
  • Provides error feedback if compilation fails

Manual Compilation

g++ -std=c++11 -o zepto_clone ZeptoClone.cpp
./zepto_clone

Files Included

  • ZeptoClone.cpp: Complete implementation (~715 lines)
    • All classes and design pattern implementations
    • Main function with demonstration flow
    • Helper utilities for initialization and display
  • compile.bat: Windows batch script for compilation and execution
  • zepto_clone.exe: Compiled executable (generated after compilation)

Technical Details

  • Language: C++11
  • Standard Library Usage:
    • iostream, string, vector, map, algorithm, cmath
  • Memory Management: Raw pointers (demonstration purposes)
  • Compilation: Requires g++ compiler with C++11 support

Benefits of This Implementation

  1. Educational Value:

    • Demonstrates multiple design patterns working together
    • Shows real-world system design principles
    • Excellent learning resource for OOP and design patterns
  2. Real-World Application:

    • Models actual quick commerce delivery systems (Zepto, Blinkit, etc.)
    • Addresses real challenges: inventory management, routing, fulfillment
  3. Extensibility:

    • Easy to add new features (payment, notifications, tracking)
    • New replenishment strategies can be added without modifying existing code
    • New inventory storage backends can be plugged in
  4. Code Quality:

    • Well-structured, object-oriented design
    • Clear separation of concerns
    • Follows SOLID principles
    • Comprehensive error handling
  5. Comprehensive Coverage:

    • Complete order-to-fulfillment lifecycle
    • Inventory management
    • Location-based routing
    • Multi-store coordination

Learning Outcomes

This implementation demonstrates:

  • Design Pattern Integration: How multiple patterns work together
  • System Design: Real-world e-commerce architecture
  • Algorithm Design: Location-based routing and order splitting
  • Object-Oriented Programming: Inheritance, polymorphism, encapsulation
  • Memory Management: Resource handling in C++
  • Problem Solving: Complex business logic implementation

Future Enhancement Opportunities

  • Smart pointers (std::unique_ptr, std::shared_ptr) for better memory safety
  • Payment gateway integration
  • Order status tracking and updates
  • Delivery time estimation based on distance
  • User authentication and session management
  • Product search and filtering capabilities
  • Discount and coupon system
  • Order history management
  • Configuration files for store locations and inventory
  • Unit tests for individual components
  • Database integration for persistent storage
  • REST API layer for web/mobile integration

Related Concepts

  • Design Patterns (Factory, Strategy, Singleton)
  • Object-Oriented Design Principles (SOLID)
  • Location-based algorithms (Euclidean distance)
  • E-commerce system architecture
  • Inventory management systems
  • Order fulfillment workflows
  • Multi-store coordination
  • Delivery partner assignment algorithms

@prajwal3114 prajwal3114 merged commit aba41a7 into OPCODE-Open-Spring-Fest:main Nov 15, 2025
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants