A secure and scalable Hospital Management System Backend built with Spring Boot.
This project implements real-world backend practices including JWT Authentication, OAuth2 Login, Role Based Access Control, DTO architecture, layered design, and relational database management.
- JWT based authentication
- Secure signup and login
- OAuth2 login integration
- Spring Security implementation
- Role Based Access Control (RBAC)
- BCrypt password encryption
- Stateless authentication
- Protected REST APIs
The system uses a centralized User entity for authentication and authorization.
Supported roles:
ADMIN
DOCTOR
PATIENT
User relationship:
User
|
+---- Patient
|
+---- Doctor
User ID is used as the main identity reference across the system.
Admin can:
- Register doctors
- Assign doctor roles
- Manage doctor profiles
- Assign departments
- Manage appointments
Doctors can:
- View appointments
- Update appointment status
- Manage their profile
Patients can:
- Create profile
- Update profile
- View appointments
- Cancel appointments
Appointment lifecycle:
REQUESTED
|
v
CONFIRMED
|
v
COMPLETED
REQUESTED / CONFIRMED
|
v
CANCELLED
Features:
- Create appointments
- Assign doctors
- Confirm appointments
- Complete appointments
- Cancel appointments
Admin can:
- Create departments
- Update departments
- Delete departments
- Add doctors to departments
- Remove doctors
- Assign department head
Implemented using JPA / Hibernate:
User
|
| OneToOne
|
Doctor
User
|
| OneToOne
|
Patient
Doctor
|
| OneToMany
|
Appointment
Department
|
| ManyToMany
|
Doctor
The project follows layered architecture:
Controller
|
v
Service
|
v
Repository
|
v
Database
Entities are not exposed directly.
Flow:
Request DTO
|
v
Controller
|
v
Service
|
v
Entity
|
v
Response DTO
Benefits:
- Secure API responses
- Clean separation
- Easy maintenance
- Loose coupling
src/main/java/com/dhaliwal/hospitalManagement
├── controller
│ ├── AdminController
│ ├── DoctorController
│ ├── PatientController
│ ├── AppointmentController
│ ├── DepartmentController
│ └── PublicController
│
├── service
│
├── repository
│
├── entity
│
├── dto
│
├── mapper
│
└── security
│
├── auth
│ ├── controller
│ │ └── AuthController
│ │
│ ├── service
│ │ └── AuthService
│ │
│ └── dto
│ ├── LoginRequestDto
│ ├── LoginResponseDto
│ ├── SignupRequestDto
│ └── SignupResponseDto
│
├── config
│ ├── WebSecurityConfig
│ └── ApplicationConfig
│
├── jwt
│ ├── JwtAuthFilter
│ └── AuthUtil
│
├── oauth2
│ └── OAuth2SuccessHandler
│
└── userdetails
└── CustomUserDetailService
User
|
v
Auth Controller
|
v
Authentication Manager
|
v
JWT Generated
|
v
Access APIs
Client
|
| Bearer Token
v
JwtAuthFilter
|
v
SecurityContext
|
v
Controller
Public:
/auth/**
/public/**
Admin:
/admin/**
Doctor:
/doctor/**
Patient:
/patient/**
- Java
- Spring Boot
- Spring Security
- Spring Data JPA
- Hibernate
- JWT
- OAuth2
- BCrypt
- PostgreSQL / MySQL
- Gradle
Clone repository:
git clone https://github.com/sukhmmeet/Hospital-Management-System-SpringBoot-Backend.gitConfigure database:
src/main/resources/application.yml
Run:
./gradlew bootRunRequired:
DATABASE_URL
DATABASE_USERNAME
DATABASE_PASSWORD
JWT_SECRET
GOOGLE_CLIENT_ID
GOOGLE_CLIENT_SECRET
Sukhmmeet
GitHub: https://github.com/sukhmmeet
⭐ Give a star if you like this project.