docs: Add DEPLOYMENT.md - complete production deployment guide for LoRRI integration

#18
Files changed (1) hide show
  1. DEPLOYMENT.md +210 -166
DEPLOYMENT.md CHANGED
@@ -1,205 +1,249 @@
1
- # πŸš€ FairRelay β€” Production Deployment Guide
2
 
3
- ## Architecture Overview (LoRRI Integration)
4
 
5
  ```
6
  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
7
- β”‚ LoRRI Production (logisticsnow.in) β”‚
8
- β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
9
- β”‚ β”‚ Indent β”‚ β”‚ Fleet β”‚ β”‚ Trip β”‚ β”‚ E-Way Bill β”‚ β”‚
10
- β”‚ β”‚ Mgmt β”‚ β”‚ Tracking β”‚ β”‚ Mgmt β”‚ β”‚ Generation β”‚ β”‚
11
- β”‚ β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
12
- β”‚ β”‚ β”‚ β”‚ β”‚ β”‚
13
- β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
14
- β”‚ β”‚ β”‚
15
- β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
16
- β”‚ β”‚ LoRRI Dispatch β”‚ β”‚
17
- β”‚ β”‚ Module β”‚ β”‚
18
- β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
19
- β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
20
- β”‚ POST /v1/allocate
21
- β”‚ (API Key Auth)
22
- β–Ό
23
- β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
24
- β”‚ FairRelay API Gateway (ops/backend-dm) β”‚
25
- β”‚ Render: https://fairrelay-api.onrender.com β”‚
26
- β”‚ β”‚
27
- β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
28
- β”‚ β”‚ /v1/allocateβ”‚ β”‚/v1/wellnessβ”‚ β”‚ /v1/gini β”‚ β”‚/v1/consolidate β”‚ β”‚
29
- β”‚ β”‚ /v1/carbon β”‚ β”‚/v1/night- β”‚ β”‚ /v1/runs β”‚ β”‚/v1/health β”‚ β”‚
30
- β”‚ β”‚ β”‚ β”‚ safety β”‚ β”‚ β”‚ β”‚ β”‚ β”‚
31
- β”‚ β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
32
- β”‚ β”‚ β”‚ β”‚
33
- β”‚ β”‚ Proxies to Brain when available β”‚ β”‚
34
- β”‚ β”‚ Falls back to demo mode otherwise β”‚ β”‚
35
- β””β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
36
- β”‚ β”‚
37
- β–Ό β–Ό
38
- β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
39
- β”‚ FairRelay AI Brain (brain/) β”‚
40
- β”‚ Render: https://fairrelay-brain.onrender.com β”‚
41
- β”‚ β”‚
42
- β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ LangGraph Workflow ───────────────────────┐ β”‚
43
- β”‚ β”‚ β”‚ β”‚
44
- β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚
45
- β”‚ β”‚ β”‚ML Effort β”‚β†’ β”‚ Route β”‚β†’ β”‚ Fairness β”‚β†’ β”‚ Route β”‚ β”‚ β”‚
46
- β”‚ β”‚ β”‚ Agent β”‚ β”‚ Planner β”‚ β”‚ Manager β”‚ β”‚Planner v2β”‚ β”‚ β”‚
47
- β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚
48
- β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚
49
- β”‚ β”‚ β–Ό β–Ό β–Ό β”‚ β”‚
50
- β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚
51
- β”‚ β”‚ β”‚ Driver β”‚β†’ β”‚ Final β”‚β†’ β”‚Explainab-β”‚β†’ β”‚ Gemini β”‚ β”‚ β”‚
52
- β”‚ β”‚ β”‚ Liaison β”‚ β”‚Resolutionβ”‚ β”‚ ility β”‚ β”‚(optional)β”‚ β”‚ β”‚
53
- β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚
54
- β”‚ β”‚ β”‚ β”‚
55
- β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
56
- β”‚ β”‚
57
- β”‚ Features: K-Means clustering, OR-Tools optimization, Gini index, β”‚
58
- β”‚ EV-first routing, night safety, recovery days, wellness scoring β”‚
59
  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
60
- β”‚
61
- β–Ό
62
- β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
63
- β”‚ Frontends (Vercel) β”‚
64
- β”‚ β”‚
65
- β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
66
- β”‚ β”‚ Landing Page β”‚ β”‚ Ops Dashboard β”‚ β”‚ Flutter App β”‚ β”‚
67
- β”‚ β”‚ fairrelay.vercel β”‚ β”‚ fairrelay-ops. β”‚ β”‚ MyFairRelay β”‚ β”‚
68
- β”‚ β”‚ .app β”‚ β”‚ vercel.app β”‚ β”‚ (Android/iOS) β”‚ β”‚
69
- β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
70
  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
71
  ```
