# kornchhimheng/medicore3 architecture

> Architecture diagram of the GitHub repository kornchhimheng/medicore3, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-08-23). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kornchhimheng/medicore3
- Repository: https://github.com/kornchhimheng/medicore3

## Overview

##### Project Type and Purpose
- This is a full-stack hospital management application split into two main parts:
a) A Java Spring Boot monolithic backend (“Project-Hospital-Management-System-testing” and its V2 variant with JWT and appointment support)
b) A React-based single-page frontend (“my-medicare-dashboard”)
- The backend exposes RESTful endpoints secured with Spring Security and JWT. It implements core hospital features (user/role management, patient/doctor entities, appointment scheduling in V2). The frontend offers UI for patients, receptionists, billing, prescriptions, and uses the backend APIs.

##### File Structure Analysis
- Top-level directories:
- Project-Hospital-Management-System-testing (Backend V1)
- Project-Hospital-Management-System V2 with Spring Security and JWT (Backend V2)
- my-medicare-dashboard (Frontend)
- Backend modules follow a layered MVC style under src/main/java:
- api.core: configuration (WebConfig, SecurityConfig), filters (JWTAuthFilter), exception handling, utilities
- api.features.hospitalmanagement: controllers, DTOs (request/response), entities, repositories, services/impl
- Resources include application.yml, log4j2 for logging, and Data JSON scripts in V2.
- Frontend uses a standard Vite+React structure: src/components, src/pages, centralized App.jsx, and config files.

##### Key README Insights
- The README only names the project (“medicorev2”) but the file tree reveals use of Spring Boot, JWT, Log4j2, a relational database (SQL scripts), and a React frontend.

