Inventory Management
Relevant source files
The following files were used as context for generating this wiki page:
- packages/core/src/services/warehouses/WarehousesProductsService.ts
- packages/common/src/entities/WarehouseProduct.ts
- packages/merchant-tablet-ionic/src/pages/+warehouse/all-products/all-products.component.ts
- packages/common/src/entities/Warehouse.ts
- packages/core/src/graphql/warehouses/warehouse.resolver.ts
- packages/admin-web-angular/src/app/pages/+fakeData/fakeData.component.ts
Inventory Management in the Ever Demand platform is a core feature that enables the tracking and management of products within warehouses (also referred to as stores or merchants). The system is designed to support both single-store and multi-vendor marketplace models. Each warehouse maintains its own inventory of products, with specific pricing, stock counts, and availability settings.
The architecture is centered around the Warehouse and WarehouseProduct entities. A Warehouse holds a collection of WarehouseProduct items, which are essentially inventory records linking a generic Product definition to a specific warehouse's stock. This allows for different prices and quantities of the same product across different merchants. The backend provides services and a GraphQL API to create, retrieve, update, and delete these inventory items, which are then consumed by various client applications, such as the Merchant Tablet App and the Admin Dashboard.
Data Model
The inventory data model is primarily defined by the Warehouse and WarehouseProduct entities. The WarehouseProduct is stored as a sub-document within the Warehouse document in MongoDB.
Sources: packages/common/src/entities/WarehouseProduct.ts, packages/common/src/entities/Warehouse.ts
Entity Relationship Diagram
This diagram shows the relationship between Warehouses, WarehouseProducts, and the global Product catalog.
WarehouseProduct Entity
The WarehouseProduct class represents a specific product available for sale within a single warehouse. It contains warehouse-specific information like price and stock count.
The table below details the key properties of the WarehouseProduct entity.
| Property | Type | Description |
|---|---|---|
price | number | The current real-time price of the product in this warehouse. |
initialPrice | number | The starting price of the product, used to calculate discounts. |
count | number | The current quantity of this product available for purchase. |
soldCount | number | The total number of units of this product that have been sold. |
product | Product | A reference to the global Product entity. |
isManufacturing | boolean | Indicates if the product requires manufacturing (e.g., a pizza). |
isCarrierRequired | boolean | If true, a carrier must be found before a customer can purchase. |
isDeliveryRequired | boolean | If true, the product requires delivery. |
isProductAvailable | boolean | A flag to mark if the product is currently available for purchase. |
isTakeaway | boolean | Indicates if the product is available for takeaway. |
Sources: packages/common/src/entities/WarehouseProduct.ts:28-121
Warehouse Entity
The Warehouse entity (also representing a Merchant or Store) contains an array of WarehouseProduct objects, which constitutes its inventory.
| Property | Type | Description |
|---|---|---|
name | string | The name of the store/merchant. |
products | WarehouseProduct[] | An array of products available at this warehouse. |
isManufacturing | boolean | A default setting for whether products in this warehouse require manufacturing. |
isCarrierRequired | boolean | A default setting for whether products require a carrier. |
productsDelivery | boolean | A flag to indicate if the store allows deliveries. |
productsTakeaway | boolean | A flag to indicate if the store allows takeaway. |
Sources: packages/common/src/entities/Warehouse.ts:70, packages/common/src/entities/Warehouse.ts:82, packages/common/src/entities/Warehouse.ts:182-195
Backend Services & API
The backend exposes inventory management functionality through services and a GraphQL API.
WarehousesProductsService
This service encapsulates the core business logic for managing products within a warehouse's inventory.
Sources: packages/core/src/services/warehouses/WarehousesProductsService.ts
Key methods include:
| Method | Description |
|---|---|
get(warehouseId, fullProducts) | Retrieves all products for a given warehouse. The fullProducts flag determines if the full Product entity is populated. |
getAvailable(warehouseId) | Retrieves only the products that are currently available for purchase from a warehouse. |
add(warehouseId, createObjects) | Adds one or more new products to a warehouse's inventory. |
update(warehouseId, productId, updateInput) | Updates an existing product in a warehouse's inventory, such as changing its price or quantity. |
remove(warehouseId, productIds) | Removes one or more products from a warehouse's inventory. |
Sources: packages/core/src/services/warehouses/WarehousesProductsService.ts:32-117
GraphQL API
The warehouse.resolver.ts file defines GraphQL queries and mutations for interacting with warehouse inventories from client applications.
Sources: packages/core/src/graphql/warehouses/warehouse.resolver.ts
Key Queries
getStoreProducts(storeId, fullProducts): Fetches all products for a specific store.getStoreAvailableProducts(storeId): Fetches only the available products for a specific store.
Key Mutations
addWarehouseProducts(warehouseId, products): Adds a list of products to a warehouse's inventory.updateWarehouseProduct(warehouseId, productId, updateInput): Updates a specific product within a warehouse's inventory.removeWarehouseProducts(warehouseId, productsIds): Removes products from a warehouse's inventory.
Sources: packages/core/src/graphql/warehouses/warehouse.resolver.ts:47-60, packages/shop-web-gatsby/ever-types.ts:762-770
Sequence Diagram: Fetching Store Products
This diagram illustrates the flow of a request from a client to fetch a store's products.
Frontend Integration
Various frontend applications consume the inventory management API to display and manage products.
Merchant Tablet Application
The merchant tablet app allows store owners to view their current inventory. The all-products.component.ts is responsible for fetching and displaying the list of all products associated with the logged-in merchant's warehouse.
The component fetches the product list in the ngOnInit lifecycle hook by calling the getStoreProducts query.
Sources: packages/merchant-tablet-ionic/src/pages/+warehouse/all-products/all-products.component.ts:60-68
Admin Fake Data Generation
The fakeData.component.ts in the admin application provides a clear example of how products are created and then added to a warehouse's inventory. This is useful for understanding the end-to-end process.
Flowchart: Adding a Product to a Warehouse
This flowchart shows the steps involved in creating a product and adding it to a warehouse's inventory, as demonstrated in the fake data generator.
The process involves:
- Creating a global
Productentity viaproductRouter.create(). - Creating a
Warehouseentity if one doesn't exist. - Creating an array of
IWarehouseProductCreateObjectwhich specifies the product ID and inventory-specific details like price. - Calling
warehouseProductsRouter.add()with thewarehouseIdand the array of product objects to associate them.
Sources: packages/admin-web-angular/src/app/pages/+fakeData/fakeData.component.ts:480-490, packages/admin-web-angular/src/app/pages/+fakeData/fakeData.component.ts:688-696
Summary
The inventory management system is a foundational part of the Ever Demand platform, providing the necessary tools to manage product stock across a distributed network of warehouses or stores. By separating the global Product definition from the WarehouseProduct inventory record, the platform offers flexibility for multi-vendor environments. The backend services and GraphQL API provide a robust interface for client applications to perform all necessary CRUD (Create, Read, Update, Delete) operations on inventory items.