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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# FairRelay β Complete Setup Guide
|
| 2 |
+
|
| 3 |
+
## Quick Start (30 seconds)
|
| 4 |
+
|
| 5 |
+
```bash
|
| 6 |
+
# Clone
|
| 7 |
+
git clone https://github.com/MUTHUKUMARAN-K-1/FairRelay.git
|
| 8 |
+
cd FairRelay
|
| 9 |
+
|
| 10 |
+
# Start Brain (AI Engine)
|
| 11 |
+
cd brain
|
| 12 |
+
pip install -r requirements.txt
|
| 13 |
+
uvicorn app.main:app --reload --port 8000
|
| 14 |
+
# β http://localhost:8000/docs (Swagger UI)
|
| 15 |
+
|
| 16 |
+
# Start Backend (API Gateway) β new terminal
|
| 17 |
+
cd ops/backend-dm
|
| 18 |
+
npm install
|
| 19 |
+
echo "BRAIN_URL=http://localhost:8000" > .env
|
| 20 |
+
node index.js
|
| 21 |
+
# β http://localhost:3000/health
|
| 22 |
+
|
| 23 |
+
# Start Dashboard β new terminal
|
| 24 |
+
cd ops/AIsupplychain/aisupply
|
| 25 |
+
npm install
|
| 26 |
+
echo "VITE_API_URL=http://localhost:3000" > .env
|
| 27 |
+
npm run dev
|
| 28 |
+
# β http://localhost:5173
|
| 29 |
+
```
|
| 30 |
+
|
| 31 |
+
Open http://localhost:5173 β Navigate to **Fair Dispatch** β Click **Run Fair Allocation**
|
| 32 |
+
|
| 33 |
+
---
|
| 34 |
+
|
| 35 |
+
## Architecture
|
| 36 |
+
|
| 37 |
+
```
|
| 38 |
+
βββββββββββββββββββββββββββββββββββββββββββ
|
| 39 |
+
β Dashboard (React + Vite) :5173 β
|
| 40 |
+
β Pages: FairDispatch, LoadConsolidation β
|
| 41 |
+
ββββββββββββββββββ¬βββββββββββββββββββββββββ
|
| 42 |
+
β axios β /api/*
|
| 43 |
+
ββββββββββββββββββΌβββββββββββββββββββββββββ
|
| 44 |
+
β API Gateway (Node.js + Express) :3000 β
|
| 45 |
+
β Auth, CRUD, Proxy to Brain β
|
| 46 |
+
ββββββββββββββββββ¬βββββββββββββββββββββββββ
|
| 47 |
+
β axios β BRAIN_URL
|
| 48 |
+
ββββββββββββββββββΌβββββββββββββββββββββββββ
|
| 49 |
+
β AI Brain (FastAPI + LangGraph) :8000 β
|
| 50 |
+
β 8 Dispatch Agents + 5 Consolidation β
|
| 51 |
+
β OR-Tools, scikit-learn, XGBoost β
|
| 52 |
+
ββββββββββββββββββ¬βββββββββββββββββββββββββ
|
| 53 |
+
β
|
| 54 |
+
ββββββββββββββββββΌβββββββββββββββββββββββββ
|
| 55 |
+
β Database: SQLite (auto) or PostgreSQL β
|
| 56 |
+
βββββββββββββββββββββββββββββββββββββββββββ
|
| 57 |
+
```
|
| 58 |
+
|
| 59 |
+
---
|
| 60 |
+
|
| 61 |
+
## Environment Variables
|
| 62 |
+
|
| 63 |
+
### Brain (`brain/.env`)
|
| 64 |
+
```env
|
| 65 |
+
# Required: NONE (SQLite auto-created)
|
| 66 |
+
# Optional:
|
| 67 |
+
DATABASE_URL=postgresql+asyncpg://user:pass@host:5432/fairrelay
|
| 68 |
+
GOOGLE_API_KEY=your-gemini-key # For LLM explanations
|
| 69 |
+
GEMINI_MODEL=gemini-2.5-flash # Model to use
|
| 70 |
+
OLA_MAPS_API_KEY=your-ola-key # For real-time traffic
|
| 71 |
+
LANGCHAIN_API_KEY=your-langsmith-key # For tracing (optional)
|
| 72 |
+
APP_ENV=development # Shows /docs + /redoc
|
| 73 |
+
```
|
| 74 |
+
|
| 75 |
+
### Backend (`ops/backend-dm/.env`)
|
| 76 |
+
```env
|
| 77 |
+
BRAIN_URL=http://localhost:8000 # Required
|
| 78 |
+
DATABASE_URL=postgresql://... # For auth/drivers/packages
|
| 79 |
+
JWT_SECRET=your-secret # For auth tokens
|
| 80 |
+
PORT=3000
|
| 81 |
+
```
|
| 82 |
+
|
| 83 |
+
### Dashboard (`ops/AIsupplychain/aisupply/.env`)
|
| 84 |
+
```env
|
| 85 |
+
VITE_API_URL=http://localhost:3000 # Points to API Gateway
|
| 86 |
+
```
|
| 87 |
+
|
| 88 |
+
---
|
| 89 |
+
|
| 90 |
+
## What Each Agent Does
|
| 91 |
+
|
| 92 |
+
### Fair Dispatch Pipeline (8 Agents)
|
| 93 |
+
|
| 94 |
+
| # | Agent | Algorithm | What it computes |
|
| 95 |
+
|---|-------|-----------|-----------------|
|
| 96 |
+
| 1 | ML Effort | Deterministic formula + traffic | NΓM effort matrix |
|
| 97 |
+
| 2 | Route Planner | OR-Tools SCIP/GLOP solver | Optimal 1-to-1 assignment |
|
| 98 |
+
| 3 | Fairness Manager | Gini coefficient | ACCEPT or REOPTIMIZE |
|
| 99 |
+
| 4 | Route Planner v2 | OR-Tools + penalties | Re-optimized assignment |
|
| 100 |
+
| 5 | Driver Liaison | Comfort band logic | Per-driver ACCEPT/COUNTER |
|
| 101 |
+
| 6 | Final Resolution | Metric-validated swaps | Resolve counter-proposals |
|
| 102 |
+
| 7 | Explainability | Template categorization | Natural language per driver |
|
| 103 |
+
| 8 | Gemini LLM | Gemini 2.5 Flash (optional) | Rich multilingual explanations |
|
| 104 |
+
|
| 105 |
+
### Load Consolidation Pipeline (5 Agents)
|
| 106 |
+
|
| 107 |
+
| # | Agent | Algorithm | What it computes |
|
| 108 |
+
|---|-------|-----------|-----------------|
|
| 109 |
+
| 1 | Geo Clustering | KMeans + Silhouette | Group nearby shipments |
|
| 110 |
+
| 2 | Time Window | Overlap filter | Split incompatible schedules |
|
| 111 |
+
| 3 | Capacity | OR-Tools CP-SAT | Bin-pack into trucks |
|
| 112 |
+
| 4 | Scoring | Multi-metric | Confidence per group |
|
| 113 |
+
| 5 | RL Insights | Q-Learning | Optimal parameters |
|
| 114 |
+
|
| 115 |
+
---
|
| 116 |
+
|
| 117 |
+
## API Endpoints
|
| 118 |
+
|
| 119 |
+
### Core Allocation
|
| 120 |
+
```bash
|
| 121 |
+
# Full LangGraph pipeline (8 agents)
|
| 122 |
+
POST /api/v1/allocate/langgraph
|
| 123 |
+
|
| 124 |
+
# Simple allocation (no LangGraph)
|
| 125 |
+
POST /api/v1/allocate
|
| 126 |
+
|
| 127 |
+
# Load consolidation (5 agents)
|
| 128 |
+
POST /api/v1/consolidate/optimize
|
| 129 |
+
|
| 130 |
+
# Compare scenarios
|
| 131 |
+
POST /api/v1/consolidate/simulate
|
| 132 |
+
```
|
| 133 |
+
|
| 134 |
+
### Monitoring
|
| 135 |
+
```bash
|
| 136 |
+
# Health check
|
| 137 |
+
GET /health
|
| 138 |
+
|
| 139 |
+
# SSE agent events (real-time)
|
| 140 |
+
GET /agent-events/stream?run_id=<uuid>
|
| 141 |
+
|
| 142 |
+
# Run history
|
| 143 |
+
GET /api/v1/runs
|
| 144 |
+
GET /api/v1/runs/<run_id>
|
| 145 |
+
```
|
| 146 |
+
|
| 147 |
+
### Driver Management
|
| 148 |
+
```bash
|
| 149 |
+
GET /api/v1/drivers
|
| 150 |
+
GET /api/v1/drivers/<id>
|
| 151 |
+
POST /api/v1/feedback
|
| 152 |
+
```
|
| 153 |
+
|
| 154 |
+
---
|
| 155 |
+
|
| 156 |
+
## Testing
|
| 157 |
+
|
| 158 |
+
```bash
|
| 159 |
+
cd brain
|
| 160 |
+
|
| 161 |
+
# Run all tests
|
| 162 |
+
pytest tests/ -v
|
| 163 |
+
|
| 164 |
+
# Run specific test
|
| 165 |
+
pytest tests/test_langgraph_workflow.py -v
|
| 166 |
+
|
| 167 |
+
# Test full workflow manually
|
| 168 |
+
python test_workflow.py
|
| 169 |
+
```
|
| 170 |
+
|
| 171 |
+
---
|
| 172 |
+
|
| 173 |
+
## Deployment
|
| 174 |
+
|
| 175 |
+
See [DEPLOYMENT.md](./DEPLOYMENT.md) for full production deployment guide with:
|
| 176 |
+
- Render (Brain + Backend)
|
| 177 |
+
- Vercel (Dashboard + Landing)
|
| 178 |
+
- LoRRI integration patterns
|
| 179 |
+
|
| 180 |
+
---
|
| 181 |
+
|
| 182 |
+
## Tech Stack
|
| 183 |
+
|
| 184 |
+
| Component | Technology |
|
| 185 |
+
|-----------|-----------|
|
| 186 |
+
| AI Engine | Python 3.11, FastAPI, LangGraph, SQLAlchemy |
|
| 187 |
+
| Optimization | OR-Tools (SCIP, CP-SAT), scikit-learn, XGBoost |
|
| 188 |
+
| Traffic | OLA Maps API (real-time Indian traffic) |
|
| 189 |
+
| LLM | Gemini 2.5 Flash (multilingual explanations) |
|
| 190 |
+
| API Gateway | Node.js, Express, Prisma, Socket.IO |
|
| 191 |
+
| Dashboard | React 19, Vite, TailwindCSS, Axios |
|
| 192 |
+
| Mobile | Flutter (driver app) |
|
| 193 |
+
| Database | PostgreSQL (prod) / SQLite (dev/demo) |
|
| 194 |
+
| Deployment | Render (Docker) + Vercel (static) |
|
| 195 |
+
|
| 196 |
+
---
|
| 197 |
+
|
| 198 |
+
## Key Differentiators
|
| 199 |
+
|
| 200 |
+
1. **Gini Coefficient Fairness** β mathematically provable workload equity (0.85 β 0.12)
|
| 201 |
+
2. **EV-First Routing** β battery feasibility + charging penalty in OR-Tools cost matrix
|
| 202 |
+
3. **Night Safety** β gender-aware routing after 9 PM (avoid high-crime zones)
|
| 203 |
+
4. **Cognitive Load Index** β 6-factor driver mental fatigue scoring
|
| 204 |
+
5. **Explainable AI** β every allocation decision has a natural language explanation
|
| 205 |
+
6. **Real-Time Traffic** β OLA Maps API integration for Indian road conditions
|
| 206 |
+
7. **Self-Improving** β Q-Learning bandit auto-tunes fairness thresholds daily
|
| 207 |
+
8. **Production TMS Integration** β designed for LoRRI (logisticsnow.in) embedding
|