FairRelay β Complete Setup Guide
Quick Start (30 seconds)
git clone https://github.com/MUTHUKUMARAN-K-1/FairRelay.git
cd FairRelay
cd brain
pip install -r requirements.txt
uvicorn app.main:app --reload --port 8000
cd ops/backend-dm
npm install
echo "BRAIN_URL=http://localhost:8000" > .env
node index.js
cd ops/AIsupplychain/aisupply
npm install
echo "VITE_API_URL=http://localhost:3000" > .env
npm run dev
Open http://localhost:5173 β Navigate to Fair Dispatch β Click Run Fair Allocation
Architecture
βββββββββββββββββββββββββββββββββββββββββββ
β Dashboard (React + Vite) :5173 β
β Pages: FairDispatch, LoadConsolidation β
ββββββββββββββββββ¬βββββββββββββββββββββββββ
β axios β /api/*
ββββββββββββββββββΌβββββββββββββββββββββββββ
β API Gateway (Node.js + Express) :3000 β
β Auth, CRUD, Proxy to Brain β
ββββββββββββββββββ¬βββββββββββββββββββββββββ
β axios β BRAIN_URL
ββββββββββββββββββΌβββββββββββββββββββββββββ
β AI Brain (FastAPI + LangGraph) :8000 β
β 8 Dispatch Agents + 5 Consolidation β
β OR-Tools, scikit-learn, XGBoost β
ββββββββββββββββββ¬βββββββββββββββββββββββββ
β
ββββββββββββββββββΌβββββββββββββββββββββββββ
β Database: SQLite (auto) or PostgreSQL β
βββββββββββββββββββββββββββββββββββββββββββ
Environment Variables
Brain (brain/.env)
# Required: NONE (SQLite auto-created)
# Optional:
DATABASE_URL=postgresql+asyncpg://user:pass@host:5432/fairrelay
GOOGLE_API_KEY=your-gemini-key # For LLM explanations
GEMINI_MODEL=gemini-2.5-flash # Model to use
OLA_MAPS_API_KEY=your-ola-key # For real-time traffic
LANGCHAIN_API_KEY=your-langsmith-key # For tracing (optional)
APP_ENV=development # Shows /docs + /redoc
Backend (ops/backend-dm/.env)
BRAIN_URL=http://localhost:8000 # Required
DATABASE_URL=postgresql://... # For auth/drivers/packages
JWT_SECRET=your-secret # For auth tokens
PORT=3000
Dashboard (ops/AIsupplychain/aisupply/.env)
VITE_API_URL=http://localhost:3000 # Points to API Gateway
What Each Agent Does
Fair Dispatch Pipeline (8 Agents)
| # |
Agent |
Algorithm |
What it computes |
| 1 |
ML Effort |
Deterministic formula + traffic |
NΓM effort matrix |
| 2 |
Route Planner |
OR-Tools SCIP/GLOP solver |
Optimal 1-to-1 assignment |
| 3 |
Fairness Manager |
Gini coefficient |
ACCEPT or REOPTIMIZE |
| 4 |
Route Planner v2 |
OR-Tools + penalties |
Re-optimized assignment |
| 5 |
Driver Liaison |
Comfort band logic |
Per-driver ACCEPT/COUNTER |
| 6 |
Final Resolution |
Metric-validated swaps |
Resolve counter-proposals |
| 7 |
Explainability |
Template categorization |
Natural language per driver |
| 8 |
Gemini LLM |
Gemini 2.5 Flash (optional) |
Rich multilingual explanations |
Load Consolidation Pipeline (5 Agents)
| # |
Agent |
Algorithm |
What it computes |
| 1 |
Geo Clustering |
KMeans + Silhouette |
Group nearby shipments |
| 2 |
Time Window |
Overlap filter |
Split incompatible schedules |
| 3 |
Capacity |
OR-Tools CP-SAT |
Bin-pack into trucks |
| 4 |
Scoring |
Multi-metric |
Confidence per group |
| 5 |
RL Insights |
Q-Learning |
Optimal parameters |
API Endpoints
Core Allocation
POST /api/v1/allocate/langgraph
POST /api/v1/allocate
POST /api/v1/consolidate/optimize
POST /api/v1/consolidate/simulate
Monitoring
GET /health
GET /agent-events/stream?run_id=<uuid>
GET /api/v1/runs
GET /api/v1/runs/<run_id>
Driver Management
GET /api/v1/drivers
GET /api/v1/drivers/<id>
POST /api/v1/feedback
Testing
cd brain
pytest tests/ -v
pytest tests/test_langgraph_workflow.py -v
python test_workflow.py
Deployment
See DEPLOYMENT.md for full production deployment guide with:
- Render (Brain + Backend)
- Vercel (Dashboard + Landing)
- LoRRI integration patterns
Tech Stack
| Component |
Technology |
| AI Engine |
Python 3.11, FastAPI, LangGraph, SQLAlchemy |
| Optimization |
OR-Tools (SCIP, CP-SAT), scikit-learn, XGBoost |
| Traffic |
OLA Maps API (real-time Indian traffic) |
| LLM |
Gemini 2.5 Flash (multilingual explanations) |
| API Gateway |
Node.js, Express, Prisma, Socket.IO |
| Dashboard |
React 19, Vite, TailwindCSS, Axios |
| Mobile |
Flutter (driver app) |
| Database |
PostgreSQL (prod) / SQLite (dev/demo) |
| Deployment |
Render (Docker) + Vercel (static) |
Key Differentiators
- Gini Coefficient Fairness β mathematically provable workload equity (0.85 β 0.12)
- EV-First Routing β battery feasibility + charging penalty in OR-Tools cost matrix
- Night Safety β gender-aware routing after 9 PM (avoid high-crime zones)
- Cognitive Load Index β 6-factor driver mental fatigue scoring
- Explainable AI β every allocation decision has a natural language explanation
- Real-Time Traffic β OLA Maps API integration for Indian road conditions
- Self-Improving β Q-Learning bandit auto-tunes fairness thresholds daily
- Production TMS Integration β designed for LoRRI (logisticsnow.in) embedding