# apknation/afyatrust architecture

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

- Interactive diagram: https://gitdiagram.com/apknation/afyatrust
- Repository: https://github.com/apknation/afyatrust

## Overview

AfyaTrust is a patient-consented clinical-record sharing platform: patients and care teams use role-specific Angular workspaces, while a Django API enforces authentication, grants and referrals, stores clinical data in PostgreSQL, and anchors record integrity to Ethereum. The documented workflow includes record verification, referral handoffs, and audited emergency access; custodial patient wallets support chain transactions. The README documents these stages, but unsampled backend and contract internals limit call-level wiring, so some documented relationships are shown with dashed, uncited edges.

Main entry points: [`frontend/src/app/app.routes.ts`](https://github.com/apknation/afyatrust/blob/main/frontend/src/app/app.routes.ts) (Role routing), [`backend/afyatrust/api/views.py`](https://github.com/apknation/afyatrust/blob/main/backend/afyatrust/api/views.py) (REST endpoints), [`frontend/src/app/services/api.service.ts`](https://github.com/apknation/afyatrust/blob/main/frontend/src/app/services/api.service.ts) (API client), [`backend/afyatrust/api/models.py`](https://github.com/apknation/afyatrust/blob/main/backend/afyatrust/api/models.py) (Clinical records)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web experience"]
  node_web_routes["Role routing<br/>[app.routes.ts]"]
  node_login["Login and signup<br/>[login.component.ts]"]
  node_register["Registration"]
  node_auth_state["Session state<br/>[auth.service.ts]"]
  node_patient_workspace["Patient workspace"]
  node_doctor_workspace["Doctor workspace"]
  node_hospital_workspace["Hospital workspace"]
  node_account["Account settings"]
  node_workspace_state["Workspace cache"]
end

subgraph group_api["API and access"]
  node_api_client["API client<br/>[api.service.ts]"]
  node_django_api["REST endpoints<br/>[views.py]"]
  node_authentication["Authentication<br/>[auth_views.py]"]
  node_wallets["Custodial wallets<br/>[wallet_manager.py]"]
end

subgraph group_clinical["Clinical data"]
  node_clinical_records[("Clinical records<br/>[models.py]")]
  node_consent_referrals[("Consent and referrals<br/>[models.py]")]
  node_postgres[("PostgreSQL")]
end

subgraph group_chain["Blockchain audit"]
  node_chain_adapter["Chain adapter<br/>[blockchain.py]"]
  node_ethereum[("Ethereum Sepolia")]
end

node_patient(("Patient"))
node_care_team(("Care team"))

node_patient -->|"opens"| node_web_routes
node_care_team -->|"opens"| node_web_routes
node_web_routes -->|"routes to"| node_login
node_web_routes -->|"routes to"| node_register
node_web_routes -->|"guards route"| node_patient_workspace
node_web_routes -->|"guards route"| node_doctor_workspace
node_web_routes -->|"guards route"| node_hospital_workspace
node_web_routes -->|"guards route"| node_account
node_login -.->|"sets session"| node_auth_state
node_register -.->|"submits registration"| node_api_client
node_patient_workspace -->|"requests data"| node_api_client
node_doctor_workspace -->|"requests data"| node_api_client
node_hospital_workspace -.->|"requests data"| node_api_client
node_account -->|"requests data"| node_api_client
node_patient_workspace -.->|"loads state"| node_workspace_state
node_doctor_workspace -->|"loads state"| node_workspace_state
node_hospital_workspace -->|"loads state"| node_workspace_state
node_api_client -.->|"HTTP requests"| node_django_api
node_django_api -->|"authenticates"| node_authentication
node_django_api -->|"reads and writes"| node_clinical_records
node_django_api -->|"checks access"| node_consent_referrals
node_clinical_records -.->|"persists"| node_postgres
node_consent_referrals -.->|"persists"| node_postgres
node_django_api -->|"uses keys"| node_wallets
node_django_api -->|"anchors and verifies"| node_chain_adapter
node_chain_adapter -.->|"reads and writes"| node_ethereum
node_clinical_records -.->|"hash integrity"| node_chain_adapter
node_consent_referrals -.->|"authorizes handoff"| node_clinical_records

click node_web_routes "https://github.com/apknation/afyatrust/blob/main/frontend/src/app/app.routes.ts"
click node_login "https://github.com/apknation/afyatrust/blob/main/frontend/src/app/pages/login/login.component.ts"
click node_register "https://github.com/apknation/afyatrust/blob/main/frontend/src/app/pages/register/register.component.ts"
click node_auth_state "https://github.com/apknation/afyatrust/blob/main/frontend/src/app/services/auth.service.ts"
click node_patient_workspace "https://github.com/apknation/afyatrust/blob/main/frontend/src/app/pages/patient/patient-dashboard/patient-dashboard.component.ts"
click node_doctor_workspace "https://github.com/apknation/afyatrust/blob/main/frontend/src/app/pages/doctor/doctor-landing/doctor-landing.component.ts"
click node_hospital_workspace "https://github.com/apknation/afyatrust/blob/main/frontend/src/app/pages/hospital/hospital-dashboard/hospital-dashboard.component.ts"
click node_account "https://github.com/apknation/afyatrust/blob/main/frontend/src/app/pages/account/account.component.ts"
click node_workspace_state "https://github.com/apknation/afyatrust/blob/main/frontend/src/app/services/workspace-state.service.ts"
click node_api_client "https://github.com/apknation/afyatrust/blob/main/frontend/src/app/services/api.service.ts"
click node_django_api "https://github.com/apknation/afyatrust/blob/main/backend/afyatrust/api/views.py"
click node_authentication "https://github.com/apknation/afyatrust/blob/main/backend/afyatrust/api/auth_views.py"
click node_wallets "https://github.com/apknation/afyatrust/blob/main/backend/afyatrust/api/wallet_manager.py"
click node_clinical_records "https://github.com/apknation/afyatrust/blob/main/backend/afyatrust/api/models.py"
click node_consent_referrals "https://github.com/apknation/afyatrust/blob/main/backend/afyatrust/api/models.py"
click node_chain_adapter "https://github.com/apknation/afyatrust/blob/main/backend/afyatrust/api/blockchain.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_web_routes,node_login,node_register,node_auth_state,node_patient_workspace,node_doctor_workspace,node_hospital_workspace,node_account,node_workspace_state toneBlue
class node_api_client,node_django_api,node_authentication,node_wallets toneAmber
class node_clinical_records,node_consent_referrals,node_postgres toneMint
class node_chain_adapter,node_ethereum toneRose
class node_patient,node_care_team toneIndigo
```

## Components

### Web experience

- [Role routing](https://github.com/apknation/afyatrust/blob/main/frontend/src/app/app.routes.ts): `frontend/src/app/app.routes.ts`
- [Login and signup](https://github.com/apknation/afyatrust/blob/main/frontend/src/app/pages/login/login.component.ts): `frontend/src/app/pages/login/login.component.ts`
- [Registration](https://github.com/apknation/afyatrust/blob/main/frontend/src/app/pages/register/register.component.ts): `frontend/src/app/pages/register/register.component.ts`
- [Session state](https://github.com/apknation/afyatrust/blob/main/frontend/src/app/services/auth.service.ts): `frontend/src/app/services/auth.service.ts`
- [Patient workspace](https://github.com/apknation/afyatrust/blob/main/frontend/src/app/pages/patient/patient-dashboard/patient-dashboard.component.ts): `frontend/src/app/pages/patient/patient-dashboard/patient-dashboard.component.ts`
- [Doctor workspace](https://github.com/apknation/afyatrust/blob/main/frontend/src/app/pages/doctor/doctor-landing/doctor-landing.component.ts): `frontend/src/app/pages/doctor/doctor-landing/doctor-landing.component.ts`
- [Hospital workspace](https://github.com/apknation/afyatrust/blob/main/frontend/src/app/pages/hospital/hospital-dashboard/hospital-dashboard.component.ts): `frontend/src/app/pages/hospital/hospital-dashboard/hospital-dashboard.component.ts`
- [Account settings](https://github.com/apknation/afyatrust/blob/main/frontend/src/app/pages/account/account.component.ts): `frontend/src/app/pages/account/account.component.ts`
- [Workspace cache](https://github.com/apknation/afyatrust/blob/main/frontend/src/app/services/workspace-state.service.ts): `frontend/src/app/services/workspace-state.service.ts`

### API and access

- [API client](https://github.com/apknation/afyatrust/blob/main/frontend/src/app/services/api.service.ts): `frontend/src/app/services/api.service.ts`
- [REST endpoints](https://github.com/apknation/afyatrust/blob/main/backend/afyatrust/api/views.py): `backend/afyatrust/api/views.py`
- [Authentication](https://github.com/apknation/afyatrust/blob/main/backend/afyatrust/api/auth_views.py): `backend/afyatrust/api/auth_views.py`
- [Custodial wallets](https://github.com/apknation/afyatrust/blob/main/backend/afyatrust/api/wallet_manager.py): `backend/afyatrust/api/wallet_manager.py`

### Clinical data

- [Clinical records](https://github.com/apknation/afyatrust/blob/main/backend/afyatrust/api/models.py): `backend/afyatrust/api/models.py`
- [Consent and referrals](https://github.com/apknation/afyatrust/blob/main/backend/afyatrust/api/models.py): `backend/afyatrust/api/models.py`
- **PostgreSQL**

### Blockchain audit

- [Chain adapter](https://github.com/apknation/afyatrust/blob/main/backend/afyatrust/api/blockchain.py): `backend/afyatrust/api/blockchain.py`
- **Ethereum Sepolia**

### Other components

- **Patient**
- **Care team**

## Connections

- Patient → Role routing: opens (evidence: `frontend/src/app/app.routes.ts`)
- Care team → Role routing: opens (evidence: `frontend/src/app/app.routes.ts`)
- Role routing → Login and signup: routes to (evidence: `frontend/src/app/app.routes.ts`)
- Role routing → Registration: routes to (evidence: `frontend/src/app/app.routes.ts`)
- Role routing → Patient workspace: guards route (evidence: `frontend/src/app/app.routes.ts`)
- Role routing → Doctor workspace: guards route (evidence: `frontend/src/app/app.routes.ts`)
- Role routing → Hospital workspace: guards route (evidence: `frontend/src/app/app.routes.ts`)
- Role routing → Account settings: guards route (evidence: `frontend/src/app/app.routes.ts`)
- Login and signup → Session state: sets session (evidence: `frontend/src/app/pages/login/login.component.ts`)
- Registration → API client: submits registration (evidence: `frontend/src/app/pages/register/register.component.ts`)
- Patient workspace → API client: requests data (evidence: `frontend/src/app/pages/patient/patient-dashboard/patient-dashboard.component.ts`)
- Doctor workspace → API client: requests data (evidence: `frontend/src/app/pages/doctor/doctor-landing/doctor-landing.component.ts`)
- Hospital workspace → API client: requests data (evidence: `frontend/src/app/pages/hospital/hospital-dashboard/hospital-dashboard.component.ts`)
- Account settings → API client: requests data (evidence: `frontend/src/app/pages/account/account.component.ts`)
- Patient workspace → Workspace cache: loads state (evidence: `frontend/src/app/pages/patient/patient-dashboard/patient-dashboard.component.ts`)
- Doctor workspace → Workspace cache: loads state (evidence: `frontend/src/app/pages/doctor/doctor-landing/doctor-landing.component.ts`)
- Hospital workspace → Workspace cache: loads state (evidence: `frontend/src/app/pages/hospital/hospital-dashboard/hospital-dashboard.component.ts`)
- API client → REST endpoints: HTTP requests
- REST endpoints → Authentication: authenticates (evidence: `backend/afyatrust/api/views.py`)
- REST endpoints → Clinical records: reads and writes (evidence: `backend/afyatrust/api/views.py`)
- REST endpoints → Consent and referrals: checks access (evidence: `backend/afyatrust/api/views.py`)
- Clinical records → PostgreSQL: persists
- Consent and referrals → PostgreSQL: persists
- REST endpoints → Custodial wallets: uses keys (evidence: `backend/afyatrust/api/views.py`)
- REST endpoints → Chain adapter: anchors and verifies (evidence: `backend/afyatrust/api/views.py`)
- Chain adapter → Ethereum Sepolia: reads and writes
- Clinical records → Chain adapter: hash integrity
- Consent and referrals → Clinical records: authorizes handoff (evidence: `backend/afyatrust/api/models.py`)
