feat: Add production deployment README with full architecture and deploy instructions for LoRRI integration

#8
by MouleeswaranM - opened
Files changed (1) hide show
  1. DEPLOYMENT.md +205 -0
DEPLOYMENT.md ADDED
@@ -0,0 +1,205 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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