# anshib-m/offgrid- architecture

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

- Interactive diagram: https://gitdiagram.com/anshib-m/offgrid-
- Repository: https://github.com/anshib-m/offgrid-

## Overview

Offgrid is a consent-first medical-history exchange. A patient signs in and presents a one-time QR; a hospital scans it, requests selected record categories, and the patient approves, narrows, or denies access for a limited time. The hospital can review permitted records, add records, and have doctors sign them; patients can manage access and see activity. The README also documents emergency access, visits and assignments, follow-ups, uploads, and optional native clients. API route details beyond the excerpts are represented at their enclosing route files; those feature links rely on README documentation.

Main entry points: [`server/src/routes/patient.ts`](https://github.com/anshib-m/offgrid-/blob/main/server/src/routes/patient.ts) (Patient routes), [`server/src/routes/hospital.ts`](https://github.com/anshib-m/offgrid-/blob/main/server/src/routes/hospital.ts) (Hospital routes), [`server/src/app.ts`](https://github.com/anshib-m/offgrid-/blob/main/server/src/app.ts) (Express API), [`web/src/patient/App.tsx`](https://github.com/anshib-m/offgrid-/blob/main/web/src/patient/App.tsx) (Patient web app)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_clients["Patient and hospital clients"]
  node_web_patient["Patient web app<br/>[App.tsx]"]
  node_web_hospital["Hospital portal<br/>[App.tsx]"]
  node_web_api["Web API client<br/>[api.ts]"]
  node_web_ui["Shared UI<br/>[ui.tsx]"]
  node_mobile_app["Native patient app<br/>[App.tsx]"]
  node_mobile_api["Native API client<br/>[api.ts]"]
  node_flutter["Optional Flutter client"]
end

subgraph group_access["API and access control"]
  node_api["Express API<br/>[app.ts]"]
  node_auth_routes["Authentication routes<br/>[auth.ts]"]
  node_auth["JWT authorization<br/>[auth.ts]"]
  node_patient_routes["Patient routes<br/>[patient.ts]"]
  node_hospital_routes["Hospital routes<br/>[hospital.ts]"]
  node_consent["Consent checks<br/>[consent.ts]"]
end

subgraph group_clinical["Clinical records"]
  node_records["Record signing<br/>[records.ts]"]
  node_uploads["Document uploads<br/>[upload.ts]"]
  node_file_store[("Uploaded files")]
end

subgraph group_operations["Visits and accountability"]
  node_db_core["Crypto and audit<br/>[core.ts]"]
  node_database[("PostgreSQL<br/>[schema.prisma]")]
  node_visits["Visits and assignment<br/>[hospital.ts]"]
  node_emergency["Emergency access<br/>[hospital.ts]"]
  node_audit_view["Access history<br/>[App.tsx]"]
end

node_patient(("Patient"))
node_hospital_staff(("Hospital staff"))

node_patient -->|"uses"| node_web_patient
node_hospital_staff -->|"uses"| node_web_hospital
node_web_patient -->|"calls"| node_web_api
node_web_hospital -->|"calls"| node_web_api
node_web_patient -->|"renders"| node_web_ui
node_web_hospital -->|"renders"| node_web_ui
node_web_ui -->|"loads documents"| node_web_api
node_web_api -->|"sends requests"| node_api
node_patient -.->|"uses"| node_mobile_app
node_mobile_app -->|"calls"| node_mobile_api
node_mobile_app -.->|"sends requests"| node_api
node_patient -.->|"uses"| node_flutter
node_api -->|"routes"| node_auth_routes
node_api -->|"routes"| node_patient_routes
node_api -->|"routes"| node_hospital_routes
node_auth_routes -->|"issues tokens"| node_auth
node_patient_routes -->|"authenticates"| node_auth
node_hospital_routes -->|"authenticates"| node_auth
node_patient_routes -->|"manages consent"| node_consent
node_hospital_routes -->|"checks access"| node_consent
node_hospital_routes -->|"verifies records"| node_records
node_patient_routes -->|"deletes uploads"| node_records
node_hospital_routes -->|"reads documents"| node_uploads
node_patient_routes -->|"reads documents"| node_uploads
node_records -->|"removes files"| node_uploads
node_patient_routes -.->|"manages visits"| node_visits
node_hospital_routes -.->|"assigns doctors"| node_visits
node_patient_routes -.->|"manages card"| node_emergency
node_hospital_routes -.->|"grants access"| node_emergency
node_patient_routes -->|"writes audit"| node_db_core
node_hospital_routes -->|"writes audit"| node_db_core
node_web_patient -->|"shows activity"| node_audit_view
node_db_core -->|"persists audit"| node_database
node_auth_routes -->|"reads and writes"| node_database
node_hospital_routes -.->|"reads and writes"| node_database
node_patient_routes -.->|"reads and writes"| node_database
node_uploads -.->|"stores files"| node_file_store
node_hospital_routes -->|"streams documents"| node_file_store
node_patient_routes -->|"streams documents"| node_file_store

click node_web_patient "https://github.com/anshib-m/offgrid-/blob/main/web/src/patient/App.tsx"
click node_web_hospital "https://github.com/anshib-m/offgrid-/blob/main/web/src/hospital/App.tsx"
click node_web_api "https://github.com/anshib-m/offgrid-/blob/main/web/src/shared/api.ts"
click node_web_ui "https://github.com/anshib-m/offgrid-/blob/main/web/src/shared/ui.tsx"
click node_mobile_app "https://github.com/anshib-m/offgrid-/blob/main/mobile/App.tsx"
click node_mobile_api "https://github.com/anshib-m/offgrid-/blob/main/mobile/src/api.ts"
click node_api "https://github.com/anshib-m/offgrid-/blob/main/server/src/app.ts"
click node_auth_routes "https://github.com/anshib-m/offgrid-/blob/main/server/src/routes/auth.ts"
click node_auth "https://github.com/anshib-m/offgrid-/blob/main/server/src/auth.ts"
click node_patient_routes "https://github.com/anshib-m/offgrid-/blob/main/server/src/routes/patient.ts"
click node_hospital_routes "https://github.com/anshib-m/offgrid-/blob/main/server/src/routes/hospital.ts"
click node_consent "https://github.com/anshib-m/offgrid-/blob/main/server/src/consent.ts"
click node_records "https://github.com/anshib-m/offgrid-/blob/main/server/src/records.ts"
click node_uploads "https://github.com/anshib-m/offgrid-/blob/main/server/src/upload.ts"
click node_db_core "https://github.com/anshib-m/offgrid-/blob/main/server/src/core.ts"
click node_database "https://github.com/anshib-m/offgrid-/blob/main/server/prisma/schema.prisma"
click node_visits "https://github.com/anshib-m/offgrid-/blob/main/server/src/routes/hospital.ts"
click node_emergency "https://github.com/anshib-m/offgrid-/blob/main/server/src/routes/hospital.ts"
click node_audit_view "https://github.com/anshib-m/offgrid-/blob/main/web/src/patient/App.tsx"
click node_flutter "https://github.com/anshib-m/offgrid-/tree/main/patient_flutter/lib"

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_web_patient,node_web_hospital,node_web_api,node_web_ui,node_mobile_app,node_mobile_api,node_flutter toneBlue
class node_api,node_auth_routes,node_auth,node_patient_routes,node_hospital_routes,node_consent toneAmber
class node_records,node_uploads,node_file_store toneMint
class node_db_core,node_database,node_visits,node_emergency,node_audit_view toneRose
class node_patient,node_hospital_staff toneIndigo
```

## Components

### Patient and hospital clients

- [Patient web app](https://github.com/anshib-m/offgrid-/blob/main/web/src/patient/App.tsx): `web/src/patient/App.tsx`
- [Hospital portal](https://github.com/anshib-m/offgrid-/blob/main/web/src/hospital/App.tsx): `web/src/hospital/App.tsx`
- [Web API client](https://github.com/anshib-m/offgrid-/blob/main/web/src/shared/api.ts): `web/src/shared/api.ts`
- [Shared UI](https://github.com/anshib-m/offgrid-/blob/main/web/src/shared/ui.tsx): `web/src/shared/ui.tsx`
- [Native patient app](https://github.com/anshib-m/offgrid-/blob/main/mobile/App.tsx): `mobile/App.tsx`
- [Native API client](https://github.com/anshib-m/offgrid-/blob/main/mobile/src/api.ts): `mobile/src/api.ts`
- [Optional Flutter client](https://github.com/anshib-m/offgrid-/tree/main/patient_flutter/lib): `patient_flutter/lib`

### API and access control

- [Express API](https://github.com/anshib-m/offgrid-/blob/main/server/src/app.ts): `server/src/app.ts`
- [Authentication routes](https://github.com/anshib-m/offgrid-/blob/main/server/src/routes/auth.ts): `server/src/routes/auth.ts`
- [JWT authorization](https://github.com/anshib-m/offgrid-/blob/main/server/src/auth.ts): `server/src/auth.ts`
- [Patient routes](https://github.com/anshib-m/offgrid-/blob/main/server/src/routes/patient.ts): `server/src/routes/patient.ts`
- [Hospital routes](https://github.com/anshib-m/offgrid-/blob/main/server/src/routes/hospital.ts): `server/src/routes/hospital.ts`
- [Consent checks](https://github.com/anshib-m/offgrid-/blob/main/server/src/consent.ts): `server/src/consent.ts`

### Clinical records

- [Record signing](https://github.com/anshib-m/offgrid-/blob/main/server/src/records.ts): `server/src/records.ts`
- [Document uploads](https://github.com/anshib-m/offgrid-/blob/main/server/src/upload.ts): `server/src/upload.ts`
- **Uploaded files**

### Visits and accountability

- [Crypto and audit](https://github.com/anshib-m/offgrid-/blob/main/server/src/core.ts): `server/src/core.ts`
- [PostgreSQL](https://github.com/anshib-m/offgrid-/blob/main/server/prisma/schema.prisma): `server/prisma/schema.prisma`
- [Visits and assignment](https://github.com/anshib-m/offgrid-/blob/main/server/src/routes/hospital.ts): `server/src/routes/hospital.ts`
- [Emergency access](https://github.com/anshib-m/offgrid-/blob/main/server/src/routes/hospital.ts): `server/src/routes/hospital.ts`
- [Access history](https://github.com/anshib-m/offgrid-/blob/main/web/src/patient/App.tsx): `web/src/patient/App.tsx`

### Other components

- **Patient**
- **Hospital staff**

## Connections

- Patient → Patient web app: uses (evidence: `README.md`)
- Hospital staff → Hospital portal: uses (evidence: `README.md`)
- Patient web app → Web API client: calls (evidence: `web/src/patient/App.tsx`)
- Hospital portal → Web API client: calls (evidence: `web/src/hospital/App.tsx`)
- Patient web app → Shared UI: renders (evidence: `web/src/patient/App.tsx`)
- Hospital portal → Shared UI: renders (evidence: `web/src/hospital/App.tsx`)
- Shared UI → Web API client: loads documents (evidence: `web/src/shared/ui.tsx`)
- Web API client → Express API: sends requests (evidence: `web/src/shared/api.ts`)
- Patient → Native patient app: uses (evidence: `README.md`)
- Native patient app → Native API client: calls (evidence: `mobile/App.tsx`)
- Native patient app → Express API: sends requests (evidence: `README.md`)
- Patient → Optional Flutter client: uses (evidence: `README.md`)
- Express API → Authentication routes: routes (evidence: `server/src/app.ts`)
- Express API → Patient routes: routes (evidence: `server/src/app.ts`)
- Express API → Hospital routes: routes (evidence: `server/src/app.ts`)
- Authentication routes → JWT authorization: issues tokens (evidence: `server/src/routes/auth.ts`)
- Patient routes → JWT authorization: authenticates (evidence: `server/src/routes/patient.ts`)
- Hospital routes → JWT authorization: authenticates (evidence: `server/src/routes/hospital.ts`)
- Patient routes → Consent checks: manages consent (evidence: `server/src/routes/patient.ts`)
- Hospital routes → Consent checks: checks access (evidence: `server/src/routes/hospital.ts`)
- Hospital routes → Record signing: verifies records (evidence: `server/src/routes/hospital.ts`)
- Patient routes → Record signing: deletes uploads (evidence: `server/src/routes/patient.ts`)
- Hospital routes → Document uploads: reads documents (evidence: `server/src/routes/hospital.ts`)
- Patient routes → Document uploads: reads documents (evidence: `server/src/routes/patient.ts`)
- Record signing → Document uploads: removes files (evidence: `server/src/records.ts`)
- Patient routes → Visits and assignment: manages visits (evidence: `README.md`)
- Hospital routes → Visits and assignment: assigns doctors (evidence: `README.md`)
- Patient routes → Emergency access: manages card (evidence: `README.md`)
- Hospital routes → Emergency access: grants access (evidence: `README.md`)
- Patient routes → Crypto and audit: writes audit (evidence: `server/src/routes/patient.ts`)
- Hospital routes → Crypto and audit: writes audit (evidence: `server/src/routes/hospital.ts`)
- Patient web app → Access history: shows activity (evidence: `web/src/patient/App.tsx`)
- Crypto and audit → PostgreSQL: persists audit (evidence: `server/src/core.ts`)
- Authentication routes → PostgreSQL: reads and writes (evidence: `server/src/routes/auth.ts`)
- Hospital routes → PostgreSQL: reads and writes (evidence: `README.md`)
- Patient routes → PostgreSQL: reads and writes (evidence: `README.md`)
- Document uploads → Uploaded files: stores files (evidence: `README.md`)
- Hospital routes → Uploaded files: streams documents (evidence: `server/src/routes/hospital.ts`)
- Patient routes → Uploaded files: streams documents (evidence: `server/src/routes/patient.ts`)
