A self-built navigation system that offers intelligent route suggestions, calculates distances, and estimates travel time based on real-time traffic data — inspired by the functionality of Google Maps.
Why build a navigation app when Google Maps exists?
Because the real challenge wasn't to compete—it was to learn, build, and optimize something complex from scratch. With limited access to premium APIs, this project became a deep dive into the fundamentals of:
- 🗺️ Geospatial computing and coordinate systems
- 🚗 Route optimization algorithms
- ⚡ Performance optimization through multithreading and caching
- 🔐 Secure authentication with JWT and Spring Security
- 📊 Real-time data processing and API integration
- 📍 Custom route suggestions between any two points
- 🌐 Multiple geolocation APIs for accurate coordinate resolution
- 🚦 Traffic-aware ETA calculation using live traffic data
- 📏 Haversine distance calculation for precise measurements
- 🚗 Multiple transport modes support (car, bike, walking)
- Multithreading: Reduced response time from 30s to ~10s
- Caching: Route and location data caching for faster repeated queries
- Async processing: Non-blocking email and data operations
- JWT-based authentication with Spring Security
- Email verification with OTP system
- Role-based access control (ADMIN/USER)
- Password encryption with BCrypt
- Session management with stateless tokens
- Real-time traffic data storage and retrieval
- Paginated traffic queries by location
- Cache management for traffic data
- Historical traffic analysis
- Java 21: Modern Java features and performance improvements
- Spring Boot 3.4.2: Rapid application development
- Spring MVC: RESTful API architecture
- Spring Data JPA: Database abstraction layer
- Spring Security: Authentication and authorization
- Maven: Build and dependency management
- PostgreSQL: Relational database for persistent storage
🌍 OpenStreetMap Nominatim API - Geolocation (lat/lon)
🛣️ Geoapify Routing API - Route planning and directions
🚦 TomTom Traffic API - Real-time traffic data
- JWT (jjwt 0.11.5): Token-based authentication
- Spring Mail: Email notifications and OTP delivery
- RestTemplate: HTTP client for external API calls
- Caffeine/Spring Cache: Performance caching
SmartCity_TrafficSystem/
├── trafficsystem/
│ ├── src/
│ │ ├── main/
│ │ │ ├── java/com/smartcity/trafficsystem/
│ │ │ │ ├── controller/ # REST API endpoints
│ │ │ │ │ ├── RouteSuggestionController.java
│ │ │ │ │ ├── TrafficDataController.java
│ │ │ │ │ └── UserController.java
│ │ │ │ ├── service/ # Business logic
│ │ │ │ │ ├── RouteSuggestionService.java
│ │ │ │ │ ├── TrafficDataService.java
│ │ │ │ │ └��─ UserService.java
│ │ │ │ ├── model/ # Entity classes
│ │ │ │ │ ├── User.java
│ │ │ │ │ ├── Role.java
│ │ │ │ │ ├── RouteSuggestion.java
│ │ │ │ │ └── TrafficData.java
│ │ │ │ ├── repository/ # Data access layer
│ │ │ │ ├── dto/ # Data transfer objects
│ │ │ │ ├── config/ # Configuration classes
│ │ │ │ │ └── SecurityConfig.java
│ │ │ │ ├── jwtAuth/ # JWT utilities
│ │ │ │ ├── email/ # Email service
│ │ │ │ └── exception/ # Custom exceptions
│ │ │ └── resources/
│ │ │ └── application.properties
│ │ └── test/
│ ├── pom.xml
│ └── mvnw
└── README.md
- Java Development Kit (JDK) 21 or higher
- Maven 3.6+ or higher
- PostgreSQL 12+ or higher
- API Keys (free):
- Geoapify API Key (Get it here)
- TomTom API Key (Get it here)
-
Clone the repository:
git clone https://github.com/rishabhrawat05/SmartCity_TrafficSystem.git cd SmartCity_TrafficSystem/trafficsystem -
Configure the database:
Create a PostgreSQL database and update
src/main/resources/application.properties:spring.datasource.url=jdbc:postgresql://localhost:5432/smartcity_traffic spring.datasource.username=your_username spring.datasource.password=your_password spring.jpa.hibernate.ddl-auto=update
-
Add API keys:
Update
application.propertieswith your API keys:geoapify.api-key=your_geoapify_api_key tomtom.api-key=your_tomtom_api_key
-
Configure email settings (optional, for OTP):
spring.mail.host=smtp.gmail.com spring.mail.port=587 spring.mail.username=your_email@gmail.com spring.mail.password=your_app_password
-
Build the project:
mvn clean install
-
Run the application:
mvn spring-boot:run
The application will start on
http://localhost:8080.
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
| POST | /api/user/signup |
Register new user | ❌ |
| POST | /api/user/verify/email |
Verify email with OTP | ❌ |
| POST | /api/user/login |
User login | ❌ |
| POST | /api/user/resend/otp |
Resend OTP | ❌ |
| GET | /api/user/getAllUser |
Get all users (Admin only) | ✅ |
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
| POST | /api/route/suggest |
Get route suggestions | ✅ |
Request Body Example:
{
"startLocation": "New Delhi",
"endLocation": "Mumbai",
"modeOfTransport": "drive"
}| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
| POST | /api/traffic/data |
Save traffic data | ✅ |
| GET | /api/traffic/data/{location} |
Get traffic data by location | ✅ |
| GET | /api/traffic/data/clearCache/{location} |
Clear traffic cache | ✅ |
- User Input: User provides start and end locations with preferred transport mode
- Geocoding: System fetches latitude/longitude using OpenStreetMap API
- Route Planning: Geoapify API calculates optimal route with turn-by-turn directions
- Traffic Analysis: TomTom API provides real-time traffic data for route segments
- ETA Calculation: System computes traffic-adjusted estimated time of arrival
- Distance Measurement: Haversine formula calculates precise distances
- Response Optimization: Multithreading and caching ensure fast responses
- ExecutorService with fixed thread pool (10 threads)
- Parallel API calls for location lookup and route calculation
- Non-blocking async operations
- Route caching: Stores frequently requested routes
- Location caching: Caches geocoded locations
- Traffic data caching: Reduces API calls for recent traffic queries
- Cache keys include location pairs and transport mode for accuracy
- JPA repository pagination for large datasets
- Indexed queries on frequently accessed columns
- Connection pooling with HikariCP
- Real-time Traffic Updates: WebSocket-based live traffic notifications
- Machine Learning Integration: Predictive traffic pattern analysis
- Alternative Routes: Multiple route options with comparison
- Mobile Application: Native iOS/Android companion app
- Route History: Save and retrieve favorite routes
- Social Features: Share routes and traffic reports
- Offline Mode: Cached maps for offline navigation
- Voice Navigation: Turn-by-turn voice guidance
- Points of Interest: Nearby restaurants, gas stations, etc.
Contributions are welcome! Here's how you can help:
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
- Free API tiers have rate limits (implement request throttling if needed)
- Traffic data accuracy depends on TomTom API coverage
- OSM Nominatim requests should respect usage policy
- Always validate user input locations
- Implement proper error handling for API failures
- Monitor API quota usage
- Use environment variables for sensitive data
Rishabh Rawat
- GitHub: @rishabhrawat05
Made with ❤️ and dedication to smarter urban mobility.