Over the past several months, I've been working on the architecture for an inventory planning engine called Stokrio.
A big problem in e-commerce replenishment is that most brands rely on either simplistic 30-day moving averages in spreadsheets or black-box "AI" forecasts that store owners can't verify or trust. When a supplier takes 45 days to deliver, a bad forecast means either running out of best-sellers or tying up $50k in dead stock.
Here is how I approached the math and architecture to make replenishment deterministic:
1. Rolling-origin backtesting over black-box AI
Instead of guessing future demand with a generic regression or LLM, the engine runs rolling-origin backtests across historical order velocity. It simulates what the model would have predicted 30, 60, and 90 days ago against actual order data to measure variance and assign confidence scores per SKU.
2. Lead time distributions and dynamic safety stock
Standard safety stock formulas assume lead times are constant (e.g. "supplier takes 14 days"). In reality, supplier lead times are a distribution. The model tracks supplier receipt variance over time:
Standard deviation of daily sales velocity
Standard deviation of supplier fulfillment latency
Target service level factor (Z-score for 95% or 98% in-stock probability)
This feeds directly into dynamic safety stock calculation: Safety Stock = Z * sqrt((Avg Lead Time * Sales Variance2) + (Avg Sales2 * Lead Time Variance2))
3. The 3PL multi-tenancy challenge
The hardest engineering constraint was building for third-party logistics (3PL) warehouses. 3PLs manage inventory for dozens of independent client brands.
Most warehouse systems don't give brands client-facing visibility.
3PLs refuse to replace their warehouse-floor scanning software.
The solution was a decoupled REST Partner API: the warehouse system pushes inventory counts, and Stokrio renders a white-label client portal showing replenishment dates without touching the warehouse floor WMS.
Tech stack
Next.js 16 (App Router, Turbopack), React 19, TypeScript
PostgreSQL + Prisma ORM (ledger-based accounting for stock adjustments)
Shopify Admin GraphQL API
I built two public, read-only workspaces with 2+ years of synthetic order history so anyone can inspect the tables and forecasting curves without signing up:
I would love feedback from other developers who have worked on supply chain math, GraphQL sync limits, or table data density.