72
 
73
- ## Deploy Commands
 
 
74
 
75
- ### 1. AI Brain (FastAPI + LangGraph) β†’ Render
76
 
77
  ```bash
78
- # From /brain directory
79
- # Render auto-deploys from GitHub via render.yaml
80
-
81
- # Environment variables (set in Render dashboard):
82
- DATABASE_URL= # Leave empty for SQLite fallback (free tier)
83
- APP_ENV=production
84
- GOOGLE_API_KEY= # Optional: enables Gemini explanations
85
- LANGCHAIN_TRACING_V2=false
 
 
 
 
 
 
 
 
86
  ```
87
 
88
- **URL**: `https://fairrelay-brain.onrender.com`
89
- **Health**: `GET /health`
90
- **Docs**: `GET /docs`
91
 
92
- ### 2. API Gateway (Node.js + Prisma) β†’ Render
93
 
94
  ```bash
95
- # From /ops/backend-dm directory
96
- # Deploy as Docker or Node.js service
97
-
98
- # Environment variables:
99
- DATABASE_URL=postgresql://... # Render PostgreSQL (free tier)
100
- BRAIN_URL=https://fairrelay-brain.onrender.com
101
- CORS_ORIGINS=https://fairrelay.vercel.app,https://fairrelay-ops.vercel.app
102
- JWT_SECRET=your-secret-here
103
- NODE_ENV=production
 
 
 
 
 
104
  ```
105
 
106
- **URL**: `https://fairrelay-api.onrender.com`
107
- **Health**: `GET /v1/health`
108
- **Docs**: `GET /api/docs`
109
 
110
- ### 3. Landing Page (React/Vite) β†’ Vercel
111
 
112
  ```bash
113
- cd landing
114
- vercel --prod
115
 
116
- # Environment variables (set in Vercel):
117
- VITE_API_URL=https://fairrelay-api.onrender.com
 
 
 
 
118
  ```
119
 
120
- ### 4. Ops Dashboard (React/Vite) β†’ Vercel
121
 
122
  ```bash
123
- cd ops/AIsupplychain/aisupply
124
- vercel --prod
125
 
126
- # Environment variables:
127
- VITE_API_BASE_URL=https://fairrelay-api.onrender.com
 
 
 
 
128
  ```
129
 
130
- ## LoRRI Integration API Contract
131
 
132
- ### Authentication
133
- ```
134
- Header: x-api-key: fr_live_xxxxxxxxxxxxxxxxxx
135
- ```
136
 
137
- ### Core Endpoint: Fair Allocation
138
- ```http
139
- POST /v1/allocate
 
 
 
140
  Content-Type: application/json
141
- x-api-key: fr_live_xxx
142
 
143
  {
144
- "drivers": [
145
- { "id": "drv_001", "name": "Rajesh Kumar", "hours_today": 4.5, "is_ill": false, "vehicle_type": "DIESEL", "gender": "M" },
146
- { "id": "drv_002", "name": "Priya Sharma", "hours_today": 8.1, "is_ill": false, "vehicle_type": "ELECTRIC", "gender": "F" }
147
- ],
148
- "routes": [
149
- { "id": "rt_A", "distance_km": 142, "difficulty": "medium" },
150
- { "id": "rt_B", "distance_km": 48, "difficulty": "easy", "is_city_centre": true }
151
- ],
152
- "options": { "ev_first": true, "night_safety": true }
153
  }
154
  ```
155
 
156
- **Response:**
157
- ```json
158
- {
159
- "success": true,
160
- "data": {
161
- "id": "run_1708394400000",
162
- "allocations": [
163
- {
164
- "driver": "drv_002",
165
- "route": "rt_B",
166
- "wellness_score": 61,
167
- "carbon_kg": "10.1",
168
- "explanation": "Priya assigned city route (EV-first). 8.1h worked β€” shorter route for recovery."
169
- }
170
- ]
171
- },
172
- "meta": {
173
- "gini_index": 0.12,
174
- "fairness_grade": "A",
175
- "carbon_kg": "39.8",
176
- "latency_ms": 284,
177
- "mode": "live"
178
- }
179
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
180
  ```
181
 
