# krishna-jajoo-git/pharmabrain architecture

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

- Interactive diagram: https://gitdiagram.com/krishna-jajoo-git/pharmabrain
- Repository: https://github.com/krishna-jajoo-git/pharmabrain

## Overview

PharmaBrain turns prescription images into patient-owned medical records: a patient uploads a prescription, the web API sends it to the OCR service for text extraction and structuring, and the resulting draft remains pending until human review and confirmation. Confirmed records support medication reconciliation, longitudinal trends, and patient-approved doctor access. The README documents the major capabilities and service integrations; source excerpts additionally show OCR forwarding, medication reconciliation, database access, and storage upload. Several feature routes and trend implementations are indexed but unsampled, so their internal call relationships are not inferred.

Main entry points: [`frontend/app`](https://github.com/krishna-jajoo-git/pharmabrain/tree/main/frontend/app) (Patient and doctor portals), [`model/final_prescription_ocr_service_windows.py`](https://github.com/krishna-jajoo-git/pharmabrain/blob/main/model/final_prescription_ocr_service_windows.py) (Prescription OCR service), [`frontend/app/api/ocr/route.ts`](https://github.com/krishna-jajoo-git/pharmabrain/blob/main/frontend/app/api/ocr/route.ts) (OCR upload API), [`frontend/components/MedicineEditor.tsx`](https://github.com/krishna-jajoo-git/pharmabrain/blob/main/frontend/components/MedicineEditor.tsx) (Draft review and editing)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web experience and APIs"]
  node_webui["Patient and doctor portals"]
  node_ocrroute["OCR upload API<br/>[route.ts]"]
  node_auth["Authentication<br/>[auth.ts]"]
end

subgraph group_extraction["Prescription extraction"]
  node_ocrservice["Prescription OCR service"]
  node_paddle["PaddleOCR"]
  node_gemini["Gemini structuring"]
  node_review["Draft review and editing<br/>[MedicineEditor.tsx]"]
  node_reviewbadges["Field confidence badges<br/>[StatusBadge.tsx]"]
  node_confirmation["Confirm or discard drafts<br/>[route.ts]"]
end

subgraph group_record["Medical record"]
  node_recordapi["Patient dashboard and timeline<br/>[route.ts]"]
  node_medicines["Medication lifecycle<br/>[route.ts]"]
  node_lifecycle["Medication reconciliation rules"]
end

subgraph group_insights["Trends and sharing"]
  node_trends["Longitudinal trend analysis<br/>[trendsService.ts]"]
  node_sharing["Consent-based doctor sharing<br/>[route.ts]"]
end

node_patient(("Patient / clinician"))
node_database[("PostgreSQL / Supabase")]
node_storage[("Prescription image storage")]

node_patient -->|"uses"| node_webui
node_webui -->|"uploads image"| node_ocrroute
node_ocrroute -->|"forwards image"| node_ocrservice
node_ocrservice -->|"extracts text"| node_paddle
node_ocrservice -->|"structures text"| node_gemini
node_ocrservice -->|"stores pipeline data"| node_database
node_ocrroute -->|"uploads image"| node_storage
node_webui -->|"reviews draft"| node_review
node_review -->|"renders confidence"| node_reviewbadges
node_review -->|"submits decision"| node_confirmation
node_confirmation -->|"records confirmation"| node_database
node_webui -->|"authenticates"| node_auth
node_webui -->|"requests dashboard"| node_recordapi
node_recordapi -->|"reads patient record"| node_database
node_webui -->|"manages medicines"| node_medicines
node_medicines -->|"reconciles courses"| node_lifecycle
node_medicines -->|"reads and writes"| node_database
node_webui -->|"views trends"| node_trends
node_webui -->|"requests access"| node_sharing
node_sharing -->|"stores consent"| node_database

click node_webui "https://github.com/krishna-jajoo-git/pharmabrain/tree/main/frontend/app"
click node_ocrroute "https://github.com/krishna-jajoo-git/pharmabrain/blob/main/frontend/app/api/ocr/route.ts"
click node_auth "https://github.com/krishna-jajoo-git/pharmabrain/blob/main/frontend/lib/auth.ts"
click node_ocrservice "https://github.com/krishna-jajoo-git/pharmabrain/blob/main/model/final_prescription_ocr_service_windows.py"
click node_review "https://github.com/krishna-jajoo-git/pharmabrain/blob/main/frontend/components/MedicineEditor.tsx"
click node_reviewbadges "https://github.com/krishna-jajoo-git/pharmabrain/blob/main/frontend/components/StatusBadge.tsx"
click node_confirmation "https://github.com/krishna-jajoo-git/pharmabrain/blob/main/frontend/app/api/confirm/%5Bid%5D/route.ts"
click node_recordapi "https://github.com/krishna-jajoo-git/pharmabrain/blob/main/frontend/app/api/user/dashboard/route.ts"
click node_medicines "https://github.com/krishna-jajoo-git/pharmabrain/blob/main/frontend/app/api/patient/medicines/route.ts"
click node_lifecycle "https://github.com/krishna-jajoo-git/pharmabrain/blob/main/frontend/lib/medicationLifecycle.ts"
click node_trends "https://github.com/krishna-jajoo-git/pharmabrain/blob/main/frontend/lib/trendsService.ts"
click node_sharing "https://github.com/krishna-jajoo-git/pharmabrain/blob/main/frontend/app/api/doctor/access-requests/route.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_webui,node_ocrroute,node_auth toneBlue
class node_ocrservice,node_paddle,node_gemini,node_review,node_reviewbadges,node_confirmation,node_database,node_storage toneAmber
class node_recordapi,node_medicines,node_lifecycle toneMint
class node_trends,node_sharing toneRose
class node_patient toneIndigo
```

## Components

### Web experience and APIs

- [Patient and doctor portals](https://github.com/krishna-jajoo-git/pharmabrain/tree/main/frontend/app): `frontend/app`
- [OCR upload API](https://github.com/krishna-jajoo-git/pharmabrain/blob/main/frontend/app/api/ocr/route.ts): `frontend/app/api/ocr/route.ts`
- [Authentication](https://github.com/krishna-jajoo-git/pharmabrain/blob/main/frontend/lib/auth.ts): `frontend/lib/auth.ts`

### Prescription extraction

- [Prescription OCR service](https://github.com/krishna-jajoo-git/pharmabrain/blob/main/model/final_prescription_ocr_service_windows.py): `model/final_prescription_ocr_service_windows.py`
- **PaddleOCR**
- **Gemini structuring**
- [Draft review and editing](https://github.com/krishna-jajoo-git/pharmabrain/blob/main/frontend/components/MedicineEditor.tsx): `frontend/components/MedicineEditor.tsx`
- [Field confidence badges](https://github.com/krishna-jajoo-git/pharmabrain/blob/main/frontend/components/StatusBadge.tsx): `frontend/components/StatusBadge.tsx`
- [Confirm or discard drafts](https://github.com/krishna-jajoo-git/pharmabrain/blob/main/frontend/app/api/confirm/%5Bid%5D/route.ts): `frontend/app/api/confirm/[id]/route.ts`

### Medical record

- [Patient dashboard and timeline](https://github.com/krishna-jajoo-git/pharmabrain/blob/main/frontend/app/api/user/dashboard/route.ts): `frontend/app/api/user/dashboard/route.ts`
- [Medication lifecycle](https://github.com/krishna-jajoo-git/pharmabrain/blob/main/frontend/app/api/patient/medicines/route.ts): `frontend/app/api/patient/medicines/route.ts`
- [Medication reconciliation rules](https://github.com/krishna-jajoo-git/pharmabrain/blob/main/frontend/lib/medicationLifecycle.ts): `frontend/lib/medicationLifecycle.ts`

### Trends and sharing

- [Longitudinal trend analysis](https://github.com/krishna-jajoo-git/pharmabrain/blob/main/frontend/lib/trendsService.ts): `frontend/lib/trendsService.ts`
- [Consent-based doctor sharing](https://github.com/krishna-jajoo-git/pharmabrain/blob/main/frontend/app/api/doctor/access-requests/route.ts): `frontend/app/api/doctor/access-requests/route.ts`

### Other components

- **Patient / clinician**
- **PostgreSQL / Supabase**
- **Prescription image storage**

## Connections

- Patient / clinician → Patient and doctor portals: uses
- Patient and doctor portals → OCR upload API: uploads image
- OCR upload API → Prescription OCR service: forwards image (evidence: `frontend/app/api/ocr/route.ts`)
- Prescription OCR service → PaddleOCR: extracts text
- Prescription OCR service → Gemini structuring: structures text
- Prescription OCR service → PostgreSQL / Supabase: stores pipeline data
- OCR upload API → Prescription image storage: uploads image (evidence: `frontend/app/api/ocr/route.ts`)
- Patient and doctor portals → Draft review and editing: reviews draft
- Draft review and editing → Field confidence badges: renders confidence (evidence: `frontend/components/MedicineEditor.tsx`)
- Draft review and editing → Confirm or discard drafts: submits decision
- Confirm or discard drafts → PostgreSQL / Supabase: records confirmation
- Patient and doctor portals → Authentication: authenticates
- Patient and doctor portals → Patient dashboard and timeline: requests dashboard
- Patient dashboard and timeline → PostgreSQL / Supabase: reads patient record (evidence: `frontend/app/api/user/dashboard/route.ts`)
- Patient and doctor portals → Medication lifecycle: manages medicines
- Medication lifecycle → Medication reconciliation rules: reconciles courses (evidence: `frontend/app/api/patient/medicines/route.ts`)
- Medication lifecycle → PostgreSQL / Supabase: reads and writes (evidence: `frontend/app/api/patient/medicines/route.ts`)
- Patient and doctor portals → Longitudinal trend analysis: views trends
- Patient and doctor portals → Consent-based doctor sharing: requests access
- Consent-based doctor sharing → PostgreSQL / Supabase: stores consent
