DIAGRAM EDITOR · REVISION 1

E-commerce and store inventory

This project shows inventory control for a retailer with an online store and physical stores. An online order and a store sale can occur at the same time. If only one unit is available, only one transaction can use that unit. The retailer can use different stock records for online orders and store sales. If the two sales channels use shared stock, they use the same stock record. Available stock is the on-hand quantity minus the quantity in active stock reservations. The ordering platform uses online stock first. It can also use store stock from a store with online fulfillment. A stock reservation holds the units for the order during payment. The stock reservation stays active after payment. At shipment, the inventory system decreases the on-hand quantity. The inventory system sets the stock reservation status to Consumed. If payment does not occur before the time limit, the inventory system releases the stock reservation. If the customer cancels the order before payment, the inventory system releases the stock reservation. The ten diagrams show different parts of the same design. Each diagram has a description.

This project contains ten diagrams. Select Edit this diagram to open that diagram in the editor.

1. Mind map · Inventory planning

Edit this diagram

Feeds availabilityFeeds availabilityOne stock promiseOne stockpromiseStock sourcesStock sourcesOnline stockOnline stockStore stockStore stockCheckoutCheckoutReserve unitsReserve unitsConfirm paymentConfirm paymentFulfillmentFulfillmentShip and consumeShip and consumeRelease expired holdsRelease expiredholds

The mind map has three branches for inventory planning. The branches show stock sources, checkout, and fulfillment. The link between Stock sources and Checkout shows how stock allocation changes available stock.

2. Ontology · Inventory terms

Edit this diagram

placesplacescontainscontainsreferencesreferencespaid bypaid byfulfilled byfulfilled byis ais ais ais ainstance ofinstance ofinstance ofinstance ofhas holdhas holdholds againstholds againststocksstocksis ais ais ais aCustomerCustomer[Class]A person who makes apurchase.Customer IDOrderOrder[Class]A purchase request withone or more order items.Order number · statusOrder itemOrder item[Class]A record of a product,its quantity, and itspurchase price.Quantity · unit priceProductProduct[Class]An item in the salescatalog.SKU · namePaymentPayment[Class]A transaction for all orpart of the order total.Amount · currencyShipmentShipment[Class]A delivery of physicalproducts from an order.Carrier · trackingnumberDigital productDigital product[Class]A product that acustomer can download.Physical productPhysical product[Class]A product that acustomer can receive ina shipment.Maya ChenMaya Chen[Individual]An example of aCustomer.Order #1042Order #1042[Individual]An example of an Order.Stock reservationStockreservation[Class]A record of the heldquantity for one orderitem.Quantity · expires atInventory stockInventory stock[Class]A stock record for aproduct at a fulfillmentlocation.On hand · held unitsStore stockStore stock[Class]Stock for sales orfulfillment from aphysical store.Online stockOnline stock[Class]Stock for online orders.Ontology · solid arrow: is a / instance of · dashed arrow: named property (domain → range)Declared concepts and property notes · no automatic inference or external-data validation

The ontology shows classes, individuals, and their relations. Store stock and online stock are classes of inventory stock. A stock reservation holds units from a stock record for one order item. Maya Chen is an example of a Customer. Order #1042 is an example of an Order.

3. Entity relationships · Order and stock records

Edit this diagram

placesplaces1 → 0..*containscontains1 → 1..*can havecan have1 → 0..*appears onappears on1 → 0..*is stocked inis stocked in1 → 0..*backsbacks1 → 0..*CustomerCustomer[PK] customer_idOrderOrder[PK] order_id[FK] customer_idstatusOrder itemOrder item[PK] order_item_id[FK] order_id[FK] product_idquantityStock reservationStock reservation[PK] reservation_id[FK] order_item_id[FK] stock_idquantity, expires_atProductProduct[PK] product_idskuInventory stockInventory stock[PK] stock_id[FK] product_idlocation, allocationon_hand, held

The entity relationship diagram shows records and their relations. An order contains one or more order items. Each order item has one product. An order item can have stock reservations from different stock records. Each stock record has an on-hand quantity and a held quantity.

A primary key identifies a record. A foreign key identifies a related record.

4. C4 System Landscape · Online and store sales

Edit this diagram

