The semáforo (traffic light) is FridgeRadar’s freshness classification engine. It assigns one of four colour-coded states to every inventory item based on how many days remain until its expiry date. Just like a real traffic light the colours have an intuitive meaning: green means all clear, yellow means pay attention, red means act now, and a special fourth state marks items that have already passed their best-before date. The semáforo state of an item is stored asDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/EstefanoARG/FridgeRadar/llms.txt
Use this file to discover all available pages before exploring further.
estado_caducidad on every InventarioResponse and drives both the UI colour coding and the Tengo Hambre recipe suggestion engine.
The Four States
| State | Value | Condition | Meaning |
|---|---|---|---|
| 🟢 Verde | "verde" | More than 7 days remaining, or no expiry date set | Item is fresh — no action needed |
| 🟡 Amarillo | "amarillo" | 3 to 7 days remaining (dias >= 3) | Use soon — approaching expiry |
| 🔴 Rojo | "rojo" | 0 to 2 days remaining (dias >= 0) | Use immediately — expires very soon |
| ⚫ Vencido | "vencido" | Past the expiry date (dias < 0) | Item is expired |
When
fecha_vencimiento is null — meaning no expiry date has been recorded — the item is always classified as "verde". FridgeRadar will never flag an item as expiring unless you have explicitly set a date.Source: calcular_estado()
The classification logic lives in app/utils/semaforo.py. The complete function is reproduced below exactly as it appears in the codebase:
es_critico() is used by the recipe engine to decide whether an item should count as a near-expiry ingredient:
dias_restantes() exposes the raw day count for display purposes:
Threshold Reference
| Threshold constant | Default value | Condition in calcular_estado |
|---|---|---|
SEMAFORO_AMARILLO_DIAS | 7 | dias > 7 → verde; dias >= 3 → amarillo |
SEMAFORO_ROJO_DIAS | 3 | dias >= 3 → amarillo; dias >= 0 → rojo |
Both thresholds are configurable via your
.env file using the SEMAFORO_AMARILLO_DIAS and SEMAFORO_ROJO_DIAS environment variables. Adjusting them lets households set tighter or looser freshness windows without touching application code.Automated Recalculation
States are not recalculated on every request. Instead, FridgeRadar uses APScheduler to run two background tasks each day:| Time | Task |
|---|---|
| 00:05 (midnight + 5 min) | Recalculates estado_caducidad for every inventory item across all households |
| 08:00 AM | Reads the freshly computed states and dispatches in-app alerts for "amarillo" and "rojo" items |
Manual Recalculation API
You can trigger a recalculation on demand without waiting for the scheduled job:Filtering Inventory by State
Becauseestado_caducidad is stored on each inventory record, you can query items at a specific freshness level directly from the inventory endpoint:
estado values: verde, amarillo, rojo, vencido.
How es_critico Drives Recipe Suggestions
The Tengo Hambre engine uses es_critico() to filter the pantry before matching ingredients to recipes. When solo_criticos: true (the default), only items in "amarillo" or "rojo" states are considered as available ingredients. This ensures recipe suggestions are optimised for reducing food waste rather than just maximising what you can cook.