# karthikdavuluri/asha architecture

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

- Interactive diagram: https://gitdiagram.com/karthikdavuluri/asha
- Repository: https://github.com/karthikdavuluri/asha

## Overview

ASHA is an offline-first companion for frontline health workers, backed by an optional FastAPI server. The main documented workflow is recording household visits offline and synchronizing them with the server; related server capabilities cover referrals, facility reports, and protocol-based health questions with deterministic safety escalation. The graph preserves major backend domains and central indexed modules. Several routes and services were not sampled, so their connections are omitted or marked unverified rather than inferred.

Main entry points: [`health-worker-backend/app/api/v1/router.py`](https://github.com/karthikdavuluri/asha/blob/main/health-worker-backend/app/api/v1/router.py) (API routes), [`health-worker-backend/app/services/synchronization/service.py`](https://github.com/karthikdavuluri/asha/blob/main/health-worker-backend/app/services/synchronization/service.py) (Synchronization), [`health-worker-backend/app/services/visits/service.py`](https://github.com/karthikdavuluri/asha/blob/main/health-worker-backend/app/services/visits/service.py) (Visits and follow-up), [`health-worker-backend/app/services/referrals/service.py`](https://github.com/karthikdavuluri/asha/blob/main/health-worker-backend/app/services/referrals/service.py) (Referrals)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Worker app"]
  node_app["Offline companion"]
end

subgraph group_api["API and access"]
  node_server["FastAPI server<br/>[main.py]"]
  node_api_router["API routes<br/>[router.py]"]
end

subgraph group_records["Care records"]
  node_households["Households<br/>[service.py]"]
  node_visits["Visits and follow-up<br/>[service.py]"]
  node_referrals["Referrals<br/>[service.py]"]
end

subgraph group_knowledge["Health guidance"]
  node_qa["Health Q&amp;A<br/>[orchestrator.py]"]
  node_retrieval["Protocol retrieval<br/>[service.py]"]
  node_safety["Safety escalation<br/>[engine.py]"]
  node_protocol_import["Protocol import<br/>[importer.py]"]
end

subgraph group_operations["Sync and reporting"]
  node_sync["Synchronization<br/>[service.py]"]
  node_reports["Facility reports<br/>[service.py]"]
  node_dataset_import["Dataset import<br/>[importer.py]"]
  node_manifest["Dataset manifest<br/>[manifest.py]"]
end

subgraph group_foundation["Shared foundations"]
  node_database[("Application database<br/>[base.py]")]
  node_db_session["Database sessions<br/>[session.py]"]
  node_config["Configuration<br/>[config.py]"]
  node_principal["Worker identity<br/>[principal.py]"]
  node_domain["Domain types<br/>[domain.py]"]
  node_schemas["Domain schemas<br/>[domain.py]"]
  node_audit["Audit records<br/>[audit.py]"]
  node_common["Service helpers<br/>[_common.py]"]
  node_text["Text normalization<br/>[text.py]"]
end

node_worker(("ASHA / ANM worker"))

node_worker -->|"uses"| node_app
node_app -.->|"optionally syncs"| node_server
node_server -->|"mounts"| node_api_router
node_api_router -.->|"routes to"| node_sync
node_api_router -.->|"routes to"| node_qa
node_api_router -.->|"routes to"| node_households
node_api_router -.->|"routes to"| node_visits
node_api_router -.->|"routes to"| node_referrals
node_api_router -.->|"routes to"| node_reports
node_qa -->|"queries"| node_retrieval
node_qa -->|"checks safety"| node_safety
node_retrieval -->|"normalizes text"| node_text
node_safety -.->|"normalizes text"| node_text
node_sync -->|"creates records"| node_households
node_sync -->|"creates records"| node_visits
node_sync -->|"creates records"| node_referrals
node_visits -->|"loads household"| node_households
node_visits -->|"records changes"| node_audit
node_referrals -.->|"records changes"| node_audit
node_reports -->|"reads and saves"| node_database
node_dataset_import -->|"loads datasets"| node_manifest
node_dataset_import -->|"imports records"| node_database
node_retrieval -->|"loads passages"| node_database
node_db_session -->|"reads settings"| node_config
node_server -->|"loads settings"| node_config
node_visits -.->|"uses helpers"| node_common
node_referrals -.->|"uses helpers"| node_common
node_sync -->|"validates payloads"| node_schemas
node_referrals -.->|"checks access"| node_principal
node_protocol_import -.->|"imports protocols"| node_database

click node_app "https://github.com/karthikdavuluri/asha/tree/main/health-worker-app"
click node_server "https://github.com/karthikdavuluri/asha/blob/main/health-worker-backend/app/main.py"
click node_api_router "https://github.com/karthikdavuluri/asha/blob/main/health-worker-backend/app/api/v1/router.py"
click node_households "https://github.com/karthikdavuluri/asha/blob/main/health-worker-backend/app/services/households/service.py"
click node_visits "https://github.com/karthikdavuluri/asha/blob/main/health-worker-backend/app/services/visits/service.py"
click node_referrals "https://github.com/karthikdavuluri/asha/blob/main/health-worker-backend/app/services/referrals/service.py"
click node_qa "https://github.com/karthikdavuluri/asha/blob/main/health-worker-backend/app/services/health_qa/orchestrator.py"
click node_retrieval "https://github.com/karthikdavuluri/asha/blob/main/health-worker-backend/app/services/protocol_retrieval/service.py"
click node_safety "https://github.com/karthikdavuluri/asha/blob/main/health-worker-backend/app/services/safety/engine.py"
click node_protocol_import "https://github.com/karthikdavuluri/asha/blob/main/health-worker-backend/app/services/protocol_import/importer.py"
click node_sync "https://github.com/karthikdavuluri/asha/blob/main/health-worker-backend/app/services/synchronization/service.py"
click node_reports "https://github.com/karthikdavuluri/asha/blob/main/health-worker-backend/app/services/reports/service.py"
click node_dataset_import "https://github.com/karthikdavuluri/asha/blob/main/health-worker-backend/app/services/dataset_import/importer.py"
click node_manifest "https://github.com/karthikdavuluri/asha/blob/main/health-worker-backend/app/services/dataset_import/manifest.py"
click node_database "https://github.com/karthikdavuluri/asha/blob/main/health-worker-backend/app/db/base.py"
click node_db_session "https://github.com/karthikdavuluri/asha/blob/main/health-worker-backend/app/db/session.py"
click node_config "https://github.com/karthikdavuluri/asha/blob/main/health-worker-backend/app/core/config.py"
click node_principal "https://github.com/karthikdavuluri/asha/blob/main/health-worker-backend/app/core/principal.py"
click node_domain "https://github.com/karthikdavuluri/asha/blob/main/health-worker-backend/app/domain.py"
click node_schemas "https://github.com/karthikdavuluri/asha/blob/main/health-worker-backend/app/schemas/domain.py"
click node_audit "https://github.com/karthikdavuluri/asha/blob/main/health-worker-backend/app/repositories/audit.py"
click node_common "https://github.com/karthikdavuluri/asha/blob/main/health-worker-backend/app/services/_common.py"
click node_text "https://github.com/karthikdavuluri/asha/blob/main/health-worker-backend/app/services/text.py"

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_app toneBlue
class node_server,node_api_router toneAmber
class node_households,node_visits,node_referrals toneMint
class node_qa,node_retrieval,node_safety,node_protocol_import,node_worker toneRose
class node_sync,node_reports,node_dataset_import,node_manifest toneIndigo
class node_database,node_db_session,node_config,node_principal,node_domain,node_schemas,node_audit,node_common,node_text toneTeal
```

## Components

### Worker app

- [Offline companion](https://github.com/karthikdavuluri/asha/tree/main/health-worker-app): `health-worker-app`

### API and access

- [FastAPI server](https://github.com/karthikdavuluri/asha/blob/main/health-worker-backend/app/main.py): `health-worker-backend/app/main.py`
- [API routes](https://github.com/karthikdavuluri/asha/blob/main/health-worker-backend/app/api/v1/router.py): `health-worker-backend/app/api/v1/router.py`

### Care records

- [Households](https://github.com/karthikdavuluri/asha/blob/main/health-worker-backend/app/services/households/service.py): `health-worker-backend/app/services/households/service.py`
- [Visits and follow-up](https://github.com/karthikdavuluri/asha/blob/main/health-worker-backend/app/services/visits/service.py): `health-worker-backend/app/services/visits/service.py`
- [Referrals](https://github.com/karthikdavuluri/asha/blob/main/health-worker-backend/app/services/referrals/service.py): `health-worker-backend/app/services/referrals/service.py`

### Health guidance

- [Health Q&A](https://github.com/karthikdavuluri/asha/blob/main/health-worker-backend/app/services/health_qa/orchestrator.py): `health-worker-backend/app/services/health_qa/orchestrator.py`
- [Protocol retrieval](https://github.com/karthikdavuluri/asha/blob/main/health-worker-backend/app/services/protocol_retrieval/service.py): `health-worker-backend/app/services/protocol_retrieval/service.py`
- [Safety escalation](https://github.com/karthikdavuluri/asha/blob/main/health-worker-backend/app/services/safety/engine.py): `health-worker-backend/app/services/safety/engine.py`
- [Protocol import](https://github.com/karthikdavuluri/asha/blob/main/health-worker-backend/app/services/protocol_import/importer.py): `health-worker-backend/app/services/protocol_import/importer.py`

### Sync and reporting

- [Synchronization](https://github.com/karthikdavuluri/asha/blob/main/health-worker-backend/app/services/synchronization/service.py): `health-worker-backend/app/services/synchronization/service.py`
- [Facility reports](https://github.com/karthikdavuluri/asha/blob/main/health-worker-backend/app/services/reports/service.py): `health-worker-backend/app/services/reports/service.py`
- [Dataset import](https://github.com/karthikdavuluri/asha/blob/main/health-worker-backend/app/services/dataset_import/importer.py): `health-worker-backend/app/services/dataset_import/importer.py`
- [Dataset manifest](https://github.com/karthikdavuluri/asha/blob/main/health-worker-backend/app/services/dataset_import/manifest.py): `health-worker-backend/app/services/dataset_import/manifest.py`

### Shared foundations

- [Application database](https://github.com/karthikdavuluri/asha/blob/main/health-worker-backend/app/db/base.py): `health-worker-backend/app/db/base.py`
- [Database sessions](https://github.com/karthikdavuluri/asha/blob/main/health-worker-backend/app/db/session.py): `health-worker-backend/app/db/session.py`
- [Configuration](https://github.com/karthikdavuluri/asha/blob/main/health-worker-backend/app/core/config.py): `health-worker-backend/app/core/config.py`
- [Worker identity](https://github.com/karthikdavuluri/asha/blob/main/health-worker-backend/app/core/principal.py): `health-worker-backend/app/core/principal.py`
- [Domain types](https://github.com/karthikdavuluri/asha/blob/main/health-worker-backend/app/domain.py): `health-worker-backend/app/domain.py`
- [Domain schemas](https://github.com/karthikdavuluri/asha/blob/main/health-worker-backend/app/schemas/domain.py): `health-worker-backend/app/schemas/domain.py`
- [Audit records](https://github.com/karthikdavuluri/asha/blob/main/health-worker-backend/app/repositories/audit.py): `health-worker-backend/app/repositories/audit.py`
- [Service helpers](https://github.com/karthikdavuluri/asha/blob/main/health-worker-backend/app/services/_common.py): `health-worker-backend/app/services/_common.py`
- [Text normalization](https://github.com/karthikdavuluri/asha/blob/main/health-worker-backend/app/services/text.py): `health-worker-backend/app/services/text.py`

### Other components

- **ASHA / ANM worker**

## Connections

- ASHA / ANM worker → Offline companion: uses
- Offline companion → FastAPI server: optionally syncs
- FastAPI server → API routes: mounts (evidence: `health-worker-backend/app/main.py`)
- API routes → Synchronization: routes to
- API routes → Health Q&A: routes to
- API routes → Households: routes to
- API routes → Visits and follow-up: routes to
- API routes → Referrals: routes to
- API routes → Facility reports: routes to
- Health Q&A → Protocol retrieval: queries (evidence: `health-worker-backend/app/services/health_qa/orchestrator.py`)
- Health Q&A → Safety escalation: checks safety (evidence: `health-worker-backend/app/services/health_qa/orchestrator.py`)
- Protocol retrieval → Text normalization: normalizes text (evidence: `health-worker-backend/app/services/protocol_retrieval/service.py`)
- Safety escalation → Text normalization: normalizes text (evidence: `health-worker-backend/app/services/safety/engine.py`)
- Synchronization → Households: creates records (evidence: `health-worker-backend/app/services/synchronization/service.py`)
- Synchronization → Visits and follow-up: creates records (evidence: `health-worker-backend/app/services/synchronization/service.py`)
- Synchronization → Referrals: creates records (evidence: `health-worker-backend/app/services/synchronization/service.py`)
- Visits and follow-up → Households: loads household (evidence: `health-worker-backend/app/services/visits/service.py`)
- Visits and follow-up → Audit records: records changes (evidence: `health-worker-backend/app/services/visits/service.py`)
- Referrals → Audit records: records changes (evidence: `health-worker-backend/app/services/referrals/service.py`)
- Facility reports → Application database: reads and saves (evidence: `health-worker-backend/app/services/reports/service.py`)
- Dataset import → Dataset manifest: loads datasets (evidence: `health-worker-backend/app/services/dataset_import/importer.py`)
- Dataset import → Application database: imports records (evidence: `health-worker-backend/app/services/dataset_import/importer.py`)
- Protocol retrieval → Application database: loads passages (evidence: `health-worker-backend/app/services/protocol_retrieval/service.py`)
- Database sessions → Configuration: reads settings (evidence: `health-worker-backend/app/db/session.py`)
- FastAPI server → Configuration: loads settings (evidence: `health-worker-backend/app/main.py`)
- Visits and follow-up → Service helpers: uses helpers (evidence: `health-worker-backend/app/services/visits/service.py`)
- Referrals → Service helpers: uses helpers (evidence: `health-worker-backend/app/services/referrals/service.py`)
- Synchronization → Domain schemas: validates payloads (evidence: `health-worker-backend/app/services/synchronization/service.py`)
- Referrals → Worker identity: checks access (evidence: `health-worker-backend/app/services/referrals/service.py`)
- Protocol import → Application database: imports protocols
