A route optimization solution for field jobs starting from Sunquick Lanka Pvt Ltd. Built with Spring Boot (Java 21) and React + Vite.
Tech Stack
| Layer | Technology |
|---|---|
| Backend | Spring Boot 4.0.6, Java 21, Maven |
| Frontend | React 18, Vite |
| Map | Leaflet.js + OpenStreetMap (free) |
| Algorithm | Nearest Neighbor (Haversine distance) |
| Testing | JUnit 5, Mockito |
oute-optimizer/ ├── backend/route-optimizer-backend/ ← Spring Boot └── frontend/route-optimizer-frontend/ ← React + Vite
- Java 21
- Maven
- Node.js 18+
- npm
cd backend/route-optimizer-backend
./mvnw spring-boot:runBackend runs at: http://localhost:8080
cd frontend/route-optimizer-frontend
npm install
npm run devFrontend runs at: http://localhost:5173
Method : GET - URL : http://localhost:8080/api/route/optimize
Returns the optimized route for all pending jobs.
Response:
{
"estimatedTotalTime": "18 min",
"message": "Route optimized successfully",
"optimizedRoute": [
{
"distanceFromPrevious": 2.85,
"estimatedTime": "4 min",
"geo_lat": "7.2940094",
"geo_lng": "79.8396836",
"id": "65",
"job_id": "JR#100065",
"job_type": "Dispensing",
"status": "Pending",
"store_name": "DOLPHINE HOTEL",
"territory": "Negombo",
"vendor_id": "2",
"visitOrder": 1
},
{
"distanceFromPrevious": 0.0,
"estimatedTime": "0 min",
"geo_lat": "7.2940094",
"geo_lng": "79.8396836",
"id": "64",
"job_id": "JR#100064",
"job_type": "Registration",
"status": "Pending",
"store_name": "DOLPHINE HOTEL",
"territory": "Negombo",
"vendor_id": "2",
"visitOrder": 2
},
{
"distanceFromPrevious": 5.39,
"estimatedTime": "8 min",
"geo_lat": "7.2455846",
"geo_lng": "79.8418470",
"id": "63",
"job_id": "JR#100063",
"job_type": "Power",
"status": "Pending",
"store_name": "GOLDI SANDS",
"territory": "Negombo",
"vendor_id": "5",
"visitOrder": 3
},
{
"distanceFromPrevious": 3.55,
"estimatedTime": "5 min",
"geo_lat": "7.2373457",
"geo_lng": "79.8729596",
"id": "62",
"job_id": "JR#100062",
"job_type": "Hardware",
"status": "Pending",
"store_name": "SURANGA CATERS- NEGAMBO",
"territory": "Negombo",
"vendor_id": "8",
"visitOrder": 4
}
],
"startLat": 7.2906,
"startLng": 79.8653,
"startLocation": "Sunquick Lanka Pvt Ltd",
"totalDistanceKm": 11.79,
"totalStops": 4
}URL : http://localhost:8080/api/route/health
Health check endpoint.
Response: Route Optimizer API is running ✅
Uses the Nearest Neighbor algorithm:
- Start at Sunquick Lanka Pvt Ltd
- Find the closest unvisited job using Haversine formula
- Visit it, then repeat until all jobs are visited
- Returns the ordered visit sequence
This project uses Leaflet.js with OpenStreetMap tiles instead of Google Maps because:
- ✅ Completely free — no credit card required
- ✅ No API key needed
- ✅ OpenStreetMap data is open-source
- ✅ Leaflet is the most popular open-source map library
- ✅ Supports markers, polylines, popups — everything needed for route display
Google Maps requires a billing account and charges after free tier limits. Leaflet + OpenStreetMap has no such restrictions.
cd backend/route-optimizer-backend
./mvnw testExpected: 9 tests passed