Real-time AI-assisted decision support for food safety incidents.
Quick Setup • Demo Runbook • Schema & API
| Item | Details |
|---|---|
| Status | Demo-ready MVP with durable backend analysis storage and trace workflow |
| Frontend | Next.js 14 + React + Tailwind (frontend/) |
| Backend | FastAPI + SQLAlchemy (backend/) |
| Data store | PostgreSQL on LinuxONE (local SQLite/Postgres also supported for dev) |
| ML services | LinuxONE-hosted pathogen models (food-risk-ml/) + backend cold-chain rule engine |
| Default local ports | Frontend 3000, Backend 8000, ML service 8100 |
TraceFront helps a food-safety operator go from a shipment file to an explainable containment decision:
- Detect anomalies in uploaded logistics/sensor data.
- Visualize distribution paths.
- Trace related lots across upstream/downstream links.
- Record a human decision with evidence and audit history.
Food incidents require fast but defensible action. TraceFront is designed to reduce time-to-decision while keeping uncertainty explicit:
- findings include rule/evidence context,
- trace results show leads (not proof),
- final containment action is recommended by the system but approved by a person.
Primary users and stakeholders:
- food safety officers / incident responders,
- operations teams (warehouse/store/factory coordination),
- demo evaluators and presenters,
- contributors extending frontend, backend, data, and ML components.
Use TraceFront during incident triage, investigation, and response review:
- right after an upload-based anomaly investigation,
- during cross-lot contamination tracing,
- when documenting who approved what and why.
- Presentation/ops environment: shared LinuxONE services (backend, database, ML) reached through local SSH tunnel.
- Contributor environment: local frontend + optional local backend for development.
High-level flow:
Upload file -> Backend analysis -> Findings + Distribution graph
-> Lot trace query -> Containment recommendation
-> Officer approval/rejection -> Durable decision history
- Upload analysis (
.csv,.xlsx,.json) with durable findings/distribution records. - Lot trace investigation with upstream/downstream/related lot ranking.
- Containment decision recording (approve/reject) with officer, reason, and timestamp.
- Demo synthetic scenario seeding (
POST /api/demo/seed, idempotent). - Frontend workflow pages (
/,/distribution,/trace,/analysis-results,/monitor,/login). - Sign-in with per-company access: a Ministry of Health officer sees everything; a company sees and enters only records its own organization is a party to.
- Record import: organizations (with contact details), lots, ingredient links and shipments from one CSV/XLSX/JSON file (
frontend/public/trace_records_template.csv), and a list of every company to notify for a traced lot. - Holds: an approved decision holds its lots until an officer lifts it; each affected company sees the hold when it signs in and acknowledges it.
- Live shipments (
/monitor): sensor readings checked as they arrive against each shipment's cold-chain limit, with alerts, a quiet-logger warning and a simulated replay of SHIP-017.
- Holds and cold-chain alerts show in the app only: nothing is sent by email or SMS, and stock is not stopped physically.
- Live readings arrive over HTTP only (no MQTT or logger vendor integration).
- A shipment carries one lot (number mixed loads
S1-A,S1-B), and there are no GS1 identifiers. - Accounts are created from the command line only; there is no sign-up, password reset or account screen.
- Uploaded cold-chain findings are rule-based, not a trained contamination detector.
| Component | Path | Role |
|---|---|---|
| Frontend app | frontend/ |
UI for upload, findings, distribution, trace, and decision workflow |
| Backend API | backend/ |
Persistence, trace logic, upload analysis endpoints, decision storage |
| ML service + model assets | food-risk-ml/ |
Pathogen model serving and model documentation/evidence |
| Data pipeline package | src/tracefront_data/ |
Offline ingestion/cleaning/feature/handoff workflows |
| Documentation | docs/, reports/ |
API details, runbooks, demo script, data/model audit artifacts |
- Detect: upload shipment/sensor file and review findings.
- Spread: inspect distribution tree to see where affected batches moved.
- Trace: open lot investigation and inspect connected upstream/downstream lots.
- Decide: compare targeted vs extended hold options and record officer decision.
Detailed presenter script: docs/demo-script.md
Recommended first read: SETUP.md
From repository root in PowerShell:
.\backend\demo-tunnel.ps1Then verify service readiness:
python -B backend\preflight.pyRun frontend:
cd frontend
npm install
npm run devOpen: http://localhost:3000
From repository root:
cd backend
python -m venv .venv
python -m pip install -r requirements.txt
cp .env.example .env
uvicorn app.main:app --reloadAPI docs: http://localhost:8000/docs
Every endpoint except GET /api/health and sign-in needs a session. Create accounts with python -m app.auth add-user (SETUP.md, step 4); the access rules are in docs/schema-and-api.md, section 6.
Windows (PowerShell) variant used in project docs:
cd backend
python -m venv .venv
.\.venv\Scripts\python -m pip install -r requirements.txt
Set-Content .env "DATABASE_URL=sqlite:///./tracefront.db"
.\.venv\Scripts\python -m uvicorn app.main:app --reload --port 8000ssh -L 8000:127.0.0.1:8000 -L 5432:127.0.0.1:5432 linux1@148.100.77.171While open:
- API: http://localhost:8000
- DB:
localhost:5432
| Method | Path | Purpose |
|---|---|---|
| GET | /api/health |
Backend/database health |
| POST | /api/auth/login, /api/auth/logout |
Sign in and out (12-hour HttpOnly session cookie) |
| GET | /api/auth/me |
The signed-in account |
| POST | /api/records/import |
Import organizations, lots, ingredient links and shipments from one file |
| GET | /api/organizations/{id}/lots |
Lots to investigate when the lead is a company |
| GET | /api/holds |
Holds in force and lifted, with affected sites |
| POST | /api/holds/{id}/acknowledge, /api/holds/{id}/release |
A company acknowledges a hold; an officer lifts it |
| GET | /api/monitor |
Live cold-chain state of every shipment with readings |
| DELETE | /api/monitor/{id}/readings |
Clear readings of a synthetic demo shipment (officers only) |
| GET/POST | /api/batches |
List/create batches |
| GET/POST | /api/organizations |
List/create organizations |
| GET/POST | /api/shipments |
List/create shipments |
| GET/POST | /api/batch-relationships |
List/create ingredient-product links |
| GET | /api/trace?batch_ids=<id>&batch_ids=<id> |
Multi-batch lot investigation |
| GET | /api/batches/{id}/trace |
Single-batch trace document |
| POST | /api/demo/seed |
Load synthetic demo scenario (idempotent) |
| POST | /api/decisions |
Record containment decision |
| POST | /api/analyses |
Upload and analyze shipment file |
| GET | /api/analyses/{id}/findings |
Retrieve stored findings |
| GET | /api/analyses/{id}/distribution |
Retrieve stored distribution graph |
| GET | /api/shipments/{id}/risk |
Rule-based shipment risk |
| POST | /api/sensor-readings |
Store shipment sensor reading |
| POST | /api/lab-results |
Store lab result |
/upload and incident entry flow/distributiondistribution graph and trace handoff/tracelot investigation, containment decision, holds and record import/monitorlive shipment temperatures and the simulated replay/loginsign-in/analysis-resultsfindings view/reportslegacy sample UI data page/designmockup-to-screen design workspace/ml-processanalysis animation preview
- Tunnel to LinuxONE (
.\backend\demo-tunnel.ps1). - Run backend/ML readiness check (
python -B backend\preflight.py). - Start frontend (
npm run dev, ornpm run buildthennpm startfor final frozen presentation build). - Run through Detect → Spread → Trace → Decide flow.
Canonical references:
- Trace connections are investigation leads, not proof of causation.
- Approved holds are recorded and shown to affected companies in the app; nothing is sent to sites by email or SMS.
- Uploaded shipment analysis is rule-based and transparent; it is not a trained contamination classifier.
- Pathogen model outputs concern FSIS laboratory sample prioritization, not direct shipment-file contamination verdicts.
- Demo synthetic scenario rows are intentionally additive/idempotent for repeat demos.
backend/ FastAPI backend, API logic, tests, deploy/tunnel scripts
frontend/ Next.js frontend pages and UI components
food-risk-ml/ Model serving stack, model cards, LinuxONE evidence
src/tracefront_data Offline data pipeline package
docs/ Runbooks, schema/API documentation, demo guides
reports/ Audits, data-quality/leakage findings, modeling handoff artifacts
data/ Raw/interim/processed data and manifests
configs/ Pipeline/data contract configuration
tests/ Offline data pipeline-focused tests
- reports/repository_audit.md
- reports/modeling_handoff.md
- reports/modeling_handoff.json
- reports/data_leakage_audit.md
- reports/m8_validation.json
Generation/reading requires Python 3.11+ standard library (SQLite for upstream cleaning), UTF-8 CSV/JSON and no native data wheels. Local Python 3.11.17 and 3.14.7 are supported. Actual IBM Z LinuxONE/s390x execution is not tested. See final validation for measured tests and portability limits.
This repository is licensed under the PolyForm Noncommercial License 1.0.0.
See /LICENSE for the full terms.
For the full concept narrative/specification, see tracefront_project_summary.md.
