# Fleet Pulse

A fleet in motion. Every command has a path back.

[HTML](https://leohteixeira.com/en/projects/fleet-pulse) · Leonardo Teixeira

## The product

Fleet Pulse is a rental and leasing simulator shipped as one Go binary. Real MQTT clients represent simulated vehicles, while a map and portfolio views expose telemetry, contracts and command state.

Stack: Go, React, TypeScript, PostgreSQL, MQTT, SSE, Leaflet

## The main flow

1. **Devices publish telemetry** — Simulated vehicles connect to the embedded mochi-mqtt broker as real clients and follow a committed Greater São Paulo route library.

2. **The browser follows the fleet** — HTTP supplies the initial snapshot. A buffered SSE stream delivers telemetry, command and area-exit events; slow clients can lose older events.

3. **A visitor sends a door command** — Lock and unlock accept an Idempotency-Key and return HTTP 202 with a command identifier. The vehicle receives the MQTT command and acknowledges it.

4. **The command settles** — PENDING → SENT → ACKED, FAILED or TIMEOUT. Expiry is five seconds from SENT; queue capacity is bounded per vehicle.

## Architecture

```text
Simulated MQTT devices ↔ embedded broker ↔ telemetry ingest / command machine
React + Leaflet ↔ HTTP API → PostgreSQL + vehicle-state cache
SSE hub → browser · React build → go:embed → single Go binary
```

### One process, explicit boundaries

Standard-library HTTP, embedded MQTT, simulator, command machine, SSE hub and embedded React assets run in one Go process.

### Durable portfolio, transient commands

PostgreSQL stores portfolio data and last-known positions, with an in-memory vehicle-state cache. Rental door command state and the live stream are lost on restart. There is no position history.

## Availability and limits

All vehicles, routes and contracts are simulated. There is no authentication: visitors share the demonstration and can perform its actions. No replicas, historical position store or real vehicle control. The accelerated simulation clock is separate from real telemetry timestamps.

[Open demo](https://leohteixeira.com/fleet-pulse/)

[Source on GitHub](https://github.com/leohteixeira/fleet-pulse)
