# faeiqkhan/healthvaultbackend architecture

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

- Interactive diagram: https://gitdiagram.com/faeiqkhan/healthvaultbackend
- Repository: https://github.com/faeiqkhan/healthvaultbackend

## Overview

1. **Overall shape**
   HealthVault is a **Spring Boot + PostgreSQL** backend for secure medical-record storage and sharing. The repository currently exposes the **core domain/persistence layer** plus a small audit service, while the README describes the higher-level API/security features that sit on top of it.

2. **Application entry point**
   `HealthVaultApplication` is the Spring Boot bootstrap class. It starts the application, wires Spring components, and connects the domain packages to the database configured in `src/main/resources/application.yaml`.

3. **Identity and access boundary**
   The `user` package models the system’s primary identity layer:
   - `User`
   - `Role`
   - `KycStatus`
   
   This is the foundation for **JWT-based authentication** and **role-based access control** described in the README. The diagram should show user identity as a gate in front of record access and KYC-dependent workflows.

4. **KYC subsystem**
   The `kyc` package contains `Doctor` and `Patient` entities plus repositories for each. This is the verification boundary that distinguishes healthcare providers from patients and likely controls who can be granted access to records. It is the business layer that supports the “authorized doctor” model.

5. **Medical record subsystem**
   The `record` package centers on `Record` and `RecordRepository`. This is the persistence boundary for medical files/record metadata. In the architecture diagram, this should be the main protected asset: records are created by patients, stored in PostgreSQL-backed persistence, and later retrieved only through authenticated/authorized flows.

6. **Audit subsystem**
   The `audit` package provides `Audit`, `UserType`, `AuditRepository`, and `AuditService`. This is a cross-cutting security trail for sensitive actions such as uploads, sharing, access attempts, or verification events. It should be shown as a side-channel that receives events from the main workflows rather than as part of the core record path.

7. **Secure file handling**
   The README states the system uses **hybrid encryption (AES + RSA)** with a **zero-knowledge approach**. Architecturally, that means:
   - file contents are encrypted before durable storage,
   - AES is used for the bulk data,
   - RSA protects the AES key or key material,
   - the server/database should not need plaintext access.
   
   This is a major trust boundary and should be drawn between client-side/file-ingest processing and database persistence.

8. **Sharing flow**
   The main data flow is: **patient uploads record → record is encrypted and stored → access is controlled by auth + KYC status + role checks → authorized doctor can retrieve/share views of the record**. The architecture is therefore not just CRUD; it is an access-controlled sharing system with patient ownership at the center.

9. **Persistence model**
   Each domain area has its own Spring Data repository:
   - `UserRepository`
   - `DoctorRepository`
   - `PatientRepository`
   - `RecordRepository`
   - `AuditRepository`
   
   This indicates a repository-per-aggregate style, with Spring Data JPA handling database access and the service layer coordinating business rules.

10. **Supporting tooling and operational surface**
   The project uses the **Maven wrapper** (`mvnw`, `pom.xml`) for build/test lifecycle, and a basic test class exists under `src/test`. The README also mentions **Swagger documentation**, which implies an API layer intended for interactive testing and integration, even though controllers are not visible in the current tree.

11. **What to emphasize in an architecture diagram**
   The most important boundaries are:
   - **API/auth layer** in front of the system,
   - **user/KYC/role validation** as access control,
   - **record storage** as the protected data plane,
   - **audit logging** as a parallel security trail,
   - **PostgreSQL** as the durable backend,
   - **encryption/key handling** as the confidentiality boundary.
   
   The current repository mostly contains the domain and persistence pieces that those flows connect to.

