Graduation Project β Mansoura University An AI-powered healthcare ecosystem seamlessly connecting patients, doctors, secretaries, and hospital managers.
medAI is a comprehensive, production-grade medical platform designed to streamline clinical and administrative hospital workflows. The system integrates advanced AI capabilities, including:
- Egyptian Arabic Medical Voice-to-Report Transcription: Tailored pipeline utilizing fine-tuned Whisper and Llama-3 models.
- AI Lab Report Analysis: Document text parsing, OCR, and medical summarization.
- Cross-Platform Mobile App: A dedicated Kotlin Multiplatform (Compose Multiplatform) client targeting Android & iOS for patients and doctors.
- Role-Based Web Dashboard: Dashboards for patients, doctors, secretaries, and managers built with Next.js.hboards.
| Layer | Technology |
|---|---|
| Frontend | Next.js 16 (React 19), Tailwind CSS v4, Radix UI, TanStack Query v5, react-hook-form + Zod v4, framer-motion, date-fns |
| Backend | NestJS 11 (Node.js), TypeScript, TypeORM, PostgreSQL 16 |
| Auth | Passport.js (Local + JWT), Argon2 hashing, httpOnly cookies, email verification |
| Queue | BullMQ v5 (Redis-backed async job processing) |
| File Storage | Azure Blob Storage (avatars, scan images, reports, audio) |
| Brevo SMTP via Nodemailer | |
| AI | Fine-tuned Whisper Large-V3 + Llama-3 8B (4-bit) for Egyptian Arabic medical voice-to-report |
| Mobile | Kotlin Multiplatform (Compose Multiplatform) β Android + iOS |
| Infra | Docker Compose (local/staging/prod), Terraform, GitHub Actions CI/CD |
βββββββββββββββ ββββββββββββββββββββββββββββββββββββββββ βββββββββββββ
β Next.js 16 ββββββΆβ NestJS 11 API ββββββΆβ PostgreSQLβ
β (Frontend) β β βββββββ ββββββββ ββββββββββββββββ β βββββββββββββ
βββββββββββββββ β βAuth β βUsersβ β Patients β β
β βββββββ€ ββββββββ€ ββββββββββββββββ€ β βββββββββββββ
βββββββββββββββ β βDocs β βSched β βAppointments β ββββββΆβ Redis β
β Kotlin App ββββββΆβ βββββββ€ ββββββββ€ ββββββββββββββββ€ β βββββββββββββ
β (Mobile) β β βScansβ βReportβ βVoice Reports β β βββββββββββββ
βββββββββββββββ β βββββββ€ ββββββββ ββββββββββββββββ ββββββΆβAzure Blob β
β βDiagnosis β BullMQ Workers β βββββββββββββ
β β (AI Pipe)β βββββββββββββββββββββββββββββΆβ AI Serverβ
ββββββββββββββββββββββββββββββββββββββββ βββββββββββββ
- Email/password registration with role selection (patient, doctor, secretary, manager)
- JWT authentication (access + refresh tokens as httpOnly cookies, auto-rotation)
- Email verification (token-based, Brevo SMTP)
- Forgot/reset password flow
- Email change with confirmation
- Profile management: name, phone, avatar upload (Azure Blob), bio, gender, birth date
Four roles with separate dashboards and permissions:
| Role | Capabilities |
|---|---|
| Patient | Book appointments, view medical records, upload scans, view diagnoses, track AI reports |
| Doctor | Manage schedules, accept appointments, view patient scans, write diagnoses, record voice reports |
| Secretary | Manage appointments (approve/reject), manage patients & medical records, upload scans, manage doctor schedules & specialities |
| Manager | Approve/reject doctor & secretary registrations, manage all users, view patients |
- Hospital-grade workflow:
pending β confirmed/cancelled β completed - Patients browse doctors by name or speciality
- View real-time available time slots for selected date
- Book an appointment from an available slot
- Secretaries/managers approve or reject pending appointments
- Patients can rate and review completed appointments
- Blacklist support for problematic users
- Schedule Templates: Define recurring weekly patterns (e.g., MonβWed 9:00β17:00)
- Apply Template: Generate concrete date slots from a template for a date range
- Schedule Slots: CRUD for individual date/time slots (e.g., 2026-07-14 09:00β09:30)
- Slots visible to patients for booking
Complete medical history management:
- Allergies (name, description)
- Chronic diseases (name, description, diagnosis date)
- Family history (relation, condition, notes)
- Surgeries (name, date, description)
- Emergency contacts (name, relation, phone, email, address)
- Patient vitals: height, weight, blood type, marital status
- Upload scan images (linked to patient & optional appointment)
- Upload medical reports (PDF/images)
- View scan images directly in browser (served from Azure Blob)
- All files stored securely in Azure Blob Storage
- Role-based access: patients see their own, doctors see assigned patients, secretaries see all
- Upload a medical report (image/PDF)
- Async analysis via BullMQ queue β external AI server
- Poll for analysis status (processing, completed, failed)
- Analysis results stored as JSONB on the report
- Doctors record spoken notes after an appointment
- Audio uploaded β BullMQ job triggers pipeline:
- FFmpeg converts to 16kHz mono WAV
- Uploads to Azure Blob
- Sends to AI server (fine-tuned Whisper Large-V3 + Llama-3 8B)
- Results: transcription + structured clinical JSON
- Supports Egyptian Arabic medical dialect
- Doctors write diagnoses linked to patient & appointment
- Structured fields: symptoms + summary
- Viewable in patient medical records
- Editable (symptoms and full diagnosis)
- Patient Dashboard: Upcoming appointments, book appointment, medical records
- Doctor Dashboard: Appointment list with details, working hours management, availability viewer
- Secretary Dashboard: All appointments overview, doctor & patient management, specialities CRUD
- Manager Dashboard: User approval workflow, patient list, user role management
- Shared Compose UI: Declarative layouts shared between Android and iOS.
- Unified Presentation: Unidirectional MVI architecture using Voyager ScreenModels.
- Native Dictation: Low-latency recording (MPEG-4 AAC) via platform hardware APIs.
- Silent Token Rotation: Ktor client auth interceptor providing automated session refresh.
- Lab Analysis Telemetry: Cold Flow-based background status polling with real-time UI feedback.
- Upload Guards: Client-side multipart upload validation restricted to 10MB limits.
- Custom Design System: Consistent colors, custom forms, and widgets across platform views.
MedAI/
βββ backend/ # NestJS API server
β βββ src/
β β βββ auth/ # Authentication module
β β βββ users/ # User management module
β β βββ patients/ # Patient medical records module
β β βββ doctors/ # Doctor profiles & specialities module
β β βββ schedules/ # Schedule templates & slots module
β β βββ appointments/ # Appointment booking module
β β βββ scans/ # Medical scan & report uploads module
β β βββ diagnosis/ # Doctor diagnosis module
β β βββ voice-reports/ # Voice report + async AI pipeline module
β β βββ report-analysis/ # Lab report AI analysis module
β β βββ mail/ # Brevo SMTP email module
β β βββ database/ # TypeORM config, migrations (25+), seeds
β β βββ shared/ # Shared entities, guards, decorators, services
β βββ tests/ # E2E tests
β βββ docker/ # Dockerfiles (dev, test, prod)
β
βββ frontend-next/ # Next.js 16 frontend
β βββ src/
β β βββ app/
β β β βββ page.js # Landing page
β β β βββ auth/ # Login, signup, forgot-password
β β β βββ (dashboard)/
β β β β βββ patient/ # Patient dashboard pages
β β β β βββ doctor/ # Doctor dashboard pages
β β β β βββ secretary/ # Secretary dashboard pages
β β β β βββ manager/ # Manager dashboard pages
β β β β βββ profile/ # User profile page
β β β βββ reset-password/
β β β βββ download/
β β βββ components/
β β β βββ ui/ # 60+ shadcn-inspired UI components
β β β βββ landing/ # Landing page sections
β β β βββ auth/ # Authentication components
β β β βββ doctor/ # Doctor-related components (18)
β β β βββ patient/ # Patient-related components (25)
β β β βββ secretary/ # Secretary components
β β β βββ manager/ # Manager components
β β β βββ schedule/ # Schedule management components (22)
β β β βββ appointments/ # Appointment components
β β β βββ scans/ # Scan/report components
β β β βββ diagnosis/ # Diagnosis components
β β β βββ voice-reports/ # Voice report components
β β βββ contexts/ # Auth, Sidebar, DoctorInfo contexts
β β βββ hooks/ # Custom React hooks
β β βββ services/ # API client services (server + client)
β β βββ lib/ # Utilities, Zod schemas, API fetch helpers
β βββ public/
β βββ docker/
β
βββ ai/ # AI pipeline (Python)
β βββ egyptian-voice-medical-analyzer/
β βββ Llama3_Egyptian_Medic_Final/ # Fine-tuned model
β βββ models/ # Model weights
β βββ main_test.py # Inference runner
β βββ requirements.txt
β
βββ mobile/ # Mobile Application
β βββ MedAI/ # Kotlin Multiplatform Project
β βββ composeApp/ # Shared Compose UI + platform code
β β βββ src/commonMain/kotlin/org/example/project/
β β βββ core/ # Base MVI framework classes
β β βββ data/ # Remote Ktor client, DTOs & repositories
β β βββ domain/ # Domain models, use cases & native audio contracts
β β βββ presentation/# View layer: screens (Voyager) & viewmodels (MVI)
β β βββ design_system/# Palette, typography, spacing and forms
β βββ iosApp/ # iOS Xcode entry point and app delegate
β
βββ infra/ # Terraform (prod/staging environments)
βββ docker-compose/ # Docker Compose (local/staging/prod)
βββ Makefile # Dev commands
- Docker & Docker Compose (with BuildKit enabled)
- Node.js 22+ (for running migrations/seeders locally)
- pnpm
- Java Development Kit (JDK) 17+ (for compiling the Mobile app)
- Android Studio / Xcode (for Android / iOS simulator builds)
# 1. Clone and enter the repo
git clone <repo-url> && cd MedAI
# 2. Configure environment
cp backend/.env.example backend/.env
# Edit backend/.env with your values (JWT secrets, Azure keys, Brevo SMTP, etc.)
# 3. Start all services
make runThis starts: NestJS API (port 8000), Next.js frontend (port 3000), PostgreSQL (5432), Redis (6379), runs migrations and seeds.
make run # Full local environment
make stop # Stop all containers
make migrate # Run pending TypeORM migrations
make generate-migration MIGRATION_NAME=name # Generate migration from entities
make seed # Run database seeders
make lint # Lint both frontend and backend
make test-backend # Run backend tests with coverage
make format # Format all code with Prettier
make clean-db # Wipe PostgreSQL data volumeKey variables (see backend/.env.example for full list):
| Variable | Description |
|---|---|
JWT_SECRET / REFRESH_TOKEN_SECRET |
Token signing secrets |
BREVO_SMTP_* |
Brevo email credentials (verification, password reset) |
AZURE_STORAGE_CONNECTION_STRING |
Azure Blob Storage (avatars, scans, reports) |
REDIS_HOST / REDIS_PORT |
Redis for BullMQ queues |
AI_SERVER_URL |
AI voice-to-report pipeline endpoint |
LAB_AI_SERVER_URL |
Lab report analysis AI endpoint |
The mobile app codebase is located at mobile/MedAI/.
Create/edit local.properties in mobile/MedAI/ and add the backend base URL:
# Android Emulator loopback pointing to host machine localhost
medai.base_url=http://10.0.2.2:8000/api/
# For iOS Simulator (localhost works directly)
# medai.base_url=http://localhost:8000/api/Ensure you have an Android virtual device running or a physical device connected:
- macOS / Linux:
cd mobile/MedAI ./gradlew :composeApp:installDebug - Windows:
cd mobile\MedAI .\gradlew.bat :composeApp:installDebug
Open the Xcode workspace inside mobile/MedAI/iosApp:
cd mobile/MedAI/iosApp
open iosApp.xcodeprojSelect your target simulator (e.g. iPhone 15) and click Run (Cmd + R) inside Xcode.
The NestJS backend exposes a REST API at /api/*. Full Swagger documentation is available at /api/docs when the server is running.
Auth: POST /api/auth/login, POST /api/auth/refresh-token, POST /api/auth/forgot-password, POST /api/auth/reset-password, POST /api/auth/change-email
Users: POST /api/users (register), GET /api/users/me, PATCH /api/users/:id, POST /api/users/:id/avatar
Patients: GET /api/patients, GET /api/patients/:id, CRUD for allergies, chronic diseases, family history, surgeries, emergency contacts
Doctors: GET /api/doctors, POST /api/doctors/search/speciality, POST /api/doctors/search/name, GET /api/doctors/top-rated, CRUD specialities
Schedules: CRUD schedule-templates, schedule-slots, POST apply-template (per doctor)
Appointments: POST /api/appointments, GET /api/appointments/me, PATCH /api/appointments/:id/status, PATCH /api/appointments/:id/review
Voice Reports: POST /api/appointments/:id/voice-reports, GET /api/appointments/:id/voice-reports/:reportId
Scans & Reports: POST /api/scans/:id, POST /api/scans/:id/:scanId/reports, GET /api/scans/images/:id/:imageId/file
Diagnoses: POST /api/diagnosis/:id, PATCH /api/diagnosis/:id/:diagnosisId
- Doctor records audio on the frontend
- Audio uploaded to backend β stored in Azure Blob β BullMQ job queued
- FFmpeg converts to 16kHz mono WAV
- Sent to AI server running fine-tuned Whisper Large-V3 (Egyptian Arabic STT)
- Transcription fed into fine-tuned Llama-3 8B (4-bit quantized) for medical NLU
- Structured clinical JSON returned and stored
- Secretary uploads report (image/PDF) for a patient
- BullMQ job triggers analysis on
LAB_AI_SERVER_URL - Frontend polls for status until complete
# Backend unit + integration tests
make test-backend
# E2E tests
pnpm --prefix backend run test:e2e
# Linting
make lint
# Run Mobile KMP shared tests
cd mobile/MedAI
./gradlew :composeApp:testDebugUnitTestThree Docker Compose environments:
| File | Purpose |
|---|---|
docker-compose/local.yaml |
Local development (hot-reload, debug) |
docker-compose/staging.yaml |
Staging environment |
docker-compose/prod.yaml |
Production (standalone Next.js build) |
Terraform configurations under infra/ for cloud infrastructure provisioning.