# saphulele/hospital_management_system architecture

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

- Interactive diagram: https://gitdiagram.com/saphulele/hospital_management_system
- Repository: https://github.com/saphulele/hospital_management_system

## Overview

#### 1. Purpose and Runtime Entry Point
This is a Java Hospital Management System focused in its implemented source on patient, doctor, and appointment management. The executable entry point is `src/src/Main.java`. The repository also contains extensive requirements, domain-modeling, workflow, and persistence-layer design documentation, but no database implementation, UI, or external-service integration is present in the source tree.

#### 2. Layered Application Structure
The implementation follows a controller → service → DTO/error-boundary organization:
- Controllers expose operation-facing endpoints or commands: `src/src/Controller/PatientController.java`, `src/src/Controller/DoctorController.java`, `src/src/Controller/AppointmentController.java`.
- Services hold domain/business operations: `src/src/services/PatientService.java`, `src/src/services/DoctorService.java`, `src/src/services/AppointmentService.java`.
- DTOs define data transferred between controllers and services: `src/src/DTO/Patientdto.java`, `src/src/DTO/DoctorDto.java`, `src/src/DTO/AppointmentDto.java`.

#### 3. Patient Management
Patient operations are centered on the patient service contract and its concrete implementation. `src/src/services/PatientService.java` defines the patient-facing business API, while `src/src/services/PatientServiceImplementation.java` supplies its current implementation. `src/src/Controller/PatientController.java` is the boundary that accepts patient requests and maps results to `Patientdto`.

Patient admission safety is explicitly modeled through `src/src/exceptions/PatientAlreadyAdmittedException.java`; lookup failures use `src/src/exceptions/PatientNotFoundException.java`.

#### 4. Doctor Availability and Coordination
Doctor lifecycle and availability behavior is separated into `src/src/Controller/DoctorController.java` and `src/src/services/DoctorService.java`, with `src/src/DTO/DoctorDto.java` carrying doctor data. This separation is architecturally important because appointment scheduling depends on doctor existence and availability. Failures are represented by `src/src/exceptions/DoctorNotFoundException.java` and `src/src/exceptions/DoctorNotAvailableException.java`.

#### 5. Appointment Scheduling Flow
Appointment handling is the principal cross-domain workflow:
1. A request enters `src/src/Controller/AppointmentController.java`.
2. `src/src/services/AppointmentService.java` coordinates appointment operations and must enforce patient/doctor constraints.
3. Appointment data crosses the boundary via `src/src/DTO/AppointmentDto.java`.
4. Scheduling failures are surfaced as `src/src/exceptions/AppointmentConflictException.java` or `src/src/exceptions/AppointmentNotFoundException.java`.

This is the key control-flow boundary joining patient identity, doctor availability, and temporal conflict rules.

#### 6. Error Handling Boundary
Domain exceptions are centralized under `src/src/exceptions`, allowing services to signal business failures without coupling to a presentation mechanism. `src/src/exceptions/GlobalExceptionHandler.java` is the top-level translation point intended to convert those failures into consistent application responses. This keeps controllers thin and makes exception behavior a shared contract across patient, doctor, and appointment flows.

#### 7. Persistence and Broader Hospital Scope
Persistence is documented as an intended abstraction rather than implemented runtime infrastructure. The design materials identify repository interfaces, in-memory storage, and future-proofing: `Implementing a Persistence Repository Layer/generic repository interface.md`, `Implementing a Persistence Repository Layer/In-Memory Implementation.md`, and `Implementing a Persistence Repository Layer/Storage-Abstraction Mechanism.md`.

The wider target domain—billing, records, beds, pharmacy, labs, surgery, and admissions—is specified in documentation such as `SPECIFICATION.md` and `Object State Modeling/Patient Admission Workflow.md`. These capabilities should be treated as planned domain expansion, not current source-level modules. No concrete database, authentication/security provider, web framework, message broker, or third-party external service is evidenced by the supplied tree.

Main entry points: [`src/src/services/AppointmentService.java`](https://github.com/saphulele/hospital_management_system/blob/main/src/src/services/AppointmentService.java) (Appointment service), [`src/src/services/PatientService.java`](https://github.com/saphulele/hospital_management_system/blob/main/src/src/services/PatientService.java) (Patient service contract), [`src/src/Main.java`](https://github.com/saphulele/hospital_management_system/blob/main/src/src/Main.java) (Application entry point), [`src/src/Controller/PatientController.java`](https://github.com/saphulele/hospital_management_system/blob/main/src/src/Controller/PatientController.java) (Patient controller)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime application"]
  node_main{{"Application entry point<br/>Java main<br/>[Main.java]"}}
end

subgraph group_patient["Patient management"]
  node_patient_controller["Patient controller"]
  node_patient_service["Patient service contract<br/>service API"]
  node_patient_impl["Patient service implementation"]
  node_patient_dto["Patient DTO<br/>[Patientdto.java]"]
end

subgraph group_doctor["Doctor management"]
  node_doctor_controller["Doctor controller"]
  node_doctor_service["Doctor service<br/>service API<br/>[DoctorService.java]"]
  node_doctor_dto["Doctor DTO<br/>[DoctorDto.java]"]
end

subgraph group_appointments["Appointment scheduling"]
  node_appointment_controller["Appointment controller"]
  node_appointment_service["Appointment service<br/>workflow service"]
  node_appointment_dto["Appointment DTO"]
end

subgraph group_errors["Error boundary"]
  node_patient_errors["Patient exceptions<br/>domain exceptions"]
  node_doctor_errors["Doctor exceptions<br/>domain exceptions"]
  node_appointment_errors["Appointment exceptions<br/>domain exceptions"]
  node_exception_handler["Global exception handler<br/>error translator"]
end

subgraph group_planned["Planned architecture"]
  node_persistence_design["Persistence repository design<br/>design documentation"]
  node_domain_spec["Hospital domain specification<br/>requirements documentation<br/>[SPECIFICATION.md]"]
  node_admission_workflow["Patient admission workflow<br/>workflow documentation"]
end

node_main -->|"starts operations"| node_patient_controller
node_main -->|"starts operations"| node_doctor_controller
node_main -->|"starts operations"| node_appointment_controller
node_patient_controller -->|"invokes"| node_patient_service
node_patient_controller -->|"maps requests and results"| node_patient_dto
node_patient_service -->|"implemented by"| node_patient_impl
node_doctor_controller -->|"invokes"| node_doctor_service
node_doctor_controller -->|"maps requests and results"| node_doctor_dto
node_appointment_controller -->|"invokes"| node_appointment_service
node_appointment_controller -->|"maps requests and results"| node_appointment_dto
node_appointment_service -->|"validates patient"| node_patient_service
node_appointment_service -->|"checks existence and availability"| node_doctor_service
node_patient_service -->|"signals business failures"| node_patient_errors
node_doctor_service -->|"signals business failures"| node_doctor_errors
node_appointment_service -->|"signals conflicts and lookup failures"| node_appointment_errors
node_patient_errors -->|"translated by"| node_exception_handler
node_doctor_errors -->|"translated by"| node_exception_handler
node_appointment_errors -->|"translated by"| node_exception_handler
node_domain_spec -.->|"details future workflow"| node_admission_workflow
node_persistence_design -.->|"supports planned expansion"| node_domain_spec

click node_main "https://github.com/saphulele/hospital_management_system/blob/main/src/src/Main.java"
click node_patient_controller "https://github.com/saphulele/hospital_management_system/blob/main/src/src/Controller/PatientController.java"
click node_patient_service "https://github.com/saphulele/hospital_management_system/blob/main/src/src/services/PatientService.java"
click node_patient_impl "https://github.com/saphulele/hospital_management_system/blob/main/src/src/services/PatientServiceImplementation.java"
click node_patient_dto "https://github.com/saphulele/hospital_management_system/blob/main/src/src/DTO/Patientdto.java"
click node_doctor_controller "https://github.com/saphulele/hospital_management_system/blob/main/src/src/Controller/DoctorController.java"
click node_doctor_service "https://github.com/saphulele/hospital_management_system/blob/main/src/src/services/DoctorService.java"
click node_doctor_dto "https://github.com/saphulele/hospital_management_system/blob/main/src/src/DTO/DoctorDto.java"
click node_appointment_controller "https://github.com/saphulele/hospital_management_system/blob/main/src/src/Controller/AppointmentController.java"
click node_appointment_service "https://github.com/saphulele/hospital_management_system/blob/main/src/src/services/AppointmentService.java"
click node_appointment_dto "https://github.com/saphulele/hospital_management_system/blob/main/src/src/DTO/AppointmentDto.java"
click node_patient_errors "https://github.com/saphulele/hospital_management_system/blob/main/src/src/exceptions/PatientAlreadyAdmittedException.java"
click node_doctor_errors "https://github.com/saphulele/hospital_management_system/blob/main/src/src/exceptions/DoctorNotAvailableException.java"
click node_appointment_errors "https://github.com/saphulele/hospital_management_system/blob/main/src/src/exceptions/AppointmentConflictException.java"
click node_exception_handler "https://github.com/saphulele/hospital_management_system/blob/main/src/src/exceptions/GlobalExceptionHandler.java"
click node_persistence_design "https://github.com/saphulele/hospital_management_system/blob/main/Implementing%20a%20Persistence%20Repository%20Layer/generic%20repository%20interface.md"
click node_domain_spec "https://github.com/saphulele/hospital_management_system/blob/main/SPECIFICATION.md"
click node_admission_workflow "https://github.com/saphulele/hospital_management_system/blob/main/Object%20State%20Modeling/Patient%20Admission%20Workflow.md"

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_main toneBlue
class node_patient_controller,node_patient_service,node_patient_impl,node_patient_dto toneAmber
class node_doctor_controller,node_doctor_service,node_doctor_dto toneMint
class node_appointment_controller,node_appointment_service,node_appointment_dto toneRose
class node_patient_errors,node_doctor_errors,node_appointment_errors,node_exception_handler toneIndigo
class node_persistence_design,node_domain_spec,node_admission_workflow toneTeal
```

## Components

### Runtime application

- [Application entry point](https://github.com/saphulele/hospital_management_system/blob/main/src/src/Main.java): Java main · `src/src/Main.java`

### Patient management

- [Patient controller](https://github.com/saphulele/hospital_management_system/blob/main/src/src/Controller/PatientController.java): controller · `src/src/Controller/PatientController.java`
- [Patient service contract](https://github.com/saphulele/hospital_management_system/blob/main/src/src/services/PatientService.java): service API · `src/src/services/PatientService.java`
- [Patient service implementation](https://github.com/saphulele/hospital_management_system/blob/main/src/src/services/PatientServiceImplementation.java): service implementation · `src/src/services/PatientServiceImplementation.java`
- [Patient DTO](https://github.com/saphulele/hospital_management_system/blob/main/src/src/DTO/Patientdto.java): DTO · `src/src/DTO/Patientdto.java`

### Doctor management

- [Doctor controller](https://github.com/saphulele/hospital_management_system/blob/main/src/src/Controller/DoctorController.java): controller · `src/src/Controller/DoctorController.java`
- [Doctor service](https://github.com/saphulele/hospital_management_system/blob/main/src/src/services/DoctorService.java): service API · Manages doctor lifecycle and availability. · `src/src/services/DoctorService.java`
- [Doctor DTO](https://github.com/saphulele/hospital_management_system/blob/main/src/src/DTO/DoctorDto.java): DTO · `src/src/DTO/DoctorDto.java`

### Appointment scheduling

- [Appointment controller](https://github.com/saphulele/hospital_management_system/blob/main/src/src/Controller/AppointmentController.java): controller · `src/src/Controller/AppointmentController.java`
- [Appointment service](https://github.com/saphulele/hospital_management_system/blob/main/src/src/services/AppointmentService.java): workflow service · Coordinates patient, doctor, and scheduling constraints. · `src/src/services/AppointmentService.java`
- [Appointment DTO](https://github.com/saphulele/hospital_management_system/blob/main/src/src/DTO/AppointmentDto.java): DTO · `src/src/DTO/AppointmentDto.java`

### Error boundary

- [Patient exceptions](https://github.com/saphulele/hospital_management_system/blob/main/src/src/exceptions/PatientAlreadyAdmittedException.java): domain exceptions · Admission and lookup failures. · `src/src/exceptions/PatientAlreadyAdmittedException.java`
- [Doctor exceptions](https://github.com/saphulele/hospital_management_system/blob/main/src/src/exceptions/DoctorNotAvailableException.java): domain exceptions · Missing or unavailable doctor failures. · `src/src/exceptions/DoctorNotAvailableException.java`
- [Appointment exceptions](https://github.com/saphulele/hospital_management_system/blob/main/src/src/exceptions/AppointmentConflictException.java): domain exceptions · Conflict and lookup failures. · `src/src/exceptions/AppointmentConflictException.java`
- [Global exception handler](https://github.com/saphulele/hospital_management_system/blob/main/src/src/exceptions/GlobalExceptionHandler.java): error translator · Converts domain failures into consistent responses. · `src/src/exceptions/GlobalExceptionHandler.java`

### Planned architecture

Documented only; not implemented at runtime.

- [Persistence repository design](https://github.com/saphulele/hospital_management_system/blob/main/Implementing%20a%20Persistence%20Repository%20Layer/generic%20repository%20interface.md): design documentation · Defines repository, in-memory, and storage-abstraction plans. · `Implementing a Persistence Repository Layer/generic repository interface.md`
- [Hospital domain specification](https://github.com/saphulele/hospital_management_system/blob/main/SPECIFICATION.md): requirements documentation · Defines broader future hospital capabilities. · `SPECIFICATION.md`
- [Patient admission workflow](https://github.com/saphulele/hospital_management_system/blob/main/Object%20State%20Modeling/Patient%20Admission%20Workflow.md): workflow documentation · Documents planned admission state modeling. · `Object State Modeling/Patient Admission Workflow.md`

## Connections

- Application entry point → Patient controller: starts operations
- Application entry point → Doctor controller: starts operations
- Application entry point → Appointment controller: starts operations
- Patient controller → Patient service contract: invokes
- Patient controller → Patient DTO: maps requests and results
- Patient service contract → Patient service implementation: implemented by
- Doctor controller → Doctor service: invokes
- Doctor controller → Doctor DTO: maps requests and results
- Appointment controller → Appointment service: invokes
- Appointment controller → Appointment DTO: maps requests and results
- Appointment service → Patient service contract: validates patient
- Appointment service → Doctor service: checks existence and availability
- Patient service contract → Patient exceptions: signals business failures
- Doctor service → Doctor exceptions: signals business failures
- Appointment service → Appointment exceptions: signals conflicts and lookup failures
- Patient exceptions → Global exception handler: translated by
- Doctor exceptions → Global exception handler: translated by
- Appointment exceptions → Global exception handler: translated by
- Hospital domain specification → Patient admission workflow: details future workflow
- Persistence repository design → Hospital domain specification: supports planned expansion
