# kpdhanya-lab/thethirdbyte architecture

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

- Interactive diagram: https://gitdiagram.com/kpdhanya-lab/thethirdbyte
- Repository: https://github.com/kpdhanya-lab/thethirdbyte

## Overview

TheThirdByte is a hybrid hospital-pharmacy workflow with separate patient and pharmacist portals. Patients upload prescriptions for AI extraction and submit them to the dispensary; pharmacists review the queue, verify prescriptions, and issue dispensing tokens. Patients then redeem tokens to collect medication. The sampled code supports these portal, extraction, data-access, and token-service responsibilities; some integration wiring is inferred only from function names and documented UI behavior, so uncertain links are omitted.

Main entry points: [`pharmacist-portal-frontend/src/App.tsx`](https://github.com/kpdhanya-lab/thethirdbyte/blob/main/pharmacist-portal-frontend/src/App.tsx) (Dispensary workflow), [`paitent-portal-frontend/src/App.tsx`](https://github.com/kpdhanya-lab/thethirdbyte/blob/main/paitent-portal-frontend/src/App.tsx) (Patient workflow), [`paitent-portal-frontend/src/components/PrescriptionUploadView.tsx`](https://github.com/kpdhanya-lab/thethirdbyte/blob/main/paitent-portal-frontend/src/components/PrescriptionUploadView.tsx) (Prescription upload), [`pharmacist-portal-frontend/src/components/DispensingBay.tsx`](https://github.com/kpdhanya-lab/thethirdbyte/blob/main/pharmacist-portal-frontend/src/components/DispensingBay.tsx) (Dispensing bay)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_patient["Patient portal"]
  node_patient_app["Patient workflow<br/>[App.tsx]"]
  node_upload["Prescription upload"]
  node_patient_data["Patient data access<br/>[supabase.ts]"]
  node_extract["Image extraction<br/>[gemini.ts]"]
  node_patient_result["Dispense readiness"]
end

subgraph group_pharmacist["Pharmacist portal"]
  node_pharmacist_app["Dispensary workflow<br/>[App.tsx]"]
  node_queue["Prescription queue"]
  node_dispensing["Dispensing bay<br/>[DispensingBay.tsx]"]
  node_interaction["Interaction review"]
  node_security["Terminal audit"]
  node_pharmacist_data["Pharmacy data access<br/>[supabase.ts]"]
end

subgraph group_tokens["Dispense tokens"]
  node_create_token["Issue token<br/>[index.ts]"]
  node_redeem_token["Redeem token<br/>[index.ts]"]
  node_token_service["Token service"]
end

subgraph group_services["External services"]
  node_database[("Supabase")]
  node_ai_service["Vision AI"]
end

node_patient_actor(("Patient"))
node_pharmacist_actor(("Pharmacist"))

node_patient_actor -->|"uses"| node_patient_app
node_patient_app -->|"looks up patient"| node_patient_data
node_patient_data -->|"reads / writes"| node_database
node_patient_app -->|"opens upload"| node_upload
node_upload -->|"extracts prescription"| node_extract
node_extract -.->|"analyzes image"| node_ai_service
node_upload -->|"submits prescription"| node_patient_data
node_pharmacist_actor -->|"uses"| node_pharmacist_app
node_pharmacist_app -->|"loads and subscribes"| node_pharmacist_data
node_pharmacist_data -->|"reads / updates"| node_database
node_pharmacist_app -->|"displays queue"| node_queue
node_pharmacist_app -->|"opens dispensing"| node_dispensing
node_pharmacist_app -->|"opens review"| node_interaction
node_dispensing -->|"resolves prescription"| node_pharmacist_data
node_dispensing -->|"requests token"| node_create_token
node_create_token -->|"validates and stores"| node_database
node_redeem_token -->|"validates and updates"| node_database
node_patient_actor -->|"presents token"| node_redeem_token
node_redeem_token -->|"returns redemption result"| node_patient_result
node_token_service -->|"manages token records"| node_database
node_pharmacist_app -->|"shows audit view"| node_security

click node_patient_app "https://github.com/kpdhanya-lab/thethirdbyte/blob/main/paitent-portal-frontend/src/App.tsx"
click node_upload "https://github.com/kpdhanya-lab/thethirdbyte/blob/main/paitent-portal-frontend/src/components/PrescriptionUploadView.tsx"
click node_patient_data "https://github.com/kpdhanya-lab/thethirdbyte/blob/main/paitent-portal-frontend/src/utils/supabase.ts"
click node_extract "https://github.com/kpdhanya-lab/thethirdbyte/blob/main/paitent-portal-frontend/src/utils/gemini.ts"
click node_pharmacist_app "https://github.com/kpdhanya-lab/thethirdbyte/blob/main/pharmacist-portal-frontend/src/App.tsx"
click node_queue "https://github.com/kpdhanya-lab/thethirdbyte/blob/main/pharmacist-portal-frontend/src/components/PrescriptionQueueView.tsx"
click node_dispensing "https://github.com/kpdhanya-lab/thethirdbyte/blob/main/pharmacist-portal-frontend/src/components/DispensingBay.tsx"
click node_interaction "https://github.com/kpdhanya-lab/thethirdbyte/blob/main/pharmacist-portal-frontend/src/components/InteractionChecker.tsx"
click node_security "https://github.com/kpdhanya-lab/thethirdbyte/blob/main/pharmacist-portal-frontend/src/components/TerminalSecurityAudit.tsx"
click node_pharmacist_data "https://github.com/kpdhanya-lab/thethirdbyte/blob/main/pharmacist-portal-frontend/src/utils/supabase.ts"
click node_create_token "https://github.com/kpdhanya-lab/thethirdbyte/blob/main/supabase/functions/create-dispense-token/index.ts"
click node_redeem_token "https://github.com/kpdhanya-lab/thethirdbyte/blob/main/supabase/functions/redeem-dispense-token/index.ts"
click node_token_service "https://github.com/kpdhanya-lab/thethirdbyte/blob/main/paitent-portal-frontend/src/server/dispenseTokenService.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_patient_app,node_upload,node_patient_data,node_extract,node_patient_result toneBlue
class node_pharmacist_app,node_queue,node_dispensing,node_interaction,node_security,node_pharmacist_data toneAmber
class node_create_token,node_redeem_token,node_token_service toneMint
class node_database,node_ai_service toneRose
class node_patient_actor,node_pharmacist_actor toneIndigo
```

## Components

### Patient portal

- [Patient workflow](https://github.com/kpdhanya-lab/thethirdbyte/blob/main/paitent-portal-frontend/src/App.tsx): `paitent-portal-frontend/src/App.tsx`
- [Prescription upload](https://github.com/kpdhanya-lab/thethirdbyte/blob/main/paitent-portal-frontend/src/components/PrescriptionUploadView.tsx): `paitent-portal-frontend/src/components/PrescriptionUploadView.tsx`
- [Patient data access](https://github.com/kpdhanya-lab/thethirdbyte/blob/main/paitent-portal-frontend/src/utils/supabase.ts): `paitent-portal-frontend/src/utils/supabase.ts`
- [Image extraction](https://github.com/kpdhanya-lab/thethirdbyte/blob/main/paitent-portal-frontend/src/utils/gemini.ts): `paitent-portal-frontend/src/utils/gemini.ts`
- **Dispense readiness**

### Pharmacist portal

- [Dispensary workflow](https://github.com/kpdhanya-lab/thethirdbyte/blob/main/pharmacist-portal-frontend/src/App.tsx): `pharmacist-portal-frontend/src/App.tsx`
- [Prescription queue](https://github.com/kpdhanya-lab/thethirdbyte/blob/main/pharmacist-portal-frontend/src/components/PrescriptionQueueView.tsx): `pharmacist-portal-frontend/src/components/PrescriptionQueueView.tsx`
- [Dispensing bay](https://github.com/kpdhanya-lab/thethirdbyte/blob/main/pharmacist-portal-frontend/src/components/DispensingBay.tsx): `pharmacist-portal-frontend/src/components/DispensingBay.tsx`
- [Interaction review](https://github.com/kpdhanya-lab/thethirdbyte/blob/main/pharmacist-portal-frontend/src/components/InteractionChecker.tsx): `pharmacist-portal-frontend/src/components/InteractionChecker.tsx`
- [Terminal audit](https://github.com/kpdhanya-lab/thethirdbyte/blob/main/pharmacist-portal-frontend/src/components/TerminalSecurityAudit.tsx): `pharmacist-portal-frontend/src/components/TerminalSecurityAudit.tsx`
- [Pharmacy data access](https://github.com/kpdhanya-lab/thethirdbyte/blob/main/pharmacist-portal-frontend/src/utils/supabase.ts): `pharmacist-portal-frontend/src/utils/supabase.ts`

### Dispense tokens

- [Issue token](https://github.com/kpdhanya-lab/thethirdbyte/blob/main/supabase/functions/create-dispense-token/index.ts): `supabase/functions/create-dispense-token/index.ts`
- [Redeem token](https://github.com/kpdhanya-lab/thethirdbyte/blob/main/supabase/functions/redeem-dispense-token/index.ts): `supabase/functions/redeem-dispense-token/index.ts`
- [Token service](https://github.com/kpdhanya-lab/thethirdbyte/blob/main/paitent-portal-frontend/src/server/dispenseTokenService.ts): `paitent-portal-frontend/src/server/dispenseTokenService.ts`

### External services

- **Supabase**
- **Vision AI**

### Other components

- **Patient**
- **Pharmacist**

## Connections

- Patient → Patient workflow: uses
- Patient workflow → Patient data access: looks up patient
- Patient data access → Supabase: reads / writes
- Patient workflow → Prescription upload: opens upload
- Prescription upload → Image extraction: extracts prescription
- Image extraction → Vision AI: analyzes image
- Prescription upload → Patient data access: submits prescription
- Pharmacist → Dispensary workflow: uses
- Dispensary workflow → Pharmacy data access: loads and subscribes
- Pharmacy data access → Supabase: reads / updates
- Dispensary workflow → Prescription queue: displays queue
- Dispensary workflow → Dispensing bay: opens dispensing
- Dispensary workflow → Interaction review: opens review
- Dispensing bay → Pharmacy data access: resolves prescription
- Dispensing bay → Issue token: requests token
- Issue token → Supabase: validates and stores
- Redeem token → Supabase: validates and updates
- Patient → Redeem token: presents token
- Redeem token → Dispense readiness: returns redemption result
- Token service → Supabase: manages token records
- Dispensary workflow → Terminal audit: shows audit view
