# imrajeevnayan/hospital-management-springboot architecture

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

- Interactive diagram: https://gitdiagram.com/imrajeevnayan/hospital-management-springboot
- Repository: https://github.com/imrajeevnayan/hospital-management-springboot

## Overview

#### Purpose and entry point
This is a server-rendered Hospital Management System for patient registration, appointment workflows, doctor views, and administration. The Spring Boot application starts at `src/main/java/com/hms/hospital/HospitalApplication.java`; browser requests are rendered as Thymeleaf HTML rather than through a separate frontend application.

#### Web and role-oriented UI boundary
MVC controllers define the application-facing request boundary and route users into role-specific pages:
- Administration: `src/main/java/com/hms/hospital/controller/AdminController.java`
- Patient/account and booking: `src/main/java/com/hms/hospital/controller/PatientController.java`, `src/main/java/com/hms/hospital/controller/AppointmentController.java`
- Doctor scheduling views: `src/main/java/com/hms/hospital/controller/DoctorController.java`

Their views are organized by role/feature under `src/main/resources/templates/admin`, `src/main/resources/templates/patient`, `src/main/resources/templates/doctor`, and `src/main/resources/templates/appointment`.

#### Authentication and authorization
Spring Security is centralized in `src/main/java/com/hms/hospital/config/SecurityConfig.java`. User identity, credentials, and assigned role are persisted through `src/main/java/com/hms/hospital/entity/User.java` and `src/main/java/com/hms/hospital/entity/Role.java`, with lookup/storage via `src/main/java/com/hms/hospital/repository/UserRepository.java`. This forms the boundary protecting administrative, doctor, and patient request paths.

#### Core domain model
The persistent business model centers on users, patient profiles, and appointments:
- `src/main/java/com/hms/hospital/entity/User.java`
- `src/main/java/com/hms/hospital/entity/Patient.java`
- `src/main/java/com/hms/hospital/entity/Appointment.java`

Appointments connect scheduling behavior to patient-facing booking/history and doctor/admin dashboards. The tree contains no separate Doctor entity or repository, so doctor identity/scheduling appears to be represented through users and controller-level flows.

#### Application service and persistence flow
The primary layered flow is controller → service → Spring Data repository → relational database. `src/main/java/com/hms/hospital/service/PatientService.java` encapsulates patient-oriented business operations, while repositories provide persistence access:
- `src/main/java/com/hms/hospital/repository/PatientRepository.java`
- `src/main/java/com/hms/hospital/repository/AppointmentRepository.java`
- `src/main/java/com/hms/hospital/repository/UserRepository.java`

This isolates web concerns from JPA-backed storage, although the available tree shows a dedicated service only for patient logic.

#### Runtime, configuration, and delivery
The runtime is a Maven/Spring Boot Java application, defined by `pom.xml` and configured through `src/main/resources/application.properties`. The README identifies PostgreSQL as the production database and Spring Security/Thymeleaf as material framework dependencies. Container deployment is supported by `Dockerfile` and `docker-compose.yml`, with Compose intended to run the application alongside its database service.

#### Main control flows
Unauthenticated users enter through `src/main/java/com/hms/hospital/controller/HomeController.java` and the login/registration templates (`src/main/resources/templates/login.html`, `src/main/resources/templates/register.html`). After authentication, role policy routes access to patient, doctor, or admin dashboards. Patient actions create/read appointment data; doctor and admin pages consume the same appointment/user records for scheduling and oversight. Database access remains behind repositories, and rendered HTML is the outbound response boundary.

