# vitroyfix/safescan architecture

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

- Interactive diagram: https://gitdiagram.com/vitroyfix/safescan
- Repository: https://github.com/vitroyfix/safescan

## Overview

SafeScan is a synthetic-data patient identity and clinical-record matching product, with an Electron/React desktop client and an Android QR/NFC scanning app backed by an API. The workflow is staff login, patient search or registration, scan verification, then patient-profile and clinical-record work; dashboards, audit, inpatient care, and AI summaries are additional capabilities. The excerpts establish the desktop routing and API structure and mobile app coordination, but not every route or screen’s internal calls, so uncertain links are omitted.

Main entry points: [`Desktop/client/src/App.jsx`](https://github.com/vitroyfix/safescan/blob/main/Desktop/client/src/App.jsx) (Desktop routes), [`Desktop/server/app.js`](https://github.com/vitroyfix/safescan/blob/main/Desktop/server/app.js) (HTTP API), [`Desktop/server/routes/patients.js`](https://github.com/vitroyfix/safescan/blob/main/Desktop/server/routes/patients.js) (Patient routes), [`Mobile/app/src/main/java/ke/safescan/mobile/ui/AppViewModel.kt`](https://github.com/vitroyfix/safescan/blob/main/Mobile/app/src/main/java/ke/safescan/mobile/ui/AppViewModel.kt) (App state)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_desktop["Desktop client"]
  node_desktop_app["Desktop routes<br/>[App.jsx]"]
  node_desktop_api["Desktop API client<br/>[api.js]"]
  node_desktop_shell["Desktop shell<br/>[Shell.jsx]"]
  node_dashboard["Dashboard<br/>[Dashboard.jsx]"]
  node_search["Patient search<br/>[Search.jsx]"]
  node_profile["Patient profile<br/>[Profile.jsx]"]
  node_care_summary["Care summary<br/>[CareSummary.jsx]"]
  node_desktop_pages["Clinical and admin pages"]
end

subgraph group_mobile["Mobile scanning"]
  node_android["Android app<br/>[MainActivity.kt]"]
  node_mobile_ui["Scan and patient UI<br/>[ScanScreen.kt]"]
  node_viewmodel["App state<br/>[AppViewModel.kt]"]
  node_nfc["NFC tag reader<br/>[NfcTagReader.kt]"]
  node_repo["Repository interface<br/>[Repo.kt]"]
  node_remote_repo["Remote repository<br/>[RemoteRepo.kt]"]
  node_demo_repo["Demo repository<br/>[DemoRepo.kt]"]
end

subgraph group_api["API and access"]
  node_api_server["HTTP API<br/>[app.js]"]
  node_auth["Authentication<br/>[auth.js]"]
  node_config["Runtime configuration<br/>[config.js]"]
  node_database[("SQLite database<br/>[db.js]")]
end

subgraph group_identity["Patient identity"]
  node_patient_routes["Patient routes<br/>[patients.js]"]
  node_patient_service["Patient and visit logic<br/>[patients.js]"]
  node_matcher["Identity matcher<br/>[matcher.js]"]
  node_scan_routes["Scan verification<br/>[scan.js]"]
end

subgraph group_clinical["Clinical records"]
  node_record_routes["Record routes<br/>[records.js]"]
  node_record_service["Clinical records<br/>[records.js]"]
  node_profile_service["Profile assembly<br/>[profile.js]"]
  node_summary_service["AI handover summary<br/>[summary.js]"]
  node_ai_service["AI integration<br/>[ai.js]"]
end

node_staff(("Hospital staff"))

node_staff -->|"uses"| node_desktop_app
node_desktop_app -->|"checks health"| node_desktop_api
node_desktop_app -->|"renders"| node_desktop_shell
node_desktop_app -->|"routes to"| node_dashboard
node_desktop_app -->|"routes to"| node_search
node_desktop_app -->|"routes to"| node_profile
node_desktop_app -->|"routes to"| node_desktop_pages
node_search -->|"requests patients"| node_desktop_api
node_dashboard -->|"loads data"| node_desktop_api
node_profile -->|"loads profile"| node_desktop_api
node_profile -->|"renders"| node_care_summary
node_android -->|"coordinates"| node_viewmodel
node_android -->|"displays"| node_mobile_ui
node_android -->|"enables reader"| node_nfc
node_viewmodel -->|"selects repository"| node_repo
node_viewmodel -->|"uses remotely"| node_remote_repo
node_viewmodel -->|"uses in demo"| node_demo_repo
node_remote_repo -->|"implements"| node_repo
node_demo_repo -->|"implements"| node_repo
node_mobile_ui -->|"uses state"| node_viewmodel
node_remote_repo -->|"calls API"| node_api_server
node_desktop_api -.->|"calls API"| node_api_server
node_api_server -->|"mounts routes"| node_auth
node_api_server -->|"mounts routes"| node_patient_routes
node_api_server -->|"mounts routes"| node_scan_routes
node_api_server -->|"mounts routes"| node_record_routes
node_api_server -->|"reads settings"| node_config
node_auth -->|"reads users"| node_database
node_patient_routes -->|"delegates"| node_patient_service
node_patient_routes -->|"uses profiles"| node_profile_service
node_patient_routes -->|"matches identity"| node_matcher
node_patient_routes -->|"uses records"| node_record_service
node_patient_service -->|"reads and writes"| node_database
node_record_routes -->|"uses patient logic"| node_patient_service
node_record_routes -->|"delegates"| node_record_service
node_record_service -.->|"persists records"| node_database
node_profile_service -->|"uses patient data"| node_patient_service
node_profile_service -->|"uses records"| node_record_service
node_profile_service -->|"uses summary"| node_summary_service
node_ai_service -->|"builds summaries"| node_summary_service

click node_desktop_app "https://github.com/vitroyfix/safescan/blob/main/Desktop/client/src/App.jsx"
click node_desktop_api "https://github.com/vitroyfix/safescan/blob/main/Desktop/client/src/api.js"
click node_desktop_shell "https://github.com/vitroyfix/safescan/blob/main/Desktop/client/src/layout/Shell.jsx"
click node_dashboard "https://github.com/vitroyfix/safescan/blob/main/Desktop/client/src/pages/Dashboard.jsx"
click node_search "https://github.com/vitroyfix/safescan/blob/main/Desktop/client/src/pages/Search.jsx"
click node_profile "https://github.com/vitroyfix/safescan/blob/main/Desktop/client/src/pages/Profile.jsx"
click node_care_summary "https://github.com/vitroyfix/safescan/blob/main/Desktop/client/src/CareSummary.jsx"
click node_desktop_pages "https://github.com/vitroyfix/safescan/tree/main/Desktop/client/src/pages"
click node_android "https://github.com/vitroyfix/safescan/blob/main/Mobile/app/src/main/java/ke/safescan/mobile/MainActivity.kt"
click node_mobile_ui "https://github.com/vitroyfix/safescan/blob/main/Mobile/app/src/main/java/ke/safescan/mobile/ui/ScanScreen.kt"
click node_viewmodel "https://github.com/vitroyfix/safescan/blob/main/Mobile/app/src/main/java/ke/safescan/mobile/ui/AppViewModel.kt"
click node_nfc "https://github.com/vitroyfix/safescan/blob/main/Mobile/app/src/main/java/ke/safescan/mobile/nfc/NfcTagReader.kt"
click node_repo "https://github.com/vitroyfix/safescan/blob/main/Mobile/app/src/main/java/ke/safescan/mobile/net/Repo.kt"
click node_remote_repo "https://github.com/vitroyfix/safescan/blob/main/Mobile/app/src/main/java/ke/safescan/mobile/net/RemoteRepo.kt"
click node_demo_repo "https://github.com/vitroyfix/safescan/blob/main/Mobile/app/src/main/java/ke/safescan/mobile/data/DemoRepo.kt"
click node_api_server "https://github.com/vitroyfix/safescan/blob/main/Desktop/server/app.js"
click node_auth "https://github.com/vitroyfix/safescan/blob/main/Desktop/server/auth.js"
click node_config "https://github.com/vitroyfix/safescan/blob/main/Desktop/server/config.js"
click node_database "https://github.com/vitroyfix/safescan/blob/main/Desktop/server/db.js"
click node_patient_routes "https://github.com/vitroyfix/safescan/blob/main/Desktop/server/routes/patients.js"
click node_patient_service "https://github.com/vitroyfix/safescan/blob/main/Desktop/server/services/patients.js"
click node_matcher "https://github.com/vitroyfix/safescan/blob/main/Desktop/server/matcher.js"
click node_scan_routes "https://github.com/vitroyfix/safescan/blob/main/Desktop/server/routes/scan.js"
click node_record_routes "https://github.com/vitroyfix/safescan/blob/main/Desktop/server/routes/records.js"
click node_record_service "https://github.com/vitroyfix/safescan/blob/main/Desktop/server/services/records.js"
click node_profile_service "https://github.com/vitroyfix/safescan/blob/main/Desktop/server/services/profile.js"
click node_summary_service "https://github.com/vitroyfix/safescan/blob/main/Desktop/server/services/summary.js"
click node_ai_service "https://github.com/vitroyfix/safescan/blob/main/Desktop/server/services/ai.js"

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_desktop_app,node_desktop_api,node_desktop_shell,node_dashboard,node_search,node_profile,node_care_summary,node_desktop_pages toneBlue
class node_android,node_mobile_ui,node_viewmodel,node_nfc,node_repo,node_remote_repo,node_demo_repo toneAmber
class node_api_server,node_auth,node_config,node_database toneMint
class node_patient_routes,node_patient_service,node_matcher,node_scan_routes toneRose
class node_record_routes,node_record_service,node_profile_service,node_summary_service,node_ai_service,node_staff toneIndigo
```

## Components

### Desktop client

- [Desktop routes](https://github.com/vitroyfix/safescan/blob/main/Desktop/client/src/App.jsx): `Desktop/client/src/App.jsx`
- [Desktop API client](https://github.com/vitroyfix/safescan/blob/main/Desktop/client/src/api.js): `Desktop/client/src/api.js`
- [Desktop shell](https://github.com/vitroyfix/safescan/blob/main/Desktop/client/src/layout/Shell.jsx): `Desktop/client/src/layout/Shell.jsx`
- [Dashboard](https://github.com/vitroyfix/safescan/blob/main/Desktop/client/src/pages/Dashboard.jsx): `Desktop/client/src/pages/Dashboard.jsx`
- [Patient search](https://github.com/vitroyfix/safescan/blob/main/Desktop/client/src/pages/Search.jsx): `Desktop/client/src/pages/Search.jsx`
- [Patient profile](https://github.com/vitroyfix/safescan/blob/main/Desktop/client/src/pages/Profile.jsx): `Desktop/client/src/pages/Profile.jsx`
- [Care summary](https://github.com/vitroyfix/safescan/blob/main/Desktop/client/src/CareSummary.jsx): `Desktop/client/src/CareSummary.jsx`
- [Clinical and admin pages](https://github.com/vitroyfix/safescan/tree/main/Desktop/client/src/pages): `Desktop/client/src/pages`

### Mobile scanning

- [Android app](https://github.com/vitroyfix/safescan/blob/main/Mobile/app/src/main/java/ke/safescan/mobile/MainActivity.kt): `Mobile/app/src/main/java/ke/safescan/mobile/MainActivity.kt`
- [Scan and patient UI](https://github.com/vitroyfix/safescan/blob/main/Mobile/app/src/main/java/ke/safescan/mobile/ui/ScanScreen.kt): `Mobile/app/src/main/java/ke/safescan/mobile/ui/ScanScreen.kt`
- [App state](https://github.com/vitroyfix/safescan/blob/main/Mobile/app/src/main/java/ke/safescan/mobile/ui/AppViewModel.kt): `Mobile/app/src/main/java/ke/safescan/mobile/ui/AppViewModel.kt`
- [NFC tag reader](https://github.com/vitroyfix/safescan/blob/main/Mobile/app/src/main/java/ke/safescan/mobile/nfc/NfcTagReader.kt): `Mobile/app/src/main/java/ke/safescan/mobile/nfc/NfcTagReader.kt`
- [Repository interface](https://github.com/vitroyfix/safescan/blob/main/Mobile/app/src/main/java/ke/safescan/mobile/net/Repo.kt): `Mobile/app/src/main/java/ke/safescan/mobile/net/Repo.kt`
- [Remote repository](https://github.com/vitroyfix/safescan/blob/main/Mobile/app/src/main/java/ke/safescan/mobile/net/RemoteRepo.kt): `Mobile/app/src/main/java/ke/safescan/mobile/net/RemoteRepo.kt`
- [Demo repository](https://github.com/vitroyfix/safescan/blob/main/Mobile/app/src/main/java/ke/safescan/mobile/data/DemoRepo.kt): `Mobile/app/src/main/java/ke/safescan/mobile/data/DemoRepo.kt`

### API and access

- [HTTP API](https://github.com/vitroyfix/safescan/blob/main/Desktop/server/app.js): `Desktop/server/app.js`
- [Authentication](https://github.com/vitroyfix/safescan/blob/main/Desktop/server/auth.js): `Desktop/server/auth.js`
- [Runtime configuration](https://github.com/vitroyfix/safescan/blob/main/Desktop/server/config.js): `Desktop/server/config.js`
- [SQLite database](https://github.com/vitroyfix/safescan/blob/main/Desktop/server/db.js): `Desktop/server/db.js`

### Patient identity

- [Patient routes](https://github.com/vitroyfix/safescan/blob/main/Desktop/server/routes/patients.js): `Desktop/server/routes/patients.js`
- [Patient and visit logic](https://github.com/vitroyfix/safescan/blob/main/Desktop/server/services/patients.js): `Desktop/server/services/patients.js`
- [Identity matcher](https://github.com/vitroyfix/safescan/blob/main/Desktop/server/matcher.js): `Desktop/server/matcher.js`
- [Scan verification](https://github.com/vitroyfix/safescan/blob/main/Desktop/server/routes/scan.js): `Desktop/server/routes/scan.js`

### Clinical records

- [Record routes](https://github.com/vitroyfix/safescan/blob/main/Desktop/server/routes/records.js): `Desktop/server/routes/records.js`
- [Clinical records](https://github.com/vitroyfix/safescan/blob/main/Desktop/server/services/records.js): `Desktop/server/services/records.js`
- [Profile assembly](https://github.com/vitroyfix/safescan/blob/main/Desktop/server/services/profile.js): `Desktop/server/services/profile.js`
- [AI handover summary](https://github.com/vitroyfix/safescan/blob/main/Desktop/server/services/summary.js): `Desktop/server/services/summary.js`
- [AI integration](https://github.com/vitroyfix/safescan/blob/main/Desktop/server/services/ai.js): `Desktop/server/services/ai.js`

### Other components

- **Hospital staff**

## Connections

- Hospital staff → Desktop routes: uses (evidence: `Desktop/client/src/App.jsx`)
- Desktop routes → Desktop API client: checks health (evidence: `Desktop/client/src/App.jsx`)
- Desktop routes → Desktop shell: renders (evidence: `Desktop/client/src/App.jsx`)
- Desktop routes → Dashboard: routes to (evidence: `Desktop/client/src/App.jsx`)
- Desktop routes → Patient search: routes to (evidence: `Desktop/client/src/App.jsx`)
- Desktop routes → Patient profile: routes to (evidence: `Desktop/client/src/App.jsx`)
- Desktop routes → Clinical and admin pages: routes to (evidence: `Desktop/client/src/App.jsx`)
- Patient search → Desktop API client: requests patients (evidence: `Desktop/client/src/pages/Search.jsx`)
- Dashboard → Desktop API client: loads data (evidence: `Desktop/client/src/pages/Dashboard.jsx`)
- Patient profile → Desktop API client: loads profile (evidence: `Desktop/client/src/pages/Profile.jsx`)
- Patient profile → Care summary: renders (evidence: `Desktop/client/src/pages/Profile.jsx`)
- Android app → App state: coordinates (evidence: `Mobile/app/src/main/java/ke/safescan/mobile/MainActivity.kt`)
- Android app → Scan and patient UI: displays (evidence: `Mobile/app/src/main/java/ke/safescan/mobile/MainActivity.kt`)
- Android app → NFC tag reader: enables reader (evidence: `Mobile/app/src/main/java/ke/safescan/mobile/MainActivity.kt`)
- App state → Repository interface: selects repository (evidence: `Mobile/app/src/main/java/ke/safescan/mobile/ui/AppViewModel.kt`)
- App state → Remote repository: uses remotely (evidence: `Mobile/app/src/main/java/ke/safescan/mobile/ui/AppViewModel.kt`)
- App state → Demo repository: uses in demo (evidence: `Mobile/app/src/main/java/ke/safescan/mobile/ui/AppViewModel.kt`)
- Remote repository → Repository interface: implements (evidence: `Mobile/app/src/main/java/ke/safescan/mobile/net/RemoteRepo.kt`)
- Demo repository → Repository interface: implements (evidence: `Mobile/app/src/main/java/ke/safescan/mobile/data/DemoRepo.kt`)
- Scan and patient UI → App state: uses state (evidence: `Mobile/app/src/main/java/ke/safescan/mobile/ui/MainScreen.kt`)
- Remote repository → HTTP API: calls API (evidence: `README.md`)
- Desktop API client → HTTP API: calls API
- HTTP API → Authentication: mounts routes (evidence: `Desktop/server/app.js`)
- HTTP API → Patient routes: mounts routes (evidence: `Desktop/server/app.js`)
- HTTP API → Scan verification: mounts routes (evidence: `Desktop/server/app.js`)
- HTTP API → Record routes: mounts routes (evidence: `Desktop/server/app.js`)
- HTTP API → Runtime configuration: reads settings (evidence: `Desktop/server/app.js`)
- Authentication → SQLite database: reads users (evidence: `Desktop/server/auth.js`)
- Patient routes → Patient and visit logic: delegates (evidence: `Desktop/server/routes/patients.js`)
- Patient routes → Profile assembly: uses profiles (evidence: `Desktop/server/routes/patients.js`)
- Patient routes → Identity matcher: matches identity (evidence: `Desktop/server/routes/patients.js`)
- Patient routes → Clinical records: uses records (evidence: `Desktop/server/routes/patients.js`)
- Patient and visit logic → SQLite database: reads and writes (evidence: `Desktop/server/services/patients.js`)
- Record routes → Patient and visit logic: uses patient logic (evidence: `Desktop/server/routes/records.js`)
- Record routes → Clinical records: delegates (evidence: `Desktop/server/routes/records.js`)
- Clinical records → SQLite database: persists records
- Profile assembly → Patient and visit logic: uses patient data (evidence: `Desktop/server/services/profile.js`)
- Profile assembly → Clinical records: uses records (evidence: `Desktop/server/services/profile.js`)
- Profile assembly → AI handover summary: uses summary (evidence: `Desktop/server/services/profile.js`)
- AI integration → AI handover summary: builds summaries (evidence: `Desktop/server/services/ai.js`)
