"The greenest mile is the one you don't drive twice."
Greenmile is an AI-powered logistics optimizer that merges outbound deliveries and inbound returns into a single smart loop โ eliminating the empty-van problem that wastes 40% of last-mile fuel in India.
Built for FAR AWAY 2026 Hackathon ยท Theme: Logistics & Transit
๐ Live Demo โ greenmile-seven.vercel.app
Every day, Indian delivery fleets run two separate trips for the same set of customers:
Trip 1 (Delivery): Warehouse โโ๐ฆโโโ Customers โโ๐ซโโโ Warehouse (van returns EMPTY)
Trip 2 (Returns): Warehouse โโ๐ซโโโ Customers โโ๐ฆโโโ Warehouse (van leaves EMPTY)
That's 2 trips, 2 fuel tanks, 2 driver shifts โ for work that one loop could cover. No existing tool on the market combines deliveries and returns into a single optimized route.
Greenmile merges both trips into one bidirectional loop:
Warehouse โโ๐ฆ deliverโโโ Customers โโโฉ๏ธ collect returnsโโโ Warehouse
ONE TRIP. ONE VAN. ONE DRIVER.
The van delivers packages on the way out and picks up returns on the way back. No empty legs. No wasted fuel.
| Metric | Before (2 Trips) | After (1 Loop) | Saved |
|---|---|---|---|
| Distance | 87 km | 52 km | โผ 35 km (40%) |
| Fuel Cost | โน653 | โน390 | โผ โน263/day |
| COโ Emissions | 19.4 kg | 11.6 kg | โผ 7.8 kg |
| Driver Hours | 8.2 hrs | 5.1 hrs | โผ 3.1 hrs |
For a 50-van fleet: โน33 lakh saved/year ยท 97 tonnes COโ avoided ยท โ 4,600 trees equivalent
- Fraud & Anomaly Detection โ Analyses return stop metadata (frequency, disputes, confirmation delays) and flags suspicious patterns with risk scores (0โ1), reasons, and actions (HOLD / VERIFY / PROCEED)
- Natural Language Briefing โ Generates a 3-sentence plain-English route summary that non-technical fleet managers can read in 10 seconds
- Return Probability Predictor โ Scores each delivery for return likelihood and pre-allocates van space for predicted returns
Graceful fallback: if no Gemini API key is provided, the system automatically falls back to heuristic anomaly detection and a static route summary โ no crash, no empty UI.
- DBSCAN Geographic Clustering โ Groups nearby stops into zones using haversine distance (eps = 3 km), so each van handles a tight geographic area
- Bidirectional Loop Optimizer โ Nearest-Neighbour seed + 2-opt improvement builds one loop: deliver outbound โ collect returns inbound โ return to warehouse
- Before/After Split Map โ Side-by-side Leaflet maps showing the old 2-trip routes (red + blue) vs the optimized green loop with progressive drawing animation
- Packing Sequencer โ SVG bird's-eye van diagram showing exactly how to load: returns at the rear (collected last), deliveries at the front (dropped first). Warehouse workers follow the numbered checklist
- Driver Mobile View โ One-stop-at-a-time interface with navigation, progress tracking, and inline anomaly warnings
- Fleet Scaler โ Slider projecting annual savings from 1 to 50 vans with live โน/COโ/hours calculations
greenmile/
โโโ backend/
โ โโโ app/
โ โ โโโ main.py # FastAPI โ /upload, /optimize endpoints
โ โ โโโ models.py # Pydantic schemas: Stop, OptimizationRequest
โ โ โโโ optimizer/
โ โ โโโ dbscan.py # DBSCAN geographic clustering (haversine)
โ โ โโโ haversine.py # Great-circle distance matrix
โ โ โโโ route.py # NN + 2-opt bidirectional loop builder
โ โ โโโ return_predictor.py # Return probability scoring heuristic
โ โโโ ai/
โ โ โโโ anomaly.py # Gemini fraud detector (google-genai SDK)
โ โ โโโ summary.py # Gemini NL route summary generator
โ โโโ requirements.txt
โโโ frontend/
โ โโโ src/
โ โ โโโ App.jsx # Main dashboard โ state management & layout
โ โ โโโ index.css # Design system (dark theme)
โ โ โโโ components/
โ โ โโโ UploadDropzone.jsx # CSV drag-and-drop upload
โ โ โโโ RouteMap.jsx # Leaflet map (before state)
โ โ โโโ SplitRouteMap.jsx # Before/After side-by-side split map
โ โ โโโ MetricCards.jsx # Animated before โ after savings cards
โ โ โโโ AnomalyBadge.jsx # AI fraud flag display panel
โ โ โโโ PackingSequencer.jsx # SVG van diagram + load order checklist
โ โ โโโ DriverView.jsx # Mobile driver interface
โ โ โโโ FleetScaler.jsx # 1โ50 van annual savings projector
โ โโโ package.json
โโโ data/
โ โโโ demo_stops.csv # 18 seeded stops โ Delhi-NCR Zone B
โโโ frontend/vercel.json # Vercel frontend deployment config
โโโ render.yaml # Render backend deployment config
flowchart TD
A([CSV Upload / Demo Data]) --> B[POST /upload]
B --> C{Validate columns, types, coordinates}
C -->|Invalid| D([400 Error + message])
C -->|Valid| E[Parsed stops JSON]
E --> F([Frontend: stop summary cards])
F --> G([Click โก Optimize])
G --> H[POST /optimize]
subgraph Pipeline ["Optimization Pipeline"]
H --> I["DBSCAN clustering<br/>(eps=3km, Haversine)"]
I --> J["NN + 2-opt per cluster<br/>(bidirectional loop)"]
J --> K["Return Probability Predictor"]
K --> L["Gemini Anomaly Detection<br/>(risk_score + reason)"]
L --> M["Gemini NL Summary<br/>(3-sentence briefing)"]
end
M --> N([Annotated route + metrics])
N --> O([Split Before/After Map])
N --> P([Metric Cards โ savings])
N --> Q([Packing Sequencer + SVG])
N --> R([Driver View])
N --> S([Fleet Scaler])
N --> T([Anomaly Badges])
- Python 3.10+ and Node.js 18+
- A Gemini API key (free tier works; the app runs in heuristic-fallback mode without one)
cd backend
pip install -r requirements.txtCreate a .env file inside backend/:
GEMINI_API_KEY=your_gemini_api_key_here
Start the server:
python -m uvicorn app.main:app --port 8000API docs โ http://localhost:8000/docs
cd frontend
npm installIf your backend is running somewhere other than localhost:8000, create a .env file inside frontend/:
VITE_API_URL=http://localhost:8000
Start the dev server:
npm run devDashboard โ http://localhost:5173
- Open http://localhost:5173
- Click "or load seeded demo data" in the upload dropzone
- Click โก Optimize โ watch the pipeline run
- Explore tabs: Route Map โ Packing Order โ Driver View โ Fleet Scaler
๐ Frontend โ greenmile-seven.vercel.app (Vercel)
frontend/vercel.json configures the Vite SPA build with client-side routing rewrites.
- Push this repo to GitHub
- Go to vercel.com โ Add New Project โ import your repo
- Set Root Directory to
frontend - In Environment Variables, add:
VITE_API_URL=https://greenmile-backend.onrender.com - Deploy โ Vercel auto-detects Vite
render.yaml at the project root configures a free-tier Python web service:
- Go to render.com โ New โ Blueprint โ connect your repo
- Render auto-reads
render.yamland provisions the service - In the Render dashboard, go to Environment and add
GEMINI_API_KEY
| Method | Endpoint | Description |
|---|---|---|
GET |
/ |
Health check โ returns API status and Gemini config |
GET |
/docs |
Interactive Swagger UI |
POST |
/upload |
Upload CSV file โ returns parsed + validated stops JSON |
POST |
/optimize |
Accepts { stops: Stop[] } โ returns optimized route with AI annotations |
{
"stop_id": "D7",
"type": "DELIVERY",
"lat": 28.5479,
"lng": 77.2118,
"address": "Malviya Nagar",
"weight_kg": 4.1,
"volume_l": 18,
"time_window_start": "12:00",
"time_window_end": "15:00",
"cluster_id": "Zone_B",
"return_count_30d": 3,
"avg_delivery_confirm_minutes": 15,
"dispute_history_count": 1
}type must be "DELIVERY" or "RETURN".
The /optimize endpoint returns:
routeโ Ordered list of stops annotated withrisk_score,flag,reason,suggested_action,return_probability,pre_stage_returnnl_summaryโ Gemini-generated 3-sentence route briefingmetricsโ Before/after distance, fuel cost, COโ, driver hoursflagged_countโ Number of stops with anomaly flagspre_staged_returnsโ Number of delivery stops pre-allocated a return bay
Required columns (see data/demo_stops.csv for a working example):
stop_id, type, lat, lng, address, weight_kg, volume_l,
time_window_start, time_window_end, cluster_id,
return_count_30d, avg_delivery_confirm_minutes, dispute_history_count
| Layer | Technology |
|---|---|
| Backend | Python 3.12 ยท FastAPI ยท Uvicorn |
| Optimization | scikit-learn (DBSCAN) ยท scipy ยท custom NN + 2-opt |
| AI | Google Gemini 2.0 Flash via google-genai SDK |
| Frontend | React 19 ยท Vite 8 ยท Tailwind CSS v3 |
| Maps | Leaflet.js ยท react-leaflet ยท dark tile layer |
| Data | pandas ยท CSV validation ยท Pydantic v2 models |
Greenmile v2.0 ยท Built for India's last mile ๐ฎ๐ณ