182
- ### Other Endpoints
183
- | Endpoint | Method | Description |
184
- |----------|--------|-------------|
185
- | `/v1/health` | GET | System + Brain connectivity |
186
- | `/v1/allocate` | POST | Fair route allocation |
187
- | `/v1/wellness` | POST | Driver wellness scoring |
188
- | `/v1/gini` | POST | Standalone Gini calculation |
189
- | `/v1/night-safety` | POST | Night safety constraints |
190
- | `/v1/carbon` | POST | COβ‚‚ emission estimates |
191
- | `/v1/consolidate` | POST | AI load consolidation |
192
- | `/v1/runs` | GET | Recent allocation history |
193
-
194
- ## What Makes This YC-Level
195
-
196
- 1. **Real AI Pipeline** β€” 6-8 LangGraph agents with OR-Tools optimization (not mock data)
197
- 2. **Fairness Metrics** β€” Gini coefficient computed per run, tracked over time
198
- 3. **SDG Alignment** β€” SDG 8 (Decent Work), SDG 10 (Inequality), SDG 13 (Climate)
199
- 4. **Production Architecture** β€” API gateway + microservice brain + SSE streaming
200
- 5. **Explainability** β€” Every allocation decision has a human-readable explanation
201
- 6. **Driver Wellness** β€” Fatigue scoring, recovery days, night safety for women
202
- 7. **EV-First Routing** β€” Prioritizes electric vehicles for city-centre routes
203
- 8. **Learning Agent** β€” Multi-armed bandit tunes fairness thresholds over time
204
- 9. **LoRRI Integration** β€” Single API call from existing TMS, zero disruption
205
- 10. **Scale** β€” K-Means + OR-Tools handles 1000+ packages in <5s
 
1
+ # FairRelay β€” Production Deployment Guide
2
 
3
+ ## Architecture Overview
4
 
5
  ```
6
  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
7
+ β”‚ LoRRI Production (logisticsnow.in) β”‚
8
+ β”‚ Embeds FairRelay via iframe/API integration β”‚
9
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
10
+ β”‚ HTTPS
11
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
12
+ β”‚ Ops Dashboard (Vercel) β”‚
13
+ β”‚ React + Vite + TailwindCSS β”‚
14
+ β”‚ Pages: FairDispatch, LoadConsolidation, AssignTasks, Analytics β”‚
15
+ β”‚ URL: https://fairrelay.vercel.app β”‚
16
+ β”‚ Root: ops/AIsupplychain/aisupply/ β”‚
17
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
18
+ β”‚ HTTPS (axios β†’ /api/*)
19
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
20
+ β”‚ Node.js API Gateway (Render) β”‚
21
+ β”‚ Express + Prisma + Socket.IO β”‚
22
+ β”‚ Auth, Drivers CRUD, Packages, E-Way Bills, Carbon, Wellness β”‚
23
+ β”‚ Proxies /api/dispatch/* β†’ Brain β”‚
24
+ β”‚ URL: https://fairrelay-backend.onrender.com β”‚
25
+ β”‚ Root: ops/backend-dm/ β”‚
26
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
27
+ β”‚ HTTPS (proxy)
28
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
29
+ β”‚ AI Brain (Render - Docker) β”‚
30
+ β”‚ FastAPI + LangGraph + SQLAlchemy β”‚
31
+ β”‚ 8 AI Agents: ML Effort β†’ Route Planner β†’ Fairness Manager β†’ β”‚
32
+ β”‚ Driver Liaison β†’ Final Resolution β†’ Explainability β†’ Learning β”‚
33
+ β”‚ + 5-Agent Consolidation Pipeline β”‚
34
+ β”‚ URL: https://fairrelay-brain.onrender.com β”‚
35
+ β”‚ Root: brain/ β”‚
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
37
+ β”‚
38
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
39
+ β”‚ Databases β”‚
40
+ β”‚ β€’ PostgreSQL (Render/Supabase) β€” primary production β”‚
41
+ β”‚ β€’ SQLite fallback (auto-created if no DATABASE_URL) β”‚
42
+ β”‚ β€’ LangSmith (optional tracing) β”‚
43
+ β”‚ β€’ Gemini 2.5 Flash (optional LLM explanations) β”‚
 
 
 
44
  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
45
  ```
46
 
47
+ ---
48
+
49
+ ## Deployment Steps
50
 
51
+ ### 1. AI Brain (FastAPI) β†’ Render
52
 
