# enos22/hospital-management-system architecture

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

- Interactive diagram: https://gitdiagram.com/enos22/hospital-management-system
- Repository: https://github.com/enos22/hospital-management-system

## Overview

This is a Flask hospital-management backend exposing APIs for appointments, identity and staff/patient administration, records, laboratory workflows, prescriptions, pharmacy, billing, reports, doctor matching, and notifications. The principal appointment flow accepts a request, checks scheduling conflicts, and persists the appointment; billing requests delegate invoice and payment operations to services. The tree and excerpts show several independent route/service styles, so this is a feature map rather than one unified pipeline. Some route families and models are unsampled; their relationships are omitted where the evidence does not establish calls.

Main entry points: [`HMS-Backend/server/app/models/medical_record.py`](https://github.com/enos22/hospital-management-system/blob/main/HMS-Backend/server/app/models/medical_record.py) (SQLAlchemy models), [`HMS-Backend/server/app/routes/appointment_routes.py`](https://github.com/enos22/hospital-management-system/blob/main/HMS-Backend/server/app/routes/appointment_routes.py) (Appointment API), [`HMS-Backend/server/app/routes/billing_routes.py`](https://github.com/enos22/hospital-management-system/blob/main/HMS-Backend/server/app/routes/billing_routes.py) (Billing and reports), [`HMS-Backend/server/app/routes/prescription_routes.py`](https://github.com/enos22/hospital-management-system/blob/main/HMS-Backend/server/app/routes/prescription_routes.py) (Prescription API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_access["Access and administration"]
  node_auth["Authentication<br/>[auth_routes.py]"]
  node_user_admin["User administration<br/>[admin_routes.py]"]
  node_patient_admin["Patient management<br/>[patient_routes.py]"]
  node_doctor_admin["Doctor management<br/>[doctor_routes.py]"]
  node_role_guard["Role authorization<br/>[role_middleware.py]"]
end

subgraph group_care["Clinical workflows"]
  node_appointment_api["Appointment API"]
  node_conflicts["Conflict checking"]
  node_appointment_service["Appointment scheduling"]
  node_record_api["Medical records API"]
  node_record_service["Record services<br/>[record_service.py]"]
  node_lab_api["Laboratory API"]
  node_prescription_api["Prescription API"]
  node_prescription_service["Prescription services"]
  node_pharmacy_api["Pharmacy inventory<br/>[pharmacy_routes.py]"]
  node_notification_api["Notification API"]
  node_notification_service["Notification delivery"]
end

subgraph group_finance["Billing and matching"]
  node_billing_api["Billing and reports<br/>[billing_routes.py]"]
  node_billing_service["Invoice and payment logic<br/>[billing_service.py]"]
  node_report_service["Financial reporting<br/>[report_service.py]"]
  node_matching_service["Doctor matching"]
end

subgraph group_platform["Persistence and shared services"]
  node_orm["SQLAlchemy models<br/>[medical_record.py]"]
  node_database[("Relational database")]
  node_responses["Response utilities<br/>[responses.py]"]
  node_seed["Initial data setup<br/>[seed.py]"]
end

node_client(("API client"))

node_client -->|"sends requests"| node_auth
node_client -->|"sends requests"| node_appointment_api
node_client -->|"sends requests"| node_billing_api
node_client -->|"sends requests"| node_record_api
node_appointment_api -->|"checks conflicts"| node_conflicts
node_appointment_api -->|"reads and writes"| node_orm
node_appointment_api -->|"formats responses"| node_responses
node_record_api -->|"delegates records"| node_record_service
node_record_service -->|"reads and writes"| node_orm
node_prescription_api -->|"delegates prescriptions"| node_prescription_service
node_prescription_api -->|"checks roles"| node_role_guard
node_prescription_service -->|"reads and writes"| node_orm
node_pharmacy_api -->|"checks roles"| node_role_guard
node_notification_api -->|"delegates delivery"| node_notification_service
node_notification_service -->|"persists notifications"| node_orm
node_billing_api -->|"delegates billing"| node_billing_service
node_billing_api -->|"requests reports"| node_report_service
node_billing_api -->|"requests matching"| node_matching_service
node_billing_service -->|"reads and writes"| node_database
node_appointment_service -.->|"scheduling persistence"| node_database
node_seed -->|"loads model data"| node_orm
node_orm -.->|"maps records"| node_database

click node_auth "https://github.com/enos22/hospital-management-system/blob/main/HMS-Backend/server/app/routes/auth_routes.py"
click node_user_admin "https://github.com/enos22/hospital-management-system/blob/main/HMS-Backend/server/app/routes/admin_routes.py"
click node_patient_admin "https://github.com/enos22/hospital-management-system/blob/main/HMS-Backend/server/app/routes/patient_routes.py"
click node_doctor_admin "https://github.com/enos22/hospital-management-system/blob/main/HMS-Backend/server/app/routes/doctor_routes.py"
click node_role_guard "https://github.com/enos22/hospital-management-system/blob/main/HMS-Backend/server/app/middleware/role_middleware.py"
click node_appointment_api "https://github.com/enos22/hospital-management-system/blob/main/HMS-Backend/server/app/routes/appointment_routes.py"
click node_conflicts "https://github.com/enos22/hospital-management-system/blob/main/HMS-Backend/server/app/utils/conflict_checker.py"
click node_appointment_service "https://github.com/enos22/hospital-management-system/blob/main/HMS-Backend/server/app/services/appointment_service.py"
click node_record_api "https://github.com/enos22/hospital-management-system/blob/main/HMS-Backend/server/app/routes/medical_record_routes.py"
click node_record_service "https://github.com/enos22/hospital-management-system/blob/main/HMS-Backend/server/app/services/record_service.py"
click node_lab_api "https://github.com/enos22/hospital-management-system/blob/main/HMS-Backend/server/app/routes/laboratory_routes.py"
click node_prescription_api "https://github.com/enos22/hospital-management-system/blob/main/HMS-Backend/server/app/routes/prescription_routes.py"
click node_prescription_service "https://github.com/enos22/hospital-management-system/blob/main/HMS-Backend/server/app/services/prescription_service.py"
click node_pharmacy_api "https://github.com/enos22/hospital-management-system/blob/main/HMS-Backend/server/app/routes/pharmacy_routes.py"
click node_notification_api "https://github.com/enos22/hospital-management-system/blob/main/HMS-Backend/server/app/routes/notification_routes.py"
click node_notification_service "https://github.com/enos22/hospital-management-system/blob/main/HMS-Backend/server/app/services/notification_service.py"
click node_billing_api "https://github.com/enos22/hospital-management-system/blob/main/HMS-Backend/server/app/routes/billing_routes.py"
click node_billing_service "https://github.com/enos22/hospital-management-system/blob/main/HMS-Backend/server/app/services/billing_service.py"
click node_report_service "https://github.com/enos22/hospital-management-system/blob/main/HMS-Backend/server/app/services/report_service.py"
click node_matching_service "https://github.com/enos22/hospital-management-system/blob/main/HMS-Backend/server/app/services/matching_service.py"
click node_orm "https://github.com/enos22/hospital-management-system/blob/main/HMS-Backend/server/app/models/medical_record.py"
click node_responses "https://github.com/enos22/hospital-management-system/blob/main/HMS-Backend/server/app/utils/responses.py"
click node_seed "https://github.com/enos22/hospital-management-system/blob/main/HMS-Backend/server/seed.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_auth,node_user_admin,node_patient_admin,node_doctor_admin,node_role_guard,node_client toneBlue
class node_appointment_api,node_conflicts,node_appointment_service,node_record_api,node_record_service,node_lab_api,node_prescription_api,node_prescription_service,node_pharmacy_api,node_notification_api,node_notification_service toneAmber
class node_billing_api,node_billing_service,node_report_service,node_matching_service toneMint
class node_orm,node_database,node_responses,node_seed toneRose
```

## Components

### Access and administration

- [Authentication](https://github.com/enos22/hospital-management-system/blob/main/HMS-Backend/server/app/routes/auth_routes.py): `HMS-Backend/server/app/routes/auth_routes.py`
- [User administration](https://github.com/enos22/hospital-management-system/blob/main/HMS-Backend/server/app/routes/admin_routes.py): `HMS-Backend/server/app/routes/admin_routes.py`
- [Patient management](https://github.com/enos22/hospital-management-system/blob/main/HMS-Backend/server/app/routes/patient_routes.py): `HMS-Backend/server/app/routes/patient_routes.py`
- [Doctor management](https://github.com/enos22/hospital-management-system/blob/main/HMS-Backend/server/app/routes/doctor_routes.py): `HMS-Backend/server/app/routes/doctor_routes.py`
- [Role authorization](https://github.com/enos22/hospital-management-system/blob/main/HMS-Backend/server/app/middleware/role_middleware.py): `HMS-Backend/server/app/middleware/role_middleware.py`

### Clinical workflows

- [Appointment API](https://github.com/enos22/hospital-management-system/blob/main/HMS-Backend/server/app/routes/appointment_routes.py): `HMS-Backend/server/app/routes/appointment_routes.py`
- [Conflict checking](https://github.com/enos22/hospital-management-system/blob/main/HMS-Backend/server/app/utils/conflict_checker.py): `HMS-Backend/server/app/utils/conflict_checker.py`
- [Appointment scheduling](https://github.com/enos22/hospital-management-system/blob/main/HMS-Backend/server/app/services/appointment_service.py): `HMS-Backend/server/app/services/appointment_service.py`
- [Medical records API](https://github.com/enos22/hospital-management-system/blob/main/HMS-Backend/server/app/routes/medical_record_routes.py): `HMS-Backend/server/app/routes/medical_record_routes.py`
- [Record services](https://github.com/enos22/hospital-management-system/blob/main/HMS-Backend/server/app/services/record_service.py): `HMS-Backend/server/app/services/record_service.py`
- [Laboratory API](https://github.com/enos22/hospital-management-system/blob/main/HMS-Backend/server/app/routes/laboratory_routes.py): `HMS-Backend/server/app/routes/laboratory_routes.py`
- [Prescription API](https://github.com/enos22/hospital-management-system/blob/main/HMS-Backend/server/app/routes/prescription_routes.py): `HMS-Backend/server/app/routes/prescription_routes.py`
- [Prescription services](https://github.com/enos22/hospital-management-system/blob/main/HMS-Backend/server/app/services/prescription_service.py): `HMS-Backend/server/app/services/prescription_service.py`
- [Pharmacy inventory](https://github.com/enos22/hospital-management-system/blob/main/HMS-Backend/server/app/routes/pharmacy_routes.py): `HMS-Backend/server/app/routes/pharmacy_routes.py`
- [Notification API](https://github.com/enos22/hospital-management-system/blob/main/HMS-Backend/server/app/routes/notification_routes.py): `HMS-Backend/server/app/routes/notification_routes.py`
- [Notification delivery](https://github.com/enos22/hospital-management-system/blob/main/HMS-Backend/server/app/services/notification_service.py): `HMS-Backend/server/app/services/notification_service.py`

### Billing and matching

- [Billing and reports](https://github.com/enos22/hospital-management-system/blob/main/HMS-Backend/server/app/routes/billing_routes.py): `HMS-Backend/server/app/routes/billing_routes.py`
- [Invoice and payment logic](https://github.com/enos22/hospital-management-system/blob/main/HMS-Backend/server/app/services/billing_service.py): `HMS-Backend/server/app/services/billing_service.py`
- [Financial reporting](https://github.com/enos22/hospital-management-system/blob/main/HMS-Backend/server/app/services/report_service.py): `HMS-Backend/server/app/services/report_service.py`
- [Doctor matching](https://github.com/enos22/hospital-management-system/blob/main/HMS-Backend/server/app/services/matching_service.py): `HMS-Backend/server/app/services/matching_service.py`

### Persistence and shared services

- [SQLAlchemy models](https://github.com/enos22/hospital-management-system/blob/main/HMS-Backend/server/app/models/medical_record.py): `HMS-Backend/server/app/models/medical_record.py`
- **Relational database**
- [Response utilities](https://github.com/enos22/hospital-management-system/blob/main/HMS-Backend/server/app/utils/responses.py): `HMS-Backend/server/app/utils/responses.py`
- [Initial data setup](https://github.com/enos22/hospital-management-system/blob/main/HMS-Backend/server/seed.py): `HMS-Backend/server/seed.py`

### Other components

- **API client**

## Connections

- API client → Authentication: sends requests (evidence: `HMS-Backend/server/app/routes/auth_routes.py`)
- API client → Appointment API: sends requests (evidence: `HMS-Backend/server/app/routes/appointment_routes.py`)
- API client → Billing and reports: sends requests (evidence: `HMS-Backend/server/app/routes/billing_routes.py`)
- API client → Medical records API: sends requests (evidence: `HMS-Backend/server/app/routes/medical_record_routes.py`)
- Appointment API → Conflict checking: checks conflicts (evidence: `HMS-Backend/server/app/routes/appointment_routes.py`)
- Appointment API → SQLAlchemy models: reads and writes (evidence: `HMS-Backend/server/app/routes/appointment_routes.py`)
- Appointment API → Response utilities: formats responses (evidence: `HMS-Backend/server/app/routes/appointment_routes.py`)
- Medical records API → Record services: delegates records (evidence: `HMS-Backend/server/app/routes/medical_record_routes.py`)
- Record services → SQLAlchemy models: reads and writes (evidence: `HMS-Backend/server/app/services/record_service.py`)
- Prescription API → Prescription services: delegates prescriptions (evidence: `HMS-Backend/server/app/routes/prescription_routes.py`)
- Prescription API → Role authorization: checks roles (evidence: `HMS-Backend/server/app/routes/prescription_routes.py`)
- Prescription services → SQLAlchemy models: reads and writes (evidence: `HMS-Backend/server/app/services/prescription_service.py`)
- Pharmacy inventory → Role authorization: checks roles (evidence: `HMS-Backend/server/app/routes/pharmacy_routes.py`)
- Notification API → Notification delivery: delegates delivery (evidence: `HMS-Backend/server/app/routes/notification_routes.py`)
- Notification delivery → SQLAlchemy models: persists notifications (evidence: `HMS-Backend/server/app/services/notification_service.py`)
- Billing and reports → Invoice and payment logic: delegates billing (evidence: `HMS-Backend/server/app/routes/billing_routes.py`)
- Billing and reports → Financial reporting: requests reports (evidence: `HMS-Backend/server/app/routes/billing_routes.py`)
- Billing and reports → Doctor matching: requests matching (evidence: `HMS-Backend/server/app/routes/billing_routes.py`)
- Invoice and payment logic → Relational database: reads and writes (evidence: `HMS-Backend/server/app/services/billing_service.py`)
- Appointment scheduling → Relational database: scheduling persistence
- Initial data setup → SQLAlchemy models: loads model data (evidence: `HMS-Backend/server/seed.py`)
- SQLAlchemy models → Relational database: maps records
