Online
Layers4
Services15+
ModeOffline-first
System Architecture
RAFIQ Architecture
Four-layer distributed architecture: edge sensors, local orchestration, application interfaces, and optional cloud sync. Edge-first design guarantees all safety-critical operations function without cloud or internet connectivity.
System Topology
EDGE LAYERPhysical Sensors & Actuators
⌚ESP32 Wearable
🛡RAQEEB MCU
🔬MQ Gas Sensors
⚡GPIO Relays
🔔Alarm Siren
LOCAL LAYERMiniPC — Ubuntu 22.04 LTS
⚙RAFIQ Core (FastAPI)
💾SQLite + WAL
📡MQTT (Mosquitto)
🧠Ollama AI
🏠Home Assistant
🚨Emergency Engine
🔄Sync Engine
🎙Voice Pipeline
APPLICATION LAYERUser Interfaces
📱Mobile App (Flutter)
🖥Web Dashboard
🤖GUI Avatar
🔊Voice Interface
CLOUD LAYEROptional — Sync & Notifications
☁Supabase PostgreSQL
📨SMS Gateway
🔔Push Notifications
Service Registry
| Service | Layer | Protocol | Port | Owner Service | Critical |
|---|---|---|---|---|---|
| RAFIQ Core | Local | HTTP/WS | 8000 | core-engine | YES |
| MQTT Broker | Local | MQTT | 1883/8883 | mqtt-broker | YES |
| Ollama AI | Local | HTTP | 11434 | ai-orchestrator | No |
| Home Assistant | Local | HTTP/WS | 8123 | ha-bridge | No |
| ESP32 Wearable | Edge | BLE | N/A | ble-gateway | YES |
| Raqeeb MCU | Edge | MQTT | N/A | emergency-engine | YES |
| Supabase | Cloud | HTTPS | 443 | sync-engine | No |
| SMS Gateway | Cloud | HTTPS | 443 | emergency-engine | No |
Communication Matrix
All inter-service communication paths
| From | To | Protocol | Direction | Async |
|---|---|---|---|---|
| ESP32 Wearable | BLE Gateway | BLE 5.0 | Push | Yes |
| BLE Gateway | MQTT Broker | MQTT | Pub | Yes |
| Raqeeb MCU | MQTT Broker | MQTT | Pub | Yes |
| MQTT Broker | Core Engine | MQTT Sub | Push | Yes |
| Core Engine | Ollama AI | HTTP | Req/Resp | Yes |
| Core Engine | Home Assistant | WS/HTTP | Bidirectional | Yes |
| Core Engine | SQLite | SQL | R/W | No |
| Sync Engine | Supabase | HTTPS | Push/Pull | Yes |
| Mobile App | Core Engine | HTTP/WS | Req/Sub | No |
| Emergency Engine | SMS Gateway | HTTPS | Push | Yes |
Edge-First Design Principles
Safety Never Blocks
Emergency shutdown, valve control, and alarm activation happen at the ESP32/edge level with zero dependency on the MiniPC, AI, or cloud.
Local-First Data
All writes persist to SQLite immediately. Cloud sync is a background best-effort operation. The system remains fully functional without any internet.
Fail Gracefully
Each service has a defined fallback: AI fails → rules engine. Cloud fails → offline queue. BLE fails → cached vitals. Failure is expected and handled.