53
  ```bash
54
+ # From the brain/ directory
55
+ cd brain
56
+
57
+ # Deploy to Render:
58
+ # 1. Create New Web Service β†’ Docker
59
+ # 2. Root Directory: brain
60
+ # 3. Dockerfile Path: ./Dockerfile
61
+ # 4. Environment Variables:
62
+ # APP_ENV=production
63
+ # PORT=8000
64
+ # DATABASE_URL= (leave empty for SQLite fallback)
65
+ # CORS_ORIGINS=https://fairrelay-backend.onrender.com,https://fairrelay.vercel.app,https://logisticsnow.in
66
+ # GOOGLE_API_KEY=<your-key> (optional, for Gemini explanations)
67
+ # GEMINI_MODEL=gemini-2.5-flash
68
+ # ENABLE_GEMINI_EXPLAIN=true
69
+ # LANGCHAIN_TRACING_V2=false
70
  ```
71
 
72
+ **Health check URL:** `/health`
73
+ **API Docs:** `https://fairrelay-brain.onrender.com/docs`
 
74
 
75
+ ### 2. Node.js Backend β†’ Render
76
 
77
  ```bash
78
+ cd ops/backend-dm
79
+
80
+ # Deploy to Render:
81
+ # 1. Create New Web Service β†’ Node
82
+ # 2. Root Directory: ops/backend-dm
83
+ # 3. Build Command: npm install
84
+ # 4. Start Command: node index.js
85
+ # 5. Environment Variables:
86
+ # NODE_ENV=production
87
+ # PORT=3000
88
+ # BRAIN_URL=https://fairrelay-brain.onrender.com
89
+ # DATABASE_URL=<your-postgres-url>
90
+ # JWT_SECRET=<random-secure-string>
91
+ # CORS_ORIGINS=https://fairrelay.vercel.app,https://logisticsnow.in
92
  ```
93
 
94
+ **Health check URL:** `/health`
 
 
95
 
96
+ ### 3. Ops Dashboard β†’ Vercel
97
 
98
  ```bash
99
+ cd ops/AIsupplychain/aisupply
 
100
 
101
+ # Deploy to Vercel:
102
+ # 1. Import from GitHub
103
+ # 2. Root Directory: ops/AIsupplychain/aisupply
104
+ # 3. Framework: Vite
105
+ # 4. Environment Variables:
106
+ # VITE_API_URL=https://fairrelay-backend.onrender.com
107
  ```
108
 
109
+ ### 4. Landing Page β†’ Vercel
110
 
111
  ```bash
112
+ cd landing
 
113
 
114
+ # Deploy to Vercel:
115
+ # 1. Import from GitHub
116
+ # 2. Root Directory: landing
117
+ # 3. Framework: Vite
118
+ # 4. Environment Variables:
119
+ # VITE_API_URL=https://fairrelay-backend.onrender.com
120
  ```
121
 
122
+ ---
123
 
124
+ ## LoRRI Integration
125
+
126
+ FairRelay integrates into LoRRI (logisticsnow.in) via:
 
127
 
128
+ ### Option A: API Integration (Recommended)
129
+ LoRRI calls FairRelay's allocation API directly:
130
+
131
+ ```bash
132
+ POST https://fairrelay-backend.onrender.com/api/dispatch/allocate
133
+ Authorization: Bearer <jwt-token>
134
  Content-Type: application/json
 
135
 
136
  {
137
+ "drivers": [...],
138
+ "routes": [...],
139
+ "packages": [...]
 
 
 
 
 
 
140
  }
141
  ```
142
 
