Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

28 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

FleetFusion πŸš€

Autonomous Supply Chain Financial Agent with Real-Time Streaming Analytics

An enterprise-grade SaaS platform that monitors supply chains in real-time, detects delays, calculates financial penalties, and autonomously proposes arbitrage solutions using Pathway streaming engine and AI-powered contract analysis.


πŸ“‹ Table of Contents

  1. Overview
  2. System Architecture
  3. Data Flow
  4. Technology Stack
  5. Quick Start
  6. Detailed Setup
  7. Features
  8. Pathway Integration
  9. Component Architecture
  10. API Documentation
  11. Deployment
  12. Development

🎯 Overview

FleetFusion is a real-time supply chain monitoring platform that combines:

  • Real-time GPS tracking of delivery vehicles
  • Streaming analytics using Pathway v0.7.0 for instant delay detection
  • AI-powered contract analysis with OpenAI integration
  • Financial arbitrage detection to minimize SLA penalties
  • Interactive visualization with dark-mode optimized maps
  • WebSocket-based real-time updates for instant frontend notifications

Key Capabilities

✨ Real-time Monitoring: Track multiple trucks simultaneously with 1-second GPS updates
πŸ’° Financial Intelligence: Detect arbitrage opportunities and calculate penalty avoidance savings
πŸ€– Autonomous Decisions: AI agent analyzes contracts and proposes optimal solutions
πŸ—ΊοΈ Live Mapping: Real road routing with OSRM integration, not straight-line approximations
⚑ Instant Alerts: Sub-second latency from GPS update to frontend notification
πŸ“Š Analytics Dashboard: Comprehensive metrics with 24-hour trend analysis


πŸ—οΈ System Architecture

