# mup-off/mhealth architecture

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

- Interactive diagram: https://gitdiagram.com/mup-off/mhealth
- Repository: https://github.com/mup-off/mhealth

## Overview

mHealth is a multilingual maternal-health mobile assistant backed by an Express API and PostgreSQL. The main user journey is account access, pregnancy-date tracking and week-aware advice; health workers also manage ANC appointments and visit records, while administrators manage workers and assignments. The graph preserves those distinct product areas and the shared API, authentication and database layers. Some mobile-to-API links reflect documented endpoints rather than inspected screen implementation; unsampled relationships are omitted where evidence is insufficient.

Main entry points: [`mobile/src/api.ts`](https://github.com/mup-off/mhealth/blob/main/mobile/src/api.ts) (API client), [`backend/src/app.ts`](https://github.com/mup-off/mhealth/blob/main/backend/src/app.ts) (REST API router), [`backend/src/config/db.ts`](https://github.com/mup-off/mhealth/blob/main/backend/src/config/db.ts) (PostgreSQL pool), [`mobile/app/login.tsx`](https://github.com/mup-off/mhealth/blob/main/mobile/app/login.tsx) (Sign-in and profile)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_mobile["Mobile experience"]
  node_auth_ui["Sign-in and profile<br/>[login.tsx]"]
  node_dashboard["Care dashboard<br/>[home.tsx]"]
  node_tracker_ui["Pregnancy tracker<br/>[tracker.tsx]"]
  node_tips_ui["Health tips<br/>[tips.tsx]"]
  node_appointments_ui["Appointment views<br/>[appointments.tsx]"]
  node_worker_ui["Worker workflows<br/>[worker.tsx]"]
  node_admin_ui["Admin and assignments<br/>[admin.tsx]"]
  node_reminders["Local reminders<br/>[notifications.ts]"]
  node_mobile_api["API client<br/>[api.ts]"]
  node_auth_storage["Token storage<br/>[storage.ts]"]
  node_localization["Language strings<br/>[i18n.ts]"]
end

subgraph group_api["API and domain"]
  node_api_app["REST API router<br/>[app.ts]"]
  node_auth_routes["Account access<br/>[auth.ts]"]
  node_user_routes["User and worker records<br/>[users.ts]"]
  node_pregnancy_routes["Pregnancy tracking<br/>[pregnancies.ts]"]
  node_tips_routes["Health advice<br/>[healthTips.ts]"]
  node_appointment_routes["ANC appointments<br/>[appointments.ts]"]
  node_admin_routes["Administration<br/>[admin.ts]"]
end

subgraph group_platform["Shared services"]
  node_auth_middleware["Token and role checks<br/>[auth.ts]"]
  node_postgres[("PostgreSQL pool<br/>[db.ts]")]
end

node_mother(("Mother"))
node_worker(("Health worker"))
node_admin_actor(("Administrator"))

node_mother -->|"signs in"| node_auth_ui
node_mother -->|"views care"| node_dashboard
node_mother -->|"sets dates"| node_tracker_ui
node_mother -->|"reads advice"| node_tips_ui
node_mother -->|"views visits"| node_appointments_ui
node_worker -->|"manages visits"| node_worker_ui
node_admin_actor -->|"manages assignments"| node_admin_ui
node_auth_ui -->|"requests API"| node_mobile_api
node_auth_ui -->|"stores token"| node_auth_storage
node_dashboard -->|"loads care data"| node_mobile_api
node_tracker_ui -->|"loads and saves"| node_mobile_api
node_tips_ui -->|"requests advice"| node_mobile_api
node_appointments_ui -->|"requests visits"| node_mobile_api
node_appointments_ui -->|"schedules alerts"| node_reminders
node_worker_ui -->|"requests workflows"| node_mobile_api
node_admin_ui -->|"requests administration"| node_mobile_api
node_mobile_api -->|"reads token"| node_auth_storage
node_mobile_api -->|"calls REST endpoints"| node_api_app
node_api_app -->|"routes auth"| node_auth_routes
node_api_app -->|"routes users"| node_user_routes
node_api_app -->|"routes pregnancies"| node_pregnancy_routes
node_api_app -->|"routes tips"| node_tips_routes
node_api_app -->|"routes appointments"| node_appointment_routes
node_api_app -->|"routes administration"| node_admin_routes
node_auth_routes -->|"creates tokens"| node_auth_middleware
node_auth_routes -->|"queries users"| node_postgres
node_user_routes -->|"queries records"| node_postgres
node_pregnancy_routes -->|"queries pregnancies"| node_postgres
node_tips_routes -->|"queries advice"| node_postgres
node_appointment_routes -->|"queries visits"| node_postgres
node_admin_routes -->|"queries administration data"| node_postgres
node_localization -->|"provides translations"| node_dashboard

click node_auth_ui "https://github.com/mup-off/mhealth/blob/main/mobile/app/login.tsx"
click node_dashboard "https://github.com/mup-off/mhealth/blob/main/mobile/app/home.tsx"
click node_tracker_ui "https://github.com/mup-off/mhealth/blob/main/mobile/app/tracker.tsx"
click node_tips_ui "https://github.com/mup-off/mhealth/blob/main/mobile/app/tips.tsx"
click node_appointments_ui "https://github.com/mup-off/mhealth/blob/main/mobile/app/appointments.tsx"
click node_worker_ui "https://github.com/mup-off/mhealth/blob/main/mobile/app/worker.tsx"
click node_admin_ui "https://github.com/mup-off/mhealth/blob/main/mobile/app/admin.tsx"
click node_reminders "https://github.com/mup-off/mhealth/blob/main/mobile/src/notifications.ts"
click node_mobile_api "https://github.com/mup-off/mhealth/blob/main/mobile/src/api.ts"
click node_auth_storage "https://github.com/mup-off/mhealth/blob/main/mobile/src/auth/storage.ts"
click node_localization "https://github.com/mup-off/mhealth/blob/main/mobile/src/i18n.ts"
click node_api_app "https://github.com/mup-off/mhealth/blob/main/backend/src/app.ts"
click node_auth_routes "https://github.com/mup-off/mhealth/blob/main/backend/src/routes/auth.ts"
click node_user_routes "https://github.com/mup-off/mhealth/blob/main/backend/src/routes/users.ts"
click node_pregnancy_routes "https://github.com/mup-off/mhealth/blob/main/backend/src/routes/pregnancies.ts"
click node_tips_routes "https://github.com/mup-off/mhealth/blob/main/backend/src/routes/healthTips.ts"
click node_appointment_routes "https://github.com/mup-off/mhealth/blob/main/backend/src/routes/appointments.ts"
click node_admin_routes "https://github.com/mup-off/mhealth/blob/main/backend/src/routes/admin.ts"
click node_auth_middleware "https://github.com/mup-off/mhealth/blob/main/backend/src/middleware/auth.ts"
click node_postgres "https://github.com/mup-off/mhealth/blob/main/backend/src/config/db.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_auth_ui,node_dashboard,node_tracker_ui,node_tips_ui,node_appointments_ui,node_worker_ui,node_admin_ui,node_reminders,node_mobile_api,node_auth_storage,node_localization toneBlue
class node_api_app,node_auth_routes,node_user_routes,node_pregnancy_routes,node_tips_routes,node_appointment_routes,node_admin_routes toneAmber
class node_auth_middleware,node_postgres toneMint
class node_mother,node_admin_actor toneIndigo
class node_worker toneRose
```

## Components

### Mobile experience

- [Sign-in and profile](https://github.com/mup-off/mhealth/blob/main/mobile/app/login.tsx): `mobile/app/login.tsx`
- [Care dashboard](https://github.com/mup-off/mhealth/blob/main/mobile/app/home.tsx): `mobile/app/home.tsx`
- [Pregnancy tracker](https://github.com/mup-off/mhealth/blob/main/mobile/app/tracker.tsx): `mobile/app/tracker.tsx`
- [Health tips](https://github.com/mup-off/mhealth/blob/main/mobile/app/tips.tsx): `mobile/app/tips.tsx`
- [Appointment views](https://github.com/mup-off/mhealth/blob/main/mobile/app/appointments.tsx): `mobile/app/appointments.tsx`
- [Worker workflows](https://github.com/mup-off/mhealth/blob/main/mobile/app/worker.tsx): `mobile/app/worker.tsx`
- [Admin and assignments](https://github.com/mup-off/mhealth/blob/main/mobile/app/admin.tsx): `mobile/app/admin.tsx`
- [Local reminders](https://github.com/mup-off/mhealth/blob/main/mobile/src/notifications.ts): `mobile/src/notifications.ts`
- [API client](https://github.com/mup-off/mhealth/blob/main/mobile/src/api.ts): `mobile/src/api.ts`
- [Token storage](https://github.com/mup-off/mhealth/blob/main/mobile/src/auth/storage.ts): `mobile/src/auth/storage.ts`
- [Language strings](https://github.com/mup-off/mhealth/blob/main/mobile/src/i18n.ts): `mobile/src/i18n.ts`

### API and domain

- [REST API router](https://github.com/mup-off/mhealth/blob/main/backend/src/app.ts): `backend/src/app.ts`
- [Account access](https://github.com/mup-off/mhealth/blob/main/backend/src/routes/auth.ts): `backend/src/routes/auth.ts`
- [User and worker records](https://github.com/mup-off/mhealth/blob/main/backend/src/routes/users.ts): `backend/src/routes/users.ts`
- [Pregnancy tracking](https://github.com/mup-off/mhealth/blob/main/backend/src/routes/pregnancies.ts): `backend/src/routes/pregnancies.ts`
- [Health advice](https://github.com/mup-off/mhealth/blob/main/backend/src/routes/healthTips.ts): `backend/src/routes/healthTips.ts`
- [ANC appointments](https://github.com/mup-off/mhealth/blob/main/backend/src/routes/appointments.ts): `backend/src/routes/appointments.ts`
- [Administration](https://github.com/mup-off/mhealth/blob/main/backend/src/routes/admin.ts): `backend/src/routes/admin.ts`

### Shared services

- [Token and role checks](https://github.com/mup-off/mhealth/blob/main/backend/src/middleware/auth.ts): `backend/src/middleware/auth.ts`
- [PostgreSQL pool](https://github.com/mup-off/mhealth/blob/main/backend/src/config/db.ts): `backend/src/config/db.ts`

### Other components

- **Mother**
- **Health worker**
- **Administrator**

## Connections

- Mother → Sign-in and profile: signs in (evidence: `README.md`)
- Mother → Care dashboard: views care (evidence: `README.md`)
- Mother → Pregnancy tracker: sets dates (evidence: `README.md`)
- Mother → Health tips: reads advice (evidence: `README.md`)
- Mother → Appointment views: views visits (evidence: `README.md`)
- Health worker → Worker workflows: manages visits (evidence: `README.md`)
- Administrator → Admin and assignments: manages assignments
- Sign-in and profile → API client: requests API (evidence: `mobile/app/login.tsx`)
- Sign-in and profile → Token storage: stores token (evidence: `README.md`)
- Care dashboard → API client: loads care data (evidence: `mobile/app/home.tsx`)
- Pregnancy tracker → API client: loads and saves (evidence: `mobile/app/tracker.tsx`)
- Health tips → API client: requests advice
- Appointment views → API client: requests visits (evidence: `mobile/app/appointments.tsx`)
- Appointment views → Local reminders: schedules alerts (evidence: `mobile/app/appointments.tsx`)
- Worker workflows → API client: requests workflows (evidence: `mobile/app/worker.tsx`)
- Admin and assignments → API client: requests administration (evidence: `mobile/app/admin.tsx`)
- API client → Token storage: reads token (evidence: `mobile/src/api.ts`)
- API client → REST API router: calls REST endpoints
- REST API router → Account access: routes auth (evidence: `backend/src/app.ts`)
- REST API router → User and worker records: routes users (evidence: `backend/src/app.ts`)
- REST API router → Pregnancy tracking: routes pregnancies (evidence: `backend/src/app.ts`)
- REST API router → Health advice: routes tips (evidence: `backend/src/app.ts`)
- REST API router → ANC appointments: routes appointments (evidence: `backend/src/app.ts`)
- REST API router → Administration: routes administration (evidence: `backend/src/app.ts`)
- Account access → Token and role checks: creates tokens (evidence: `backend/src/routes/auth.ts`)
- Account access → PostgreSQL pool: queries users (evidence: `backend/src/routes/auth.ts`)
- User and worker records → PostgreSQL pool: queries records (evidence: `backend/src/routes/users.ts`)
- Pregnancy tracking → PostgreSQL pool: queries pregnancies (evidence: `backend/src/routes/pregnancies.ts`)
- Health advice → PostgreSQL pool: queries advice (evidence: `backend/src/routes/healthTips.ts`)
- ANC appointments → PostgreSQL pool: queries visits (evidence: `backend/src/routes/appointments.ts`)
- Administration → PostgreSQL pool: queries administration data (evidence: `backend/src/routes/admin.ts`)
- Language strings → Care dashboard: provides translations (evidence: `mobile/app/home.tsx`)