143
+ ### Option B: Embedded Dashboard
144
+ Embed the FairDispatch page in an iframe:
145
+
146
+ ```html
147
+ <iframe src="https://fairrelay.vercel.app/fair-dispatch"
148
+ width="100%" height="800px"
149
+ frameborder="0" allow="clipboard-read">
150
+ </iframe>
151
+ ```
152
+
153
+ ### Option C: Webhook Integration
154
+ LoRRI sends webhook events β†’ FairRelay processes β†’ returns results:
155
+
156
+ ```
157
+ LoRRI β†’ POST /api/v1/allocate (with drivers + packages)
158
+ ← Response with fair assignments + explanations
159
+ β†’ POST /api/v1/consolidate/optimize (with shipments + trucks)
160
+ ← Response with consolidated groups + carbon savings
161
+ ```
162
+
163
+ ---
164
+
165
+ ## AI Agent Pipeline (What runs on each allocation)
166
+
167
+ | Phase | Agent | What it does | Latency |
168
+ |-------|-------|-------------|---------|
169
+ | 1 | ML Effort Agent | Builds [drivers Γ— routes] effort matrix | ~50ms |
170
+ | 2 | Route Planner | OR-Tools linear assignment (proposal 1) | ~100ms |
171
+ | 3a | Fairness Manager | Evaluates Gini/stddev/max_gap | ~20ms |
172
+ | 3b | Route Planner (re-opt) | Penalized assignment if unfair | ~80ms |
173
+ | 4 | Driver Liaison | Per-driver comfort band negotiation | ~30ms |
174
+ | 5 | Final Resolution | Resolves counter-proposals via swaps | ~50ms |
175
+ | 6 | Explainability | Generates natural language explanations | ~100ms |
176
+ | 6b | Gemini LLM (optional) | Rich multilingual explanations | ~2s |
177
+ | 7 | Learning Agent | Creates episode for config auto-tuning | ~10ms |
178
+
179
+ **Total pipeline:** ~450ms (without Gemini) / ~2.5s (with Gemini)
180
+
181
+ ---
182
+
183
+ ## Environment Variables Reference
184
+
185
+ ### Brain (FastAPI)
186
+ | Variable | Required | Default | Description |
187
+ |----------|----------|---------|-------------|
188
+ | `DATABASE_URL` | No | SQLite | PostgreSQL URL or empty for SQLite |
189
+ | `APP_ENV` | No | production | `development` or `production` |
190
+ | `GOOGLE_API_KEY` | No | β€” | Gemini API key for LLM explanations |
191
+ | `GEMINI_MODEL` | No | gemini-2.5-flash | Model for explanations |
192
+ | `ENABLE_GEMINI_EXPLAIN` | No | false | Enable Gemini agent |
193
+ | `LANGCHAIN_API_KEY` | No | β€” | LangSmith tracing key |
194
+ | `CORS_ORIGINS` | No | * | Comma-separated allowed origins |
195
+
196
+ ### Backend (Node.js)
197
+ | Variable | Required | Default | Description |
198
+ |----------|----------|---------|-------------|
199
+ | `DATABASE_URL` | Yes* | β€” | PostgreSQL for auth/drivers/packages |
200
+ | `BRAIN_URL` | Yes | localhost:8000 | URL of the AI brain service |
201
+ | `JWT_SECRET` | Yes | β€” | Secret for JWT token signing |
202
+ | `CORS_ORIGINS` | No | localhost | Allowed CORS origins |
203
+ | `PORT` | No | 3000 | Server port |
204
+
205
+ ### Dashboard (React)
206
+ | Variable | Required | Default | Description |
207
+ |----------|----------|---------|-------------|
208
+ | `VITE_API_URL` | Yes | /api | Backend URL (Render) |
209
+
210
+ ---
211
+
212
+ ## Local Development
213
+
214
+ ```bash
215
+ # Terminal 1: AI Brain
216
+ cd brain
217
+ pip install -r requirements.txt
218
+ uvicorn app.main:app --reload --port 8000
219
+
220
+ # Terminal 2: Node.js Backend
221
+ cd ops/backend-dm
222
+ npm install
223
+ echo "BRAIN_URL=http://localhost:8000" > .env
224
+ node index.js
225
+
226
+ # Terminal 3: Ops Dashboard
227
+ cd ops/AIsupplychain/aisupply
228
+ npm install
229
+ echo "VITE_API_URL=http://localhost:3000" > .env
230
+ npm run dev
231
  ```
232
 
233
+ Open http://localhost:5173 β†’ FairDispatch page β†’ Run Fair Allocation
234
+
235
+ ---
236
+
237
+ ## Production Checklist
238
+
239
+ - [ ] Brain deployed on Render (Docker) βœ“ Health check passes
240
+ - [ ] Node.js backend on Render βœ“ `/health` returns healthy
241
+ - [ ] Dashboard on Vercel βœ“ Connects to backend
242
+ - [ ] PostgreSQL database provisioned (Render/Supabase)
243
+ - [ ] `BRAIN_URL` in backend points to brain service
244
+ - [ ] `VITE_API_URL` in dashboard points to backend
245
+ - [ ] CORS origins include `logisticsnow.in`
246
+ - [ ] Gemini API key configured (optional but recommended)
247
+ - [ ] SSL/HTTPS on all services (automatic on Render/Vercel)
248
+ - [ ] Rate limiting active on auth endpoints
249
+ - [ ] Socket.IO CORS configured for real-time updates