Inspiration

Cold chain logistics loses $35 billion annually due to temperature failures. During COVID-19, millions of Pfizer and Moderna vaccine doses were wasted because of temperature excursions. Johnson & Johnson had to destroy 15 million doses in a single incident. Walmart loses billions yearly to produce spoilage despite operating 10,000+ refrigerated trucks. These numbers made me realize that current monitoring systems are reactive - by the time someone notices a problem, the cargo is already damaged. I wanted to build something that catches issues the moment they happen and tells operators exactly what to do.

What it does

Cyber-Physical Guard monitors a fleet of trucks carrying temperature-sensitive cargo like vaccines, insulin, frozen seafood, electronics, and fresh produce. When temperatures go outside safe ranges, the system detects it within seconds using Apache Flink SQL stream processing. It then generates AI-powered recommendations through Google Gemini - not just "temperature is high" but specific actions like which facility to reroute to and who to notify. The dashboard shows everything in real-time on a live map where trucks turn red when critical, and clicking on them reveals the full AI analysis.

How we built it

We used Confluent Cloud for real-time data streaming with Apache Kafka handling truck telemetry every 2 seconds. Apache Flink SQL processes the stream and detects temperature violations based on cargo-specific thresholds. Critical alerts go to a separate Kafka topic in AVRO format. A Python FastAPI backend consumes these alerts, calls Google Gemini 2.0 Flash for AI recommendations, and broadcasts to the dashboard via WebSocket. The frontend uses vanilla JavaScript with Leaflet.js for the interactive map. BigQuery stores historical data for analytics. Everything runs in Docker containers on an Ubuntu server with Nginx handling traffic.

Challenges we ran into

Getting AVRO serialization right between Flink and Python was tricky. The schema had to match exactly or messages would fail silently. WebSocket connection management was another challenge - we had to implement proper timeout handling (4-minute demo limit, 2-minute idle disconnect) to prevent resource exhaustion. Matching the Flink SQL output schema with what the Python consumer expected took several iterations. Also, ensuring the AI recommendations came back fast enough to feel real-time required optimizing the Gemini prompts to get sub-2-second responses.

Accomplishments that we're proud of

The system detects anomalies in under a second - that's faster than any human could react. The AI recommendations are genuinely useful with specific actions, not generic advice. We built a complete end-to-end pipeline from data generation to AI-powered alerts in a real-time dashboard. The architecture is production-ready with proper error handling, automatic reconnection, and session management. Seeing trucks turn red on the map and AI recommendations appear within seconds of a temperature violation feels like magic.

What we learned

Flink SQL is surprisingly powerful - complex anomaly detection with a simple WHERE clause instead of writing custom stream processing code. Real-time systems need careful timeout management. Gemini 2.0 Flash is fast enough for real-time use cases. AVRO schema management is critical when multiple systems need to communicate. WebSocket connections need heartbeats and proper cleanup. Docker makes deployment consistent across environments. The combination of Confluent Cloud and Google AI creates a powerful platform for intelligent real-time applications.

What's next for Cyber-Physical Guard

Predictive alerts using historical patterns to warn before temperatures actually exceed thresholds. Integration with actual GPS tracking APIs for real truck routes. Mobile app for drivers with push notifications. Multi-tenant support for different logistics companies. Machine learning models trained on historical data to predict equipment failures. Integration with warehouse management systems for automated rerouting. Adding more sensor types like humidity, vibration, and door open/close events. Expanding to other industries like pharmaceutical manufacturing and food processing plants.

Built With

Share this project:

Updates