Main entry points: [`src/main/java/com/hms/hospital/config/SecurityConfig.java`](https://github.com/imrajeevnayan/hospital-management-springboot/blob/main/src/main/java/com/hms/hospital/config/SecurityConfig.java) (SecurityConfig), [`src/main/java/com/hms/hospital/repository/UserRepository.java`](https://github.com/imrajeevnayan/hospital-management-springboot/blob/main/src/main/java/com/hms/hospital/repository/UserRepository.java) (UserRepository), [`src/main/java/com/hms/hospital/repository/PatientRepository.java`](https://github.com/imrajeevnayan/hospital-management-springboot/blob/main/src/main/java/com/hms/hospital/repository/PatientRepository.java) (PatientRepository), [`src/main/java/com/hms/hospital/repository/AppointmentRepository.java`](https://github.com/imrajeevnayan/hospital-management-springboot/blob/main/src/main/java/com/hms/hospital/repository/AppointmentRepository.java) (AppointmentRepository)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web &amp; UI"]
  node_web_controllers["Role MVC controllers<br/>MVC request boundary"]
  node_home_controller["HomeController<br/>public MVC controller"]
  node_templates["Thymeleaf views<br/>server-rendered HTML"]
end

subgraph group_core["Application Core"]
  node_security["SecurityConfig<br/>authentication &amp; authorization"]
  node_patient_service["PatientService<br/>application service"]
  node_user_role["User &amp; Role<br/>identity domain model<br/>[User.java]"]
  node_patient["Patient<br/>[Patient.java]"]
  node_appointment["Appointment<br/>scheduling entity<br/>[Appointment.java]"]
end

subgraph group_data["Persistence"]
  node_user_repository["UserRepository<br/>Spring Data repository"]
  node_patient_repository["PatientRepository<br/>Spring Data repository"]
  node_appointment_repository["AppointmentRepository<br/>Spring Data repository"]
  node_postgresql[("PostgreSQL<br/>relational database")]
end

subgraph group_runtime["Runtime &amp; Delivery"]
  node_application{{"HospitalApplication<br/>Spring Boot entry point"}}
  node_pom["Maven build<br/>build definition<br/>[pom.xml]"]
  node_properties["Application properties<br/>runtime configuration"]
  node_compose["Docker Compose<br/>deployment topology<br/>[docker-compose.yml]"]
end

node_pom -->|"builds"| node_application
node_properties -->|"configures"| node_application
node_compose -->|"runs"| node_application
node_compose -->|"runs"| node_postgresql
node_home_controller -->|"renders"| node_templates
node_web_controllers -->|"renders"| node_templates
node_security -.->|"secures login flow"| node_home_controller
node_security -->|"authorizes roles"| node_web_controllers
node_security -->|"loads identities"| node_user_repository
node_user_repository -->|"persists"| node_user_role
node_web_controllers -->|"patient operations"| node_patient_service
node_patient_service -->|"manages profiles"| node_patient_repository
node_web_controllers -->|"booking &amp; scheduling"| node_appointment_repository
node_patient_repository -->|"persists"| node_patient
node_appointment_repository -->|"persists"| node_appointment
node_user_repository -->|"stores"| node_postgresql
node_patient_repository -->|"stores"| node_postgresql
node_appointment_repository -->|"stores"| node_postgresql

click node_application "https://github.com/imrajeevnayan/hospital-management-springboot/blob/main/src/main/java/com/hms/hospital/HospitalApplication.java"
click node_pom "https://github.com/imrajeevnayan/hospital-management-springboot/blob/main/pom.xml"
click node_properties "https://github.com/imrajeevnayan/hospital-management-springboot/blob/main/src/main/resources/application.properties"
click node_compose "https://github.com/imrajeevnayan/hospital-management-springboot/blob/main/docker-compose.yml"
click node_home_controller "https://github.com/imrajeevnayan/hospital-management-springboot/blob/main/src/main/java/com/hms/hospital/controller/HomeController.java"
click node_security "https://github.com/imrajeevnayan/hospital-management-springboot/blob/main/src/main/java/com/hms/hospital/config/SecurityConfig.java"
click node_patient_service "https://github.com/imrajeevnayan/hospital-management-springboot/blob/main/src/main/java/com/hms/hospital/service/PatientService.java"
click node_user_role "https://github.com/imrajeevnayan/hospital-management-springboot/blob/main/src/main/java/com/hms/hospital/entity/User.java"
click node_patient "https://github.com/imrajeevnayan/hospital-management-springboot/blob/main/src/main/java/com/hms/hospital/entity/Patient.java"
click node_appointment "https://github.com/imrajeevnayan/hospital-management-springboot/blob/main/src/main/java/com/hms/hospital/entity/Appointment.java"
click node_user_repository "https://github.com/imrajeevnayan/hospital-management-springboot/blob/main/src/main/java/com/hms/hospital/repository/UserRepository.java"
click node_patient_repository "https://github.com/imrajeevnayan/hospital-management-springboot/blob/main/src/main/java/com/hms/hospital/repository/PatientRepository.java"
click node_appointment_repository "https://github.com/imrajeevnayan/hospital-management-springboot/blob/main/src/main/java/com/hms/hospital/repository/AppointmentRepository.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_web_controllers,node_home_controller,node_templates toneBlue
class node_security,node_patient_service,node_user_role,node_patient,node_appointment toneAmber
class node_user_repository,node_patient_repository,node_appointment_repository,node_postgresql toneMint
class node_application,node_pom,node_properties,node_compose toneRose
```

## Components

### Web & UI

Server-rendered request boundary and role-specific views.

- **Role MVC controllers**: MVC request boundary · Admin, patient, appointment, and doctor request flows.
- [HomeController](https://github.com/imrajeevnayan/hospital-management-springboot/blob/main/src/main/java/com/hms/hospital/controller/HomeController.java): public MVC controller · `src/main/java/com/hms/hospital/controller/HomeController.java`
- **Thymeleaf views**: server-rendered HTML · Role and feature templates render browser responses.

### Application Core

Security, patient logic, and persistent domain.

- [SecurityConfig](https://github.com/imrajeevnayan/hospital-management-springboot/blob/main/src/main/java/com/hms/hospital/config/SecurityConfig.java): authentication & authorization · Protects role-specific request paths. · `src/main/java/com/hms/hospital/config/SecurityConfig.java`
- [PatientService](https://github.com/imrajeevnayan/hospital-management-springboot/blob/main/src/main/java/com/hms/hospital/service/PatientService.java): application service · Encapsulates patient-oriented business operations. · `src/main/java/com/hms/hospital/service/PatientService.java`
- [User & Role](https://github.com/imrajeevnayan/hospital-management-springboot/blob/main/src/main/java/com/hms/hospital/entity/User.java): identity domain model · Credentials and assigned roles define access. · `src/main/java/com/hms/hospital/entity/User.java`
- [Patient](https://github.com/imrajeevnayan/hospital-management-springboot/blob/main/src/main/java/com/hms/hospital/entity/Patient.java): patient profile entity · `src/main/java/com/hms/hospital/entity/Patient.java`
- [Appointment](https://github.com/imrajeevnayan/hospital-management-springboot/blob/main/src/main/java/com/hms/hospital/entity/Appointment.java): scheduling entity · Shared by booking, doctor scheduling, and administration. · `src/main/java/com/hms/hospital/entity/Appointment.java`

### Persistence

Spring Data access to PostgreSQL.

- [UserRepository](https://github.com/imrajeevnayan/hospital-management-springboot/blob/main/src/main/java/com/hms/hospital/repository/UserRepository.java): Spring Data repository · `src/main/java/com/hms/hospital/repository/UserRepository.java`
- [PatientRepository](https://github.com/imrajeevnayan/hospital-management-springboot/blob/main/src/main/java/com/hms/hospital/repository/PatientRepository.java): Spring Data repository · `src/main/java/com/hms/hospital/repository/PatientRepository.java`
- [AppointmentRepository](https://github.com/imrajeevnayan/hospital-management-springboot/blob/main/src/main/java/com/hms/hospital/repository/AppointmentRepository.java): Spring Data repository · `src/main/java/com/hms/hospital/repository/AppointmentRepository.java`
- **PostgreSQL**: relational database

### Runtime & Delivery

Spring Boot build, configuration, and containers.

- [HospitalApplication](https://github.com/imrajeevnayan/hospital-management-springboot/blob/main/src/main/java/com/hms/hospital/HospitalApplication.java): Spring Boot entry point · `src/main/java/com/hms/hospital/HospitalApplication.java`
- [Maven build](https://github.com/imrajeevnayan/hospital-management-springboot/blob/main/pom.xml): build definition · `pom.xml`
- [Application properties](https://github.com/imrajeevnayan/hospital-management-springboot/blob/main/src/main/resources/application.properties): runtime configuration · `src/main/resources/application.properties`
- [Docker Compose](https://github.com/imrajeevnayan/hospital-management-springboot/blob/main/docker-compose.yml): deployment topology · Runs the application with its database service. · `docker-compose.yml`

## Connections

- Maven build → HospitalApplication: builds
- Application properties → HospitalApplication: configures
- Docker Compose → HospitalApplication: runs
- Docker Compose → PostgreSQL: runs
- HomeController → Thymeleaf views: renders
- Role MVC controllers → Thymeleaf views: renders
- SecurityConfig → HomeController: secures login flow
- SecurityConfig → Role MVC controllers: authorizes roles
- SecurityConfig → UserRepository: loads identities
- UserRepository → User & Role: persists
- Role MVC controllers → PatientService: patient operations
- PatientService → PatientRepository: manages profiles
- Role MVC controllers → AppointmentRepository: booking & scheduling
- PatientRepository → Patient: persists
- AppointmentRepository → Appointment: persists
- UserRepository → PostgreSQL: stores
- PatientRepository → PostgreSQL: stores
- AppointmentRepository → PostgreSQL: stores