Main entry points: [`src/main/java/com/faeiq/healthvault/HealthVaultApplication.java`](https://github.com/faeiqkhan/healthvaultbackend/blob/main/src/main/java/com/faeiq/healthvault/HealthVaultApplication.java) (HealthVault), [`src/main/resources/application.yaml`](https://github.com/faeiqkhan/healthvaultbackend/blob/main/src/main/resources/application.yaml) (PostgreSQL), [`src/main/java/com/faeiq/healthvault/record/repository/RecordRepository.java`](https://github.com/faeiqkhan/healthvaultbackend/blob/main/src/main/java/com/faeiq/healthvault/record/repository/RecordRepository.java) (Record repo), [`src/main/java/com/faeiq/healthvault/audit/service/AuditService.java`](https://github.com/faeiqkhan/healthvaultbackend/blob/main/src/main/java/com/faeiq/healthvault/audit/service/AuditService.java) (Audit service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_platform["Platform"]
  node_app["HealthVault<br/>Spring Boot app"]
  node_build["Maven build<br/>Build tool<br/>[pom.xml]"]
  node_api["API layer<br/>REST/security"]
end

subgraph group_identity["Identity"]
  node_user["User<br/>Identity model<br/>[User.java]"]
  node_role["Role<br/>RBAC enum<br/>[Role.java]"]
  node_kycstatus["KYC status<br/>Verification enum<br/>[KycStatus.java]"]
  node_doctor["Doctor<br/>KYC entity<br/>[Doctor.java]"]
  node_patient["Patient<br/>KYC entity<br/>[Patient.java]"]
  node_userrepo["User repo<br/>Spring Data repo"]
  node_doctorrepo["Doctor repo<br/>Spring Data repo"]
  node_patientrepo["Patient repo<br/>Spring Data repo"]
end

subgraph group_data["Data"]
  node_encrypt{{"Encryption<br/>AES+RSA boundary"}}
  node_record["Record<br/>[Record.java]"]
  node_recordrepo["Record repo<br/>Spring Data repo"]
  node_db[("PostgreSQL<br/>Database<br/>[application.yaml]")]
end

subgraph group_audit["Audit"]
  node_auditservice["Audit service<br/>Security trail<br/>[AuditService.java]"]
  node_audit["Audit<br/>Log entity<br/>[Audit.java]"]
  node_auditrepo["Audit repo<br/>Spring Data repo"]
end

node_build -->|"builds"| node_app
node_app -->|"starts"| node_api
node_app -->|"wires"| node_userrepo
node_app -->|"wires"| node_doctorrepo
node_app -->|"wires"| node_patientrepo
node_app -->|"wires"| node_recordrepo
node_app -->|"wires"| node_auditservice
node_api -->|"authenticates"| node_user
node_api -->|"authorizes"| node_role
node_api -->|"checks"| node_kycstatus
node_api -->|"validates"| node_doctor
node_api -->|"validates"| node_patient
node_api -->|"uploads"| node_encrypt
node_encrypt -->|"stores via"| node_recordrepo
node_recordrepo -->|"persists"| node_record
node_userrepo -->|"persists"| node_db
node_doctorrepo -->|"persists"| node_db
node_patientrepo -->|"persists"| node_db
node_recordrepo -->|"persists"| node_db
node_auditservice -->|"writes"| node_audit
node_auditservice -->|"persists"| node_auditrepo
node_auditrepo -->|"persists"| node_db
node_api -.->|"logs"| node_auditservice
node_encrypt -.->|"protects"| node_db
node_api -->|"reads"| node_recordrepo

click node_app "https://github.com/faeiqkhan/healthvaultbackend/blob/main/src/main/java/com/faeiq/healthvault/HealthVaultApplication.java"
click node_build "https://github.com/faeiqkhan/healthvaultbackend/blob/main/pom.xml"
click node_user "https://github.com/faeiqkhan/healthvaultbackend/blob/main/src/main/java/com/faeiq/healthvault/user/entity/User.java"
click node_role "https://github.com/faeiqkhan/healthvaultbackend/blob/main/src/main/java/com/faeiq/healthvault/user/entity/Role.java"
click node_kycstatus "https://github.com/faeiqkhan/healthvaultbackend/blob/main/src/main/java/com/faeiq/healthvault/user/entity/KycStatus.java"
click node_doctor "https://github.com/faeiqkhan/healthvaultbackend/blob/main/src/main/java/com/faeiq/healthvault/kyc/entity/Doctor.java"
click node_patient "https://github.com/faeiqkhan/healthvaultbackend/blob/main/src/main/java/com/faeiq/healthvault/kyc/entity/Patient.java"
click node_userrepo "https://github.com/faeiqkhan/healthvaultbackend/blob/main/src/main/java/com/faeiq/healthvault/user/repository/UserRepository.java"
click node_doctorrepo "https://github.com/faeiqkhan/healthvaultbackend/blob/main/src/main/java/com/faeiq/healthvault/kyc/repository/DoctorRepository.java"
click node_patientrepo "https://github.com/faeiqkhan/healthvaultbackend/blob/main/src/main/java/com/faeiq/healthvault/kyc/repository/PatientRepository.java"
click node_record "https://github.com/faeiqkhan/healthvaultbackend/blob/main/src/main/java/com/faeiq/healthvault/record/entity/Record.java"
click node_recordrepo "https://github.com/faeiqkhan/healthvaultbackend/blob/main/src/main/java/com/faeiq/healthvault/record/repository/RecordRepository.java"
click node_db "https://github.com/faeiqkhan/healthvaultbackend/blob/main/src/main/resources/application.yaml"
click node_auditservice "https://github.com/faeiqkhan/healthvaultbackend/blob/main/src/main/java/com/faeiq/healthvault/audit/service/AuditService.java"
click node_audit "https://github.com/faeiqkhan/healthvaultbackend/blob/main/src/main/java/com/faeiq/healthvault/audit/entity/Audit.java"
click node_auditrepo "https://github.com/faeiqkhan/healthvaultbackend/blob/main/src/main/java/com/faeiq/healthvault/audit/repository/AuditRepository.java"

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_build,node_api toneBlue
class node_user,node_role,node_kycstatus,node_doctor,node_patient,node_userrepo,node_doctorrepo,node_patientrepo toneAmber
class node_encrypt,node_record,node_recordrepo,node_db toneMint
class node_auditservice,node_audit,node_auditrepo toneRose
```

## Components

### Platform

Spring Boot bootstrap and build/runtime surface.

- [HealthVault](https://github.com/faeiqkhan/healthvaultbackend/blob/main/src/main/java/com/faeiq/healthvault/HealthVaultApplication.java): Spring Boot app · Application bootstrap and Spring component wiring. · `src/main/java/com/faeiq/healthvault/HealthVaultApplication.java`
- [Maven build](https://github.com/faeiqkhan/healthvaultbackend/blob/main/pom.xml): Build tool · Maven wrapper and project build lifecycle. · `pom.xml`
- **API layer**: REST/security · Conceptual API and authentication boundary described in the repository documentation.

### Identity

Users, roles, and KYC verification boundary.

- [User](https://github.com/faeiqkhan/healthvaultbackend/blob/main/src/main/java/com/faeiq/healthvault/user/entity/User.java): Identity model · Primary account and access identity. · `src/main/java/com/faeiq/healthvault/user/entity/User.java`
- [Role](https://github.com/faeiqkhan/healthvaultbackend/blob/main/src/main/java/com/faeiq/healthvault/user/entity/Role.java): RBAC enum · Authorization roles for access control. · `src/main/java/com/faeiq/healthvault/user/entity/Role.java`
- [KYC status](https://github.com/faeiqkhan/healthvaultbackend/blob/main/src/main/java/com/faeiq/healthvault/user/entity/KycStatus.java): Verification enum · Verification state used in access decisions. · `src/main/java/com/faeiq/healthvault/user/entity/KycStatus.java`
- [Doctor](https://github.com/faeiqkhan/healthvaultbackend/blob/main/src/main/java/com/faeiq/healthvault/kyc/entity/Doctor.java): KYC entity · Verified clinician identity and profile. · `src/main/java/com/faeiq/healthvault/kyc/entity/Doctor.java`
- [Patient](https://github.com/faeiqkhan/healthvaultbackend/blob/main/src/main/java/com/faeiq/healthvault/kyc/entity/Patient.java): KYC entity · Patient identity and ownership side of records. · `src/main/java/com/faeiq/healthvault/kyc/entity/Patient.java`
- [User repo](https://github.com/faeiqkhan/healthvaultbackend/blob/main/src/main/java/com/faeiq/healthvault/user/repository/UserRepository.java): Spring Data repo · Persistence for user accounts. · `src/main/java/com/faeiq/healthvault/user/repository/UserRepository.java`
- [Doctor repo](https://github.com/faeiqkhan/healthvaultbackend/blob/main/src/main/java/com/faeiq/healthvault/kyc/repository/DoctorRepository.java): Spring Data repo · Persistence for doctor verification records. · `src/main/java/com/faeiq/healthvault/kyc/repository/DoctorRepository.java`
- [Patient repo](https://github.com/faeiqkhan/healthvaultbackend/blob/main/src/main/java/com/faeiq/healthvault/kyc/repository/PatientRepository.java): Spring Data repo · Persistence for patient verification records. · `src/main/java/com/faeiq/healthvault/kyc/repository/PatientRepository.java`

### Data

Record storage, encryption boundary, and PostgreSQL persistence.

- **Encryption**: AES+RSA boundary · Zero-knowledge file protection boundary before durable storage.
- [Record](https://github.com/faeiqkhan/healthvaultbackend/blob/main/src/main/java/com/faeiq/healthvault/record/entity/Record.java): Medical record · Protected record metadata and file reference. · `src/main/java/com/faeiq/healthvault/record/entity/Record.java`
- [Record repo](https://github.com/faeiqkhan/healthvaultbackend/blob/main/src/main/java/com/faeiq/healthvault/record/repository/RecordRepository.java): Spring Data repo · Persistence boundary for records. · `src/main/java/com/faeiq/healthvault/record/repository/RecordRepository.java`
- [PostgreSQL](https://github.com/faeiqkhan/healthvaultbackend/blob/main/src/main/resources/application.yaml): Database · Durable backend for domain entities and records. · `src/main/resources/application.yaml`

### Audit

Security trail for sensitive actions and access events.

- [Audit service](https://github.com/faeiqkhan/healthvaultbackend/blob/main/src/main/java/com/faeiq/healthvault/audit/service/AuditService.java): Security trail · Coordinates audit events for sensitive actions. · `src/main/java/com/faeiq/healthvault/audit/service/AuditService.java`
- [Audit](https://github.com/faeiqkhan/healthvaultbackend/blob/main/src/main/java/com/faeiq/healthvault/audit/entity/Audit.java): Log entity · Stored audit event for access and workflow tracing. · `src/main/java/com/faeiq/healthvault/audit/entity/Audit.java`
- [Audit repo](https://github.com/faeiqkhan/healthvaultbackend/blob/main/src/main/java/com/faeiq/healthvault/audit/repository/AuditRepository.java): Spring Data repo · Persistence for audit events. · `src/main/java/com/faeiq/healthvault/audit/repository/AuditRepository.java`

## Connections

- Maven build → HealthVault: builds · Maven build produces the Spring Boot application.
- HealthVault → API layer: starts · Bootstraps the HTTP and security-facing application surface.
- HealthVault → User repo: wires · Spring injects identity persistence into the application context.
- HealthVault → Doctor repo: wires · Spring injects KYC persistence into the application context.
- HealthVault → Patient repo: wires · Spring injects KYC persistence into the application context.
- HealthVault → Record repo: wires · Spring injects record persistence into the application context.
- HealthVault → Audit service: wires · Spring injects audit coordination into the application context.
- API layer → User: authenticates · API/security decisions are anchored on the user identity model.
- API layer → Role: authorizes · Role-based access control gates protected actions.
- API layer → KYC status: checks · Verification state influences access and workflow eligibility.
- API layer → Doctor: validates · Doctor status is part of the authorized clinician boundary.
- API layer → Patient: validates · Patient identity establishes ownership of records.
- API layer → Encryption: uploads · Incoming files are encrypted before persistence.
- Encryption → Record repo: stores via · Encrypted record payloads are persisted through the record repository.
- Record repo → Record: persists · Record metadata and references are stored as domain entities.
- User repo → PostgreSQL: persists · User accounts are stored in PostgreSQL.
- Doctor repo → PostgreSQL: persists · Doctor KYC data is stored in PostgreSQL.
- Patient repo → PostgreSQL: persists · Patient KYC data is stored in PostgreSQL.
- Record repo → PostgreSQL: persists · Record metadata is stored in PostgreSQL.
- Audit service → Audit: writes · Audit service creates trail entries for sensitive actions.
- Audit service → Audit repo: persists · Audit entries are saved through the repository boundary.
- Audit repo → PostgreSQL: persists · Audit trail data is stored in PostgreSQL.
- API layer → Audit service: logs · Authentication, access, and sharing events are audited.
- Encryption → PostgreSQL: protects · Encrypted data reaches storage without requiring plaintext at rest.
- API layer → Record repo: reads · Authorized users retrieve records through guarded flows.
