scmgo is a Go library for practical inventory and supply-chain calculations.
The inventory package provides clear and reusable functions for common inventory policy calculations such as reorder point, safety stock, EOQ, min/max levels, lead-time demand helpers, service-level-based threshold planning, and policy summary helpers.
The goal is to keep the API:
- simple
- transparent
- practical
- easy to embed in Go applications
The inventory package is released as v1.0.0 and is intended to provide a stable public API for practical inventory policy calculations.
As of v1.0.0, the inventory package includes:
ReorderPointSafetyStockBasicEOQMinMaxLevelsZScoreForServiceLevelSafetyStockWithServiceLevelReorderPointWithServiceLevelDemandDuringLeadTimeStdDevDemandDuringLeadTimeTargetInventoryLevelTargetInventoryLevelWithServiceLevelMinMaxLevelsWithServiceLevelBuildPolicySummaryBuildPolicySummaryWithServiceLevel
Many inventory and supply-chain calculations still live in spreadsheets, internal notes, or one-off scripts. scmgo provides a lightweight Go-native alternative for developers building:
- inventory tools
- supply-chain applications
- planning dashboards
- internal operations services
- educational and analytical tools
The package is intentionally small, explicit, and easy to embed.
go get github.com/motah-fard/scmgo/inventory@latestCurrent package:
github.com/motah-fard/scmgo/inventory
package main
import (
"fmt"
"log"
"github.com/motah-fard/scmgo/inventory"
)
func main() {
summary, err := inventory.BuildPolicySummary(inventory.PolicySummaryInput{
DailyDemand: 100,
LeadTimeDays: 5,
ReviewPeriodDays: 7,
SafetyStockUnits: 50,
})
if err != nil {
log.Fatal(err)
}
fmt.Printf("reorder point: %.0f\n", summary.ReorderPoint)
fmt.Printf("target level: %.0f\n", summary.TargetInventoryLevel)
}These helpers provide a higher-level API for common inventory planning workflows. They are useful when you want one call to return the main planning outputs instead of assembling them manually from several lower-level functions.
Builds a policy summary from average demand, lead time, review period, and fixed safety stock.
summary, err := inventory.BuildPolicySummary(inventory.PolicySummaryInput{
DailyDemand: 100,
LeadTimeDays: 5,
ReviewPeriodDays: 7,
SafetyStockUnits: 50,
})Returned fields include:
- expected demand during lead time
- safety stock
- reorder point
- target inventory level
- min level
- max level
Builds a policy summary using service-level-based reorder point logic and demand variability.
summary, err := inventory.BuildPolicySummaryWithServiceLevel(inventory.PolicySummaryServiceLevelInput{
DailyDemand: 100,
LeadTimeDays: 5,
ReviewPeriodDays: 7,
DemandStdDevPerDay: 20,
ServiceLevel: 0.95,
})This is useful for dashboards, reorder recommendations, and embedded inventory planning logic where service-level assumptions matter.
Calculates reorder point using average daily demand, lead time, and safety stock.
rp, err := inventory.ReorderPoint(inventory.ReorderPointInput{
AvgDailyDemand: 100,
LeadTimeDays: 5,
SafetyStockUnits: 50,
})Calculates safety stock using a max-demand and average-demand approach.
ss, err := inventory.SafetyStockBasic(inventory.SafetyStockInput{
MaxDailyDemand: 120,
MaxLeadTimeDays: 7,
AvgDailyDemand: 100,
AvgLeadTimeDays: 5,
})Calculates economic order quantity.
eoq, err := inventory.EOQ(inventory.EOQInput{
AnnualDemand: 10000,
OrderingCost: 50,
HoldingCostPerUnit: 2,
})Calculates minimum and maximum inventory levels from reorder point and order quantity.
levels, err := inventory.MinMaxLevels(inventory.MinMaxInput{
ReorderPoint: 300,
OrderQuantity: 200,
})Converts a target cycle service level into a standard normal z-score.
z, err := inventory.ZScoreForServiceLevel(0.95)Calculates safety stock using demand variability, lead time, and a target service level.
ss, err := inventory.SafetyStockWithServiceLevel(inventory.SafetyStockWithServiceLevelInput{
StdDevDailyDemand: 10,
LeadTimeDays: 4,
ServiceLevel: 0.95,
})Calculates reorder point using average demand, lead time, demand variability, and a target service level.
rp, err := inventory.ReorderPointWithServiceLevel(inventory.ReorderPointWithServiceLevelInput{
AvgDailyDemand: 50,
LeadTimeDays: 4,
StdDevDailyDemand: 10,
ServiceLevel: 0.95,
})Calculates expected demand during lead time.
d, err := inventory.DemandDuringLeadTime(inventory.DemandDuringLeadTimeInput{
AvgDailyDemand: 100,
LeadTimeDays: 5,
})Calculates the standard deviation of demand during lead time.
sd, err := inventory.StdDevDemandDuringLeadTime(inventory.StdDevDemandDuringLeadTimeInput{
StdDevDailyDemand: 10,
LeadTimeDays: 4,
})Calculates target inventory level from expected demand coverage and safety stock.
level, err := inventory.TargetInventoryLevel(inventory.TargetInventoryLevelInput{
ExpectedDemandDuringLeadTime: 500,
SafetyStockUnits: 50,
})Calculates target inventory level using average demand, lead time, demand variability, and a target service level.
level, err := inventory.TargetInventoryLevelWithServiceLevel(inventory.TargetInventoryLevelWithServiceLevelInput{
AvgDailyDemand: 50,
LeadTimeDays: 4,
StdDevDailyDemand: 10,
ServiceLevel: 0.95,
})Calculates min/max inventory levels using a service-level-based reorder point and a fixed order quantity.
levels, err := inventory.MinMaxLevelsWithServiceLevel(inventory.MinMaxLevelsWithServiceLevelInput{
AvgDailyDemand: 50,
LeadTimeDays: 4,
StdDevDailyDemand: 10,
ServiceLevel: 0.95,
OrderQuantity: 200,
})scmgo is intentionally designed to be:
- small and focused
- explicit rather than clever
- easy to test
- easy to read
- suitable for both production use and teaching
The package validates inputs and returns explicit errors for invalid values such as:
- negative demand
- negative expected demand
- negative lead time
- negative review period
- negative safety stock
- invalid service level
- negative standard deviation
- invalid holding cost
This keeps behavior predictable and makes the library easier to integrate into larger systems.
- Input units must be consistent
- If demand is measured per day, lead time should also be in days
- EOQ uses the classic Wilson EOQ formula
- Service-level calculations assume a normal approximation
SafetyStockBasicuses a simple max/average demand and lead-time formulaStdDevDemandDuringLeadTimeassumes independent daily demand variability across lead-time periods- Policy summary helpers combine lead-time coverage, review-period coverage, safety stock, reorder point, target inventory level, and min/max outputs into a single result
This project follows semantic versioning.
v0.1.xfocused on core deterministic inventory formulasv0.2.xadded service-level-based inventory calculationsv0.3.xadded lead-time demand and variability helpersv0.4.0added target inventory level and service-level policy helpersv0.5.0added policy summary helpers and improved API consistency for inventory planning workflowsv0.6.0focused on documentation tightening, package consistency, and API stabilization ahead ofv1.0.0v1.0.0is the first stable release of theinventorypackage
- Go package docs: pkg.go.dev/github.com/motah-fard/scmgo/inventory
- Releases: github.com/motah-fard/scmgo/releases
This project is licensed under the MIT License. See the LICENSE file for details.