Overview
The Fleet Dashboard (/fleet) provides a unified real-time view of all fleet operations including tractors, trailers, and drivers. It is the main entry point for the Fleet Management module.
Route:
/fleetRepository: Hemut-Prod (Next.js frontend)Key Features
KPI Cards
Real-time metrics for tractor utilization, trailer utilization, active drivers, and critical alerts
Interactive Map
Live vehicle and trailer locations with Leaflet maps, multiple view modes (Tractors, Trailers, Drivers)
Fleet Panels
Quick access to active tractors, trailer pool, and driver status with filtering and search
Real-time Updates
SSE (Server-Sent Events) for live data streaming without page refresh
Architecture
API Endpoints
REST Endpoints
| Method | Endpoint | Description |
|---|---|---|
GET | /api/drivers/current | Fetch all current drivers |
GET | /locations/current | Fetch vehicle/tractor locations |
GET | /api/trailers/current | Fetch all trailer data |
GET | /api/movements?limit=500 | Fetch movements for vehicle-load associations |
GET | /api/orders/by-ids?ids=... | Fetch customer names for orders |
SSE Streams (Real-time)
| Endpoint | Event Type | Description |
|---|---|---|
/stream/locations | location_update | Real-time vehicle location updates |
/api/trailers/stream | location_update | Real-time trailer location updates |
All endpoints are prefixed with the Tracking Backend URL (
NEXT_PUBLIC_TRACKING_BACKEND_URL).File Structure
| Category | Files | Description |
|---|---|---|
| Pages | pages/fleet.tsx | Next.js page component |
| Components | 7 files | UI components for dashboard, maps, status indicators |
| Hooks | 2 files | Data fetching and SSE management |
| Types | 3 files | TypeScript type definitions |
Pages
Next.js page components
Components
React UI components
Hooks
Custom React hooks
Types
TypeScript definitions
Quick File Reference (13 files)
Quick File Reference (13 files)
Pages (1 file)
pages/fleet.tsx— Main entry point
FleetManagement.tsx— Navigation wrapperUnifiedFleetDashboard.tsx— Main dashboardLiveVehicleMap.tsx— Vehicle mapLiveTrailerMap.tsx— Trailer mapConnectionStatusIndicator.tsx— SSE status badgeConnectionStatus.tsx— Full status displayMapLegend.tsx— Map color legend
useUnifiedFleetData.ts— Combined fleet datauseVehicleLocations.ts— Vehicle locations
unified-fleet.ts— Fleet typesvehicle-locations.ts— Vehicle typestrailer-locations.ts— Trailer types
Data Flow
Initial Load
- Page Mount:
pages/fleet.tsxrendersFleetManagement - Route Detection:
FleetManagementdetects/fleetpath, rendersUnifiedFleetDashboard - Hook Initialization:
useUnifiedFleetDatahook initializes - Parallel REST Calls: Fetches drivers, vehicles, and trailers concurrently
- SSE Connection: Establishes SSE connections for real-time updates
- Render: Dashboard displays with initial data
Real-time Updates
- SSE Event: Backend sends
location_updateevent - Hook Processing:
useUnifiedFleetDataupdates state - Statistics Recalculation:
useMemorecomputes KPIs - Component Re-render: Map and panels update automatically
Statistics Computed
The dashboard displays real-time KPIs computed from the fleet data:| KPI | Calculation |
|---|---|
| Tractor Utilization | (vehicles with drivers / total vehicles) × 100 |
| Trailer Utilization | (moving trailers / total trailers) × 100 |
| Available Trailers | Count of trailers with speed < 5 mph |
| Active Drivers | Count of drivers with status = “active” |
| Critical Alerts | Count of fault codes + HOS warnings |

