# tamzidrahman1029/health-care-encryption architecture

> Architecture diagram of the GitHub repository tamzidrahman1029/health-care-encryption, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/tamzidrahman1029/health-care-encryption
- Repository: https://github.com/tamzidrahman1029/health-care-encryption

## Overview

This repository is a prototype for encrypting and sharing electronic health records (EHRs), with encrypted files kept off-chain and record metadata and hashes registered on a blockchain. The intended workflow is to encrypt an EHR, protect its AES key, store the ciphertext, register its reference and hash, then let an authorized hospital retrieve and verify the file before decrypting it. The sampled API implements token checks and hash verification; the receiver script demonstrates ML-KEM-based transfer and decryption. Separate ECC, ML-KEM, and object-storage utilities are also present. README evidence only describes a minimal Hardhat project, so wiring for unsampled modules is not inferred.

Main entry points: [`hospital_api.py`](https://github.com/tamzidrahman1029/health-care-encryption/blob/main/hospital_api.py) (EHR request API), [`HospitalB_Node/hospital_b_receive.py`](https://github.com/tamzidrahman1029/health-care-encryption/blob/main/HospitalB_Node/hospital_b_receive.py) (Hospital receiver), [`blockchain/contracts/EHRStorage.sol`](https://github.com/tamzidrahman1029/health-care-encryption/blob/main/blockchain/contracts/EHRStorage.sol) (EHR metadata contract), [`encrypt_patient.py`](https://github.com/tamzidrahman1029/health-care-encryption/blob/main/encrypt_patient.py) (EHR encryption)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_crypto["EHR cryptography"]
  node_ehr["EHR encryption<br/>[encrypt_patient.py]"]
  node_aes["AES key setup"]
  node_ecc["ECC key protection"]
  node_mlkem["ML-KEM protection"]
  node_eccrecover["ECC recovery"]
  node_mlkemrecover["ML-KEM recovery"]
  node_decrypt["Load and decrypt"]
  node_hash["Hash generation<br/>[generate_hash.py]"]
end

subgraph group_registry["Blockchain registry"]
  node_contract[("EHR metadata contract<br/>[EHRStorage.sol]")]
  node_register["Record registration"]
  node_chain["Blockchain node"]
end

subgraph group_storage["Encrypted storage"]
  node_privatefiles[("Private file store")]
  node_objectapi["Object storage API<br/>[fastapi_storage.py]"]
  node_objectfiles[("Object files")]
end

subgraph group_sharing["Hospital sharing"]
  node_api["EHR request API<br/>[hospital_api.py]"]
  node_receiver["Hospital receiver"]
end

node_hospital(("Hospital staff"))

node_hospital -->|"provides EHR"| node_ehr
node_hospital -->|"requests record"| node_api
node_hospital -->|"initiates transfer"| node_receiver
node_hospital -->|"uploads file"| node_objectapi
node_ehr -->|"uses key"| node_aes
node_ehr -->|"hashes ciphertext"| node_hash
node_aes -.->|"protects key"| node_ecc
node_aes -.->|"protects key"| node_mlkem
node_eccrecover -.->|"provides key"| node_decrypt
node_mlkemrecover -.->|"provides key"| node_decrypt
node_api -->|"reads records"| node_chain
node_api -->|"queries metadata"| node_contract
node_api -->|"reads ciphertext"| node_privatefiles
node_api -->|"verifies file"| node_hash
node_api -->|"returns verified file"| node_hospital
node_register -->|"submits transaction"| node_chain
node_register -->|"adds record"| node_contract
node_chain -->|"executes calls"| node_contract
node_receiver -->|"adds and reads records"| node_contract
node_receiver -->|"wraps AES key"| node_mlkem
node_receiver -->|"recovers AES key"| node_mlkemrecover
node_receiver -->|"checks ciphertext"| node_hash
node_receiver -->|"decrypts EHR"| node_decrypt
node_objectapi -->|"writes and serves"| node_objectfiles

click node_ehr "https://github.com/tamzidrahman1029/health-care-encryption/blob/main/encrypt_patient.py"
click node_aes "https://github.com/tamzidrahman1029/health-care-encryption/blob/main/generate_aes_key.py"
click node_ecc "https://github.com/tamzidrahman1029/health-care-encryption/blob/main/ecc_key_protection.py"
click node_mlkem "https://github.com/tamzidrahman1029/health-care-encryption/blob/main/mlkem_key_protection.py"
click node_eccrecover "https://github.com/tamzidrahman1029/health-care-encryption/blob/main/recover_and_decrypt.py"
click node_mlkemrecover "https://github.com/tamzidrahman1029/health-care-encryption/blob/main/mlkem_recover_and_decrypt.py"
click node_decrypt "https://github.com/tamzidrahman1029/health-care-encryption/blob/main/load_and_decrypt.py"
click node_hash "https://github.com/tamzidrahman1029/health-care-encryption/blob/main/generate_hash.py"
click node_api "https://github.com/tamzidrahman1029/health-care-encryption/blob/main/hospital_api.py"
click node_receiver "https://github.com/tamzidrahman1029/health-care-encryption/blob/main/HospitalB_Node/hospital_b_receive.py"
click node_contract "https://github.com/tamzidrahman1029/health-care-encryption/blob/main/blockchain/contracts/EHRStorage.sol"
click node_register "https://github.com/tamzidrahman1029/health-care-encryption/blob/main/blockchain/blockchain_register.py"
click node_privatefiles "https://github.com/tamzidrahman1029/health-care-encryption/tree/main/private_storage"
click node_objectapi "https://github.com/tamzidrahman1029/health-care-encryption/blob/main/storage_server/fastapi_storage.py"
click node_objectfiles "https://github.com/tamzidrahman1029/health-care-encryption/tree/main/storage_server/ehr_object_storage"

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_ehr,node_aes,node_ecc,node_mlkem,node_eccrecover,node_mlkemrecover,node_decrypt,node_hash toneBlue
class node_contract,node_register,node_chain toneAmber
class node_privatefiles,node_objectapi,node_objectfiles toneMint
class node_api,node_receiver toneRose
class node_hospital toneIndigo
```

## Components

### EHR cryptography

- [EHR encryption](https://github.com/tamzidrahman1029/health-care-encryption/blob/main/encrypt_patient.py): `encrypt_patient.py`
- [AES key setup](https://github.com/tamzidrahman1029/health-care-encryption/blob/main/generate_aes_key.py): `generate_aes_key.py`
- [ECC key protection](https://github.com/tamzidrahman1029/health-care-encryption/blob/main/ecc_key_protection.py): `ecc_key_protection.py`
- [ML-KEM protection](https://github.com/tamzidrahman1029/health-care-encryption/blob/main/mlkem_key_protection.py): `mlkem_key_protection.py`
- [ECC recovery](https://github.com/tamzidrahman1029/health-care-encryption/blob/main/recover_and_decrypt.py): `recover_and_decrypt.py`
- [ML-KEM recovery](https://github.com/tamzidrahman1029/health-care-encryption/blob/main/mlkem_recover_and_decrypt.py): `mlkem_recover_and_decrypt.py`
- [Load and decrypt](https://github.com/tamzidrahman1029/health-care-encryption/blob/main/load_and_decrypt.py): `load_and_decrypt.py`
- [Hash generation](https://github.com/tamzidrahman1029/health-care-encryption/blob/main/generate_hash.py): `generate_hash.py`

### Blockchain registry

- [EHR metadata contract](https://github.com/tamzidrahman1029/health-care-encryption/blob/main/blockchain/contracts/EHRStorage.sol): `blockchain/contracts/EHRStorage.sol`
- [Record registration](https://github.com/tamzidrahman1029/health-care-encryption/blob/main/blockchain/blockchain_register.py): `blockchain/blockchain_register.py`
- **Blockchain node**

### Encrypted storage

- [Private file store](https://github.com/tamzidrahman1029/health-care-encryption/tree/main/private_storage): `private_storage`
- [Object storage API](https://github.com/tamzidrahman1029/health-care-encryption/blob/main/storage_server/fastapi_storage.py): `storage_server/fastapi_storage.py`
- [Object files](https://github.com/tamzidrahman1029/health-care-encryption/tree/main/storage_server/ehr_object_storage): `storage_server/ehr_object_storage`

### Hospital sharing

- [EHR request API](https://github.com/tamzidrahman1029/health-care-encryption/blob/main/hospital_api.py): `hospital_api.py`
- [Hospital receiver](https://github.com/tamzidrahman1029/health-care-encryption/blob/main/HospitalB_Node/hospital_b_receive.py): `HospitalB_Node/hospital_b_receive.py`

### Other components

- **Hospital staff**

## Connections

- Hospital staff → EHR encryption: provides EHR
- Hospital staff → EHR request API: requests record
- Hospital staff → Hospital receiver: initiates transfer
- Hospital staff → Object storage API: uploads file
- EHR encryption → AES key setup: uses key
- EHR encryption → Hash generation: hashes ciphertext
- AES key setup → ECC key protection: protects key
- AES key setup → ML-KEM protection: protects key
- ECC recovery → Load and decrypt: provides key
- ML-KEM recovery → Load and decrypt: provides key
- EHR request API → Blockchain node: reads records
- EHR request API → EHR metadata contract: queries metadata
- EHR request API → Private file store: reads ciphertext
- EHR request API → Hash generation: verifies file
- EHR request API → Hospital staff: returns verified file
- Record registration → Blockchain node: submits transaction
- Record registration → EHR metadata contract: adds record
- Blockchain node → EHR metadata contract: executes calls
- Hospital receiver → EHR metadata contract: adds and reads records
- Hospital receiver → ML-KEM protection: wraps AES key
- Hospital receiver → ML-KEM recovery: recovers AES key
- Hospital receiver → Hash generation: checks ciphertext
- Hospital receiver → Load and decrypt: decrypts EHR
- Object storage API → Object files: writes and serves
