The backend is built with python-socketio mounted on top of a FastAPI application and served as a combined ASGI app. Clients connect toDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/elzackarias/Hackaton3B-Reto1/llms.txt
Use this file to discover all available pages before exploring further.
http://localhost:8000 using the Socket.IO protocol, which negotiates a WebSocket transport with an automatic polling fallback. The server is configured with cors_allowed_origins="*", so any origin may connect during development.
Connecting to the Server
useSocket hook configures reconnectionAttempts: 5 and reconnectionDelay: 2000 ms, and falls back to local mock data if the server is not reachable within 3 seconds.
Lifecycle Events
When a client connects or disconnects, the server logs the Socket.IO session ID (sid) for diagnostics.
| Event | Direction | Server log message |
|---|---|---|
connect | Client → Server | Cliente conectado: {sid} |
disconnect | Client → Server | Cliente desconectado: {sid} |
Server-Emitted Events
The following events are broadcast to all connected clients bysio.emit(). Each is emitted from a synchronous callback that safely schedules work onto the running asyncio event loop.
inventory_update
Fired after every successful InventoryEngine.process_event() call. Carries both the raw inventory event and the updated stock state for the affected SKU — the primary event for keeping the frontend product list in sync.
The inventory event that triggered the update.
Full current stock state for the affected SKU.
Example payload
detection_event
Emitted in the same broadcast batch as inventory_update, carrying only the raw InventoryEvent object (no accompanying stock state). Useful for components that maintain an event log independently of per-SKU stock.
An
InventoryEvent object — identical to the event key in inventory_update. See the field listing above.Example payload
alert
Fired only when stock_current crosses below the alert threshold for the first time — i.e., when is_alert transitions from false to true. The payload shape is identical to inventory_update.
alert fires once per threshold crossing. If the SKU is already in an alert state when the next removal arrives, no new alert event is emitted — only inventory_update is sent. This prevents duplicate alert toasts in the UI.The
InventoryEvent that caused the threshold to be crossed. Same fields as in inventory_update.The
ProductStock state immediately after the crossing. is_alert will be true. Same fields as in inventory_update.Example payload
prediction_update
Fired after every inventory event when at least two removal events exist in the SKU’s history, giving the PredictionEngine enough data to compute a meaningful rate. The payload is wrapped in a data envelope.
A
StockPrediction object.Example payload
heatmap_update
Fired after every inventory event. Provides per-slot interaction counts for the default time window returned by HeatmapEngine.get_heatmap(). Use this to keep a live activity heatmap overlay up to date without polling /api/heatmap.
The result of
HeatmapEngine.get_heatmap(). Contains per-slot interaction counts and intensity values for the active time window.Example payload
narrative
Fired when NarrativeEngine.generate() produces a new message, subject to a cooldown of 30 seconds per SKU/message-type combination. This prevents the frontend from being flooded with repeated messages during rapid removal sequences. The payload is wrapped in a data envelope.
A
NarrativeMessage object.Example payload
video_frame
Fired for every camera frame processed by the camera pipeline. Frames are encoded as base64 JPEG strings and emitted at up to 5 FPS (max_fps=5 in stream_loop). Each frame is scaled to 640 px wide (stream_width=640) before encoding to keep bandwidth manageable.
Base64-encoded JPEG image string. Render it by prefixing with the
data:image/jpeg;base64, data URI scheme.Example payload
Full Subscription Example
The following snippet mirrors the logic used in the frontenduseSocket hook and demonstrates subscribing to all server events in a single setup block.