ZeptoLite - Inventory Management is a low-level design (LLD) for a simplified inventory and order fulfillment system, inspired by hyperlocal delivery platforms like Zepto. It manages products, inventory, dark stores (warehouses), user carts, orders, and delivery partners. The system uses design patterns like Factory, Strategy, and Singleton to ensure modularity and scalability.
- Product Management: Products with SKU, name, and price, created via a factory.
- Inventory Management: Tracks stock levels across dark stores using an
InventoryStore
abstraction. - Dark Store Management: Supports multiple dark stores with location-based proximity search.
- Replenishment Strategies: Implements threshold-based and weekly replenishment strategies.
- Order Processing: Handles user carts, order splitting across dark stores, and delivery partner assignment.
- Singleton Managers: Uses
DarkStoreManager
andOrderManager
for centralized control.
The system is divided into several key components, as illustrated in the class diagram:
- Product: Represents a product with
sku
,name
, andprice
. - User: A user with a name and coordinates (
x
,y
), owning aCart
. - Cart: Manages items as pairs of
Product
and quantity, with methods to add items and calculate totals. - Order: Represents an order with an ID, user, items, delivery partners, and total amount.
- DeliveryPartner: A simple entity with a name, assigned to fulfill orders.
- ProductFactory: Creates
Product
instances based on SKU with predefined names and prices.
- InventoryStore (Interface): Defines methods for adding/removing products, checking stock, and listing available products.
- DbInventoryStore: Implements
InventoryStore
usingHashMap
for stock and product storage. - InventoryManager: Manages inventory operations, delegating to an
InventoryStore
. - DarkStore: Represents a warehouse with a name, coordinates, and an
InventoryManager
. Supports replenishment via a strategy. - DarkStoreManager (Singleton): Manages a list of dark stores and finds nearby stores based on user location.
- ReplenishStrategy (Interface): Defines the
replenish
method for inventory replenishment. - ThresholdReplenishStrategy: Replenishes stock if it falls below a threshold.
- WeeklyReplenishStrategy: Placeholder for weekly replenishment logic.
- OrderManager (Singleton): Manages orders, placing them by finding nearby dark stores and assigning delivery partners.
- ZeptoHelper: Utility class to initialize dark stores and display available products to users.
- Initialize the System:
- The
ZeptoHelper
class sets up dark stores with initial stock and replenishment strategies.
- The
- User Interaction:
- A
User
is created with coordinates. - The user adds items to their
Cart
. ZeptoHelper.showAllItems
displays available products within 5 km.
- A
- Order Placement:
OrderManager.placeOrder
processes the cart, finding nearby dark stores and assigning delivery partners.- Orders may be split across multiple dark stores if items are unavailable in a single store.
- Replenishment:
- Dark stores use a
ReplenishStrategy
to restock items when needed.
- Dark stores use a
- Factory Pattern:
ProductFactory
creates products. - Strategy Pattern:
ReplenishStrategy
allows flexible replenishment logic. - Singleton Pattern:
DarkStoreManager
andOrderManager
ensure single instances for global management.
The entry point is ZeptoLite.java
. Compile and run it to see a demo:
- Initializes dark stores with sample stock.
- Creates a user, displays available products, adds items to the cart, and places an order.
- Outputs the order summary, including items, total, and assigned delivery partners.
Refer to the provided class diagram for a visual representation of the system architecture, showing relationships between classes, methods, and attributes.