Online
Documentationv2.1
Guides8
API Endpoints12+
Code Examples30+

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.

Quick StartGet RAFIQ running in 10 minutes
  1. 01
    Clone the repo
    git clone https://github.com/phantoms/rafiq-core
  2. 02
    Install dependencies
    Python 3.11, Ollama, Mosquitto, SQLite
  3. 03
    Configure environment
    Copy .env.example, fill in Supabase URL + JWT keys
  4. 04
    Run migrations
    python -m alembic upgrade head
  5. 05
    Start services
    sudo systemctl start rafiq.service
  6. 06
    Verify health
    curl localhost:8000/api/v1/health

Full Install Script

install.sh
bash
# 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.service

First API Call

test_api.sh
bash
# 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.sh
bash
# 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/#" -v

Documentation 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.

Ubuntu 22.04Python 3.11Ollama

Core Architecture

Services · Threading · Lifecycle

Deep-dive into the FastAPI core, service orchestration model, asyncio threading, and graceful startup/shutdown lifecycle.

FastAPIasynciosystemd

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.

OpenAPISwaggerMQTT

Database Guide

SQLite · Supabase · Sync

SQLite schema setup, WAL configuration, Supabase project setup, RLS policies, and sync engine configuration guide.

SQLiteSupabaseAlembic

Deployment Guide

systemd · Docker · Production

Step-by-step production deployment: systemd service files, environment variable management, log rotation, and health monitoring.

systemdlogrotatemonit

Troubleshooting

Logs · Debug · Common Issues

Diagnostic guides for common failure modes: MQTT disconnects, AI timeouts, sync failures, and BLE pairing issues.

journalctlMQTT debugstrace

Security Hardening

TLS · JWT · Certificates

Production security guide: TLS certificate management, JWT key rotation, MQTT ACL setup, and Supabase RLS policy configuration.

OpenSSLLet's EncryptACL

Contributing

Dev setup · Testing · PRs

Guide for contributing to RAFIQ: local development setup, test suite, coding standards, and pull request process.

pytestmypypre-commit

Changelog

v2.1.02024-11-01LATEST
  • 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
v2.0.02024-09-15
  • 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
v1.5.02024-07-22
  • 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