# shin201005/medical-ledger architecture

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

- Interactive diagram: https://gitdiagram.com/shin201005/medical-ledger
- Repository: https://github.com/shin201005/medical-ledger

## Overview

Medical Ledger is a role-based medical-record and product-management application, with a separate AI service for identity, image, and product analysis. The user-facing flow runs from the browser through its shared API client to backend domain endpoints; AI capabilities are also exposed as HTTP endpoints. The excerpts show client requests and several internal calls, but do not show backend application wiring or most service-to-service calls, so those links are omitted. Unexcerpted domain modules are represented by their exact module directories.

Main entry points: [`frontend/src/services/api.ts`](https://github.com/shin201005/medical-ledger/blob/main/frontend/src/services/api.ts) (API client), [`frontend/src/main.tsx`](https://github.com/shin201005/medical-ledger/blob/main/frontend/src/main.tsx) (Browser application), [`backend/src/utils/errors.js`](https://github.com/shin201005/medical-ledger/blob/main/backend/src/utils/errors.js) (Error responses), [`backend/src/modules/products/routes.js`](https://github.com/shin201005/medical-ledger/blob/main/backend/src/modules/products/routes.js) (Products and packages)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Web application"]
  node_web["Browser application<br/>[main.tsx]"]
  node_session["Authentication session<br/>[Session.tsx]"]
  node_api_client["API client<br/>[api.ts]"]
  node_records_ui["Medical records UI<br/>[Records.tsx]"]
  node_ekyc_ui["eKYC UI<br/>[Ekyc.tsx]"]
  node_products_ui["Product management UI<br/>[Products.tsx]"]
  node_image_lab_ui["Image lab UI<br/>[ImageLab.tsx]"]
end

subgraph group_backend["Medical Ledger backend"]
  node_database[("Application database<br/>[db.js]")]
  node_security["Request security<br/>[security.js]"]
  node_auth["Authentication and wallets"]
  node_patients["Patient management"]
  node_doctors_hospitals["Care organizations"]
  node_ekyc["Identity verification"]
  node_records["Medical records<br/>[controller.js]"]
  node_consent["Record consent"]
  node_products["Products and packages<br/>[routes.js]"]
  node_laboratories["Laboratory workflows"]
  node_verification["Public verification"]
  node_blockchain["Blockchain operations<br/>[controller.js]"]
  node_audit["Audit trail"]
  node_errors["Error responses<br/>[errors.js]"]
end

subgraph group_ai["AI services"]
  node_ai_api["AI HTTP service<br/>[main.py]"]
  node_identity_ai["Identity matching<br/>[identity.py]"]
  node_image_lab_ai["Image processing lab<br/>[image_lab.py]"]
  node_product_search_ai["Product label search<br/>[product_search.py]"]
  node_package_search_ai["Package image search<br/>[package_search.py]"]
  node_csv_clean["Laboratory CSV cleaning<br/>[csv_service.py]"]
end

subgraph group_integrations["External systems"]
  node_blockchain_network{{"Blockchain network"}}
  node_ipfs[("IPFS storage")]
  node_ai_endpoint{{"AI endpoint"}}
end

node_user(("Staff and patients"))

node_user -->|"uses"| node_web
node_web -->|"provides session"| node_session
node_web -->|"routes to"| node_records_ui
node_web -->|"routes to"| node_ekyc_ui
node_web -->|"routes to"| node_products_ui
node_web -->|"routes to"| node_image_lab_ui
node_session -->|"requests"| node_api_client
node_records_ui -->|"requests"| node_api_client
node_ekyc_ui -->|"requests"| node_api_client
node_products_ui -->|"requests"| node_api_client
node_image_lab_ui -->|"requests"| node_api_client
node_api_client -->|"HTTP requests"| node_ai_endpoint
node_api_client -.->|"formats failures"| node_errors
node_security -->|"loads session and user"| node_database
node_security -->|"raises errors"| node_errors
node_auth -->|"uses authentication"| node_security
node_auth -->|"wraps responses"| node_errors
node_records -->|"reads records"| node_database
node_records -->|"returns responses"| node_errors
node_products -->|"uses role checks"| node_security
node_products -->|"wraps responses"| node_errors
node_products -.->|"runs image search"| node_product_search_ai
node_products -.->|"searches packages"| node_package_search_ai
node_ai_api -->|"verifies identity"| node_identity_ai
node_ai_api -->|"processes images"| node_image_lab_ai
node_ai_api -->|"analyzes labels"| node_product_search_ai
node_ai_api -->|"cleans CSV"| node_csv_clean
node_identity_ai -->|"uses imaging"| node_image_lab_ai
node_product_search_ai -->|"uses identity helpers"| node_identity_ai
node_product_search_ai -->|"uses image helpers"| node_image_lab_ai
node_package_search_ai -->|"uses image helpers"| node_image_lab_ai
node_blockchain -.->|"submits transactions"| node_blockchain_network
node_records -.->|"stores documents"| node_ipfs

click node_web "https://github.com/shin201005/medical-ledger/blob/main/frontend/src/main.tsx"
click node_session "https://github.com/shin201005/medical-ledger/blob/main/frontend/src/features/auth/Session.tsx"
click node_api_client "https://github.com/shin201005/medical-ledger/blob/main/frontend/src/services/api.ts"
click node_records_ui "https://github.com/shin201005/medical-ledger/blob/main/frontend/src/features/records/Records.tsx"
click node_ekyc_ui "https://github.com/shin201005/medical-ledger/blob/main/frontend/src/features/ekyc/Ekyc.tsx"
click node_products_ui "https://github.com/shin201005/medical-ledger/blob/main/frontend/src/features/products/Products.tsx"
click node_image_lab_ui "https://github.com/shin201005/medical-ledger/blob/main/frontend/src/features/image-lab/ImageLab.tsx"
click node_database "https://github.com/shin201005/medical-ledger/blob/main/backend/src/config/db.js"
click node_security "https://github.com/shin201005/medical-ledger/blob/main/backend/src/middlewares/security.js"
click node_auth "https://github.com/shin201005/medical-ledger/tree/main/backend/src/modules/auth"
click node_patients "https://github.com/shin201005/medical-ledger/tree/main/backend/src/modules/patients"
click node_doctors_hospitals "https://github.com/shin201005/medical-ledger/tree/main/backend/src/modules/doctors"
click node_ekyc "https://github.com/shin201005/medical-ledger/tree/main/backend/src/modules/ekyc"
click node_records "https://github.com/shin201005/medical-ledger/blob/main/backend/src/modules/medical-records/controller.js"
click node_consent "https://github.com/shin201005/medical-ledger/tree/main/backend/src/modules/consent"
click node_products "https://github.com/shin201005/medical-ledger/blob/main/backend/src/modules/products/routes.js"
click node_laboratories "https://github.com/shin201005/medical-ledger/tree/main/backend/src/modules/laboratories"
click node_verification "https://github.com/shin201005/medical-ledger/tree/main/backend/src/modules/verification"
click node_blockchain "https://github.com/shin201005/medical-ledger/blob/main/backend/src/modules/blockchain/controller.js"
click node_audit "https://github.com/shin201005/medical-ledger/tree/main/backend/src/modules/audit"
click node_errors "https://github.com/shin201005/medical-ledger/blob/main/backend/src/utils/errors.js"
click node_ai_api "https://github.com/shin201005/medical-ledger/blob/main/ai_medical_service/main.py"
click node_identity_ai "https://github.com/shin201005/medical-ledger/blob/main/ai_medical_service/identity.py"
click node_image_lab_ai "https://github.com/shin201005/medical-ledger/blob/main/ai_medical_service/image_lab.py"
click node_product_search_ai "https://github.com/shin201005/medical-ledger/blob/main/ai_medical_service/product_search.py"
click node_package_search_ai "https://github.com/shin201005/medical-ledger/blob/main/ai_medical_service/package_search.py"
click node_csv_clean "https://github.com/shin201005/medical-ledger/blob/main/ai_medical_service/csv_service.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,node_session,node_api_client,node_records_ui,node_ekyc_ui,node_products_ui,node_image_lab_ui toneBlue
class node_database,node_security,node_auth,node_patients,node_doctors_hospitals,node_ekyc,node_records,node_consent,node_products,node_laboratories,node_verification,node_blockchain,node_audit,node_errors toneAmber
class node_ai_api,node_identity_ai,node_image_lab_ai,node_product_search_ai,node_package_search_ai,node_csv_clean toneMint
class node_blockchain_network,node_ipfs,node_ai_endpoint toneRose
class node_user toneIndigo
```

## Components

### Web application

- [Browser application](https://github.com/shin201005/medical-ledger/blob/main/frontend/src/main.tsx): `frontend/src/main.tsx`
- [Authentication session](https://github.com/shin201005/medical-ledger/blob/main/frontend/src/features/auth/Session.tsx): `frontend/src/features/auth/Session.tsx`
- [API client](https://github.com/shin201005/medical-ledger/blob/main/frontend/src/services/api.ts): `frontend/src/services/api.ts`
- [Medical records UI](https://github.com/shin201005/medical-ledger/blob/main/frontend/src/features/records/Records.tsx): `frontend/src/features/records/Records.tsx`
- [eKYC UI](https://github.com/shin201005/medical-ledger/blob/main/frontend/src/features/ekyc/Ekyc.tsx): `frontend/src/features/ekyc/Ekyc.tsx`
- [Product management UI](https://github.com/shin201005/medical-ledger/blob/main/frontend/src/features/products/Products.tsx): `frontend/src/features/products/Products.tsx`
- [Image lab UI](https://github.com/shin201005/medical-ledger/blob/main/frontend/src/features/image-lab/ImageLab.tsx): `frontend/src/features/image-lab/ImageLab.tsx`

### Medical Ledger backend

- [Application database](https://github.com/shin201005/medical-ledger/blob/main/backend/src/config/db.js): `backend/src/config/db.js`
- [Request security](https://github.com/shin201005/medical-ledger/blob/main/backend/src/middlewares/security.js): `backend/src/middlewares/security.js`
- [Authentication and wallets](https://github.com/shin201005/medical-ledger/tree/main/backend/src/modules/auth): `backend/src/modules/auth`
- [Patient management](https://github.com/shin201005/medical-ledger/tree/main/backend/src/modules/patients): `backend/src/modules/patients`
- [Care organizations](https://github.com/shin201005/medical-ledger/tree/main/backend/src/modules/doctors): `backend/src/modules/doctors`
- [Identity verification](https://github.com/shin201005/medical-ledger/tree/main/backend/src/modules/ekyc): `backend/src/modules/ekyc`
- [Medical records](https://github.com/shin201005/medical-ledger/blob/main/backend/src/modules/medical-records/controller.js): `backend/src/modules/medical-records/controller.js`
- [Record consent](https://github.com/shin201005/medical-ledger/tree/main/backend/src/modules/consent): `backend/src/modules/consent`
- [Products and packages](https://github.com/shin201005/medical-ledger/blob/main/backend/src/modules/products/routes.js): `backend/src/modules/products/routes.js`
- [Laboratory workflows](https://github.com/shin201005/medical-ledger/tree/main/backend/src/modules/laboratories): `backend/src/modules/laboratories`
- [Public verification](https://github.com/shin201005/medical-ledger/tree/main/backend/src/modules/verification): `backend/src/modules/verification`
- [Blockchain operations](https://github.com/shin201005/medical-ledger/blob/main/backend/src/modules/blockchain/controller.js): `backend/src/modules/blockchain/controller.js`
- [Audit trail](https://github.com/shin201005/medical-ledger/tree/main/backend/src/modules/audit): `backend/src/modules/audit`
- [Error responses](https://github.com/shin201005/medical-ledger/blob/main/backend/src/utils/errors.js): `backend/src/utils/errors.js`

### AI services

- [AI HTTP service](https://github.com/shin201005/medical-ledger/blob/main/ai_medical_service/main.py): `ai_medical_service/main.py`
- [Identity matching](https://github.com/shin201005/medical-ledger/blob/main/ai_medical_service/identity.py): `ai_medical_service/identity.py`
- [Image processing lab](https://github.com/shin201005/medical-ledger/blob/main/ai_medical_service/image_lab.py): `ai_medical_service/image_lab.py`
- [Product label search](https://github.com/shin201005/medical-ledger/blob/main/ai_medical_service/product_search.py): `ai_medical_service/product_search.py`
- [Package image search](https://github.com/shin201005/medical-ledger/blob/main/ai_medical_service/package_search.py): `ai_medical_service/package_search.py`
- [Laboratory CSV cleaning](https://github.com/shin201005/medical-ledger/blob/main/ai_medical_service/csv_service.py): `ai_medical_service/csv_service.py`

### External systems

- **Blockchain network**
- **IPFS storage**
- **AI endpoint**

### Other components

- **Staff and patients**

## Connections

- Staff and patients → Browser application: uses (evidence: `frontend/src/main.tsx`)
- Browser application → Authentication session: provides session (evidence: `frontend/src/main.tsx`)
- Browser application → Medical records UI: routes to (evidence: `frontend/src/main.tsx`)
- Browser application → eKYC UI: routes to (evidence: `frontend/src/main.tsx`)
- Browser application → Product management UI: routes to (evidence: `frontend/src/main.tsx`)
- Browser application → Image lab UI: routes to (evidence: `frontend/src/main.tsx`)
- Authentication session → API client: requests (evidence: `frontend/src/features/auth/Session.tsx`)
- Medical records UI → API client: requests (evidence: `frontend/src/features/records/Records.tsx`)
- eKYC UI → API client: requests (evidence: `frontend/src/features/ekyc/Ekyc.tsx`)
- Product management UI → API client: requests
- Image lab UI → API client: requests (evidence: `frontend/src/features/image-lab/ImageLab.tsx`)
- API client → AI endpoint: HTTP requests (evidence: `frontend/src/services/api.ts`)
- API client → Error responses: formats failures
- Request security → Application database: loads session and user (evidence: `backend/src/middlewares/security.js`)
- Request security → Error responses: raises errors (evidence: `backend/src/middlewares/security.js`)
- Authentication and wallets → Request security: uses authentication (evidence: `backend/src/modules/auth/routes.js`)
- Authentication and wallets → Error responses: wraps responses (evidence: `backend/src/modules/auth/routes.js`)
- Medical records → Application database: reads records (evidence: `backend/src/modules/medical-records/controller.js`)
- Medical records → Error responses: returns responses (evidence: `backend/src/modules/medical-records/controller.js`)
- Products and packages → Request security: uses role checks (evidence: `backend/src/modules/products/routes.js`)
- Products and packages → Error responses: wraps responses (evidence: `backend/src/modules/products/routes.js`)
- Products and packages → Product label search: runs image search
- Products and packages → Package image search: searches packages
- AI HTTP service → Identity matching: verifies identity (evidence: `ai_medical_service/main.py`)
- AI HTTP service → Image processing lab: processes images (evidence: `ai_medical_service/main.py`)
- AI HTTP service → Product label search: analyzes labels (evidence: `ai_medical_service/main.py`)
- AI HTTP service → Laboratory CSV cleaning: cleans CSV (evidence: `ai_medical_service/main.py`)
- Identity matching → Image processing lab: uses imaging (evidence: `ai_medical_service/identity.py`)
- Product label search → Identity matching: uses identity helpers (evidence: `ai_medical_service/product_search.py`)
- Product label search → Image processing lab: uses image helpers (evidence: `ai_medical_service/product_search.py`)
- Package image search → Image processing lab: uses image helpers (evidence: `ai_medical_service/package_search.py`)
- Blockchain operations → Blockchain network: submits transactions
- Medical records → IPFS storage: stores documents