##### Diagramming the System Architecture
a. Main Components
1. Client/User Interface
- Web browser running the React SPA (“my-medicare-dashboard”)
2. API Gateway / Backend
- Spring Boot application (V2 recommended):
- Security Layer (SecurityConfig, JWTAuthFilter, CustomAuthenticationProvider)
- Controllers (AuthenticationController, PatientController, DoctorController, AppointmentController)
- Service Layer (AuthenticationService, PatientService, UserService, AppointmentService)
- Repository Layer (Spring Data JPA repositories)
- Domain Entities (User, Patient, Doctor, Appointment, Role, Permission)
3. Database
- Relational database (configured via application.yml, populated by Data/ScriptDatabase.sql)
4. Auxiliary Services
- Log storage (Log4j2 → logs/hospital-management)
- External API calls if any (e.g., medication lookup) – currently handled through a React component and possibly a backend util.
b. Relationships and Interactions
- Browser ←→ React SPA: user actions trigger HTTP requests (REST calls)
- React SPA → Backend Controllers: POST/GET to /api/auth, /api/patients, /api/appointments, etc.
- Controllers → Services → Repositories → Database: standard Spring layered calls
- Security Filter Chain (JWTAuthFilter) intercepts incoming requests, validates token via JwtTokenUtil, delegates to OurUserDetailsService
- ExceptionHandleAdviser globally handles exceptions, formatting ErrorResponse/ApiResponse
- Logging intercepts API calls (api-logging.log) and system events (system-logging.log)
c. Architectural Patterns & Principles
- Layered Architecture (Controller → Service → Repository)
- Security as a cross-cutting concern via Spring Security filters
- DTO mapping to decouple API contract from persistence entities
- Exception handling with @ControllerAdvice
- Configuration management via YAML profiles
d. Technologies & Frameworks
- Backend: Java 17+, Spring Boot, Spring Security, JWT, Spring Data JPA, Hibernate, Log4j2, Maven
- Frontend: React, Vite, JSX, CSS, ESLint
- Database: Any RDBMS (SQL scripts included)

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Frontend"
        Browser["Web Browser"]:::frontend
        ReactSPA["React SPA"]:::frontend
    end
    Browser --> ReactSPA
    ReactSPA -->|"HTTP REST"| AuthenticationController

    subgraph "Backend"
        AppMain["ProjectHospitalManagementSystemApplication"]:::config

        subgraph "Security Layer"
            JWTAuthFilter["JWTAuthFilter"]:::security
            CustomAuthProvider["CustomAuthenticationProvider"]:::security
            AuthEntryPoint["CustomAuthenticationEntryPoint"]:::security
            AccessDeniedHandler["CustomAccessDeniedHandler"]:::security
            OurUserDetailsService["OurUserDetailsService"]:::security
            JwtTokenUtil["JwtTokenUtil"]:::security
        end

        subgraph "Controllers"
            AuthenticationController["AuthenticationController"]:::controller
            PatientController["PatientController"]:::controller
            DoctorController["DoctorController"]:::controller
            AppointmentController["AppointmentController"]:::controller
        end

        subgraph "Services"
            AuthenticationService["AuthenticationService"]:::service
            PatientService["PatientService"]:::service
            DoctorService["DoctorService"]:::service
            AppointmentService["AppointmentService"]:::service
            UserService["UserService"]:::service
        end

        subgraph "Repositories"
            UserRepository["UserRepository"]:::repository
            PatientRepository["PatientRepository"]:::repository
            DoctorRepository["DoctorRepository"]:::repository
            AppointmentRepository["AppointmentRepository"]:::repository
            RoleRepository["RoleRepository"]:::repository
            PermissionRepository["PermissionRepository"]:::repository
        end

        subgraph "Utilities"
            DateTimeUtil["DateTimeUtil"]:::utility
            PageUtil["PageUtil"]:::utility
            GlobalConstant["GlobalConstant"]:::utility
        end

        WebConfig["WebConfig"]:::config
        SecurityConfig["SecurityConfig"]:::config
        ExceptionHandleAdviser["ExceptionHandleAdviser"]:::exception
    end

    ReactSPA -->|"/api/auth"| AuthenticationController
    AuthenticationController -->|calls| AuthenticationService
    AuthenticationService -->|uses| JwtTokenUtil
    AuthenticationService -->|loads user| OurUserDetailsService
    AuthenticationService -->|CRUD| UserRepository
    AuthenticationController -->|"issues JWT"| JwtTokenUtil
    JWTAuthFilter --> OurUserDetailsService
    JWTAuthFilter --> ExceptionHandleAdviser
    AuthenticationController --> ExceptionHandleAdviser

    PatientController --> PatientService
    PatientService --> PatientRepository
    DoctorController --> DoctorService
    DoctorService --> DoctorRepository
    AppointmentController --> AppointmentService
    AppointmentService --> AppointmentRepository

    ControllersLayer["Controllers"] --> WebConfig
    ControllersLayer --> SecurityConfig
    ServicesLayer["Services"] --> WebConfig
    ServicesLayer --> SecurityConfig

    ServicesLayer --> DateTimeUtil
    ServicesLayer --> PageUtil
    ServicesLayer --> GlobalConstant

    subgraph "Database"
        DB["Relational Database"]:::database
    end

    UserRepository --> DB
    PatientRepository --> DB
    DoctorRepository --> DB
    AppointmentRepository --> DB
    RoleRepository --> DB
    PermissionRepository --> DB

    subgraph "Logging"
        Logs["Log4j2 Logs"]:::logging
    end

    AuthenticationController --> Logs
    PatientController --> Logs
    DoctorController --> Logs
    AppointmentController --> Logs
    ExceptionHandleAdviser --> Logs

    classDef frontend fill:#1E90FF,stroke:#333,color:#fff
    classDef controller fill:#32CD32,stroke:#333,color:#000
    classDef service fill:#32CD32,stroke:#333,color:#000
    classDef repository fill:#32CD32,stroke:#333,color:#000
    classDef security fill:#FF8C00,stroke:#333,color:#000
    classDef config fill:#FF8C00,stroke:#333,color:#000
    classDef exception fill:#FF8C00,stroke:#333,color:#000
    classDef utility fill:#D3D3D3,stroke:#333,color:#000
    classDef database fill:#A9A9A9,stroke:#333,color:#000
    classDef logging fill:#FFD700,stroke:#333,color:#000

    click ReactSPA "https://github.com/kornchhimheng/medicore3/tree/main/my-medicare-dashboard/"
    click AppMain "https://github.com/kornchhimheng/medicore3/blob/main/src/main/java/com/hospital/management/api/ProjectHospitalManagementSystemApplication.java"
    click WebConfig "https://github.com/kornchhimheng/medicore3/blob/main/src/main/java/com/hospital/management/api/core/configuration/WebConfig.java"
    click SecurityConfig "https://github.com/kornchhimheng/medicore3/blob/main/src/main/java/com/hospital/management/api/core/configuration/SecurityConfig.java"
    click JWTAuthFilter "https://github.com/kornchhimheng/medicore3/blob/main/src/main/java/com/hospital/management/api/core/filter/JWTAuthFilter.java"
    click CustomAuthProvider "https://github.com/kornchhimheng/medicore3/blob/main/src/main/java/com/hospital/management/api/core/filter/CustomAuthenticationProvider.java"
    click AuthEntryPoint "https://github.com/kornchhimheng/medicore3/blob/main/src/main/java/com/hospital/management/api/core/security/CustomAuthenticationEntryPoint.java"
    click AccessDeniedHandler "https://github.com/kornchhimheng/medicore3/blob/main/src/main/java/com/hospital/management/api/core/security/CustomAccessDeniedHandler.java"
    click OurUserDetailsService "https://github.com/kornchhimheng/medicore3/blob/main/src/main/java/com/hospital/management/api/core/security/OurUserDetailsService.java"
    click JwtTokenUtil "https://github.com/kornchhimheng/medicore3/blob/main/src/main/java/com/hospital/management/api/core/security/JwtTokenUtil.java"
    click GlobalConstant "https://github.com/kornchhimheng/medicore3/blob/main/src/main/java/com/hospital/management/api/core/utils/GlobalConstant.java"
    click ExceptionHandleAdviser "https://github.com/kornchhimheng/medicore3/blob/main/src/main/java/com/hospital/management/api/core/exceptions/ExceptionHandleAdviser.java"
    click AuthenticationController "https://github.com/kornchhimheng/medicore3/blob/main/src/main/java/com/hospital/management/api/features/hospitalmanagement/controller/AuthenticationController.java"
    click PatientController "https://github.com/kornchhimheng/medicore3/blob/main/src/main/java/com/hospital/management/api/features/hospitalmanagement/controller/PatientController.java"
    click DoctorController "https://github.com/kornchhimheng/medicore3/blob/main/src/main/java/com/hospital/management/api/features/hospitalmanagement/controller/DoctorController.java"
    click AppointmentController "https://github.com/kornchhimheng/medicore3/blob/main/src/main/java/com/hospital/management/api/features/hospitalmanagement/controller/AppointmentController.java"
    click AuthenticationService "https://github.com/kornchhimheng/medicore3/blob/main/src/main/java/com/hospital/management/api/features/hospitalmanagement/service/AuthenticationService.java"
    click PatientService "https://github.com/kornchhimheng/medicore3/blob/main/src/main/java/com/hospital/management/api/features/hospitalmanagement/service/PatientService.java"
    click DoctorService "https://github.com/kornchhimheng/medicore3/blob/main/src/main/java/com/hospital/management/api/features/hospitalmanagement/service/DoctorService.java"
    click AppointmentService "https://github.com/kornchhimheng/medicore3/blob/main/src/main/java/com/hospital/management/api/features/hospitalmanagement/service/AppointmentService.java"
    click UserService "https://github.com/kornchhimheng/medicore3/blob/main/src/main/java/com/hospital/management/api/features/hospitalmanagement/service/UserService.java"
    click UserRepository "https://github.com/kornchhimheng/medicore3/blob/main/src/main/java/com/hospital/management/api/features/hospitalmanagement/repository/UserRepository.java"
    click PatientRepository "https://github.com/kornchhimheng/medicore3/blob/main/src/main/java/com/hospital/management/api/features/hospitalmanagement/repository/PatientRepository.java"
    click DoctorRepository "https://github.com/kornchhimheng/medicore3/blob/main/src/main/java/com/hospital/management/api/features/hospitalmanagement/repository/DoctorRepository.java"
    click AppointmentRepository "https://github.com/kornchhimheng/medicore3/blob/main/src/main/java/com/hospital/management/api/features/hospitalmanagement/repository/AppointmentRepository.java"
    click RoleRepository "https://github.com/kornchhimheng/medicore3/blob/main/src/main/java/com/hospital/management/api/features/hospitalmanagement/repository/RoleRepository.java"
    click PermissionRepository "https://github.com/kornchhimheng/medicore3/blob/main/src/main/java/com/hospital/management/api/features/hospitalmanagement/repository/PermissionRepository.java"
    click DateTimeUtil "https://github.com/kornchhimheng/medicore3/blob/main/src/main/java/com/hospital/management/api/features/hospitalmanagement/util/DateTimeUtil.java"
    click PageUtil "https://github.com/kornchhimheng/medicore3/blob/main/src/main/java/com/hospital/management/api/features/hospitalmanagement/util/PageUtil.java"
    click AuthenticationService "https://github.com/kornchhimheng/medicore3/blob/main/my-medicare-dashboard/src/main.jsx"
    click ReactSPA "https://github.com/kornchhimheng/medicore3/blob/main/my-medicare-dashboard/src/App.jsx"
    click ReactSPA "https://github.com/kornchhimheng/medicore3/tree/main/my-medicare-dashboard/src/components/"
    click ReactSPA "https://github.com/kornchhimheng/medicore3/tree/main/my-medicare-dashboard/src/pages/"
```
