Online
System Architecturev2.1
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

ServiceLayerProtocolPortOwner ServiceCritical
RAFIQ CoreLocalHTTP/WS8000core-engineYES
MQTT BrokerLocalMQTT1883/8883mqtt-brokerYES
Ollama AILocalHTTP11434ai-orchestratorNo
Home AssistantLocalHTTP/WS8123ha-bridgeNo
ESP32 WearableEdgeBLEN/Able-gatewayYES
Raqeeb MCUEdgeMQTTN/Aemergency-engineYES
SupabaseCloudHTTPS443sync-engineNo
SMS GatewayCloudHTTPS443emergency-engineNo

Communication Matrix

All inter-service communication paths

FromToProtocolDirectionAsync
ESP32 WearableBLE GatewayBLE 5.0PushYes
BLE GatewayMQTT BrokerMQTTPubYes
Raqeeb MCUMQTT BrokerMQTTPubYes
MQTT BrokerCore EngineMQTT SubPushYes
Core EngineOllama AIHTTPReq/RespYes
Core EngineHome AssistantWS/HTTPBidirectionalYes
Core EngineSQLiteSQLR/WNo
Sync EngineSupabaseHTTPSPush/PullYes
Mobile AppCore EngineHTTP/WSReq/SubNo
Emergency EngineSMS GatewayHTTPSPushYes
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.