Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

7 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŸข Greenmile โ€” Bidirectional Last-Mile Logistics Optimizer

"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


๐Ÿ“Œ The Problem

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.

๐Ÿ’ก The Solution

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.

Impact Per Van Per Day

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


โœจ Key Features

๐Ÿง  AI-Powered Intelligence (Gemini 2.0 Flash)

  • 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.

๐Ÿ—บ๏ธ Route Optimization Engine

  • 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

๐Ÿ“ฆ Operations Tools

  • 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

๐Ÿ—๏ธ Architecture

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

System Flow

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])
Loading

๐Ÿš€ Quick Start

Prerequisites

  • Python 3.10+ and Node.js 18+
  • A Gemini API key (free tier works; the app runs in heuristic-fallback mode without one)

1. Backend

cd backend
pip install -r requirements.txt

Create a .env file inside backend/:

GEMINI_API_KEY=your_gemini_api_key_here

Start the server:

python -m uvicorn app.main:app --port 8000

API docs โ†’ http://localhost:8000/docs

2. Frontend

cd frontend
npm install

If 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 dev

Dashboard โ†’ http://localhost:5173

3. Try the Demo

  1. Open http://localhost:5173
  2. Click "or load seeded demo data" in the upload dropzone
  3. Click โšก Optimize โ€” watch the pipeline run
  4. Explore tabs: Route Map โ†’ Packing Order โ†’ Driver View โ†’ Fleet Scaler

โ˜๏ธ Deployment

๐ŸŒ Frontend โ†’ greenmile-seven.vercel.app (Vercel)

Frontend โ†’ Vercel

frontend/vercel.json configures the Vite SPA build with client-side routing rewrites.

  1. Push this repo to GitHub
  2. Go to vercel.com โ†’ Add New Project โ†’ import your repo
  3. Set Root Directory to frontend
  4. In Environment Variables, add:
    VITE_API_URL=https://greenmile-backend.onrender.com
    
  5. Deploy โ€” Vercel auto-detects Vite

Backend โ†’ Render

render.yaml at the project root configures a free-tier Python web service:

  1. Go to render.com โ†’ New โ†’ Blueprint โ†’ connect your repo
  2. Render auto-reads render.yaml and provisions the service
  3. In the Render dashboard, go to Environment and add GEMINI_API_KEY

๐Ÿ”Œ API Reference

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 Schema

{
  "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".

Optimization Response

The /optimize endpoint returns:

  • route โ€” Ordered list of stops annotated with risk_score, flag, reason, suggested_action, return_probability, pre_stage_return
  • nl_summary โ€” Gemini-generated 3-sentence route briefing
  • metrics โ€” Before/after distance, fuel cost, COโ‚‚, driver hours
  • flagged_count โ€” Number of stops with anomaly flags
  • pre_staged_returns โ€” Number of delivery stops pre-allocated a return bay

CSV Format

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

๐Ÿ› ๏ธ Tech Stack

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 ๐Ÿ‡ฎ๐Ÿ‡ณ

Releases

Packages

Contributors

Languages