Places ordersPlaces ordersReserves stock [HTTPS]Reserves stock [HTTPS]Authorizes payments [HTTPS]Authorizes payments [HTTPS]Picks ordersPicks ordersBooks deliveries [HTTPS]Books deliveries [HTTPS]Sends delivery events [Events]Sends delivery events[Events]Records store sales [HTTPS]Records store sales [HTTPS]CustomerCustomer[Person]Sends orders to the ordering platform.Ordering platformOrdering platform[Software system]Receives customer orders and sendsrequests to the inventory system.Inventory systemInventory system[Software system]Stores stock records and holds stockfor orders.Payment providerPayment provider[Software system · External]Gives payment authorization andrefunds.Shipping serviceShipping service[Software system · External]Receives shipment requests and sendsdelivery data.Analytics platformAnalytics platform[Software system]Gives information about fulfillmentand delivery.Warehouse teamWarehouse team[Person]Selects stock and prepares shipments.Store point of saleStore point of sale[Software system]POSSends store sales data to theinventory system.System landscape · All systemsKey: [Type] = C4 element · External = outside ownership · dashed boundary = containmentArrow = directed interaction · [technology] on a line = communication protocol

The C4 System Landscape shows the sales channels and their related systems. The store point of sale sends store sales data to the inventory system. The ordering platform sends stock reservation requests to the same inventory system. The diagram also shows the warehouse team, shipping service, payment provider, and analytics platform.

5. C4 System Context · Ordering platform

Edit this diagram

Places ordersPlaces ordersReserves stock [HTTPS]Reserves stock [HTTPS]Authorizes payments [HTTPS]Authorizes payments [HTTPS]CustomerCustomer[Person]Sends orders to the ordering platform.Ordering platformOrdering platform[Software system]Receives customer orders and sendsrequests to the inventory system.Inventory systemInventory system[Software system]Stores stock records and holds stockfor orders.Payment providerPayment provider[Software system · External]Gives payment authorization andrefunds.System context · Ordering platformKey: [Type] = C4 element · External = outside ownership · dashed boundary = containmentArrow = directed interaction · [technology] on a line = communication protocol

The C4 System Context shows the ordering platform and its users and external systems. The customer sends an order to the ordering platform. The ordering platform sends a stock reservation request to the inventory system. The payment provider gives payment authorization.

6. C4 Containers · Ordering platform

Edit this diagram

Ordering platform [Software systemboundary]Stores and retrieves orders [SQL/TLS]Stores and retrieves orders[SQL/TLS]Places and tracks orders [HTTPS]Places and tracks orders[HTTPS]Submits orders [HTTPS / JSON]Submits orders [HTTPS /JSON]Reserves stock [HTTPS]Reserves stock [HTTPS]Authorizes payment [HTTPS]Authorizes payment [HTTPS]Starts receipt job [HTTP]Starts receipt job [HTTP]Updates order status [SQL / TLS]Updates order status [SQL /TLS]CustomerCustomer[Person]Sends orders to the ordering platform.Web applicationWeb application[Container]TypeScript / browserShows order status and sends customerorders to the Web API.Web APIWeb API[Container]Rust / HTTPSReceives order requests and sends themto the order service.Order databaseOrder database[Container]PostgreSQLStores orders and their fulfillmentstatus.Receipt workerReceipt worker[Container]Rust background serviceMakes receipts and updates orderstatus.Inventory systemInventory system[Software system]Stores stock records and holds stockfor orders.Payment providerPayment provider[Software system · External]Gives payment authorization andrefunds.Container · Ordering platformKey: [Type] = C4 element · External = outside ownership · dashed boundary = containmentArrow = directed interaction · [technology] on a line = communication protocol

The C4 Containers diagram shows the web application, Web API, order database, and receipt worker. The Web API sends requests to the inventory system and the payment provider. The order database stores order records. The receipt worker makes a receipt after the Web API records the order.

7. C4 Components · Web API

Edit this diagram

Web API [Container boundary]Stores confirmed order [SQL/TLS]Stores confirmed order[SQL/TLS]Updates order status [SQL / TLS]Updates order status [SQL /TLS]Passes validated request [Rust call]Passes validated request[Rust call]Requests stock reservation [Rust call]Requests stock reservation[Rust call]Reserves stock [HTTPS]Reserves stock [HTTPS]Requests authorization [Rust call]Requests authorization [Rustcall]Authorizes payment [HTTPS]Authorizes payment [HTTPS]Starts receipt job [HTTP]Starts receipt job [HTTP]Order controllerOrder controller[Component]Rust / HTTPValidates requests and sends them tothe order service.Order serviceOrder service[Component]RustUses the inventory client and thepayment client to process orders.Inventory clientInventory client[Component]Rust / HTTPSSends stock reservation requests tothe inventory system.Payment clientPayment client[Component]Rust / HTTPSSends payment authorization requeststo the payment provider.Order databaseOrder database[Container]PostgreSQLStores orders and their fulfillmentstatus.Receipt workerReceipt worker[Container]Rust background serviceMakes receipts and updates orderstatus.Inventory systemInventory system[Software system]Stores stock records and holds stockfor orders.Payment providerPayment provider[Software system · External]Gives payment authorization andrefunds.Component · Web APIKey: [Type] = C4 element · External = outside ownership · dashed boundary = containmentArrow = directed interaction · [technology] on a line = communication protocol

