# 🩺 RPM Morocco — B2B Health-Tech Remote Patient Monitoring Platform
Production-ready, full-stack B2B Remote Patient Monitoring (RPM) platform engineered for clinic chains and hospital networks in Morocco.
---
## 🏗️ 1. Architecture & Tech Stack Selection
| Component | Technology | Rationale & Selection Criteria |
| :--- | :--- | :--- |
| **Frontend** | **React 18 + Vite + TypeScript + Tailwind v4 + Radix UI** | Rebuilt directly from the Figma design bundle with zero visual loss, ultra-fast HMR, lightweight asset bundle suitable for clinical networks. |
| **Backend API** | **Node.js + Express + TypeScript** | Standard, battle-tested REST & Server-Sent Events (SSE) streaming API sharing TypeScript types with the frontend. |
| **Database** | **PostgreSQL + Prisma ORM** *(Zero-config SQLite fallback for local dev)* | Strict ACID compliance, relational integrity (Patients ↔ Staff ↔ Vitals ↔ Records ↔ Appointments), and GPS spatial capabilities. |
| **Authentication** | **JWT with HttpOnly / Secure / SameSite Cookies + bcrypt** | Implements Role-Based Access Control (RBAC) across 5 clinical roles (`admin`, `cardiologist`, `physician`, `nurse`, `technician`, `patient`). |
| **Hosting** | **Google Cloud Run / Render / Vercel / Railway** | Containerized serverless execution with auto-scaling, zero idle cost, and automatic SSL. |
---
## 📊 2. Entity-Relationship & Data Model Overview
```
[User] (id, email, passwordHash, role, clinic, patientId)
│
â–Ľ 1:1
[Patient] (id, name, age, condition, ward, spo2, hr, bpSys, bpDia, alert, thresholdSpo2, thresholdHrHigh)
├──► 1:N [VitalLog] (id, patientId, timestamp, spo2, hr, bpSys, bpDia, riskLevel)
├──► 1:N [Appointment] (id, patientId, doctorId, type, date, time, duration, status)
├──► 1:1 [MedRecord] (patientId, bloodType, allergies, emergencyContact, gpsLat, gpsLng)
│ ├──► 1:N [Medication] (id, name, dose, freq, indication)
│ ├──► 1:N [ClinicalNote] (id, author, role, date, text, tags)
│ └──► 1:N [ChatMes …