# pranayagrawal2116/abdm_yashfeen architecture

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

- Interactive diagram: https://gitdiagram.com/pranayagrawal2116/abdm_yashfeen
- Repository: https://github.com/pranayagrawal2116/abdm_yashfeen

## Overview

Sarita is a healthcare-record and ABDM integration backend, with M1-style patient/facility workflows and separate M2 and M3 integration flows. Users and ABDM callbacks enter through the Express application and API routes; the backend handles identity/linking, consent, and health-information transfer, with FHIR document construction and patient-data storage supporting those flows. M2 callback/consent and M3 consent paths are distinct. The README provides no architectural detail, and several subsystems are unsampled; those are included where the tree identifies them, without asserting unverified call relationships.

Main entry points: [`backend/m2/transfer/M2DataTransferManager.js`](https://github.com/pranayagrawal2116/abdm_yashfeen/blob/main/backend/m2/transfer/M2DataTransferManager.js) (M2 Data Transfer), [`backend/m2/consent/M2ConsentManager.js`](https://github.com/pranayagrawal2116/abdm_yashfeen/blob/main/backend/m2/consent/M2ConsentManager.js) (M2 Consent Manager), [`backend/app.js`](https://github.com/pranayagrawal2116/abdm_yashfeen/blob/main/backend/app.js) (Express Application), [`backend/m2/routes`](https://github.com/pranayagrawal2116/abdm_yashfeen/tree/main/backend/m2/routes) (M2 API Routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and Linking"]
  node_app["Express Application<br/>[app.js]"]
  node_m1routes["M1 API Routes"]
  node_linking["HIP Linking"]
  node_consentapi["Consent API"]
  node_gatewayservice["Gateway Client<br/>[gatewayService.js]"]
end

subgraph group_m2["ABDM M2"]
  node_m2routes["M2 API Routes"]
  node_m2consent["M2 Consent Manager"]
  node_m2callback["M2 Callback Manager"]
  node_m2transfer["M2 Data Transfer"]
  node_m2hi["Health Information Requests"]
  node_m2tokens["M2 Token Manager<br/>[M2TokenManager.js]"]
  node_m2crypto["M2 Encryption"]
end

subgraph group_m3["ABDM M3"]
  node_m3routes["M3 API Routes"]
  node_m3consent["M3 Consent Service"]
  node_m3callback["M3 Callback Controller"]
  node_m3tokens["M3 Token Manager<br/>[M3TokenManager.js]"]
end

subgraph group_records["Records and Persistence"]
  node_m2tx[("M2 Transactions")]
  node_fhir["FHIR Builders"]
  node_patientstorage[("M2 Patient Storage")]
  node_m3storage[("M3 Patient Storage")]
  node_m3consentstore[("M3 Consent Store<br/>[M3ConsentStore.js]")]
end

node_user(("Patient / Operator"))
node_gateway{{"ABDM Gateway"}}

node_user -->|"sends requests"| node_app
node_app -->|"mounts routes"| node_m1routes
node_app -->|"mounts routes"| node_m2routes
node_app -.->|"mounts routes"| node_m3routes
node_m1routes -.->|"routes requests"| node_linking
node_m1routes -.->|"routes requests"| node_consentapi
node_linking -->|"posts link requests"| node_gateway
node_linking -->|"registers link context"| node_m2consent
node_consentapi -->|"uses gateway client"| node_gatewayservice
node_gatewayservice -->|"fetches session token"| node_gateway
node_m2routes -.->|"routes consent"| node_m2consent
node_m2routes -.->|"routes transfers"| node_m2transfer
node_m2routes -->|"routes storage"| node_patientstorage
node_m2callback -->|"dispatches callbacks"| node_m2consent
node_m2consent -->|"registers handlers"| node_m2callback
node_m2consent -->|"updates transactions"| node_m2tx
node_m2transfer -->|"uses request manager"| node_m2hi
node_m2transfer -->|"checks consent"| node_m2consent
node_m2transfer -->|"gets tokens"| node_m2tokens
node_m2transfer -->|"encrypts data"| node_m2crypto
node_m2transfer -->|"records transfers"| node_m2tx
node_m2transfer -->|"builds FHIR bundles"| node_fhir
node_m2tokens -.->|"requests gateway sessions"| node_gateway
node_m3routes -->|"routes callbacks"| node_m3callback
node_m3callback -->|"uses consent service"| node_m3consent
node_m3callback -->|"uses consent store"| node_m3consentstore
node_m3callback -->|"uses patient storage"| node_m3storage
node_m3tokens -->|"fetches session token"| node_gateway

click node_app "https://github.com/pranayagrawal2116/abdm_yashfeen/blob/main/backend/app.js"
click node_m1routes "https://github.com/pranayagrawal2116/abdm_yashfeen/tree/main/backend/routes"
click node_linking "https://github.com/pranayagrawal2116/abdm_yashfeen/blob/main/backend/controllers/hipLinkingController.js"
click node_consentapi "https://github.com/pranayagrawal2116/abdm_yashfeen/blob/main/backend/controllers/consentController.js"
click node_gatewayservice "https://github.com/pranayagrawal2116/abdm_yashfeen/blob/main/backend/services/gatewayService.js"
click node_m2routes "https://github.com/pranayagrawal2116/abdm_yashfeen/tree/main/backend/m2/routes"
click node_m2consent "https://github.com/pranayagrawal2116/abdm_yashfeen/blob/main/backend/m2/consent/M2ConsentManager.js"
click node_m2callback "https://github.com/pranayagrawal2116/abdm_yashfeen/blob/main/backend/m2/callbacks/M2CallbackManager.js"
click node_m2transfer "https://github.com/pranayagrawal2116/abdm_yashfeen/blob/main/backend/m2/transfer/M2DataTransferManager.js"
click node_m2hi "https://github.com/pranayagrawal2116/abdm_yashfeen/blob/main/backend/m2/healthInformation/M2HealthInformationRequestManager.js"
click node_m2tokens "https://github.com/pranayagrawal2116/abdm_yashfeen/blob/main/backend/m2/tokens/M2TokenManager.js"
click node_m2crypto "https://github.com/pranayagrawal2116/abdm_yashfeen/blob/main/backend/m2/encryption/M2EncryptionService.js"
click node_m2tx "https://github.com/pranayagrawal2116/abdm_yashfeen/blob/main/backend/m2/transactions/M2TransactionStore.js"
click node_fhir "https://github.com/pranayagrawal2116/abdm_yashfeen/tree/main/backend/m2/fhir"
click node_patientstorage "https://github.com/pranayagrawal2116/abdm_yashfeen/blob/main/backend/m2/storage/PatientStorageService.js"
click node_m3routes "https://github.com/pranayagrawal2116/abdm_yashfeen/tree/main/backend/m3/routes"
click node_m3consent "https://github.com/pranayagrawal2116/abdm_yashfeen/blob/main/backend/m3/services/m3ConsentService.js"
click node_m3callback "https://github.com/pranayagrawal2116/abdm_yashfeen/blob/main/backend/m3/controllers/m3CallbackController.js"
click node_m3storage "https://github.com/pranayagrawal2116/abdm_yashfeen/blob/main/backend/m3/services/m3PatientStorageService.js"
click node_m3tokens "https://github.com/pranayagrawal2116/abdm_yashfeen/blob/main/backend/m3/tokens/M3TokenManager.js"
click node_m3consentstore "https://github.com/pranayagrawal2116/abdm_yashfeen/blob/main/backend/m3/store/M3ConsentStore.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_app,node_m1routes,node_linking,node_consentapi,node_gatewayservice toneBlue
class node_m2routes,node_m2consent,node_m2callback,node_m2transfer,node_m2hi,node_m2tokens,node_m2crypto toneAmber
class node_m3routes,node_m3consent,node_m3callback,node_m3tokens toneMint
class node_m2tx,node_fhir,node_patientstorage,node_m3storage,node_m3consentstore toneRose
class node_user,node_gateway toneIndigo
```

## Components

### API and Linking

- [Express Application](https://github.com/pranayagrawal2116/abdm_yashfeen/blob/main/backend/app.js): `backend/app.js`
- [M1 API Routes](https://github.com/pranayagrawal2116/abdm_yashfeen/tree/main/backend/routes): `backend/routes`
- [HIP Linking](https://github.com/pranayagrawal2116/abdm_yashfeen/blob/main/backend/controllers/hipLinkingController.js): `backend/controllers/hipLinkingController.js`
- [Consent API](https://github.com/pranayagrawal2116/abdm_yashfeen/blob/main/backend/controllers/consentController.js): `backend/controllers/consentController.js`
- [Gateway Client](https://github.com/pranayagrawal2116/abdm_yashfeen/blob/main/backend/services/gatewayService.js): `backend/services/gatewayService.js`

### ABDM M2

- [M2 API Routes](https://github.com/pranayagrawal2116/abdm_yashfeen/tree/main/backend/m2/routes): `backend/m2/routes`
- [M2 Consent Manager](https://github.com/pranayagrawal2116/abdm_yashfeen/blob/main/backend/m2/consent/M2ConsentManager.js): `backend/m2/consent/M2ConsentManager.js`
- [M2 Callback Manager](https://github.com/pranayagrawal2116/abdm_yashfeen/blob/main/backend/m2/callbacks/M2CallbackManager.js): `backend/m2/callbacks/M2CallbackManager.js`
- [M2 Data Transfer](https://github.com/pranayagrawal2116/abdm_yashfeen/blob/main/backend/m2/transfer/M2DataTransferManager.js): `backend/m2/transfer/M2DataTransferManager.js`
- [Health Information Requests](https://github.com/pranayagrawal2116/abdm_yashfeen/blob/main/backend/m2/healthInformation/M2HealthInformationRequestManager.js): `backend/m2/healthInformation/M2HealthInformationRequestManager.js`
- [M2 Token Manager](https://github.com/pranayagrawal2116/abdm_yashfeen/blob/main/backend/m2/tokens/M2TokenManager.js): `backend/m2/tokens/M2TokenManager.js`
- [M2 Encryption](https://github.com/pranayagrawal2116/abdm_yashfeen/blob/main/backend/m2/encryption/M2EncryptionService.js): `backend/m2/encryption/M2EncryptionService.js`

### ABDM M3

- [M3 API Routes](https://github.com/pranayagrawal2116/abdm_yashfeen/tree/main/backend/m3/routes): `backend/m3/routes`
- [M3 Consent Service](https://github.com/pranayagrawal2116/abdm_yashfeen/blob/main/backend/m3/services/m3ConsentService.js): `backend/m3/services/m3ConsentService.js`
- [M3 Callback Controller](https://github.com/pranayagrawal2116/abdm_yashfeen/blob/main/backend/m3/controllers/m3CallbackController.js): `backend/m3/controllers/m3CallbackController.js`
- [M3 Token Manager](https://github.com/pranayagrawal2116/abdm_yashfeen/blob/main/backend/m3/tokens/M3TokenManager.js): `backend/m3/tokens/M3TokenManager.js`

### Records and Persistence

- [M2 Transactions](https://github.com/pranayagrawal2116/abdm_yashfeen/blob/main/backend/m2/transactions/M2TransactionStore.js): `backend/m2/transactions/M2TransactionStore.js`
- [FHIR Builders](https://github.com/pranayagrawal2116/abdm_yashfeen/tree/main/backend/m2/fhir): `backend/m2/fhir`
- [M2 Patient Storage](https://github.com/pranayagrawal2116/abdm_yashfeen/blob/main/backend/m2/storage/PatientStorageService.js): `backend/m2/storage/PatientStorageService.js`
- [M3 Patient Storage](https://github.com/pranayagrawal2116/abdm_yashfeen/blob/main/backend/m3/services/m3PatientStorageService.js): `backend/m3/services/m3PatientStorageService.js`
- [M3 Consent Store](https://github.com/pranayagrawal2116/abdm_yashfeen/blob/main/backend/m3/store/M3ConsentStore.js): `backend/m3/store/M3ConsentStore.js`

### Other components

- **Patient / Operator**
- **ABDM Gateway**

## Connections

- Patient / Operator → Express Application: sends requests (evidence: `backend/app.js`)
- Express Application → M1 API Routes: mounts routes (evidence: `backend/app.js`)
- Express Application → M2 API Routes: mounts routes (evidence: `backend/app.js`)
- Express Application → M3 API Routes: mounts routes (evidence: `backend/app.js`)
- M1 API Routes → HIP Linking: routes requests
- M1 API Routes → Consent API: routes requests
- HIP Linking → ABDM Gateway: posts link requests (evidence: `backend/controllers/hipLinkingController.js`)
- HIP Linking → M2 Consent Manager: registers link context (evidence: `backend/controllers/hipLinkingController.js`)
- Consent API → Gateway Client: uses gateway client (evidence: `backend/controllers/consentController.js`)
- Gateway Client → ABDM Gateway: fetches session token (evidence: `backend/services/gatewayService.js`)
- M2 API Routes → M2 Consent Manager: routes consent
- M2 API Routes → M2 Data Transfer: routes transfers
- M2 API Routes → M2 Patient Storage: routes storage (evidence: `backend/m2/routes/patientStorageRoutes.js`)
- M2 Callback Manager → M2 Consent Manager: dispatches callbacks (evidence: `backend/m2/consent/M2ConsentManager.js`)
- M2 Consent Manager → M2 Callback Manager: registers handlers (evidence: `backend/m2/consent/M2ConsentManager.js`)
- M2 Consent Manager → M2 Transactions: updates transactions (evidence: `backend/m2/consent/M2ConsentManager.js`)
- M2 Data Transfer → Health Information Requests: uses request manager (evidence: `backend/m2/transfer/M2DataTransferManager.js`)
- M2 Data Transfer → M2 Consent Manager: checks consent (evidence: `backend/m2/transfer/M2DataTransferManager.js`)
- M2 Data Transfer → M2 Token Manager: gets tokens (evidence: `backend/m2/transfer/M2DataTransferManager.js`)
- M2 Data Transfer → M2 Encryption: encrypts data (evidence: `backend/m2/transfer/M2DataTransferManager.js`)
- M2 Data Transfer → M2 Transactions: records transfers (evidence: `backend/m2/transfer/M2DataTransferManager.js`)
- M2 Data Transfer → FHIR Builders: builds FHIR bundles (evidence: `backend/m2/transfer/M2DataTransferManager.js`)
- M2 Token Manager → ABDM Gateway: requests gateway sessions
- M3 API Routes → M3 Callback Controller: routes callbacks (evidence: `backend/m3/routes/m3CallbackRoutes.js`)
- M3 Callback Controller → M3 Consent Service: uses consent service (evidence: `backend/m3/controllers/m3CallbackController.js`)
- M3 Callback Controller → M3 Consent Store: uses consent store (evidence: `backend/m3/controllers/m3CallbackController.js`)
- M3 Callback Controller → M3 Patient Storage: uses patient storage (evidence: `backend/m3/controllers/m3CallbackController.js`)
- M3 Token Manager → ABDM Gateway: fetches session token (evidence: `backend/m3/tokens/M3TokenManager.js`)