The C4 Components diagram shows the parts of the Web API. The order controller sends the request to the order service. The order service uses the inventory client for stock reservation requests. The order service uses the payment client for payment requests. The inventory system compares the requested quantity with available stock.

8. State workflow · Stock reservation status

Edit this diagram

Reserve stockReserve stockRule enough-eligible-stockAccept paymentAccept paymentShip orderShip orderStock unavailableStock unavailableExpire or cancelExpire or cancelCheckout startedCheckout startedStock held · awaiting paymentStock held ·awaiting paymentPaid · stock still heldPaid · stock stillheldShipped · hold consumedShipped · holdconsumedNo eligible stockNo eligible stockHold releasedHold releasedBusiness rulesRule enough-eligible-stock · The inventory system must reject a stock reservationrequest if the requested quantity is zero or less. It must also reject the requestif the requested quantity is more than the quantity of available stock.

The state workflow shows changes in the stock reservation status. If sufficient stock is available, the inventory system makes a stock reservation. If the requested quantity is more than the quantity of available stock, the inventory system rejects the stock reservation request. The stock reservation stays active after payment. At shipment, the inventory system sets the stock reservation status to Consumed.

The inventory system releases the stock reservation if payment does not occur before the time limit. It also releases the stock reservation if the customer cancels the order before payment.

9. Ordered request · Stock reservation

Edit this diagram

Reserve stock · Checkout started → Stock held · awaiting paymentRule enough-eligible-stock · The inventory system must reject a stock reservation request if therequested quantity is zero or less. It must also reject the request if the requested quantity ismore than the quantity of available stock.Before the decision1. Web API (Rust / HTTPS)Receive the order item and its requested quantity.2. Inventory service (Service and database)Read the stock records for online stock and store stock available for online fulfillment. Useone stock record for shared stock.3. Inventory service (Service and database) · Check ruleCompare the requested quantity with available stock in the reservation transaction.If allowed1. Inventory service (Service and database) ·Save togetherSave the stock reservation, inventory update,and reservation status in one transaction.2. Web API (Rust / HTTPS) · After savingShow the payment time limit. Continue topayment.If refused1. Web API (Rust / HTTPS)Show the stock shortage. Keep the order and theinventory stock in their initial condition.

The ordered request shows the software steps for a stock reservation. The inventory service compares the requested quantity with available stock. If sufficient stock is available, the inventory service saves the stock reservation, inventory update, and reservation status in one transaction. If the requested quantity is more than the quantity of available stock, the inventory service rejects the request. The examples show a request that the inventory service accepts and a request that it rejects.

Facts and checks

Save together

If any write fails, keep none of these changes.

Acceptance examples

Two units requested, three available

Starting state: Checkout started · Eligible available units: 3 · Requested units: 2

Allowed · State: Stock held · awaiting payment · Saved writes: order-state, stock-hold, held-stock
The inventory system holds two units. One unit stays available.

Three units requested, two available

Starting state: Checkout started · Eligible available units: 2 · Requested units: 3

Refused · State: Checkout started · Saved writes: None
The inventory system rejects the request. Two units stay available.

10. Requirements traceability · Shared stock

Edit this diagram

supportssupportssatisfiessatisfiesverifiesverifiesOnline and store salesOnline and store sales[Evidence]ID: entity-evidenceScenario · Example retailerAn online checkout and a store sale can occurat the same time.One sale per unitOne sale per unit[Requirement]ID: entity-requirementRequirement · The two sales channels use thesame stock record for shared stock.Shared stock recordShared stock record[Design Decision]ID: entity-designDesign · The inventory system compares andupdates the same stock record in onetransaction.Test with one unitTest with one unit[Test]ID: entity-testPlanned test · Start an online checkout and astore sale at the same time. Only onetransaction must use the last unit.

The requirements traceability diagram shows the relation between the requirement, the design decision, and the planned test. The requirement prevents two sales of the same unit. The design uses the same stock record for both sales channels.

The planned test uses one unit of shared stock. An online checkout and a store sale start at the same time. The test must show that only one transaction uses the unit.

Cardinality: 1 means one; 0..1 optional; 0..* zero or more; 1..* one or more. Arrows follow the displayed relationship direction. Color categories are author-defined. This visual export does not embed the editable source document.

Open editable project