# aryan22n/pharmabrain- architecture

> Architecture diagram of the GitHub repository aryan22n/pharmabrain-, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/aryan22n/pharmabrain-
- Repository: https://github.com/aryan22n/pharmabrain-

## Overview

Single-Hospital-Pro is a patient-and-clinician medical-record application centered on turning prescription images into clinician-reviewed structured records. The main workflow runs from image upload through OCR and Gemini-assisted structuring to draft review, correction, and confirmation; the product also supports patient history, timelines, trends, and clinician access workflows. The graph combines sampled source with README-documented capabilities and integrations; links not established by those excerpts or documentation are omitted.

Main entry points: [`model/final_prescription_ocr_service_windows.py`](https://github.com/aryan22n/pharmabrain-/blob/main/model/final_prescription_ocr_service_windows.py) (OCR and extraction service), [`frontend/app/upload/page.tsx`](https://github.com/aryan22n/pharmabrain-/blob/main/frontend/app/upload/page.tsx) (Prescription upload), [`frontend/app/extractions/[id]/page.tsx`](https://github.com/aryan22n/pharmabrain-/blob/main/frontend/app/extractions/%5Bid%5D/page.tsx) (Extraction review), [`frontend/app/api/confirm/[id]/route.ts`](https://github.com/aryan22n/pharmabrain-/blob/main/frontend/app/api/confirm/%5Bid%5D/route.ts) (Confirm or discard)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web experience"]
  node_webapp["Patient and clinician UI"]
  node_auth["Accounts and sessions<br/>[auth.ts]"]
  node_authforms["Role-based sign-in<br/>[AuthForm.tsx]"]
  node_upload["Prescription upload<br/>[page.tsx]"]
  node_ocrroute["OCR API route<br/>[route.ts]"]
  node_review["Extraction review<br/>[page.tsx]"]
  node_medicineeditor["Medicine editor<br/>[MedicineEditor.tsx]"]
  node_statusbadge["Review status badges<br/>[StatusBadge.tsx]"]
  node_confirm["Confirm or discard<br/>[route.ts]"]
end

subgraph group_clinical["Clinical records"]
  node_recordviews["Patient record views"]
  node_timeline["Medical timeline<br/>[page.tsx]"]
  node_trends["Vitals and trends<br/>[route.ts]"]
  node_sharing["Patient access sharing<br/>[route.ts]"]
  node_medication["Medication lifecycle"]
end

subgraph group_processing["Prescription processing"]
  node_ocrservice["OCR and extraction service"]
  node_medicineimport["Medicine master import"]
end

subgraph group_services["Storage and services"]
  node_database[("Shared application database")]
  node_storageclient["Image storage integration<br/>[supabaseStorage.ts]"]
  node_supabase[("Supabase Storage")]
  node_paddle["PaddleOCR"]
  node_gemini["Google Gemini"]
end

node_patient(("Patient"))
node_clinician(("Clinician"))

node_patient -->|"uses"| node_webapp
node_clinician -->|"uses"| node_webapp
node_webapp -->|"presents"| node_authforms
node_authforms -->|"authenticates"| node_auth
node_patient -->|"submits image"| node_upload
node_clinician -->|"submits image"| node_upload
node_upload -->|"sends image"| node_ocrroute
node_ocrroute -->|"calls over HTTP"| node_ocrservice
node_ocrservice -->|"extracts text"| node_paddle
node_ocrservice -->|"structures draft"| node_gemini
node_ocrservice -->|"stores records"| node_database
node_ocrservice -->|"returns draft"| node_review
node_review -->|"renders fields"| node_medicineeditor
node_medicineeditor -->|"renders badges"| node_statusbadge
node_clinician -->|"reviews draft"| node_review
node_review -->|"submits corrections"| node_confirm
node_confirm -->|"confirms record"| node_database
node_confirm -.->|"updates medication"| node_medication
node_upload -->|"stores image"| node_storageclient
node_storageclient -->|"uploads image"| node_supabase
node_patient -->|"views records"| node_recordviews
node_recordviews -->|"reads records"| node_database
node_patient -->|"views history"| node_timeline
node_timeline -->|"reads history"| node_database
node_patient -->|"views trends"| node_trends
node_trends -->|"reads observations"| node_database
node_clinician -->|"requests access"| node_sharing
node_sharing -.->|"records requests"| node_database
node_medicineimport -->|"imports medicines"| node_database

click node_webapp "https://github.com/aryan22n/pharmabrain-/tree/main/frontend/app"
click node_auth "https://github.com/aryan22n/pharmabrain-/blob/main/frontend/lib/auth.ts"
click node_authforms "https://github.com/aryan22n/pharmabrain-/blob/main/frontend/components/auth/AuthForm.tsx"
click node_upload "https://github.com/aryan22n/pharmabrain-/blob/main/frontend/app/upload/page.tsx"
click node_ocrroute "https://github.com/aryan22n/pharmabrain-/blob/main/frontend/app/api/ocr/route.ts"
click node_review "https://github.com/aryan22n/pharmabrain-/blob/main/frontend/app/extractions/%5Bid%5D/page.tsx"
click node_medicineeditor "https://github.com/aryan22n/pharmabrain-/blob/main/frontend/components/MedicineEditor.tsx"
click node_statusbadge "https://github.com/aryan22n/pharmabrain-/blob/main/frontend/components/StatusBadge.tsx"
click node_confirm "https://github.com/aryan22n/pharmabrain-/blob/main/frontend/app/api/confirm/%5Bid%5D/route.ts"
click node_recordviews "https://github.com/aryan22n/pharmabrain-/tree/main/frontend/app/patient"
click node_timeline "https://github.com/aryan22n/pharmabrain-/blob/main/frontend/app/patient/timeline/page.tsx"
click node_trends "https://github.com/aryan22n/pharmabrain-/blob/main/frontend/app/api/patient/trends/route.ts"
click node_sharing "https://github.com/aryan22n/pharmabrain-/blob/main/frontend/app/api/doctor/access-requests/route.ts"
click node_medication "https://github.com/aryan22n/pharmabrain-/blob/main/frontend/lib/medicationLifecycle.ts"
click node_ocrservice "https://github.com/aryan22n/pharmabrain-/blob/main/model/final_prescription_ocr_service_windows.py"
click node_medicineimport "https://github.com/aryan22n/pharmabrain-/blob/main/model/import_medicines_bulk.py"
click node_storageclient "https://github.com/aryan22n/pharmabrain-/blob/main/frontend/lib/supabaseStorage.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_webapp,node_auth,node_authforms,node_upload,node_ocrroute,node_review,node_medicineeditor,node_statusbadge,node_confirm toneBlue
class node_recordviews,node_timeline,node_trends,node_sharing,node_medication toneAmber
class node_ocrservice,node_medicineimport toneMint
class node_database,node_storageclient,node_supabase,node_paddle,node_gemini toneRose
class node_patient,node_clinician toneIndigo
```

## Components

### Web experience

- [Patient and clinician UI](https://github.com/aryan22n/pharmabrain-/tree/main/frontend/app): `frontend/app`
- [Accounts and sessions](https://github.com/aryan22n/pharmabrain-/blob/main/frontend/lib/auth.ts): `frontend/lib/auth.ts`
- [Role-based sign-in](https://github.com/aryan22n/pharmabrain-/blob/main/frontend/components/auth/AuthForm.tsx): `frontend/components/auth/AuthForm.tsx`
- [Prescription upload](https://github.com/aryan22n/pharmabrain-/blob/main/frontend/app/upload/page.tsx): `frontend/app/upload/page.tsx`
- [OCR API route](https://github.com/aryan22n/pharmabrain-/blob/main/frontend/app/api/ocr/route.ts): `frontend/app/api/ocr/route.ts`
- [Extraction review](https://github.com/aryan22n/pharmabrain-/blob/main/frontend/app/extractions/%5Bid%5D/page.tsx): `frontend/app/extractions/[id]/page.tsx`
- [Medicine editor](https://github.com/aryan22n/pharmabrain-/blob/main/frontend/components/MedicineEditor.tsx): `frontend/components/MedicineEditor.tsx`
- [Review status badges](https://github.com/aryan22n/pharmabrain-/blob/main/frontend/components/StatusBadge.tsx): `frontend/components/StatusBadge.tsx`
- [Confirm or discard](https://github.com/aryan22n/pharmabrain-/blob/main/frontend/app/api/confirm/%5Bid%5D/route.ts): `frontend/app/api/confirm/[id]/route.ts`

### Clinical records

- [Patient record views](https://github.com/aryan22n/pharmabrain-/tree/main/frontend/app/patient): `frontend/app/patient`
- [Medical timeline](https://github.com/aryan22n/pharmabrain-/blob/main/frontend/app/patient/timeline/page.tsx): `frontend/app/patient/timeline/page.tsx`
- [Vitals and trends](https://github.com/aryan22n/pharmabrain-/blob/main/frontend/app/api/patient/trends/route.ts): `frontend/app/api/patient/trends/route.ts`
- [Patient access sharing](https://github.com/aryan22n/pharmabrain-/blob/main/frontend/app/api/doctor/access-requests/route.ts): `frontend/app/api/doctor/access-requests/route.ts`
- [Medication lifecycle](https://github.com/aryan22n/pharmabrain-/blob/main/frontend/lib/medicationLifecycle.ts): `frontend/lib/medicationLifecycle.ts`

### Prescription processing

- [OCR and extraction service](https://github.com/aryan22n/pharmabrain-/blob/main/model/final_prescription_ocr_service_windows.py): `model/final_prescription_ocr_service_windows.py`
- [Medicine master import](https://github.com/aryan22n/pharmabrain-/blob/main/model/import_medicines_bulk.py): `model/import_medicines_bulk.py`

### Storage and services

- **Shared application database**
- [Image storage integration](https://github.com/aryan22n/pharmabrain-/blob/main/frontend/lib/supabaseStorage.ts): `frontend/lib/supabaseStorage.ts`
- **Supabase Storage**
- **PaddleOCR**
- **Google Gemini**

### Other components

- **Patient**
- **Clinician**

## Connections

- Patient → Patient and clinician UI: uses (evidence: `README.md`)
- Clinician → Patient and clinician UI: uses (evidence: `README.md`)
- Patient and clinician UI → Role-based sign-in: presents (evidence: `README.md`)
- Role-based sign-in → Accounts and sessions: authenticates (evidence: `frontend/components/auth/AuthForm.tsx`)
- Patient → Prescription upload: submits image (evidence: `README.md`)
- Clinician → Prescription upload: submits image (evidence: `README.md`)
- Prescription upload → OCR API route: sends image (evidence: `README.md`)
- OCR API route → OCR and extraction service: calls over HTTP (evidence: `README.md`)
- OCR and extraction service → PaddleOCR: extracts text (evidence: `README.md`)
- OCR and extraction service → Google Gemini: structures draft (evidence: `README.md`)
- OCR and extraction service → Shared application database: stores records (evidence: `README.md`)
- OCR and extraction service → Extraction review: returns draft (evidence: `README.md`)
- Extraction review → Medicine editor: renders fields (evidence: `frontend/components/MedicineEditor.tsx`)
- Medicine editor → Review status badges: renders badges (evidence: `frontend/components/MedicineEditor.tsx`)
- Clinician → Extraction review: reviews draft (evidence: `README.md`)
- Extraction review → Confirm or discard: submits corrections (evidence: `README.md`)
- Confirm or discard → Shared application database: confirms record (evidence: `README.md`)
- Confirm or discard → Medication lifecycle: updates medication
- Prescription upload → Image storage integration: stores image (evidence: `README.md`)
- Image storage integration → Supabase Storage: uploads image (evidence: `frontend/lib/supabaseStorage.ts`)
- Patient → Patient record views: views records (evidence: `README.md`)
- Patient record views → Shared application database: reads records (evidence: `README.md`)
- Patient → Medical timeline: views history (evidence: `README.md`)
- Medical timeline → Shared application database: reads history (evidence: `README.md`)
- Patient → Vitals and trends: views trends (evidence: `README.md`)
- Vitals and trends → Shared application database: reads observations (evidence: `frontend/app/api/patient/trends/route.ts`)
- Clinician → Patient access sharing: requests access (evidence: `README.md`)
- Patient access sharing → Shared application database: records requests
- Medicine master import → Shared application database: imports medicines (evidence: `model/import_medicines_bulk.py`)
