# Architettura realtime (WebSocket + polling)

## Requisiti supportati
- channel separati
- namespace/eventi separati
- multi-app coexistence su server condiviso

## Envelope evento consigliata
```json
{
  "app_id": "sporthub",
  "namespace": "sporthub",
  "channel": "channel_booking",
  "event": "booking.created",
  "center_id": 1,
  "payload": {"booking_id": 1001}
}
```

## Channel strategy
- `channel_booking`: eventi prenotazioni (`booking.created`, `booking.updated`, `booking.cancelled`)
- `channel_admin`: KPI e stato operativo
- `channel_notifications`: toast/in-app notifications
- `channel_live_updates`: aggiornamenti dashboard/calendario

## Fallback polling
- endpoint: `GET /api/events/poll?center_id={id}&since_id={lastId}`
- intervallo default: `8000ms`
- payload da tabella `event_outbox`
- ripristino automatico a WebSocket quando disponibile

## Multi-app coexistence
- ogni evento include `app_id`
- client filtra su `app_id === sporthub`
- channel naming con prefisso progetto se necessario (`sporthub.channel_booking`)
