A production-grade Hospital Management System backend built with Spring Boot 3.x, featuring role-based access control, JWT authentication, OAuth2 social login, and a clean layered architecture.
| Layer | Technology |
|---|---|
| Language | Java 21 |
| Framework | Spring Boot 4.x.x |
| Security | Spring Security 6, JWT (jjwt 0.12.6), OAuth2 |
| Persistence | Spring Data JPA, Hibernate |
| Database | PostgreSQL |
| Mapping | ModelMapper 3.2 |
| Utilities | Lombok |
| Build Tool | Maven |
- JWT Authentication — Stateless login with access token generation and validation
- OAuth2 Social Login — Google & GitHub login with automatic user provisioning
- Role-Based Access Control (RBAC) —
ADMIN,DOCTOR,PATIENTroles with fine-grained permission types - Appointment Management — Patients book appointments; doctors view their schedules
- Doctor Onboarding — Admins onboard doctors directly from existing user accounts
- Patient Management — Paginated patient listing, profile retrieval, and insurance association
- Method-Level Security —
@PreAuthorizeand@Securedannotations for service-layer protection - Global Exception Handling — Centralized
@RestControllerAdvicefor consistent error responses - Custom JPQL Queries — Blood group aggregation, date-range filtering, bulk update operations
com.smit.projects.clinixhub
├── config/ # App-wide beans (ModelMapper, PasswordEncoder, AuthManager)
├── controller/ # REST controllers (Admin, Auth, Doctor, Patient, Public)
├── dto/ # Request & Response DTOs
├── entity/ # JPA entities (User, Patient, Doctor, Appointment, Insurance, Department)
│ └── type/ # Enums (RoleType, PermissionType, BloodGroupType, AuthProviderType)
├── error/ # GlobalExceptionHandler & ApiError
├── repository/ # Spring Data JPA repositories with custom queries
├── security/ # JWT filter, AuthService, AuthUtil, OAuth2 success handler, WebSecurityConfig
└── service/ # Business logic (Appointment, Doctor, Patient, Insurance)
| Method | Endpoint | Description |
|---|---|---|
GET |
/api/v1/public/doctors |
List all doctors |
| Method | Endpoint | Description |
|---|---|---|
POST |
/api/v1/auth/signup |
Register a new user |
POST |
/api/v1/auth/login |
Login and receive JWT |
| Method | Endpoint | Description |
|---|---|---|
GET |
/api/v1/admin/patients |
Get all patients (paginated) |
POST |
/api/v1/admin/onBoardNewDoctor |
Onboard a user as a doctor |
| Method | Endpoint | Description |
|---|---|---|
GET |
/api/v1/doctors/appointments |
Get own appointments |
| Method | Endpoint | Description |
|---|---|---|
POST |
/api/v1/patients/appointments |
Book a new appointment |
GET |
/api/v1/patients/profile |
View patient profile |
Request
└─► JwtAuthFilter (OncePerRequestFilter)
├── Extracts & validates Bearer token
├── Loads User from DB
└── Sets Authentication in SecurityContextHolder
└─► WebSecurityConfig (authorizeHttpRequests)
├── /public/**, /auth/** → permitAll
├── DELETE /admin/** → APPOINTMENT_DELETE or USER_MANAGE permission
├── /admin/** → ROLE_ADMIN
├── /doctors/** → ROLE_DOCTOR or ROLE_ADMIN
└── everything else → authenticated
Permission Types: PATIENT_READ, PATIENT_WRITE, APPOINTMENT_READ, APPOINTMENT_WRITE, APPOINTMENT_DELETE, USER_MANAGE, REPORT_VIEW
User ──────── Patient (1:1, @MapsId)
User ──────── Doctor (1:1, @MapsId)
Patient ───── Insurance (1:1, owning side)
Patient ───── Appointment (1:N)
Doctor ───── Appointment (1:N)
Doctor ───── Department (M:N)
- Java 21+
- PostgreSQL running locally
- Maven 3.8+
-
Clone the repository
git clone https://github.com/smit/clinixhub.git cd clinixhub -
Configure the database in
src/main/resources/application.propertiesspring.datasource.url=jdbc:postgresql://localhost:5432/clinixhubDB spring.datasource.username=your_username spring.datasource.password=your_password
-
Set your JWT secret
jwt.secretKey=your_strong_secret_key_minimum_32_chars -
Run the application
mvn spring-boot:run
-
Access the API at
http://localhost:8080/api/v1
To enable Google / GitHub login, add your OAuth2 credentials in application.yml:
spring:
security:
oauth2:
client:
registration:
google:
client-id: YOUR_GOOGLE_CLIENT_ID
client-secret: YOUR_GOOGLE_CLIENT_SECRET
github:
client-id: YOUR_GITHUB_CLIENT_ID
client-secret: YOUR_GITHUB_CLIENT_SECRET@MapsIdon Doctor & Patient — Shares the primary key withUser, enforcing a strict 1:1 relationship at the DB level without a separate foreign key column.- Permission-based + Role-based hybrid — Roles group coarse access; permissions allow fine-grained control (e.g., only certain roles can perform DELETE on admin routes).
HandlerExceptionResolverin JwtAuthFilter — Routes filter-layer exceptions through Spring MVC's exception handling pipeline soGlobalExceptionHandlercan produce consistent JSON error responses.- Stateless sessions —
SessionCreationPolicy.STATELESSensures no server-side session state; every request is authenticated via JWT.
Smit
Built as part of hands-on Spring Boot learning — covering JPA relationships, Spring Security internals, JWT, OAuth2, and clean REST API design.