# arn101/publichealthmap architecture

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

- Interactive diagram: https://gitdiagram.com/arn101/publichealthmap
- Repository: https://github.com/arn101/publichealthmap

## Overview

#### Purpose and Topology
PublicHealthMap is a Bangladesh critical-disease registry. It combines a React/Vite single-page client, Express API, and local Oracle Database with PL/SQL for transactional registry operations, surveillance aggregation, and research exports. Root development orchestration is `run-dev.js`; API and client run on ports 5000 and 3000 respectively.

#### Application Entry Points
- Backend HTTP service: `backend/server.js`
- React bootstrap and application shell: `frontend/src/main.jsx`, `frontend/src/App.jsx`
- Database connection layer: `backend/db.js`
- Authentication and role enforcement: `backend/auth.js`

The frontend communicates with the Express API; the API owns Oracle access and does not expose database connectivity to clients.

#### Role-Separated Workflows
The system has three privileged operating domains:
- Hospital staff locate/create patients and submit disease-specific cases through `frontend/src/pages/HospitalPortal.jsx`.
- Researchers request filtered, anonymized data exports through `frontend/src/pages/ResearcherPortal.jsx`.
- Ministry administrators approve organizations, manage diseases, and configure forms through `frontend/src/pages/AdminPortal.jsx`.

Authentication is JWT/credential-based and Oracle-backed, with environment-provided Oracle and JWT/admin secrets via `backend/.env.template`.

#### Registry and Validation Boundary
Patient identity validation is implemented on both sides of the API boundary: `backend/patient-validation.js` and `frontend/src/lib/patientValidation.js`. This supports Bangladesh NID, birth-certificate, and mobile formats while preserving server-side enforcement. Disease and field catalogs centralize registry/form definitions in `backend/disease-catalog.js` and `backend/field-catalog.js`; the hospital workflow renders disease-specific case capture from these definitions and database form setup.

#### Oracle Schema and PL/SQL Layer
Oracle is a material part of application behavior, not merely persistence. Schema bootstrap begins at `schema.sql` and is operationalized by:
- `backend/scripts/create-tables.js`
- `backend/scripts/create-triggers.js`
- `backend/scripts/create-compound-trigger.js`
- `backend/scripts/create-indexes.js`

Packages and procedures establish database-owned case handling, surveillance statistics, and researcher export behavior: `backend/scripts/setup-case-pkg.js`, `backend/scripts/setup-stats-proc.js`, and `backend/scripts/setup-research-pkg.js`. Triggers and packages form the integrity/aggregation boundary beneath Express.

#### Surveillance and Public Presentation
The client includes public disease surveillance with category, disease, and geographic filters, choropleth visualization, charts, and rankings. Geographic assets are bundled locally, notably `frontend/src/data/bgd_adm1.geojson`, `frontend/src/data/_cand.geojson`, and `frontend/src/data/bangladeshDivisions.js`. Visualization components reside in `frontend/src/components/Charts.jsx`; API-backed aggregate results are expected to originate from Oracle statistics procedures.

#### Provisioning, Migration, and Demo Data
Database setup is script-driven and ordered for a fresh Oracle schema. Domain taxonomy/forms and body imagery are provisioned by `backend/scripts/setup-disease-taxonomy.js`, `backend/scripts/setup-disease-forms.js`, and `backend/scripts/setup-body-images.js`. Data/image and approval evolution are handled through `backend/scripts/migrate-images-to-blob.js` and `backend/scripts/migrate-hospital-approval.js`. `backend/scripts/seed-demo-data.js` populates district hospitals, patients, skewed disease cases, research organizations, and refreshed statistics.

Main entry points: [`backend/server.js`](https://github.com/arn101/publichealthmap/blob/main/backend/server.js) (HTTP API), [`schema.sql`](https://github.com/arn101/publichealthmap/blob/main/schema.sql) (Oracle database), [`frontend/src/App.jsx`](https://github.com/arn101/publichealthmap/blob/main/frontend/src/App.jsx) (Application shell), [`frontend/src/pages/HospitalPortal.jsx`](https://github.com/arn101/publichealthmap/blob/main/frontend/src/pages/HospitalPortal.jsx) (Hospital case workflow)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["React client"]
  node_client_bootstrap["Client bootstrap<br/>React entry<br/>[main.jsx]"]
  node_app_shell["Application shell<br/>React routing<br/>[App.jsx]"]
  node_hospital_portal["Hospital case workflow<br/>staff portal<br/>[HospitalPortal.jsx]"]
  node_research_portal["Research export workflow<br/>research portal"]
  node_admin_portal["Administration workflow<br/>admin portal<br/>[AdminPortal.jsx]"]
  node_client_validation["Client identity validation<br/>validation library"]
  node_surveillance_ui["Public surveillance UI<br/>map and charts<br/>[Charts.jsx]"]
  node_geography["Bangladesh geography<br/>local map assets<br/>[bgd_adm1.geojson]"]
end

subgraph group_api["Express API"]
  node_api_server["HTTP API<br/>Express service<br/>[server.js]"]
  node_auth["Authentication and roles<br/>JWT auth<br/>[auth.js]"]
  node_server_validation["Server identity validation<br/>validation boundary"]
  node_registry_catalogs["Disease and field catalogs<br/>registry definitions<br/>[disease-catalog.js]"]
  node_oracle_connection["Oracle connection layer<br/>database access<br/>[db.js]"]
end

subgraph group_oracle["Oracle registry"]
  node_oracle_db[("Oracle database<br/>transactional registry<br/>[schema.sql]")]
  node_plsql_case["Case integrity package<br/>PL/SQL package<br/>[setup-case-pkg.js]"]
  node_plsql_stats["Surveillance statistics<br/>PL/SQL procedure"]
  node_plsql_research["Research export package<br/>PL/SQL package"]
end

subgraph group_provisioning["Database provisioning"]
  node_schema_setup["Schema and trigger setup<br/>bootstrap scripts<br/>[create-tables.js]"]
  node_domain_provisioning["Domain form provisioning<br/>setup scripts"]
  node_migration_seed["Migrations and demo seed<br/>data evolution<br/>[seed-demo-data.js]"]
end

node_dev{{"Development runner<br/>Node orchestration<br/>[run-dev.js]"}}

node_dev -->|"starts client"| node_client_bootstrap
node_dev -->|"starts API"| node_api_server
node_client_bootstrap -->|"mounts"| node_app_shell
node_app_shell -->|"routes to"| node_hospital_portal
node_app_shell -->|"routes to"| node_research_portal
node_app_shell -->|"routes to"| node_admin_portal
node_hospital_portal -->|"validates identity"| node_client_validation
node_hospital_portal -->|"patient and case requests"| node_api_server
node_research_portal -->|"export requests"| node_api_server
node_admin_portal -->|"management requests"| node_api_server
node_surveillance_ui -->|"renders geography"| node_geography
node_surveillance_ui -->|"aggregate queries"| node_api_server
node_api_server -->|"authorizes"| node_auth
node_api_server -->|"enforces validation"| node_server_validation
node_api_server -->|"uses definitions"| node_registry_catalogs
node_api_server -->|"queries through"| node_oracle_connection
node_oracle_connection -->|"connects to"| node_oracle_db
node_oracle_db -->|"executes"| node_plsql_case
node_oracle_db -->|"executes"| node_plsql_stats
node_oracle_db -->|"executes"| node_plsql_research
node_schema_setup -->|"bootstraps schema"| node_oracle_db
node_domain_provisioning -->|"provisions forms"| node_oracle_db
node_migration_seed -->|"evolves and populates"| node_oracle_db
node_plsql_stats -.->|"aggregate results"| node_surveillance_ui
node_plsql_research -.->|"anonymized exports"| node_research_portal

click node_dev "https://github.com/arn101/publichealthmap/blob/main/run-dev.js"
click node_client_bootstrap "https://github.com/arn101/publichealthmap/blob/main/frontend/src/main.jsx"
click node_app_shell "https://github.com/arn101/publichealthmap/blob/main/frontend/src/App.jsx"
click node_hospital_portal "https://github.com/arn101/publichealthmap/blob/main/frontend/src/pages/HospitalPortal.jsx"
click node_research_portal "https://github.com/arn101/publichealthmap/blob/main/frontend/src/pages/ResearcherPortal.jsx"
click node_admin_portal "https://github.com/arn101/publichealthmap/blob/main/frontend/src/pages/AdminPortal.jsx"
click node_client_validation "https://github.com/arn101/publichealthmap/blob/main/frontend/src/lib/patientValidation.js"
click node_surveillance_ui "https://github.com/arn101/publichealthmap/blob/main/frontend/src/components/Charts.jsx"
click node_geography "https://github.com/arn101/publichealthmap/blob/main/frontend/src/data/bgd_adm1.geojson"
click node_api_server "https://github.com/arn101/publichealthmap/blob/main/backend/server.js"
click node_auth "https://github.com/arn101/publichealthmap/blob/main/backend/auth.js"
click node_server_validation "https://github.com/arn101/publichealthmap/blob/main/backend/patient-validation.js"
click node_registry_catalogs "https://github.com/arn101/publichealthmap/blob/main/backend/disease-catalog.js"
click node_oracle_connection "https://github.com/arn101/publichealthmap/blob/main/backend/db.js"
click node_oracle_db "https://github.com/arn101/publichealthmap/blob/main/schema.sql"
click node_plsql_case "https://github.com/arn101/publichealthmap/blob/main/backend/scripts/setup-case-pkg.js"
click node_plsql_stats "https://github.com/arn101/publichealthmap/blob/main/backend/scripts/setup-stats-proc.js"
click node_plsql_research "https://github.com/arn101/publichealthmap/blob/main/backend/scripts/setup-research-pkg.js"
click node_schema_setup "https://github.com/arn101/publichealthmap/blob/main/backend/scripts/create-tables.js"
click node_domain_provisioning "https://github.com/arn101/publichealthmap/blob/main/backend/scripts/setup-disease-taxonomy.js"
click node_migration_seed "https://github.com/arn101/publichealthmap/blob/main/backend/scripts/seed-demo-data.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_client_bootstrap,node_app_shell,node_hospital_portal,node_research_portal,node_admin_portal,node_client_validation,node_surveillance_ui,node_geography toneBlue
class node_api_server,node_auth,node_server_validation,node_registry_catalogs,node_oracle_connection toneAmber
class node_oracle_db,node_plsql_case,node_plsql_stats,node_plsql_research toneMint
class node_schema_setup,node_domain_provisioning,node_migration_seed toneRose
class node_dev toneNeutral
```

## Components

### React client

- [Client bootstrap](https://github.com/arn101/publichealthmap/blob/main/frontend/src/main.jsx): React entry · `frontend/src/main.jsx`
- [Application shell](https://github.com/arn101/publichealthmap/blob/main/frontend/src/App.jsx): React routing · `frontend/src/App.jsx`
- [Hospital case workflow](https://github.com/arn101/publichealthmap/blob/main/frontend/src/pages/HospitalPortal.jsx): staff portal · Finds patients and submits disease-specific cases. · `frontend/src/pages/HospitalPortal.jsx`
- [Research export workflow](https://github.com/arn101/publichealthmap/blob/main/frontend/src/pages/ResearcherPortal.jsx): research portal · Requests filtered anonymized exports. · `frontend/src/pages/ResearcherPortal.jsx`
- [Administration workflow](https://github.com/arn101/publichealthmap/blob/main/frontend/src/pages/AdminPortal.jsx): admin portal · Manages approvals, diseases, and forms. · `frontend/src/pages/AdminPortal.jsx`
- [Client identity validation](https://github.com/arn101/publichealthmap/blob/main/frontend/src/lib/patientValidation.js): validation library · `frontend/src/lib/patientValidation.js`
- [Public surveillance UI](https://github.com/arn101/publichealthmap/blob/main/frontend/src/components/Charts.jsx): map and charts · Filters and visualizes aggregate disease statistics. · `frontend/src/components/Charts.jsx`
- [Bangladesh geography](https://github.com/arn101/publichealthmap/blob/main/frontend/src/data/bgd_adm1.geojson): local map assets · `frontend/src/data/bgd_adm1.geojson`

### Express API

- [HTTP API](https://github.com/arn101/publichealthmap/blob/main/backend/server.js): Express service · Owns all client access to Oracle. · `backend/server.js`
- [Authentication and roles](https://github.com/arn101/publichealthmap/blob/main/backend/auth.js): JWT auth · Oracle-backed credentials enforce privileged domains. · `backend/auth.js`
- [Server identity validation](https://github.com/arn101/publichealthmap/blob/main/backend/patient-validation.js): validation boundary · Enforces NID, birth-certificate, and mobile formats. · `backend/patient-validation.js`
- [Disease and field catalogs](https://github.com/arn101/publichealthmap/blob/main/backend/disease-catalog.js): registry definitions · Centralizes disease and form-field definitions. · `backend/disease-catalog.js`
- [Oracle connection layer](https://github.com/arn101/publichealthmap/blob/main/backend/db.js): database access · `backend/db.js`

### Oracle registry

- [Oracle database](https://github.com/arn101/publichealthmap/blob/main/schema.sql): transactional registry · Stores identities, cases, organizations, forms, and aggregates. · `schema.sql`
- [Case integrity package](https://github.com/arn101/publichealthmap/blob/main/backend/scripts/setup-case-pkg.js): PL/SQL package · Database-owned case handling and integrity boundary. · `backend/scripts/setup-case-pkg.js`
- [Surveillance statistics](https://github.com/arn101/publichealthmap/blob/main/backend/scripts/setup-stats-proc.js): PL/SQL procedure · Produces aggregate results for surveillance. · `backend/scripts/setup-stats-proc.js`
- [Research export package](https://github.com/arn101/publichealthmap/blob/main/backend/scripts/setup-research-pkg.js): PL/SQL package · Produces filtered anonymized researcher exports. · `backend/scripts/setup-research-pkg.js`

### Database provisioning

- [Schema and trigger setup](https://github.com/arn101/publichealthmap/blob/main/backend/scripts/create-tables.js): bootstrap scripts · Creates tables, triggers, compound trigger, and indexes. · `backend/scripts/create-tables.js`
- [Domain form provisioning](https://github.com/arn101/publichealthmap/blob/main/backend/scripts/setup-disease-taxonomy.js): setup scripts · Provisions taxonomy, disease forms, and body imagery. · `backend/scripts/setup-disease-taxonomy.js`
- [Migrations and demo seed](https://github.com/arn101/publichealthmap/blob/main/backend/scripts/seed-demo-data.js): data evolution · Migrates images and approvals, then seeds demo registry data. · `backend/scripts/seed-demo-data.js`

### Other components

- [Development runner](https://github.com/arn101/publichealthmap/blob/main/run-dev.js): Node orchestration · Starts the API and Vite client. · `run-dev.js`

## Connections

- Development runner → Client bootstrap: starts client
- Development runner → HTTP API: starts API
- Client bootstrap → Application shell: mounts
- Application shell → Hospital case workflow: routes to
- Application shell → Research export workflow: routes to
- Application shell → Administration workflow: routes to
- Hospital case workflow → Client identity validation: validates identity
- Hospital case workflow → HTTP API: patient and case requests
- Research export workflow → HTTP API: export requests
- Administration workflow → HTTP API: management requests
- Public surveillance UI → Bangladesh geography: renders geography
- Public surveillance UI → HTTP API: aggregate queries
- HTTP API → Authentication and roles: authorizes
- HTTP API → Server identity validation: enforces validation
- HTTP API → Disease and field catalogs: uses definitions
- HTTP API → Oracle connection layer: queries through
- Oracle connection layer → Oracle database: connects to
- Oracle database → Case integrity package: executes
- Oracle database → Surveillance statistics: executes
- Oracle database → Research export package: executes
- Schema and trigger setup → Oracle database: bootstraps schema
- Domain form provisioning → Oracle database: provisions forms
- Migrations and demo seed → Oracle database: evolves and populates
- Surveillance statistics → Public surveillance UI: aggregate results
- Research export package → Research export workflow: anonymized exports
