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
InventoryStoreabstraction. - 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
DarkStoreManagerandOrderManagerfor 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
Productand 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
Productinstances based on SKU with predefined names and prices.
- InventoryStore (Interface): Defines methods for adding/removing products, checking stock, and listing available products.
- DbInventoryStore: Implements
InventoryStoreusingHashMapfor 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
replenishmethod 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
ZeptoHelperclass sets up dark stores with initial stock and replenishment strategies.
- The
- User Interaction:
- A
Useris created with coordinates. - The user adds items to their
Cart. ZeptoHelper.showAllItemsdisplays available products within 5 km.
- A
- Order Placement:
OrderManager.placeOrderprocesses 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
ReplenishStrategyto restock items when needed.
- Dark stores use a
- Factory Pattern:
ProductFactorycreates products. - Strategy Pattern:
ReplenishStrategyallows flexible replenishment logic. - Singleton Pattern:
DarkStoreManagerandOrderManagerensure 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.
