Documentation 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.
backend/contracts.py centralizes every inter-module data type used across the Anaquel Inteligente 3B pipeline — from YOLOv8 detections (M2) through inventory tracking (M3), predictions (M6), heatmaps (M7), and narrative generation (M8). frontend/src/types/index.ts mirrors the key types in TypeScript so the React dashboard stays in sync with the backend contracts without a shared code-gen step.
Python Dataclasses (contracts.py)
EventType
An Enum that identifies the direction of a stock movement. Used as the event_type field on DetectionEvent.
Value:
"retiro". A product was removed from the shelf by a customer.Value:
"devolucion". A product was returned to the shelf.DetectionEvent
Contract C2 — produced by the Detection Engine (M2) and consumed by the Inventory Engine (M3). Carries the raw vision data for a single stock-movement event detected by YOLOv8.
UUID string uniquely identifying this detection event.
EventType.RETIRO or EventType.DEVOLUCION.Machine-readable product identifier, e.g.
"nachos_naturasol".Human-readable product name, e.g.
"Nachos Con Sal Naturasol 200gr".Shelf slot number where the detection occurred.
YOLOv8 detection confidence in the range
[0.0, 1.0].Python
datetime object representing when the event was detected.Bounding box in pixel coordinates:
(x1, y1, x2, y2).Detected item count in the slot before the event.
Detected item count in the slot after the event.
SlotDetection
Contract C3 (internal to M2) — represents a single slot’s detection result within a DetectionResult. Carries enriched context including a stock-level classification.
Machine-readable product identifier.
Human-readable product name.
Shelf slot number.
Bounding box:
(x1, y1, x2, y2).Detection confidence in
[0.0, 1.0].Number of product units detected in the slot.
Categorical stock status:
"ok" | "warning" | "critical".DetectionResult
Contract C3 — the complete output of one inference pass by the Detection Engine (M2). Aggregates all SlotDetection objects produced from a single camera frame.
Unix timestamp (seconds since epoch) when the frame was processed.
Mapping of
sku_id → detected count across all slots in the frame.List of per-slot detection results. Defaults to an empty list.
AnnotatedFrame
Contract C3 (internal to M2) — pairs a raw video frame with its detection results. Used internally by the camera pipeline and video overlay (VideoOverlay) to render bounding-box annotations before encoding the frame for broadcast. This type is not transmitted over the WebSocket or REST API — it exists only within the M2 camera-processing thread.
Raw BGR image array as returned by OpenCV. Not JSON-serializable; used only in-process.
Unix timestamp (seconds since epoch) when the frame was captured.
The
SlotDetection results associated with this frame.ProductStock
Contract C5 — the authoritative stock state for a single SKU as maintained by the Inventory Engine (M3). Broadcast on every inventory_update and alert WebSocket event.
Machine-readable product identifier.
Human-readable product name.
Shelf slot number.
Stock count at session start (used to compute fill rate).
Current stock count.
Fractional alert threshold. An alert fires when
stock_current / stock_initial drops below this value (e.g. 0.2 = 20%).True if the SKU is currently at or below the alert threshold.Datetime of the most recent event affecting this SKU, or
None if no event has occurred.InventoryState
Contract C5 — a snapshot of the full shelf inventory at a given point in time, returned by GET /api/inventory.
Datetime when the inventory state was last modified.
List of
ProductStock objects for every registered SKU.InventoryEvent
Contract C5 — the processed, inventory-level record of a stock movement. Produced by InventoryEngine.process_event() from a DetectionEvent and emitted on inventory_update and detection_event WebSocket events.
InventoryEvent is distinct from DetectionEvent. DetectionEvent carries raw vision data (bbox, count_before, count_after), while InventoryEvent carries inventory-level data (stock_before, stock_after) in terms that the dashboard and engines consume.UUID string uniquely identifying this inventory event.
"retiro" or "devolucion" as a plain string (not the EventType enum).Machine-readable product identifier.
Human-readable product name.
Shelf slot number.
Inventory stock count before this event was applied.
Inventory stock count after this event was applied.
Detection confidence forwarded from the originating
DetectionEvent.Datetime when the event was processed.
SKUHistory
Contract C6 — aggregated removal history for a single SKU, passed from the Inventory Engine (M3) to the Prediction Engine (M6) to compute depletion rates.
Machine-readable product identifier.
Human-readable product name.
Current stock count at the time this history snapshot was taken.
Initial stock count (used to compute remaining capacity).
Ordered list of
datetime timestamps for every removal event recorded for this SKU. The Prediction Engine requires at least 2 entries to calculate a rate.StockPrediction
Contract C6 — depletion forecast produced by the Prediction Engine (M6) from a SKUHistory. Broadcast on the prediction_update WebSocket event and served by GET /api/predictions.
Machine-readable product identifier.
Human-readable product name.
Stock count at prediction time.
Exponentially weighted moving average of removal rate in units per hour (
alpha=0.3).Predicted datetime when stock reaches zero, or
None if the rate is zero or indeterminate.Minutes until predicted depletion, or
None.Acceleration of demand:
"acelerando" | "estable" | "desacelerando".Prediction confidence based on sample size:
"alta" | "media" | "baja".InteractionEvent
Contract C4 — represents a physical interaction with a shelf slot, used by the Heatmap Engine (M7) to build activity maps. Currently emitted with region=(0, 0, 0, 0) pending full M2 bounding-box integration.
Shelf slot where the interaction occurred.
Product involved in the interaction.
Pixel region of the interaction:
(x1, y1, x2, y2).Datetime of the interaction.
"hand_detected" | "product_moved".NarrativeMessage
Contract C7 — a human-readable Spanish message produced by the Narrative Engine (M8) and delivered to the frontend via the narrative WebSocket event. Subject to a 30-second cooldown per SKU/message-type pair.
UUID string uniquely identifying this message.
"info" | "warning" | "critical".Human-readable Spanish message, e.g.
"⚠️ Nachos Con Sal Naturasol 200gr está al 50% de su capacidad.".Related SKU, or
None for store-wide messages.Datetime when the message was generated.
Emoji icon matching the severity level, e.g.
"⚠️", "🚨", "ℹ️".TypeScript Interfaces (frontend/src/types/index.ts)
The frontend mirrors the key backend contracts as TypeScript interfaces. Note that datetime fields become string (ISO 8601) and some interfaces include additional frontend-only fields (e.g. source_id, alert_level) used by the dashboard’s multi-camera adapter layer.
Contract Map
The table below shows which contract is consumed by which engine module.| Contract | Dataclass(es) | Producer | Consumer(s) |
|---|---|---|---|
| C2 | DetectionEvent, EventType | M2 | M3 |
| C3 | SlotDetection, DetectionResult, AnnotatedFrame | M2 | M2 (internal) |
| C4 | InteractionEvent | M3 | M7 |
| C5 | ProductStock, InventoryState, InventoryEvent | M3 | M4, WebSocket, REST |
| C6 | SKUHistory, StockPrediction | M3 | M6 |
| C7 | NarrativeMessage | M8 | M4, WebSocket |