Documentation
RAFIQ Documentation
Comprehensive guides for setting up, deploying, and extending the RAFIQ AI Healthcare OS. Start with Quick Setup if you're new, or jump directly to the API Reference or Architecture guide.
- 01Clone the repogit clone https://github.com/phantoms/rafiq-core
- 02Install dependenciesPython 3.11, Ollama, Mosquitto, SQLite
- 03Configure environmentCopy .env.example, fill in Supabase URL + JWT keys
- 04Run migrationspython -m alembic upgrade head
- 05Start servicessudo systemctl start rafiq.service
- 06Verify healthcurl localhost:8000/api/v1/health
Full Install Script
# RAFIQ quick install (Ubuntu 22.04)
git clone https://github.com/phantoms/rafiq-core
cd rafiq-core
# Install Python 3.11 + dependencies
python3.11 -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt
# Install Ollama + models
curl -fsSL https://ollama.ai/install.sh | sh
ollama pull medgemma:4b
ollama pull qwen2.5:3b
# Install & configure MQTT
sudo apt install -y mosquitto mosquitto-clients
sudo cp config/mosquitto.conf /etc/mosquitto/conf.d/rafiq.conf
# Configure environment
cp .env.example .env && nano .env # Fill in your secrets
# Initialize database & run migrations
python -m alembic upgrade head
# Start all services
sudo systemctl enable --now rafiq.serviceFirst API Call
# Test your first API call
curl http://localhost:8000/api/v1/health
# Expected response
{
"status": "online",
"services": {
"core": "running",
"mqtt": "connected",
"ai": "ready",
"sync": "idle",
"emergency":"armed"
},
"uptime_s": 142,
"version": "2.1.4"
}MQTT Test
# Test MQTT connectivity
mosquitto_pub \
-h localhost \
-t rafiq/wearable/test-device/heartrate \
-m '{"bpm": 72, "device_id": "test-device"}' \
-q 1
# Subscribe to all RAFIQ events
mosquitto_sub -h localhost -t "rafiq/#" -vDocumentation Sections
Setup & Installation
Ubuntu · Python · SQLite · Mosquitto
Complete guide for setting up RAFIQ on a fresh Ubuntu 22.04 MiniPC, including all dependencies, environment, and first-run configuration.
Core Architecture
Services · Threading · Lifecycle
Deep-dive into the FastAPI core, service orchestration model, asyncio threading, and graceful startup/shutdown lifecycle.
API Reference
REST · WebSocket · MQTT
Complete specification for all 12 REST endpoints, 6 WebSocket event types, and the full MQTT topic taxonomy with payload schemas.
Database Guide
SQLite · Supabase · Sync
SQLite schema setup, WAL configuration, Supabase project setup, RLS policies, and sync engine configuration guide.
Deployment Guide
systemd · Docker · Production
Step-by-step production deployment: systemd service files, environment variable management, log rotation, and health monitoring.
Troubleshooting
Logs · Debug · Common Issues
Diagnostic guides for common failure modes: MQTT disconnects, AI timeouts, sync failures, and BLE pairing issues.
Security Hardening
TLS · JWT · Certificates
Production security guide: TLS certificate management, JWT key rotation, MQTT ACL setup, and Supabase RLS policy configuration.
Contributing
Dev setup · Testing · PRs
Guide for contributing to RAFIQ: local development setup, test suite, coding standards, and pull request process.
Changelog
- Sync Engine rewrite — priority scheduler + vector clock conflict resolution
- MedGemma:4b upgrade — improved health analysis accuracy
- Emergency engine failsafe improvements — direct hardware fallback
- BLE gateway stability improvements for ESP32 reconnection
- Full offline support — all core features work without internet
- RAQEEB gas sensor integration — MQ-2/4/7/135 support
- ESP32 wearable BLE stack — GATT profile + fall detection
- Home Assistant bidirectional bridge via WebSocket API
- Supabase sync engine — bidirectional with retry queue
- Home Assistant MQTT bridge — initial integration
- Voice pipeline — Whisper STT + Piper TTS + wake word
- JWT authentication system with refresh tokens