High-Level Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                          FleetFusion Platform                          β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   GPS Sensors   β”‚      β”‚         Pathway Streaming Engine             β”‚
β”‚   (Simulated)   │──────▢         (backend-pathway/)                   β”‚
β”‚   1Hz Updates   β”‚      β”‚                                               β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
                         β”‚  β”‚  1. GPS Connector (Custom Python)      β”‚  β”‚
                         β”‚  β”‚     β€’ Ingests truck location data      β”‚  β”‚
                         β”‚  β”‚     β€’ Validates schemas                β”‚  β”‚
                         β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
                         β”‚                    ↓                          β”‚
                         β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
                         β”‚  β”‚  2. Transformations (Temporal Windows) β”‚  β”‚
                         β”‚  β”‚     β€’ 60-second sliding windows        β”‚  β”‚
                         β”‚  β”‚     β€’ Velocity monitoring              β”‚  β”‚
                         β”‚  β”‚     β€’ Delay detection                  β”‚  β”‚
                         β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
                         β”‚                    ↓                          β”‚
                         β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
                         β”‚  β”‚  3. Contract Analysis (AI/RAG)         β”‚  β”‚
                         β”‚  β”‚     β€’ OpenAI integration               β”‚  β”‚
                         β”‚  β”‚     β€’ Contract RAG queries             β”‚  β”‚
                         β”‚  β”‚     β€’ Penalty calculations             β”‚  β”‚
                         β”‚  β”‚     β€’ Arbitrage detection              β”‚  β”‚
                         β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
                         β”‚                    ↓                          β”‚
                         β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
                         β”‚  β”‚  4. WebSocket Output (Real-time)       β”‚  β”‚
                         β”‚  β”‚     β€’ Event streaming                  β”‚  β”‚
                         β”‚  β”‚     β€’ Alert broadcasting               β”‚  β”‚
                         β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
                         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                            β”‚
                                            β”‚ WebSocket (ws://localhost:8765)
                                            ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                        Next.js Frontend (app/)                           β”‚
β”‚                                                                           β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚  Landing Page    β”‚  β”‚   Dashboard      β”‚  β”‚  Analytics         β”‚   β”‚
β”‚  β”‚  β€’ Features      β”‚  β”‚   β€’ Live Map     β”‚  β”‚  β€’ Metrics         β”‚   β”‚
β”‚  β”‚  β€’ Auto-metrics  β”‚  β”‚   β€’ Agent Stream β”‚  β”‚  β€’ Trends          β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β”‚                                                                           β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚           React-Leaflet Map + OSRM Routing                       β”‚   β”‚
β”‚  β”‚           β€’ Dark mode optimized tiles                            β”‚   β”‚
β”‚  β”‚           β€’ Real-time truck positions                            β”‚   β”‚
β”‚  β”‚           β€’ Dynamic status colors (πŸŸ’πŸŸ‘πŸ”΄πŸ’œ)                      β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                     External Services (No Auth)                          β”‚
β”‚  β€’ OpenStreetMap (Map Tiles)                                            β”‚
β”‚  β€’ OSRM (Routing API)                                                   β”‚
β”‚  β€’ OpenAI (LLM for contract analysis)                                   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Architecture Layers

1. Data Ingestion Layer (Pathway Custom Connector)

  • Custom Python connector using pw.io.python.ConnectorSubject
  • Simulates GPS sensors with configurable update frequency (default: 1Hz)
  • Handles 3 concurrent truck streams
  • Schema validation and type checking

2. Streaming Processing Layer (Pathway Core)

  • Temporal Windows: 60-second sliding windows with 10-second hops
  • Real-time Aggregations: Min/max/avg velocity calculations
  • Stream Joins: Dynamic joining of delayed trucks with contract data
  • Event Detection: Status change detection (on-time β†’ delayed β†’ critical)

3. Intelligence Layer (AI/LLM)

  • OpenAI GPT-4 integration for contract analysis
  • RAG (Retrieval Augmented Generation) for contract queries
  • Penalty calculation algorithms
  • Arbitrage opportunity detection

4. Output Layer (WebSocket + JSONL)

  • Real-time WebSocket server for frontend updates
  • JSONL file outputs for debugging and archival
  • Event broadcasting with sub-second latency

5. Presentation Layer (Next.js Frontend)

  • Server-side rendering with App Router
  • Dynamic imports for map components (SSR disabled)
  • Real-time state management with React hooks
  • Smooth animations with Framer Motion

πŸ”„ Data Flow

End-to-End Data Pipeline

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Step 1: GPS Data Generation                                             β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
    πŸ“ Simulated GPS sensors emit position updates every 1 second
    πŸ“Š Data: {truck_id, lat, lon, velocity, timestamp, ...}
                                  ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Step 2: Pathway Ingestion (Custom Connector)                            β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
    πŸ”Œ ConnectorSubject.next_json() receives GPS updates
    βœ… Schema validation (pw.schema_from_types)
    πŸ’Ύ Creates streaming Pathway table
                                  ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Step 3: Temporal Window Analysis (60s windows, 10s hop)                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
    ⏰ Group GPS updates into time-based windows
    πŸ“Š Calculate velocity statistics per truck
    πŸ” Detect velocity drops below threshold (<10 km/h = delay)
                                  ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Step 4: Delay Detection & Classification                                β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
    🟒 ON-TIME:   velocity >= 65 km/h
    🟑 DELAYED:   velocity < 65 km/h (minor issue)
    πŸ”΄ CRITICAL:  velocity < 10 km/h + duration > 180s (SLA breach)
                                  ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Step 5: Contract Analysis (Stream Join)                                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
    πŸ”— Join delayed trucks with contract data
    πŸ“„ Retrieve SLA terms, penalty clauses, delivery deadlines
    πŸ’° Calculate potential financial penalties
                                  ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Step 6: AI Analysis (OpenAI + RAG)                                      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
    πŸ€– Query OpenAI with contract context + delay info
    πŸ” RAG: Retrieve relevant contract clauses
    πŸ’‘ Generate arbitrage recommendations:
       β€’ Alternative supplier costs
       β€’ Relief vehicle availability
       β€’ Net savings calculations
                                  ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Step 7: Event Broadcasting (WebSocket)                                  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
    πŸ“‘ Broadcast events to connected WebSocket clients
    πŸ“€ Event types:
       β€’ gps_update (truck position)
       β€’ status_change (πŸŸ’β†’πŸŸ‘β†’πŸ”΄)
       β€’ delay_detected (alert)
       β€’ arbitrage_opportunity (modal trigger)
                                  ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Step 8: Frontend Update (React State + Map)                             β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
    πŸ—ΊοΈ Update truck markers on map
    πŸ“Š Refresh metrics in dashboard
    🎨 Animate status color changes
    πŸ”” Show arbitrage modal with confetti
                                  ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Step 9: User Action (1-Click Fix)                                       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
    πŸ‘† User clicks "Execute Fix"
    πŸŽ‰ Confetti animation (2 seconds)
    πŸ’œ Truck status β†’ RESOLVED
    βœ… Problem solved, delivery back on track

Timeline Example (12-Second Demo Scenario)

T+0s  : πŸš€ System initialized, 3 trucks loaded
        β€’ TRK-402: Pune β†’ Mumbai (Priya Sharma)
        β€’ TRK-301: Bangalore β†’ Delhi (Rajesh Kumar)
        β€’ TRK-205: Mumbai β†’ Kolkata (Anita Desai)

T+2s  : πŸ“‘ All trucks reporting GPS (status: 🟒 ON-TIME)
        Velocities: 68 km/h, 72 km/h, 65 km/h

T+5s  : 🟑 TRK-402 velocity drops to 0 km/h
        Event: "Truck stopped - possible traffic jam"
        Status: ON-TIME β†’ DELAYED

T+8s  : πŸ”΄ TRK-402 stopped for >180 seconds
        Event: "Critical delay - SLA breach imminent"
        Contract analysis triggered
        AI calculates: $2,500 penalty incoming
        Status: DELAYED β†’ CRITICAL

T+10s : πŸ’‘ Arbitrage opportunity detected
        Alternative supplier found: $800 cost
        Net savings: $2,500 - $800 = $1,700
        Modal appears on dashboard

T+12s : πŸ‘† User clicks "Execute 1-Click Fix"
        πŸŽ‰ Confetti animation
        πŸ’œ TRK-402 status β†’ RESOLVED
        Relief vehicle dispatched
        Original truck issue noted for post-delivery analysis

πŸ› οΈ Technology Stack

Frontend (Next.js)

Technology Version Purpose
Next.js 14 React framework with App Router
TypeScript 5 Type safety and developer experience
Tailwind CSS 4 Utility-first styling with dark mode
Framer Motion 12 Animation library for smooth transitions
React-Leaflet 5.0 Interactive map component
Leaflet 1.9 Core mapping library
Lucide React Latest Modern icon library
canvas-confetti Latest Celebration animations

Backend (Pathway Streaming)

Technology Version Purpose
Pathway 0.7.0 Streaming data processing engine
Python 3.12+ Runtime environment
OpenAI Latest LLM integration for contract analysis
websockets Latest Real-time communication
aiohttp Latest Async HTTP client for OpenAI API

External Services (No Auth Required)

Service Purpose Endpoint
OpenStreetMap Map tiles tile.openstreetmap.org
OSRM Road routing router.project-osrm.org
OpenAI API Contract analysis api.openai.com

πŸš€ Quick Start

One-Command Demo (Recommended)

The fastest way to run the complete demo:

./start-demo.sh

This automated script will:

  • βœ… Check all prerequisites
  • βœ… Install dependencies if needed
  • βœ… Start all services (Pathway, WebSocket, Frontend)
  • βœ… Monitor processes
  • βœ… Provide access URLs
  • βœ… Gracefully shutdown with Ctrl+C

See DEMO.md for complete demo guide and presentation tips.


Manual Setup

If you prefer to start services individually:

Prerequisites

  • Node.js 18+ and npm
  • Python 3.12+
  • Git

1. Clone Repository

git clone <repository-url>
cd GenAI_Proj

2. Frontend Setup

# Install dependencies
npm install

# Start development server
npm run dev

Open http://localhost:3000

3. Backend Setup (Pathway)

# Navigate to backend directory
cd backend-pathway

# Create virtual environment
python3 -m venv venv-pathway
source venv-pathway/bin/activate  # On Windows: venv-pathway\Scripts\activate

# Install dependencies
pip install -r requirements-pathway.txt

# Set up environment variables
echo "OPENAI_API_KEY=your_key_here" > .env

# Start streaming pipeline
python main.py

4. Start WebSocket Server

# In a separate terminal (backend-pathway directory)
source venv-pathway/bin/activate
python websocket_server.py

You should now have:

  • βœ… Frontend running on http://localhost:3000
  • βœ… Pathway pipeline processing GPS data
  • βœ… WebSocket server on ws://localhost:8765

πŸ“– Detailed Setup

Frontend Configuration

Environment Variables

Create .env.local in root directory:

# Optional: Only needed if using real authentication
NEXTAUTH_SECRET=your-secret-key-here
NEXTAUTH_URL=http://localhost:3000

# Pathway WebSocket URL
NEXT_PUBLIC_WS_URL=ws://localhost:8765

Development Commands

# Development server with hot reload
npm run dev

# Production build
npm run build

# Start production server
npm start

# Linting
npm run lint

# Type checking
npm run type-check

Backend Configuration

Pathway Setup

cd backend-pathway

# Verify Pathway installation
python -c "import pathway as pw; print(f'Pathway version: {pw.__version__}')"

# Expected output: Pathway version: 0.7.0

Environment Variables

Create .env in backend-pathway/:

# Required for AI contract analysis
OPENAI_API_KEY=sk-your-openai-api-key

# Optional: Customize WebSocket port
WEBSOCKET_PORT=8765

# Optional: Customize GPS update frequency (seconds)
GPS_UPDATE_INTERVAL=1

Running Tests

# Unit tests for connectors
PYTHONPATH=. python tests/test_connectors.py

# Integration tests
PYTHONPATH=. python tests/test_integration.py

# LLM integration tests (requires OpenAI API key)
PYTHONPATH=. python tests/test_llm_xpack.py

# Transformation tests
PYTHONPATH=. python tests/test_transformations.py

✨ Features

Core Functionality

πŸ—ΊοΈ Real-Time Map Visualization

  • Dark Mode Optimized: Inverted OSM tiles with custom CSS filters
  • Live Truck Tracking: 3 trucks with real-time position updates
  • OSRM Road Routing: Actual road routes, not straight lines
  • Dynamic Status Colors:
    • 🟒 Green: On-time (velocity >= 65 km/h)
    • 🟑 Yellow: Minor delay (velocity < 65 km/h)
    • πŸ”΄ Red: Critical delay (stopped >180s, SLA breach)
    • πŸ’œ Purple: Resolved (fix executed)

πŸ“Š Analytics Dashboard

  • 24-Hour Metrics: Auto-updating statistics
    • Active shipments
    • On-time delivery rate
    • Average delay
    • Arbitrage savings
  • Agent Activity Stream: Real-time event log
  • Financial Impact Tracking: Penalty avoidance calculations

πŸ€– Autonomous Agent

  • Delay Detection: Sub-second latency from GPS to alert
  • Contract Analysis: AI-powered RAG queries
  • Arbitrage Detection: Finds cost-effective alternatives
  • 1-Click Execution: User approves, agent handles rest

πŸ’° Financial Intelligence

  • SLA Penalty Calculation: Real-time penalty tracking
  • Alternative Supplier Costs: Market rate queries
  • Net Savings Analysis: ROI calculations
  • Trend Visualization: Historical performance

Map Features

Smart Centering

  • Auto-fit: Dynamically zooms to show all trucks
  • Centering Button: Manual recenter control (βŠ• icon)
  • Smooth Animation: 0.5s transition
  • Fallback: Centers on India if no trucks

Route Visualization

  • Real Roads: OSRM routing for accurate paths
  • Color-Coded: Matches truck status
  • Eco-Routes: Optional carbon-optimized paths (dashed lines)
  • Caching: Stores fetched routes for performance

Zoom Controls

  • Min Zoom: 3 (prevents excessive zoom-out)
  • Max Zoom: 18 (street-level detail)
  • Bounded: Prevents map wrapping
  • Viscosity: Rigid boundary enforcement

UI/UX Features

🎨 Modern Design

  • Glassmorphism: Frosted glass effect on cards
  • Dark Mode: Optimized for low-light viewing
  • Smooth Animations: Spring physics transitions
  • Responsive: Desktop-first, mobile-compatible

🎊 Celebration Effects

  • Confetti Animation: On arbitrage execution
    • Duration: 2 seconds
    • Particles: 50 per burst
    • Two-sided launch
    • High z-index overlay

⚑ Performance

  • Lazy Loading: Map components load client-side only
  • Route Caching: Prevents redundant OSRM requests
  • Rate Limiting: 300ms delay between route fetches
  • GPU Acceleration: CSS will-change optimization

🌊 Pathway Integration

Architecture Overview

FleetFusion leverages Pathway v0.7.0 for real-time streaming analytics with a modular team-based architecture:

Team A: Data Ingestion     β†’ Custom GPS Connector
Team B: Transformations    β†’ Temporal Windows + Delay Detection
Team C: AI Integration     β†’ LLM + RAG for Contract Analysis
Team D: Output Layer       β†’ WebSocket Broadcasting

Custom GPS Connector (Team A)

Location: backend-pathway/connectors/gps_connector.py

class GPSConnector(pw.io.python.ConnectorSubject):
    def __init__(self):
        super().__init__()
        self.trucks = [
            {"truck_id": "TRK-402", "driver": "Priya Sharma", ...},
            {"truck_id": "TRK-301", "driver": "Rajesh Kumar", ...},
            {"truck_id": "TRK-205", "driver": "Anita Desai", ...}
        ]
    
    def run(self):
        while True:
            for truck in self.trucks:
                # Simulate GPS update
                self.next_json(truck)
            self.commit()
            time.sleep(1)  # 1Hz update frequency

Schema: See backend-pathway/docs/GPS_STREAM_SCHEMA.md

Temporal Windows (Team B)

Location: backend-pathway/transformations/delay_detection.py

# 60-second sliding windows with 10-second hop
windowed = gps_stream.windowby(
    pw.this.timestamp,
    window=pw.temporal.sliding(
        hop=datetime.timedelta(seconds=10),
        duration=datetime.timedelta(seconds=60)
    ),
    instance=pw.this.truck_id
)

# Velocity aggregations
velocity_stats = windowed.reduce(
    truck_id=pw.this._pw_instance,
    avg_velocity=pw.reducers.avg(pw.this.velocity),
    min_velocity=pw.reducers.min(pw.this.velocity),
    max_velocity=pw.reducers.max(pw.this.velocity)
)

# Delay detection
delayed = velocity_stats.filter(pw.this.min_velocity < 10)

AI Contract Analysis (Team C)

Location: backend-pathway/llm/contract_rag.py

from pathway.xpacks.llm import llms

# RAG pipeline for contract queries
contract_rag = llms.DocumentStore(
    docs_folder="data/contracts/",
    embedder=llms.OpenAIEmbedder(api_key=os.getenv("OPENAI_API_KEY"))
)

# Join delayed trucks with contract analysis
arbitrage_opportunities = delayed.join(
    contract_rag.query(
        prompt=f"Find alternative suppliers for {truck_id}. Calculate net savings."
    )
)

WebSocket Output (Team D)

Location: backend-pathway/adapters/websocket_output.py

class WebSocketOutput:
    async def send_event(self, event_type: str, data: dict):
        for client in self.connected_clients:
            await client.send(json.dumps({
                "type": event_type,
                "data": data,
                "timestamp": time.time()
            }))

# Connect to Pathway output
pw.io.subscribe(truck_status, on_change=websocket_output.send_event)

Key Pathway Features Used

  1. Custom Python Connectors: pw.io.python.ConnectorSubject
  2. Schema Validation: pw.schema_from_types()
  3. Temporal Windows: pw.temporal.sliding()
  4. Stream Joins: table1.join(table2, ...)
  5. Aggregations: pw.reducers.avg(), min(), max()
  6. Filtering: table.filter(condition)
  7. Output Adapters: Custom WebSocket integration
  8. LLM Integration: pathway.xpacks.llm

πŸ›οΈ Component Architecture

Frontend Structure

app/
β”œβ”€β”€ page.tsx                          # Landing page
β”œβ”€β”€ dashboard/
β”‚   └── page.tsx                      # Main dashboard (map + agent stream)
β”œβ”€β”€ analytics/
β”‚   └── page.tsx                      # Analytics & trends
β”œβ”€β”€ login/
β”‚   └── page.tsx                      # Authentication page
β”œβ”€β”€ track/
β”‚   └── [orderId]/page.tsx           # Public tracking page
β”œβ”€β”€ layout.tsx                        # Root layout with providers
└── globals.css                       # Global styles + dark mode

components/
β”œβ”€β”€ SupplyChainMap.tsx                # Main map component (Leaflet)
β”œβ”€β”€ SessionProvider.tsx               # NextAuth session wrapper
β”œβ”€β”€ landing/
β”‚   └── FeatureCards.tsx              # Auto-updating metric cards
└── dashboard/
    β”œβ”€β”€ AgentOverlay.tsx              # Right sidebar event stream
    └── FinancialModal.tsx            # Arbitrage opportunity modal

lib/
β”œβ”€β”€ hooks/
β”‚   β”œβ”€β”€ useSupplyChainStream.ts      # WebSocket hook + simulation
β”‚   └── useRealTimeMetrics.ts        # 24h metric aggregation
β”œβ”€β”€ utils/
β”‚   β”œβ”€β”€ routing.ts                    # OSRM API wrapper
β”‚   └── calculations.ts               # Financial calculations
└── types/
    └── index.ts                      # TypeScript definitions

types/
└── next-auth.d.ts                    # NextAuth type extensions

Backend Structure

backend-pathway/
β”œβ”€β”€ main.py                           # Pipeline orchestration
β”œβ”€β”€ websocket_server.py               # WebSocket server (asyncio)
β”‚
β”œβ”€β”€ connectors/
β”‚   β”œβ”€β”€ __init__.py
β”‚   └── gps_connector.py              # Custom GPS streaming connector
β”‚
β”œβ”€β”€ transformations/
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ delay_detection.py            # Temporal windows + aggregations
β”‚   └── demo_scenario.py              # 12-second scripted demo
β”‚
β”œβ”€β”€ llm/
β”‚   β”œβ”€β”€ __init__.py
β”‚   └── contract_rag.py               # OpenAI + RAG integration
β”‚
β”œβ”€β”€ adapters/
β”‚   β”œβ”€β”€ __init__.py
β”‚   └── websocket_output.py           # WebSocket event broadcaster
β”‚
β”œβ”€β”€ tests/
β”‚   β”œβ”€β”€ test_connectors.py            # Unit tests
β”‚   β”œβ”€β”€ test_transformations.py       # Transform logic tests
β”‚   β”œβ”€β”€ test_llm_xpack.py            # AI integration tests
β”‚   └── test_integration.py           # End-to-end tests
β”‚
β”œβ”€β”€ docs/
β”‚   β”œβ”€β”€ GPS_STREAM_SCHEMA.md         # Data schema documentation
β”‚   └── TRANSFORMATIONS.md            # Transformation logic guide
β”‚
β”œβ”€β”€ data/
β”‚   β”œβ”€β”€ contracts/                    # Sample contract PDFs
β”‚   └── routes/                       # Pre-computed OSRM routes
β”‚
└── output/
    β”œβ”€β”€ gps_stream.jsonl              # GPS updates (debugging)
    β”œβ”€β”€ truck_status.jsonl            # Processed status (debugging)
    β”œβ”€β”€ events.jsonl                  # Event log
    └── arbitrage_opportunities.jsonl # Financial insights

πŸ“‘ API Documentation

WebSocket Events

Server β†’ Client Events

1. gps_update

Real-time truck position update

{
  "type": "gps_update",
  "data": {
    "truck_id": "TRK-402",
    "lat": 18.7234,
    "lon": 73.6543,
    "velocity": 68,
    "timestamp": 1704484800
  },
  "timestamp": 1704484800.123
}
2. status_change

Truck status transition

{
  "type": "status_change",
  "data": {
    "truck_id": "TRK-402",
    "old_status": "on-time",
    "new_status": "delayed",
    "reason": "Velocity drop detected"
  },
  "timestamp": 1704484805.456
}
3. delay_detected

Critical delay alert

{
  "type": "delay_detected",
  "data": {
    "truck_id": "TRK-402",
    "severity": "critical",
    "duration": 185,
    "estimated_penalty": 2500,
    "contract_id": "CNT-789"
  },
  "timestamp": 1704484810.789
}
4. arbitrage_opportunity

Financial arbitrage detected

{
  "type": "arbitrage_opportunity",
  "data": {
    "truck_id": "TRK-402",
    "contract_penalty": 2500,
    "alternative_cost": 800,
    "net_savings": 1700,
    "supplier": "FastTrack Logistics",
    "eta_improvement": "2 hours",
    "confidence": 0.92
  },
  "timestamp": 1704484815.012
}

Client β†’ Server Events

subscribe

Subscribe to specific truck updates

{
  "action": "subscribe",
  "truck_ids": ["TRK-402", "TRK-301"]
}
execute_fix

Execute arbitrage solution

{
  "action": "execute_fix",
  "truck_id": "TRK-402",
  "solution_id": "ARB-12345"
}

REST API (Optional)

GET /api/trucks

Get all active trucks

Response:

{
  "trucks": [
    {
      "truck_id": "TRK-402",
      "driver": "Priya Sharma",
      "status": "on-time",
      "current_location": {"lat": 18.7234, "lon": 73.6543},
      "velocity": 68,
      "cargo_value": 45000,
      "contract_id": "CNT-789"
    }
  ],
  "total": 3,
  "timestamp": 1704484800
}

GET /api/contracts/:id

Get contract details

Response:

{
  "contract_id": "CNT-789",
  "client": "TechCorp Industries",
  "origin": "Pune",
  "destination": "Mumbai",
  "sla_hours": 6,
  "penalty_per_hour": 500,
  "cargo_value": 45000
}

🚒 Deployment

Vercel (Frontend - Recommended)

# Install Vercel CLI
npm i -g vercel

# Deploy
vercel deploy --prod

# Set environment variables in Vercel dashboard
# NEXT_PUBLIC_WS_URL=wss://your-backend-url.com

Docker (Backend)

Build & Run

cd backend-pathway

# Build image
docker build -t fleetfusion-pathway .

# Run container
docker run -d \
  -p 8765:8765 \
  -e OPENAI_API_KEY=your_key \
  --name pathway-backend \
  fleetfusion-pathway

Docker Compose

docker-compose up -d

docker-compose.yml:

version: '3.8'
services:
  pathway:
    build: ./backend-pathway
    ports:
      - "8765:8765"
    environment:
      - OPENAI_API_KEY=${OPENAI_API_KEY}
    volumes:
      - ./backend-pathway/output:/app/output

Production Checklist

  • Set OPENAI_API_KEY in environment
  • Configure WebSocket URL (NEXT_PUBLIC_WS_URL)
  • Enable HTTPS/WSS for production
  • Set up monitoring (logs, metrics)
  • Configure CORS for WebSocket
  • Enable rate limiting
  • Set up database for contract storage (optional)
  • Configure CDN for static assets
  • Set up error tracking (Sentry)

πŸ‘¨β€πŸ’» Development

Local Development Workflow

  1. Frontend Hot Reload:

    npm run dev
    # Runs on http://localhost:3000
    # Changes auto-reload
  2. Backend Development:

    cd backend-pathway
    source venv-pathway/bin/activate
    python main.py
    # Monitor output/ directory for JSONL files
  3. WebSocket Server:

    python websocket_server.py
    # Runs on ws://localhost:8765

Testing Strategy

Frontend Tests

# Type checking
npm run type-check

# Linting
npm run lint

# Component tests (if configured)
npm run test

Backend Tests

cd backend-pathway

# Run all tests
PYTHONPATH=. python -m pytest tests/

# Run specific test file
PYTHONPATH=. python tests/test_connectors.py

# With coverage
PYTHONPATH=. pytest --cov=. tests/

Debugging

Frontend Debugging

  • Open browser DevTools
  • Check Console for errors
  • Monitor Network tab for WebSocket messages
  • Use React DevTools for component inspection

Backend Debugging

  • Check backend-pathway/output/*.jsonl files
  • Monitor Pathway logs in terminal
  • Use print() statements in connectors
  • Enable Pathway debug mode: pw.run(monitoring_level=pw.MonitoringLevel.ALL)

Performance Optimization

Frontend

  • Use React.memo() for expensive components
  • Lazy load map with next/dynamic
  • Optimize images with Next.js Image component
  • Use CSS will-change for animated elements

Backend

  • Batch GPS updates before committing
  • Use Pathway's built-in aggregations (optimized C++)
  • Cache OSRM route responses
  • Limit WebSocket broadcast rate (e.g., max 10 updates/second)

πŸ“š Additional Resources

Documentation

Tutorials

Inspiration


🀝 Contributing

Contributions are welcome! Please follow these guidelines:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit changes (git commit -m 'Add amazing feature')
  4. Push to branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Code Style

  • Frontend: Follow ESLint rules (npm run lint)
  • Backend: Follow PEP 8 (black formatter recommended)
  • Commits: Use conventional commits (e.g., feat:, fix:, docs:)

πŸ“„ License

This project is built for educational and demonstration purposes.


πŸ› Recent Bug Fixes & Improvements

December 2025 Updates

βœ… Fixed Pathway Pipeline Stability

  • Issue: Pipeline was crashing due to incorrect windowby() API usage
  • Fix: Updated temporal window syntax to use groupby().windowby() pattern
  • Impact: Pipeline now runs stably without crashes
  • Files Changed: backend-pathway/transformations/delay_detection.py

βœ… Fixed Arbitrage Popup Display

  • Issue: Arbitrage opportunities weren't showing in the frontend modal
  • Root Cause: 5-second delay filter was blocking legitimate opportunities
  • Fix:
    • Reduced connection freshness check from 5s to 2s
    • Added comprehensive logging for arbitrage flow
    • Fixed field name mapping (camelCase vs snake_case)
  • Impact: Arbitrage popups now appear within 2-3 seconds of detection
  • Files Changed:
    • lib/hooks/useWebSocket.ts
    • backend-pathway/adapters/websocket_output.py

βœ… Fixed Agent Stream After Arbitrage Execution

  • Issue: Critical alerts continued showing after clicking "Execute 1-Click Fix"
  • Root Cause: No mechanism to filter alerts for resolved trucks
  • Fix:
    • Added resolvedTrucksSet to track executed arbitrage solutions
    • Filter critical events for resolved trucks from agent stream
    • Update truck status to "resolved" (πŸ’œ purple marker)
    • Display success message: "βœ… TRK-402 RESOLVED - Relief truck dispatched!"
    • Clear existing critical alerts on execution
  • Impact: Clean UX - alerts stop immediately after problem is solved
  • Files Changed: lib/hooks/useWebSocket.ts

βœ… Enhanced Status Visualization

  • Issue: Resolved trucks needed visual distinction
  • Fix: Added purple (πŸ’œ) status color for resolved trucks
  • Impact: Clear visual feedback on map and legend
  • Files Changed: components/SupplyChainMap.tsx (already supported resolved status)

Technical Improvements

Pathway API Migration

# Old (crashed):
gps_stream.windowby(...)

# New (stable):
gps_stream
  .groupby(pw.this.truck_id)
  .windowby(
    pw.this.timestamp,
    window=pw.temporal.sliding(duration=60000, hop=10000)
  )
  .reduce(...)

WebSocket Event Filtering

// Filter critical events for resolved trucks
const filteredEvents = events.filter(event => {
  const isCriticalAlert = event.message.includes('CRITICAL');
  if (isCriticalAlert) {
    const truckId = event.message.match(/TRK-\d+/)?.[0];
    return !resolvedTrucksSet.has(truckId);
  }
  return true;
});

Arbitrage Opportunity Flow

1. Backend detects critical delay (velocity < 10 km/h)
2. AI analyzes contract + calculates savings
3. WebSocket broadcasts arbitrage opportunity
4. Frontend checks: isFresh && !isDismissed && !hasExisting
5. Modal appears with confetti animation
6. User clicks "Execute 1-Click Fix"
7. Truck status β†’ RESOLVED (πŸ’œ)
8. Critical alerts filtered out
9. Success message added to stream

Performance Metrics

Metric Before After
Arbitrage popup delay Never showed 2-3 seconds
Critical alert persistence Infinite Stops on resolve
Pipeline stability Crashed Stable
Status update latency N/A <1 second

Future Enhancements

  • Persist resolved status in backend (currently frontend-only)
  • Add analytics for arbitrage execution rate
  • Implement undo functionality for executed fixes
  • Add real-time cost savings counter
  • Export arbitrage decisions to CSV/PDF reports

πŸ™ Acknowledgments

  • Pathway team for the streaming engine and hackathon
  • OpenStreetMap contributors for map data
  • OSRM project for routing API
  • Next.js team for the awesome framework

Built with ❀️ for real-time supply chain intelligence

πŸš€ Production-ready β€’ πŸŒ™ Dark mode optimized β€’ ⚑ Sub-second latency β€’ πŸ”’ No API keys required (except OpenAI)

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages