MediWyz — digital health platform connecting patients with providers across Africa (Next.js 15 + NestJS + PostgreSQL)
# MediWyz — Digital Health Platform
A multi-country SaaS platform connecting patients with 17+ provider types across Mauritius, Madagascar, Kenya, Togo, Benin, and Rwanda. Built on **Next.js 15** (frontend) + **NestJS 10** (backend) + **Flutter** (mobile), with a configurable workflow engine, real-time video/chat, insurance SaaS, and an AI health assistant.
---
## Table of Contents
- System Architecture
- Tech Stack
- Repository Structure
- Data Model
- Dynamic Role System
- Workflow Engine
- Insurance SaaS & Money Flow
- Real-time (Socket.IO)
- AI Assistant
- CI/CD Pipeline
- Development Setup
- Environment Variables
- User Types & Demo Accounts
- API Documentation
---
## System Architecture
```mermaid
graph TB
subgraph Clients
WEB["Next.js 15\nBrowser / SSR"]
MOB["Flutter 3\nAndroid & iOS"]
end
subgraph Edge
NGINX["nginx\nReverse Proxy + SSL\nmediwyz.com"]
end
subgraph AppLayer["Application Layer (Docker)"]
NEXT["Next.js 15\nPort 3000\nFrontend only\nProxies /api/* → NestJS"]
NEST["NestJS 10\nPort 3001\nSingle backend API"]
end
subgraph Realtime["Real-time (NestJS port 3001)"]
WS1["WebRtcGateway\nSignaling"]
WS2["ChatGateway\nMessages"]
WS3["NotificationsGateway\nPush events"]
end
subgraph Data
PG["PostgreSQL 16\n50+ tables\nPrisma 6 ORM"]
end
subgraph Registry["Container Registry"]
GHCR["GHCR\
nghcr.io"]
end
WEB -->|HTTPS| NGINX
MOB -->|HTTPS REST| NGINX
MOB -->|WebSocket| NGINX
NGINX -->|:3000| NEXT
NGINX -->|:3001| NEST
NEXT -->|Rewrite /api/*| NEST
NEST --- WS1
NEST --- WS2
NEST --- WS3
NEST -->|Prisma| PG
GHCR -->|docker pull| NEXT
GHCR -->|docker pull| NEST
```
### Key architectural decisions
| Decision | Rationale |
|----------|-----------|
| **NestJS is the ONLY backend** | Next.js is pure frontend. `app/api/` removed. All `/api/*` proxied via `next.config.ts` rewrites |
| **Dynamic roles** | Provider roles (Doctor, Nurse, Optician…) are DB rows in `ProviderRole`, not code enums |
| **Single …