MediLink is a modern, scalable, containerized SaaS platform engineered for clinical workflows, multi-role hospital management (Patients, Doctors, Administrators), electronic health records (EHR), scheduling, and billing.
- Multi-Role Access Control (RBAC):
- Patients: Book doctor appointments, view diagnosis history, access prescriptions, and process full/partial medical payments.
- Doctors: Manage clinical appointments, record diagnoses, issue prescriptions, and view assigned patient charts.
- Hospital Admins: Monitor platform revenue, oversee appointment metrics, approve insurance claims, and audit platform activity.
- Enterprise Performance & Query Optimization:
- Zero N+1 Query Overhead: All DRF ViewSets utilize explicit
select_related()andprefetch_related()joins. - Double-Booking Prevention: Transactional slot locking prevents overlapping doctor schedules.
- Invoice & Partial Payment Tracking: Supports itemized billing, auto-calculated tax/discounts, instant PDF invoice generation, and status sync (
pending,partially_paid,paid).
- Zero N+1 Query Overhead: All DRF ViewSets utilize explicit
- Asynchronous Task Processing:
- Celery + Redis: Background worker handles automated appointment reminders and hourly overdue invoice reconciliation.
- Production Containerization:
- Docker Compose: Orchestrates 6 micro-services (Postgres, Redis, Django API, Celery Worker, Celery Beat, and React Nginx SPA).
Agents run on the Claude API (default model claude-opus-5-5, configurable with AI_MODEL) with a manual tool-use loop. Three rules apply to all of them:
- RBAC on every tool. Each agent only sees its user's tools, and every tool re-uses the same data scoping as the REST API.
- Human in the loop. Tools that change data (book, cancel, invoice, message) only propose an action card. Nothing is written until a person clicks Approve, and everything is re-validated at that point.
- Audit log. Every tool call is recorded (
AgentToolCall) and visible in AI Operations.
| Agent | Who | What it does |
|---|---|---|
| Booking assistant | Patient | "Chest discomfort, cardiologist next week, mornings" → picks the specialty, finds doctors, checks real free slots, proposes a booking for approval. Also explains the patient's own records and bills. |
| Emergency guardrail | Patient | Deterministic detection (chest pain + breathlessness, stroke signs, self-harm…) that never calls the model and always tells the patient to call emergency services. |
| Prescription safety agent | Doctor | Deterministic engine: allergy cross-reactivity (incl. brand names), drug–drug interactions, duplicate therapy, condition contraindications, age cautions, dose ceilings. Runs before saving (blocking modal) and after (persisted alerts that need acknowledgement, with a mandatory note for critical alerts). |
| Pre-visit brief | Doctor | One-screen summary of history, meds, vitals trends and pending labs, with computed red flags. Pre-generated hourly by Celery for visits in the next 36 hours. |
| Clinical copilot chat | Doctor | Patient-history Q&A and medication checks, limited to patients the doctor actually treats. |
| Lab result explainer | Patient + Doctor | Flags out-of-range analytes, writes a plain-language, non-diagnostic explanation, notifies the patient, and alerts the doctor on abnormal results. |
| Operations analyst | Admin | Natural-language analytics (revenue, no-shows, appointments, outstanding balances) over parameterised ORM tools (no free-form SQL), rendered as charts in the chat. |
| Billing / claims agent | Admin | Insurance claim pre-check (policy mismatch, missing diagnosis, duplicates, late filing → risk score), invoice drafting from completed visits, patient outreach drafts. |
| Collections agent | Celery (daily) | Overdue invoices: gentle reminder → payment-plan offer → escalation to admins. Idempotent and audited. |
| Care follow-up agent | Celery (daily) | Nudges chronic-condition patients with no recent visit, and patients with abnormal labs and no follow-up booked. |
No API key? It still works. Without ANTHROPIC_API_KEY the app runs in rules-only mode. The safety engine, briefs, lab flags, claim checks and proactive agents are deterministic, and the chat answers common requests with the same audited tools. Server-side refusal fallback (fallbacks: "default") is enabled on every Claude call.
Browser: patients · doctors · admins
│ HTTPS
▼
Ingress: ingress-nginx (kind) · Traefik + TLS (k3s) [Compose: port 3000]
│
▼
React 18 SPA on nginx: serves the app, proxies /api /admin /swagger
│ /api
▼
Django REST API (gunicorn) ───── agent chat, tool use ─────► Claude API
│ │ ▲
│ SQL │ enqueue │
▼ ▼ │
PostgreSQL 15 Redis 7 ◄─── schedule ─── Celery beat │
▲ │ │
│ ORM │ consume │
│ ▼ │
└────────── Celery worker ── briefs · labs · agents ───────┘
- One origin. nginx serves the SPA and proxies the API, so the HttpOnly JWT cookies and CSRF work without any cross-site setup. It resolves the backend per request, so a DNS hiccup or a backend restart returns a brief 502 instead of crash-looping the frontend.
- Background work. Model saves (lab results, near-term appointments) and the beat schedule (hourly: overdue invoices, reminders, pre-visit briefs; daily: collections, care follow-ups) enqueue Celery tasks on Redis.
- Interactive diagram with guided views and links to the source of each component:
docs/architecture/medilink-architecture.html(open it in a browser; it is rendered frommedilink.architecture.json).
Ensure Docker Desktop is running, then run:
# Start all 6 services (Database, Redis, API, Worker, Beat, Frontend)
docker compose up --build -dPopulate the database with pre-configured Doctors, Patients, Appointments, Medical Records, and Billing:
docker compose exec backend python manage.py seed_demo_data- 🌐 Web Application: http://localhost:3000
- 🔌 REST API & Swagger Docs: http://localhost:8000/api/ · http://localhost:3000/swagger/
- ⚙️ Django Admin Portal: http://localhost:3000/admin/
To enable the Claude-powered agents, set ANTHROPIC_API_KEY (e.g. in a .env file next to docker-compose.yml) before docker compose up.
Kustomize manifests for a local kind cluster and for a free, always-on k3s cluster on Oracle Cloud's Always Free tier (HTTPS via Let's Encrypt, multi-arch images built by GitHub Actions) live in deploy/k8s. Step-by-step guide: DEPLOYMENT.md.
On the local kind cluster the app is served at http://medilink.localtest.me:8080 (localtest.me always resolves to 127.0.0.1).
Locust scenarios replay the API calls the frontend makes for each role: 6 patients : 3 doctors : 1 admin, about 34 reads per write and one request per second per user, including the row-locked book-and-cancel path. Claude-backed endpoints are left out (paid and throttled).
# Quick run against Docker Compose
cd loadtest && locust --headless -u 50 -r 5 -t 3m --html reports/run.html
# Capacity test inside Kubernetes: distributed Locust in its own namespace, traffic
# through the ingress, stepping toward 100,000 users and stopping at the first
# saturated step (>5% failures or p95 > 5 s)
cd loadtest && ./k8s/run.shMeasured so far on a 12-core laptop (app and load generator share the machine):
| Setup | Users | Requests/s | Failures | p50 | p95 | p99 |
|---|---|---|---|---|---|---|
| Docker Compose | 50 | 42 | 0.01% | 34 ms | 85 ms | 160 ms |
| kind, 1 backend pod | 40 | 39 | 0% | 28 ms | 72 ms | 120 ms |
| kind, 1 backend pod, ramp to 100 | ≤100 | 84 | 0% | 34 ms | 130 ms | 250 ms |
The full stepped run, which finds where one backend pod saturates, is the next measurement. Guide, settings and cleanup of test bookings: loadtest/README.md.
Use these credentials to seamlessly demonstrate different user perspectives in interviews:
| Role | Username | Password | Key Responsibilities |
|---|---|---|---|
| Hospital Admin | admin |
AdminPassword123! |
System statistics, revenue metrics, insurance claim approvals |
| Cardiologist | doctor_sarah |
DoctorPassword123! |
Patient chart review, clinical record creation, appointments |
| Pediatrician | doctor_james |
DoctorPassword123! |
Availability schedules, prescription management |
| Patient 1 | patient_john |
PatientPassword123! |
Active hypertension record, partial invoice payment |
| Patient 2 | patient_emma |
PatientPassword123! |
Paid invoices, upcoming scheduled appointments |
| Service | Technology | Port | Description |
|---|---|---|---|
db |
PostgreSQL 15 | 5432 |
Relational storage with persistent volume & health check |
redis |
Redis 7 Alpine | 6379 |
Fast in-memory cache & Celery task queue broker |
backend |
Django 4.2 + Gunicorn | 8000 |
REST API with automated migrations on boot |
celery-worker |
Celery 5.3 | Internal | Background tasks: reminders, lab explanations, pre-visit briefs |
celery-beat |
Celery Beat | Internal | Scheduled agents: invoice reconciler, reminders, briefs, collections, care follow-ups |
frontend |
React 18 + Nginx (unprivileged) | 3000 |
SPA + reverse proxy for /api/, /admin/, /django-static/ |
cd backend
python -m venv venv
venv\Scripts\activate # Windows (or source venv/bin/activate on Linux/Mac)
pip install -r requirements.txt
python manage.py migrate
python manage.py seed_demo_data
python manage.py runserver
python manage.py test # 45 tests: RBAC, billing, auth cookies, agents, safety enginecd frontend
npm install --legacy-peer-deps
npm start- Privilege Escalation Prevention: Public registration strictly denies unauthorized
adminrole elevation. - Password Validation: Enforces complexity checks and confirmation checks across frontend and backend.
- Robust DRF Permissions: Custom permission classes verify authentication state before inspecting user attributes, preventing
AnonymousUsercrashes. - CORS Hardening: Configurable origin whitelists preventing cross-origin resource exploitation.
- Cookie JWT + CSRF: HttpOnly access/refresh cookies with real refresh-token rotation and blacklisting on logout. CSRF is enforced on every cookie-authenticated request.
- Least-privilege data access: Users only see patients/users they have a relationship with. Payments, claims decisions and invoice edits are admin-only, and payments are locked per invoice to prevent overpayment races.
- Hardened containers: Non-root images, read-only root filesystems, restricted Pod Security Standard, and NetworkPolicies isolating Postgres and Redis.