Fresh decisions. Connected stores.
Demand forecasting, fresh-goods replenishment, and delivery planning.
An open-source decision workspace for independent mini-mart chains.
Get started · Live demo · Features · Architecture · Research · Contribute
Fresh groceries create a daily balancing act: order too much and stock expires; order too little and customers leave empty-handed. FreshMesh brings forecasting, inventory decisions, surplus handling, and delivery planning into one workflow for store managers and chain owners.
Built around a Ho Chi Minh City demo, it combines a Vietnamese-language interface and AI assistant with explicit data provenance and human approval. This repository contains the working prototype, reproducible data pipeline, and research reports.
| 01 / Anticipate demand Explore forecast ranges and replenishment needs across stores. |
02 / Compare decisions Weigh markdowns, stock transfers, and delivery plans with explicit assumptions. |
03 / Stay in control Review proposals before approval and follow every decision through its audit trail. |
Explore the README
The morning brief counts up, the surplus card opens the cash comparison of markdown and transfer, and the owner approves the draft. Recorded on the deployed app; click the animation for the 1080p60 MP4.
Actual screenshots from the deployed demo, captured at 1440 × 1000. The interface is in Vietnamese and displays illustrative business data. Click any image to view it at full size.
Welcome to FreshMesh![]() |
Demand, with uncertainty![]() |
Compare replenishment options![]() |
Plan the delivery round![]() |
| Capability | What it does |
|---|---|
| Demand forecasting | Local quantile forecasts with P10/P50/P90 intervals and conformal calibration. |
| Federated learning | Experiments across independent chains, with comparisons against local models and optional differential-privacy experiments. |
| Replenishment | Inventory recommendations accounting for shelf life, demand uncertainty, and operational constraints. |
| Surplus decisions | Compare scheduled markdowns with inter-store transfers using consistent cash-value assumptions. |
| Delivery planning | PACO vehicle routing through the external routing-PL solver, including pickup points and time windows. |
| Vietnamese AI assistant | Claude tool calling, source-labelled answers, numerical checks, and draft proposals. Requires an API key. |
| Human approval | Review, edit, approve, or reject drafts; inspect the decision audit trail. |
| Traceable evidence | Dataset identifiers, assumptions, AI parameter prompts, and experiment protocols accompany results. |
Use Python 3.12+, uv, Node.js 22.13+ with npm, Git, and Docker with Compose v2. The commands below use Bash (Linux, macOS, or WSL).
git clone --recurse-submodules https://github.com/ttadev24/FreshMesh.git
cd FreshMesh
uv sync --locked
(cd web && npm ci)For an existing clone, run git submodule update --init --recursive. The solver is a separate repository pinned by the submodule.
docker compose up -d --build solver
curl --fail http://localhost:8000/healthThe default solver port is 8000. If it is occupied, copy .env.example to .env and change both FRESHMESH_SOLVER_PORT and FRESHMESH_SOLVER_URL before starting Compose. The solver must be ready before routing requests succeed.
scripts/bootstrap.sh --skip-flThis builds the three chain databases and local models using committed snapshots and seed 42. It does not require an LLM key or new public-data downloads. Run it in a fresh checkout or with a separate FRESHMESH_DATA_DIR: it regenerates demo data.
For the full federated-learning experiments and models, run scripts/bootstrap.sh without --skip-fl. This also writes experiment outputs under docs/experiments/. When FL artifacts are absent, /api/network/fl returns 503 fl_not_ready.
In one terminal, from the repository root:
scripts/dev_api.shIn another terminal:
cd web
npm run devOpen http://localhost:3100 and sign in with one of the accounts the bootstrap creates (see data_sim/generate.py).
The API listens on 127.0.0.1:8100. The development script permits a local development signing key when FRESHMESH_SECRET is absent. For a persistent installation, set a random secret of at least 32 characters in the root .env.local; see configuration.
| Role | Scope |
|---|---|
| Chain owner | All stores within the respective chain |
| Store manager | Store CH1 within the respective chain |
- AI chat: copy
.env.local.exampleto the root.env.local, addANTHROPIC_API_KEY, and restart the API. Without it, chat returns503 llm_unavailable; dashboards and decision tools remain available. - Map tiles: copy
web/.env.local.exampletoweb/.env.local, setNEXT_PUBLIC_VIETMAP_API_KEY, and restart the web app. Rebuild production assets after changing this key. - Road geometry: set the separate server-side
FRESHMESH_VIETMAP_ROUTE_KEYin the root.env.local. Without it, maps use labelled straight-line segments. - Jev guardrail: optional OpenRouter integration; see configuration.
These providers may require paid accounts. The software license does not include access to their services.
- Sign in as a chain owner and inspect forecasts and data sources.
- Create a replenishment proposal, or compare markdowns and stock transfers.
- Review quantities, assumptions, and expected outcomes in the draft.
- Approve or reject the draft and inspect the audit record.
- Generate a delivery plan with the running solver.
You can also use the Python entry points:
# Replenishment workflow through the same service layer as the API
uv run python -m decision.cli flow1 --chain CHAIN_A --store A-CH1 --items rau,thit
# Solve a synthetic example delivery batch
uv run python -m routing.cli routing/examples/batch_q7.json
# Inspect dataset provenance and recorded AI parameter prompts
uv run python -m provenance show
uv run python -m provenance promptsThe assistant proposes drafts. Approval through POST /api/drafts/{id}/approve is the execution boundary for local records, including purchases, markdown schedules, transfers, and route dispatch markers.
flowchart TD
Web[Next.js dashboard] --> API[FastAPI gateway]
API --> Agent[Vietnamese AI assistant]
Agent --> Services[Shared decision services]
API --> Services
Services --> Forecast[Local and federated forecasts]
Services --> Decisions[Replenishment / markdown / transfer]
Services --> Router[Routing adapter]
Router --> Solver[routing-PL / PACO]
Services --> DB[(Per-chain SQLite databases)]
Services --> Draft[Draft proposal]
Draft --> Approval[Human approval]
Approval --> Audit[Local action records and audit trail]
Sources[Public snapshots + AI parameters] --> Generator[Seeded data generator]
Generator --> DB
Provenance[Provenance registry] -. source labels .-> Services
| Directory | Responsibility |
|---|---|
web/ |
Next.js, React, TypeScript, ECharts, and VietMap UI |
api/ |
Authentication, authorization, service endpoints, drafts, and audit access |
agent/ |
Claude integration, tools, SQL restrictions, verification, and evaluations |
forecasting/ |
Quantile models, baselines, calibration, and federated experiments |
decision/ |
Inventory, markdown, transfer, and trade-off calculations |
routing/ |
Solver adapter, validation, caching, CLI, and routing-PL submodule |
data_sim/, data_real/ |
Demo generation, public snapshots, and AI-generated parameters |
data_frn/ |
Separate validation pipeline for FreshRetailNet-50K |
provenance/, data/provenance/ |
Dataset registry, manifests, prompts, and responses |
simulation/ |
Inventory simulations and routing benchmarks |
tests/, web/e2e/ |
Python tests and Playwright scenarios |
docs/ |
Methods, configuration, protocols, and research results |
The repository reports unsuccessful outcomes as well as improvements. These are results from the committed experiments, not guarantees for live stores.
| Experiment | Recorded finding | Evidence |
|---|---|---|
| Federated forecasting | With the configuration chosen on the validation window (20 rounds, lr 5e-4), FL beat local forecasting: WAPE 0.4551 vs 0.4694 (3.0% better), and 0.5236 vs 0.5377 for new stores with 14 days of history. Mean of 3 seeds, rerun and reproduced exactly. An earlier run on the previous data generation was 0.54% worse than local. The deployed FL configuration does not enable DP. | FL results |
| 30-day inventory simulation | The original policy missed waste targets for all three chains. The revised policy met them for A and C, but not B; it was adjusted after seeing results. | Simulation results |
| Delivery routing | PACO used 320.8 km vs 985.7 km for one-trip-per-order, but still had 29 projected late stops. | Routing benchmark |
| Assistant evaluation | The recorded 32-question run reached 90.6% tool selection accuracy; later prompt changes were not re-evaluated in that report. | Agent evaluation |
| Real retail data | FreshRetailNet-50K has a separate audit and pre-registered protocol. It represents Chinese retail demand, not Vietnamese mini-mart transactions. Forecasting: the 28-day quantile baseline beat the FreshMesh MLP (WAPE 0.314 vs 0.327), so F1 and F2 failed; the exploratory P10–P90 coverage check F3 passed (78.7%, target band 75–85%). Inventory (688 stores, 2-day shelf life): I1 failed. FreshMesh needed 1.42 and 1.10 points more waste than the best tuned baseline at 10% and 15% stockout. | Audit · Protocol · Forecast · Inventory |
View the recorded routing benchmark
The chart compares the recorded solver runs. See the benchmark report for instance sizes, feasibility, late stops, and baseline definitions.
Additional constraints:
- Routing uses a 1.3 distance multiplier; the OSRM car-profile check found a median of 1.58. Distances and arrival times may be underestimated. VietMap geometry only changes the rendered road path. Details.
- A cold solver request can take seconds or longer. Successful routes are cached by batch hash with
cachedandsolved_atmetadata; solver failures are surfaced as errors. - Public locations and weather are combined with synthetic business activity. Every result must preserve its provenance labels. Data provenance.
- SQL guards and numerical checks have limits: computed expressions over real columns can still produce misleading values. Operational limitations.
- Dependency constraints and deployment considerations are documented in Security. This prototype has no production support guarantee.
uv run pytest # Default suite excludes integration tests
uv run ruff check
(cd web && npm run lint && npm run typecheck)
# Requires a running solver
uv run pytest -m integration
# Requires bootstrapped demo data and a solver; Playwright can start API/web
(cd web && npx playwright install chromium && npm run test:e2e)Some chat scenarios require provider credentials and incur API usage. Read the contribution guide before running external-service evaluations or changing experiment outputs.
| Start here | Further reading |
|---|---|
| Configuration and troubleshooting | Environment files, ports, optional integrations, production commands |
| Decision methods | Inventory and surplus objectives and assumptions |
| API contract notes | Endpoint behavior and integration details |
| Data provenance | Sources, AI prompts, and dataset rights |
| Data assumptions | Simulation and economic assumptions |
| Operational limitations | Known constraints and evaluation caveats |
| Original design | Design rationale and intended workflows |
| Third-party notices | Upstream projects, data licenses, and template sources |
The README and community guides are in English. Some existing technical reports and the application are in Vietnamese; translations are welcome.
Bug reports, documentation fixes, translations, and reproducible research improvements are welcome.
- Read Contributing for setup, checks, and the pull-request process.
- Follow the Code of Conduct, adapted from Contributor Covenant 2.1.
- Use GitHub Issues for bugs and feature proposals.
- Follow Security for vulnerability reports; avoid publishing exploit details in ordinary issues.
- See Support for usage questions.
GPL-3.0-only · Third-party notices





