Skip to content

Jinzo03/velocity_project

Repository files navigation

VeloCity: Real-Time Fleet Tracking & AI Dispatch Pipeline

Docker FastAPI React PostgreSQL MQTT Gemini

Overview

VeloCity is a containerized microservices application designed to simulate, ingest, process, and analyze real-time geospatial IoT telemetry. Built as a comprehensive Data Engineering portfolio project, it bridges the gap between raw sensor data, stream processing, and Generative AI.

velocity_frontend-Opera2026-03-0521-05-16-ezgif com-video-to-gif-converter

🚀 Key Features

  • 📡 High-Throughput Data Streaming (IoT): A Python-based virtual sensor publishes GPS coordinates via the MQTT protocol (Eclipse Mosquitto broker), replacing traditional, blocking HTTP requests.
  • 🧮 Real-Time Stream Processing: The FastAPI backend acts as a subscriber, intercepting the stream and applying the Haversine formula (spherical trigonometry) to calculate the truck's distance from a central hub dynamically.
  • 🚨 Automated Geofencing: If a vehicle breaches a predefined 2km radius, the system instantly triggers a state update, turning the React dashboard's geofence red and throwing a critical alert.
  • 🗺️ Intelligent Map Tracking: Features a premium Dark Mode SaaS UI with an auto-following map camera that automatically breaks its lock if the user manually drags the map to inspect the route.
  • 🧠 GenAI Dispatcher: Integrates the modern google-genai SDK with Gemini 2.5 Flash. The AI acts as a virtual fleet manager, querying the PostGIS database to generate human-readable performance reports based on coordinate history.
  • 🐳 True Microservices Architecture: The entire stack (Database, Broker, Backend, Frontend, and Simulator) is orchestrated via Docker Compose across a custom Docker network.

🏗️ System Architecture

  1. Virtual Truck (Python): Generates GPS drift and publishes to velocity/telemetry.
  2. Mosquitto Broker: Handles Pub/Sub message queuing.
  3. FastAPI Backend: Subscribes to the broker, runs math models, saves to DB, and serves REST endpoints.
  4. PostgreSQL + PostGIS: Stores the historical spatial data.
  5. React + Leaflet (Vite): Polls the backend, renders the live map, draws polyline paths, and displays the Gemini AI analysis.

🛠️ Tech Stack

  • Frontend: React, Vite, React-Leaflet, Custom CSS (Dark Theme)
  • Backend: Python 3.10, FastAPI, Uvicorn, Paho-MQTT, Google GenAI SDK
  • Database: PostgreSQL with PostGIS extension, SQLModel (ORM)
  • Infrastructure: Docker, Docker Compose, Eclipse Mosquitto

How to Run the Project

Because this project is fully containerized, you do not need to install Node.js, Python, or PostgreSQL on your local machine. You only need Docker.

1. Clone the repository:

git clone [https://github.com/YOUR_USERNAME/velocity.git](https://github.com/YOUR_USERNAME/velocity.git)
cd velocity

2. Configure Environment Variables (Security First): This project uses a .env file to keep API keys secure.

Copy the example file:

cp .env.example .env

Open the new .env file and insert your free Google Gemini API key (get one from Google AI Studio),or use another API key from a different LLM.

3. Build and launch the cluster:

docker compose up --build

4. Access the Dashboard: Open your browser and navigate to http://localhost:5173. You will see the truck begin its route, update the KPI metrics in real-time, and eventually trigger the geofence breach.

🔮 Future Improvements

While the current architecture successfully handles real-time single-vehicle telemetry, the following upgrades are planned for enterprise scale:

  • True WebSockets: Replace the frontend's REST API polling (setInterval) with a bi-directional WebSocket connection (FastAPI WebSockets) for instant, zero-latency state updates.
  • Multi-Vehicle Scaling: Upgrade the Python simulator to spawn multiple asynchronous threads, publishing telemetry for an entire fleet of 50+ trucks to distinct MQTT topics (e.g., velocity/telemetry/+).
  • Time-Series Database: Migrate from standard PostgreSQL to TimescaleDB or InfluxDB to optimize querying massive amounts of historical coordinate data.
  • Cloud Deployment: Map the local Docker Compose network to a cloud provider (AWS EC2 or Google Cloud Compute Engine) with a reverse proxy (Nginx/Traefik) handling SSL termination.

License

This project is open-source and available under the MIT License.

About

An enterprise-grade, containerized IoT fleet tracking platform. Features real-time MQTT streaming, PostGIS spatial data, mathematical geofencing, and Gemini 2.5 Flash AI dispatch analytics.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors