# simpledotorg/simple-server architecture

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

- Interactive diagram: https://gitdiagram.com/simpledotorg/simple-server
- Repository: https://github.com/simpledotorg/simple-server

## Overview

Simple Server is the backend for the Simple mobile app and population-health dashboards, supporting hypertension and diabetes care. The main workflow is a mobile client sending API requests or synchronizing patient data; Rails API controllers handle the request, with patient-care records and analytics/reporting as distinct domain stages. Admins also explore regional reports and download district data, while partner imports and asynchronous notifications provide separate capabilities. The sampled sources show report construction and routing, but not most API, import, or job internals; those links are therefore omitted or marked unverified.

Main entry points: [`config/routes.rb`](https://github.com/simpledotorg/simple-server/blob/master/config/routes.rb) (API Routing), [`app/controllers/api/v3`](https://github.com/simpledotorg/simple-server/tree/master/app/controllers/api/v3) (V3 API), [`app/controllers/api/v4`](https://github.com/simpledotorg/simple-server/tree/master/app/controllers/api/v4) (V4 API), [`app/controllers/reports/regions_controller.rb`](https://github.com/simpledotorg/simple-server/blob/master/app/controllers/reports/regions_controller.rb) (Regional Reports)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["App APIs"]
  node_api_routes["API Routing<br/>[routes.rb]"]
  node_api_v3["V3 API"]
  node_api_v4["V4 API"]
end

subgraph group_care["Patient Care"]
  node_patient_records["Patient Records<br/>[patient.rb]"]
  node_appointments["Appointments"]
  node_telehealth["Telehealth"]
  node_dr_rai["Dr Rai Plans"]
end

subgraph group_analytics["Analytics Reports"]
  node_reports_routes["Report Routing<br/>[routes.rb]"]
  node_region_reports["Regional Reports"]
  node_report_repository["Report Metrics<br/>[repository.rb]"]
  node_analytics_queries["Analytics Queries"]
  node_exports["District Exports<br/>[exporter.rb]"]
end

subgraph group_operations["Integrations Operations"]
  node_bulk_import["FHIR Bulk Import<br/>[importer.rb]"]
  node_background_jobs["Background Jobs"]
  node_messaging["SMS Messaging<br/>[channel.rb]"]
end

node_mobile(("Simple App"))
node_admin(("Dashboard Admin"))
node_database[("Application Database")]

node_mobile -.->|"requests"| node_api_routes
node_api_routes -->|"routes to"| node_api_v3
node_api_routes -->|"routes to"| node_api_v4
node_api_v3 -.->|"syncs records"| node_patient_records
node_api_v4 -.->|"manages records"| node_patient_records
node_api_routes -->|"routes to"| node_appointments
node_api_routes -->|"routes to"| node_telehealth
node_admin -->|"requests reports"| node_reports_routes
node_reports_routes -->|"routes to"| node_region_reports
node_region_reports -.->|"builds metrics"| node_report_repository
node_report_repository -->|"queries metrics"| node_analytics_queries
node_region_reports -->|"builds exports"| node_exports
node_api_routes -->|"routes to"| node_dr_rai
node_api_routes -.->|"accepts imports"| node_bulk_import
node_background_jobs -.->|"dispatches messages"| node_messaging
node_api_v3 -.->|"reads and writes"| node_database
node_api_v4 -.->|"reads and writes"| node_database
node_report_repository -.->|"queries data"| node_database

click node_api_routes "https://github.com/simpledotorg/simple-server/blob/master/config/routes.rb"
click node_api_v3 "https://github.com/simpledotorg/simple-server/tree/master/app/controllers/api/v3"
click node_api_v4 "https://github.com/simpledotorg/simple-server/tree/master/app/controllers/api/v4"
click node_patient_records "https://github.com/simpledotorg/simple-server/blob/master/app/models/patient.rb"
click node_appointments "https://github.com/simpledotorg/simple-server/blob/master/app/controllers/appointments_controller.rb"
click node_telehealth "https://github.com/simpledotorg/simple-server/blob/master/app/controllers/api/v4/teleconsultations_controller.rb"
click node_reports_routes "https://github.com/simpledotorg/simple-server/blob/master/config/routes.rb"
click node_region_reports "https://github.com/simpledotorg/simple-server/blob/master/app/controllers/reports/regions_controller.rb"
click node_report_repository "https://github.com/simpledotorg/simple-server/blob/master/app/models/reports/repository.rb"
click node_analytics_queries "https://github.com/simpledotorg/simple-server/tree/master/app/queries"
click node_exports "https://github.com/simpledotorg/simple-server/blob/master/app/exporters/monthly_district_report/exporter.rb"
click node_dr_rai "https://github.com/simpledotorg/simple-server/blob/master/app/controllers/dr_rai/action_plans_controller.rb"
click node_bulk_import "https://github.com/simpledotorg/simple-server/blob/master/app/services/bulk_api_import/importer.rb"
click node_background_jobs "https://github.com/simpledotorg/simple-server/tree/master/app/jobs"
click node_messaging "https://github.com/simpledotorg/simple-server/blob/master/app/services/messaging/channel.rb"

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_api_routes,node_api_v3,node_api_v4 toneBlue
class node_patient_records,node_appointments,node_telehealth,node_dr_rai,node_database toneAmber
class node_reports_routes,node_region_reports,node_report_repository,node_analytics_queries,node_exports toneMint
class node_bulk_import,node_background_jobs,node_messaging toneRose
class node_mobile,node_admin toneIndigo
```

## Components

### App APIs

- [API Routing](https://github.com/simpledotorg/simple-server/blob/master/config/routes.rb): `config/routes.rb`
- [V3 API](https://github.com/simpledotorg/simple-server/tree/master/app/controllers/api/v3): `app/controllers/api/v3`
- [V4 API](https://github.com/simpledotorg/simple-server/tree/master/app/controllers/api/v4): `app/controllers/api/v4`

### Patient Care

- [Patient Records](https://github.com/simpledotorg/simple-server/blob/master/app/models/patient.rb): `app/models/patient.rb`
- [Appointments](https://github.com/simpledotorg/simple-server/blob/master/app/controllers/appointments_controller.rb): `app/controllers/appointments_controller.rb`
- [Telehealth](https://github.com/simpledotorg/simple-server/blob/master/app/controllers/api/v4/teleconsultations_controller.rb): `app/controllers/api/v4/teleconsultations_controller.rb`
- [Dr Rai Plans](https://github.com/simpledotorg/simple-server/blob/master/app/controllers/dr_rai/action_plans_controller.rb): `app/controllers/dr_rai/action_plans_controller.rb`

### Analytics Reports

- [Report Routing](https://github.com/simpledotorg/simple-server/blob/master/config/routes.rb): `config/routes.rb`
- [Regional Reports](https://github.com/simpledotorg/simple-server/blob/master/app/controllers/reports/regions_controller.rb): `app/controllers/reports/regions_controller.rb`
- [Report Metrics](https://github.com/simpledotorg/simple-server/blob/master/app/models/reports/repository.rb): `app/models/reports/repository.rb`
- [Analytics Queries](https://github.com/simpledotorg/simple-server/tree/master/app/queries): `app/queries`
- [District Exports](https://github.com/simpledotorg/simple-server/blob/master/app/exporters/monthly_district_report/exporter.rb): `app/exporters/monthly_district_report/exporter.rb`

### Integrations Operations

- [FHIR Bulk Import](https://github.com/simpledotorg/simple-server/blob/master/app/services/bulk_api_import/importer.rb): `app/services/bulk_api_import/importer.rb`
- [Background Jobs](https://github.com/simpledotorg/simple-server/tree/master/app/jobs): `app/jobs`
- [SMS Messaging](https://github.com/simpledotorg/simple-server/blob/master/app/services/messaging/channel.rb): `app/services/messaging/channel.rb`

### Other components

- **Simple App**
- **Dashboard Admin**
- **Application Database**

## Connections

- Simple App → API Routing: requests
- API Routing → V3 API: routes to (evidence: `config/routes.rb`)
- API Routing → V4 API: routes to (evidence: `config/routes.rb`)
- V3 API → Patient Records: syncs records
- V4 API → Patient Records: manages records
- API Routing → Appointments: routes to (evidence: `config/routes.rb`)
- API Routing → Telehealth: routes to (evidence: `config/routes.rb`)
- Dashboard Admin → Report Routing: requests reports (evidence: `config/routes.rb`)
- Report Routing → Regional Reports: routes to (evidence: `config/routes.rb`)
- Regional Reports → Report Metrics: builds metrics
- Report Metrics → Analytics Queries: queries metrics (evidence: `app/models/reports/repository.rb`)
- Regional Reports → District Exports: builds exports (evidence: `app/controllers/reports/regions_controller.rb`)
- API Routing → Dr Rai Plans: routes to (evidence: `config/routes.rb`)
- API Routing → FHIR Bulk Import: accepts imports
- Background Jobs → SMS Messaging: dispatches messages
- V3 API → Application Database: reads and writes
- V4 API → Application Database: reads and writes
- Report Metrics → Application Database: queries data
