# subrata-bauri/healthchare-privacy architecture

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

- Interactive diagram: https://gitdiagram.com/subrata-bauri/healthchare-privacy
- Repository: https://github.com/subrata-bauri/healthchare-privacy

## Overview

HealthChain is a role-based healthcare application for registering patients, doctors and hospitals, sharing encrypted medical records under patient-approved access, and auditing activity without exposing access patterns on-chain. The main flow runs from role-specific UI through authenticated API controllers to record and access services; patients can revoke access by rotating encryption keys and re-encrypting records. Access events are mixed into Merkle batches, with roots anchored on Ethereum. The tree omits contract source files, so the on-chain subsystem is represented at its documented boundary; unsampled page and audit implementations are not inferred in detail.

Main entry points: [`backend/src/services/blockchainService.js`](https://github.com/subrata-bauri/healthchare-privacy/blob/main/backend/src/services/blockchainService.js) (Contract integration), [`backend/src/app.js`](https://github.com/subrata-bauri/healthchare-privacy/blob/main/backend/src/app.js) (Express API), [`backend/src/services/keyRotationService.js`](https://github.com/subrata-bauri/healthchare-privacy/blob/main/backend/src/services/keyRotationService.js) (Epoch key rotation), [`backend/src/services/mixingService.js`](https://github.com/subrata-bauri/healthchare-privacy/blob/main/backend/src/services/mixingService.js) (Access-log mixing)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Web application"]
  node_web["Role-based pages"]
  node_auth_ui["Session context<br/>[AuthContext.jsx]"]
  node_api_client["HTTP client<br/>[client.js]"]
  node_wallet_ui["Wallet operations<br/>[blockchain.js]"]
end

subgraph group_api["API and domain"]
  node_api_app["Express API<br/>[app.js]"]
  node_auth_routes["Authentication routes<br/>[authRoutes.js]"]
  node_record_routes["Record routes<br/>[recordRoutes.js]"]
  node_access_routes["Access routes<br/>[accessRoutes.js]"]
  node_user_routes["User routes<br/>[userRoutes.js]"]
  node_key_routes["Key routes<br/>[keyRoutes.js]"]
  node_record_controller["Record handling"]
  node_access_controller["Access decisions"]
  node_user_controller["Role administration<br/>[userController.js]"]
  node_key_controller["Key operations<br/>[keyController.js]"]
  node_auth_middleware["JWT and role checks<br/>[auth.js]"]
end

subgraph group_privacy["Privacy services"]
  node_record_service["Record encryption pipeline<br/>[recordService.js]"]
  node_crypto["AES and hashing<br/>[cryptoService.js]"]
  node_rotation["Epoch key rotation"]
  node_mixing["Access-log mixing<br/>[mixingService.js]"]
  node_merkle["Merkle proofs<br/>[merkleService.js]"]
end

subgraph group_state["Persistence and chain"]
  node_ipfs["Encrypted file storage<br/>[ipfsService.js]"]
  node_models[("MongoDB domain records")]
  node_chain_service["Contract integration"]
  node_contracts{{"Ethereum registries and anchors"}}
end

node_users(("Patients, doctors, hospitals, admins"))

node_users -->|"use"| node_web
node_web -->|"authenticate"| node_auth_ui
node_web -->|"request"| node_api_client
node_web -->|"sign transactions"| node_wallet_ui
node_auth_ui -->|"refresh session"| node_api_client
node_api_client -->|"HTTP /api"| node_api_app
node_api_app -->|"mount"| node_auth_routes
node_api_app -->|"mount"| node_record_routes
node_api_app -->|"mount"| node_access_routes
node_api_app -->|"mount"| node_user_routes
node_api_app -->|"mount"| node_key_routes
node_record_routes -->|"protect routes"| node_auth_middleware
node_access_routes -->|"protect routes"| node_auth_middleware
node_user_routes -->|"protect routes"| node_auth_middleware
node_key_routes -->|"protect routes"| node_auth_middleware
node_record_routes -->|"dispatch"| node_record_controller
node_access_routes -->|"dispatch"| node_access_controller
node_user_routes -->|"dispatch"| node_user_controller
node_key_routes -->|"dispatch"| node_key_controller
node_record_controller -->|"process records"| node_record_service
node_record_controller -->|"read and write"| node_models
node_record_controller -->|"anchor and verify"| node_chain_service
node_record_controller -->|"log access"| node_mixing
node_record_service -.->|"encrypt and decrypt"| node_crypto
node_record_service -.->|"store files"| node_ipfs
node_access_controller -->|"persist grants"| node_models
node_access_controller -->|"check chain access"| node_chain_service
node_access_controller -->|"record events"| node_mixing
node_access_controller -->|"revoke and rotate"| node_rotation
node_user_controller -->|"manage profiles"| node_models
node_user_controller -->|"register on chain"| node_chain_service
node_user_controller -->|"record events"| node_mixing
node_key_controller -->|"manage epochs"| node_rotation
node_key_controller -->|"anchor commitments"| node_chain_service
node_rotation -->|"read and update epochs"| node_models
node_rotation -->|"encrypt records"| node_crypto
node_rotation -->|"replace ciphertext"| node_ipfs
node_rotation -->|"anchor new epoch"| node_chain_service
node_mixing -->|"persist batches"| node_models
node_mixing -->|"build proofs"| node_merkle
node_mixing -->|"anchor root"| node_chain_service
node_chain_service -->|"call contracts"| node_contracts
node_wallet_ui -.->|"sign transactions"| node_contracts

click node_web "https://github.com/subrata-bauri/healthchare-privacy/tree/main/frontend/src/pages"
click node_auth_ui "https://github.com/subrata-bauri/healthchare-privacy/blob/main/frontend/src/context/AuthContext.jsx"
click node_api_client "https://github.com/subrata-bauri/healthchare-privacy/blob/main/frontend/src/api/client.js"
click node_wallet_ui "https://github.com/subrata-bauri/healthchare-privacy/blob/main/frontend/src/api/blockchain.js"
click node_api_app "https://github.com/subrata-bauri/healthchare-privacy/blob/main/backend/src/app.js"
click node_auth_routes "https://github.com/subrata-bauri/healthchare-privacy/blob/main/backend/src/routes/authRoutes.js"
click node_record_routes "https://github.com/subrata-bauri/healthchare-privacy/blob/main/backend/src/routes/recordRoutes.js"
click node_access_routes "https://github.com/subrata-bauri/healthchare-privacy/blob/main/backend/src/routes/accessRoutes.js"
click node_user_routes "https://github.com/subrata-bauri/healthchare-privacy/blob/main/backend/src/routes/userRoutes.js"
click node_key_routes "https://github.com/subrata-bauri/healthchare-privacy/blob/main/backend/src/routes/keyRoutes.js"
click node_record_controller "https://github.com/subrata-bauri/healthchare-privacy/blob/main/backend/src/controllers/recordController.js"
click node_access_controller "https://github.com/subrata-bauri/healthchare-privacy/blob/main/backend/src/controllers/accessController.js"
click node_user_controller "https://github.com/subrata-bauri/healthchare-privacy/blob/main/backend/src/controllers/userController.js"
click node_key_controller "https://github.com/subrata-bauri/healthchare-privacy/blob/main/backend/src/controllers/keyController.js"
click node_auth_middleware "https://github.com/subrata-bauri/healthchare-privacy/blob/main/backend/src/middleware/auth.js"
click node_record_service "https://github.com/subrata-bauri/healthchare-privacy/blob/main/backend/src/services/recordService.js"
click node_crypto "https://github.com/subrata-bauri/healthchare-privacy/blob/main/backend/src/services/cryptoService.js"
click node_rotation "https://github.com/subrata-bauri/healthchare-privacy/blob/main/backend/src/services/keyRotationService.js"
click node_mixing "https://github.com/subrata-bauri/healthchare-privacy/blob/main/backend/src/services/mixingService.js"
click node_merkle "https://github.com/subrata-bauri/healthchare-privacy/blob/main/backend/src/services/merkleService.js"
click node_ipfs "https://github.com/subrata-bauri/healthchare-privacy/blob/main/backend/src/services/ipfsService.js"
click node_models "https://github.com/subrata-bauri/healthchare-privacy/tree/main/backend/src/models"
click node_chain_service "https://github.com/subrata-bauri/healthchare-privacy/blob/main/backend/src/services/blockchainService.js"
click node_contracts "https://github.com/subrata-bauri/healthchare-privacy/tree/main/blockchain"

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,node_auth_ui,node_api_client,node_wallet_ui toneBlue
class node_api_app,node_auth_routes,node_record_routes,node_access_routes,node_user_routes,node_key_routes,node_record_controller,node_access_controller,node_user_controller,node_key_controller,node_auth_middleware toneAmber
class node_record_service,node_crypto,node_rotation,node_mixing,node_merkle toneMint
class node_ipfs,node_models,node_chain_service,node_contracts toneRose
class node_users toneIndigo
```

## Components

### Web application

- [Role-based pages](https://github.com/subrata-bauri/healthchare-privacy/tree/main/frontend/src/pages): `frontend/src/pages`
- [Session context](https://github.com/subrata-bauri/healthchare-privacy/blob/main/frontend/src/context/AuthContext.jsx): `frontend/src/context/AuthContext.jsx`
- [HTTP client](https://github.com/subrata-bauri/healthchare-privacy/blob/main/frontend/src/api/client.js): `frontend/src/api/client.js`
- [Wallet operations](https://github.com/subrata-bauri/healthchare-privacy/blob/main/frontend/src/api/blockchain.js): `frontend/src/api/blockchain.js`

### API and domain

- [Express API](https://github.com/subrata-bauri/healthchare-privacy/blob/main/backend/src/app.js): `backend/src/app.js`
- [Authentication routes](https://github.com/subrata-bauri/healthchare-privacy/blob/main/backend/src/routes/authRoutes.js): `backend/src/routes/authRoutes.js`
- [Record routes](https://github.com/subrata-bauri/healthchare-privacy/blob/main/backend/src/routes/recordRoutes.js): `backend/src/routes/recordRoutes.js`
- [Access routes](https://github.com/subrata-bauri/healthchare-privacy/blob/main/backend/src/routes/accessRoutes.js): `backend/src/routes/accessRoutes.js`
- [User routes](https://github.com/subrata-bauri/healthchare-privacy/blob/main/backend/src/routes/userRoutes.js): `backend/src/routes/userRoutes.js`
- [Key routes](https://github.com/subrata-bauri/healthchare-privacy/blob/main/backend/src/routes/keyRoutes.js): `backend/src/routes/keyRoutes.js`
- [Record handling](https://github.com/subrata-bauri/healthchare-privacy/blob/main/backend/src/controllers/recordController.js): `backend/src/controllers/recordController.js`
- [Access decisions](https://github.com/subrata-bauri/healthchare-privacy/blob/main/backend/src/controllers/accessController.js): `backend/src/controllers/accessController.js`
- [Role administration](https://github.com/subrata-bauri/healthchare-privacy/blob/main/backend/src/controllers/userController.js): `backend/src/controllers/userController.js`
- [Key operations](https://github.com/subrata-bauri/healthchare-privacy/blob/main/backend/src/controllers/keyController.js): `backend/src/controllers/keyController.js`
- [JWT and role checks](https://github.com/subrata-bauri/healthchare-privacy/blob/main/backend/src/middleware/auth.js): `backend/src/middleware/auth.js`

### Privacy services

- [Record encryption pipeline](https://github.com/subrata-bauri/healthchare-privacy/blob/main/backend/src/services/recordService.js): `backend/src/services/recordService.js`
- [AES and hashing](https://github.com/subrata-bauri/healthchare-privacy/blob/main/backend/src/services/cryptoService.js): `backend/src/services/cryptoService.js`
- [Epoch key rotation](https://github.com/subrata-bauri/healthchare-privacy/blob/main/backend/src/services/keyRotationService.js): `backend/src/services/keyRotationService.js`
- [Access-log mixing](https://github.com/subrata-bauri/healthchare-privacy/blob/main/backend/src/services/mixingService.js): `backend/src/services/mixingService.js`
- [Merkle proofs](https://github.com/subrata-bauri/healthchare-privacy/blob/main/backend/src/services/merkleService.js): `backend/src/services/merkleService.js`

### Persistence and chain

- [Encrypted file storage](https://github.com/subrata-bauri/healthchare-privacy/blob/main/backend/src/services/ipfsService.js): `backend/src/services/ipfsService.js`
- [MongoDB domain records](https://github.com/subrata-bauri/healthchare-privacy/tree/main/backend/src/models): `backend/src/models`
- [Contract integration](https://github.com/subrata-bauri/healthchare-privacy/blob/main/backend/src/services/blockchainService.js): `backend/src/services/blockchainService.js`
- [Ethereum registries and anchors](https://github.com/subrata-bauri/healthchare-privacy/tree/main/blockchain): `blockchain`

### Other components

- **Patients, doctors, hospitals, admins**

## Connections

- Patients, doctors, hospitals, admins → Role-based pages: use
- Role-based pages → Session context: authenticate (evidence: `frontend/src/pages/DoctorDashboard.jsx`)
- Role-based pages → HTTP client: request (evidence: `frontend/src/pages/AccessManagement.jsx`)
- Role-based pages → Wallet operations: sign transactions (evidence: `frontend/src/pages/AccessManagement.jsx`)
- Session context → HTTP client: refresh session (evidence: `frontend/src/context/AuthContext.jsx`)
- HTTP client → Express API: HTTP /api
- Express API → Authentication routes: mount (evidence: `backend/src/app.js`)
- Express API → Record routes: mount (evidence: `backend/src/app.js`)
- Express API → Access routes: mount (evidence: `backend/src/app.js`)
- Express API → User routes: mount (evidence: `backend/src/app.js`)
- Express API → Key routes: mount (evidence: `backend/src/app.js`)
- Record routes → JWT and role checks: protect routes (evidence: `backend/src/routes/recordRoutes.js`)
- Access routes → JWT and role checks: protect routes (evidence: `backend/src/routes/accessRoutes.js`)
- User routes → JWT and role checks: protect routes (evidence: `backend/src/routes/userRoutes.js`)
- Key routes → JWT and role checks: protect routes (evidence: `backend/src/routes/keyRoutes.js`)
- Record routes → Record handling: dispatch (evidence: `backend/src/routes/recordRoutes.js`)
- Access routes → Access decisions: dispatch (evidence: `backend/src/routes/accessRoutes.js`)
- User routes → Role administration: dispatch (evidence: `backend/src/routes/userRoutes.js`)
- Key routes → Key operations: dispatch (evidence: `backend/src/routes/keyRoutes.js`)
- Record handling → Record encryption pipeline: process records (evidence: `backend/src/controllers/recordController.js`)
- Record handling → MongoDB domain records: read and write (evidence: `backend/src/controllers/recordController.js`)
- Record handling → Contract integration: anchor and verify (evidence: `backend/src/controllers/recordController.js`)
- Record handling → Access-log mixing: log access (evidence: `backend/src/controllers/recordController.js`)
- Record encryption pipeline → AES and hashing: encrypt and decrypt
- Record encryption pipeline → Encrypted file storage: store files
- Access decisions → MongoDB domain records: persist grants (evidence: `backend/src/controllers/accessController.js`)
- Access decisions → Contract integration: check chain access (evidence: `backend/src/controllers/accessController.js`)
- Access decisions → Access-log mixing: record events (evidence: `backend/src/controllers/accessController.js`)
- Access decisions → Epoch key rotation: revoke and rotate (evidence: `backend/src/controllers/accessController.js`)
- Role administration → MongoDB domain records: manage profiles (evidence: `backend/src/controllers/userController.js`)
- Role administration → Contract integration: register on chain (evidence: `backend/src/controllers/userController.js`)
- Role administration → Access-log mixing: record events (evidence: `backend/src/controllers/userController.js`)
- Key operations → Epoch key rotation: manage epochs (evidence: `backend/src/controllers/keyController.js`)
- Key operations → Contract integration: anchor commitments (evidence: `backend/src/controllers/keyController.js`)
- Epoch key rotation → MongoDB domain records: read and update epochs (evidence: `backend/src/services/keyRotationService.js`)
- Epoch key rotation → AES and hashing: encrypt records (evidence: `backend/src/services/keyRotationService.js`)
- Epoch key rotation → Encrypted file storage: replace ciphertext (evidence: `backend/src/services/keyRotationService.js`)
- Epoch key rotation → Contract integration: anchor new epoch (evidence: `backend/src/services/keyRotationService.js`)
- Access-log mixing → MongoDB domain records: persist batches (evidence: `backend/src/services/mixingService.js`)
- Access-log mixing → Merkle proofs: build proofs (evidence: `backend/src/services/mixingService.js`)
- Access-log mixing → Contract integration: anchor root (evidence: `backend/src/services/mixingService.js`)
- Contract integration → Ethereum registries and anchors: call contracts (evidence: `backend/src/services/blockchainService.js`)
- Wallet operations → Ethereum registries and anchors: sign transactions
