# dilansriyantha/clinic-management-system architecture

> Architecture diagram of the GitHub repository dilansriyantha/clinic-management-system, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dilansriyantha/clinic-management-system
- Repository: https://github.com/dilansriyantha/clinic-management-system

## Overview

##### Project Type & Purpose
- This is a full-stack, desktop-enabled Clinic Management System (CMS) comprising:
- A React/TypeScript frontend (in “frontend/”) wrapped in Electron (root index.html, main.js, preload.js)
- A Spring Boot Java backend (“backend/”) exposing REST endpoints
- A MySQL database (“database/” + docker-compose.yml)
- Supporting utilities as separate packages: InvoiceGenerator, PrintJobHandler, BackupScheduler

##### High-Level File Structure & Architectural Patterns
- Top-level:
- InvoiceFiles/ folder for storing generated PDF invoices
- backend/: Spring Boot monolith following layered (Controller → Service → Repository → Model) MVC
- database/: Dockerfile + init SQL
- docker-compose.yml: orchestrates backend + database (and can include other services)
- frontend/: Vite-powered React app + Electron bootstrap
- packages/: three auxiliary tools (Java jar, .NET executables, Node wrappers)
- Patterns:
- Monolithic backend exposing REST + JWT security
- Frontend-backend separation via HTTP/S API
- Electron for desktop shell
- External “micro-tools” invoked via Node scripts or CLI

##### README Insights
- Core modules: Patients, Appointments, Clinics, Prescriptions, Invoices, Pharmacy stock, Schedules, Users, Dashboards
- Tech stack: Java 17+, Spring Boot, MySQL, React/TypeScript, Electron, .NET, Java CLI tools, Node wrappers
- Key non-functional: Role-based access, local backup scheduling, PDF invoice generation, print job handling

##### Main Components
a. Desktop Client (Electron)
- Shell (main.js, preload.js)
- React SPA (served from /frontend)
- Local IPC / HTTP bridge to backend and utilities
b. API Layer (Spring Boot)
- Controllers (e.g., AuthController, AppointmentController, etc.)
- Services (business logic)
- Repositories → MySQL DB
- Security (JwtAuthFilter, SecurityConfig)
c. Database
- MySQL container (init.sql)
d. File Storage
- InvoiceFiles/ directory for PDFs
e. External Tools
- InvoiceGenerator (Java JAR + Node API wrapper)
- PrintJobHandler (C# executable + Node API wrapper)
- BackupScheduler (.NET console app)
f. Docker Compose
- Orchestration of backend, database (and potentially other micro-tools)

##### Interactions & Data Flows
- User clicks in Electron UI → React → HTTP(S) to Spring Boot REST endpoints
- Spring Boot → CRUD on MySQL (via JPA Repositories)
- For invoice creation: Backend calls the InvoiceGenerator API (local microservice or CLI) → writes PDF to InvoiceFiles/
- For printing: Backend or Electron UI invokes PrintJobHandler → sends PDF to printer
- BackupScheduler runs on schedule → dumps DB → pushes to cloud/local backup
- JWT issued by AuthService → sent in HTTP header for protected endpoints

##### Architectural Patterns & Principles
- Layered architecture in backend (Controller → Service → Repository → Model)
- Separation of concerns: UI vs. API vs. Persistence vs. Utilities
- Use of JWT for stateless authentication
- Electron for desktop bundling of web UI
- Docker Compose for environment consistency
- CLI-based micro-tools orchestrated via Node wrappers

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Electron App
    subgraph "Electron App"
        direction TB
        Index["index.html"]:::frontend
        ShellMain["main.js"]:::frontend
        Preload["preload.js"]:::frontend
        ReactApp["React SPA"]:::frontend
    end

    %% Spring Boot App
    subgraph "Spring Boot App"
        direction TB
        subgraph "Controllers"
            direction TB
            AuthCtrl["AuthController"]:::backend
            AppointmentCtrl["AppointmentController"]:::backend
            ClinicsCtrl["ClinicsController"]:::backend
            InvoiceCtrl["InvoiceController"]:::backend
            PrescriptionCtrl["PrescriptionController"]:::backend
            PatientCtrl["PatientController"]:::backend
            StockCtrl["StockController"]:::backend
            ScheduleCtrl["ScheduleController"]:::backend
            UserCtrl["UserController"]:::backend
            DashboardCtrl["DashboardController"]:::backend
        end
        Security["Security (JwtAuthFilter, SecurityConfig)"]:::backend
        Services["Services"]:::backend
        Repositories["Repositories"]:::backend
        Models["Models (Entities)"]:::backend
    end

    %% Data Stores
    Database[(MySQL Container)]:::database
    FileStore[/InvoiceFiles/]:::database

    %% Utilities
    subgraph "External Utilities"
        direction TB
        InvGen["InvoiceGenerator"]:::utility
        PrintHandler["PrintJobHandler"]:::utility
        BackupSched["BackupScheduler"]:::utility
    end

    %% Connections
    Index --> ShellMain
    ShellMain --> Preload
    ShellMain --> ReactApp
    Preload --> ReactApp
    ReactApp -->|"HTTP/JSON"| AuthCtrl
    ReactApp -->|"HTTP/JSON"| AppointmentCtrl
    ReactApp -->|"HTTP/JSON"| ClinicsCtrl
    ReactApp -->|"HTTP/JSON"| InvoiceCtrl
    ReactApp -->|"HTTP/JSON"| PrescriptionCtrl
    ReactApp -->|"HTTP/JSON"| PatientCtrl
    ReactApp -->|"HTTP/JSON"| StockCtrl
    ReactApp -->|"HTTP/JSON"| ScheduleCtrl
    ReactApp -->|"HTTP/JSON"| UserCtrl
    ReactApp -->|"HTTP/JSON"| DashboardCtrl

    AuthCtrl --> Security
    AppointmentCtrl --> Services
    ClinicsCtrl --> Services
    InvoiceCtrl --> Services
    PrescriptionCtrl --> Services
    PatientCtrl --> Services
    StockCtrl --> Services
    ScheduleCtrl --> Services
    UserCtrl --> Services
    DashboardCtrl --> Services

    Services --> Repositories
    Repositories --> Models
    Repositories -->|"JDBC"| Database

    InvoiceCtrl -->|"Invoke CLI"| InvGen
    InvGen -->|"File I/O (PDF)"| FileStore

    InvoiceCtrl -->|"Invoke CLI"| PrintHandler
    ReactApp -->|"IPC/CLI"| PrintHandler

    BackupSched -->|"Scheduled dump"| Database

    %% Click Events - Electron
    click Index "https://github.com/dilansriyantha/clinic-management-system/blob/dev/index.html"
    click ShellMain "https://github.com/dilansriyantha/clinic-management-system/blob/dev/main.js"
    click Preload "https://github.com/dilansriyantha/clinic-management-system/blob/dev/preload.js"
    click ReactApp "https://github.com/dilansriyantha/clinic-management-system/blob/dev/frontend/src/main.tsx"

    %% Click Events - Frontend structure
    click ReactApp "https://github.com/dilansriyantha/clinic-management-system/tree/dev/frontend/"
    click ReactApp "https://github.com/dilansriyantha/clinic-management-system/blob/dev/frontend/src/App.tsx"
    click ReactApp "https://github.com/dilansriyantha/clinic-management-system/tree/dev/frontend/src/pages/"
    click ReactApp "https://github.com/dilansriyantha/clinic-management-system/tree/dev/frontend/src/components/"
    click ReactApp "https://github.com/dilansriyantha/clinic-management-system/tree/dev/frontend/src/hooks/"
    click ReactApp "https://github.com/dilansriyantha/clinic-management-system/tree/dev/frontend/src/routes/"

    %% Click Events - Backend
    click AuthCtrl "https://github.com/dilansriyantha/clinic-management-system/blob/dev/backend/src/main/java/org/cms/Authentication/AuthController.java"
    click AppointmentCtrl "https://github.com/dilansriyantha/clinic-management-system/blob/dev/backend/src/main/java/org/cms/AppointmentManagement/Controllers/AppointmentController.java"
    click ClinicsCtrl "https://github.com/dilansriyantha/clinic-management-system/blob/dev/backend/src/main/java/org/cms/ClinicManagement/Controllers/ClinicsController.java"
    click InvoiceCtrl "https://github.com/dilansriyantha/clinic-management-system/blob/dev/backend/src/main/java/org/cms/InvoiceManagement/Controllers/InvoiceController.java"
    click PrescriptionCtrl "https://github.com/dilansriyantha/clinic-management-system/blob/dev/backend/src/main/java/org/cms/PrescriptionManagement/Controllers/PrescriptionController.java"
    click PatientCtrl "https://github.com/dilansriyantha/clinic-management-system/blob/dev/backend/src/main/java/org/cms/PatientMangement/Controllers/PatientController.java"
    click StockCtrl "https://github.com/dilansriyantha/clinic-management-system/blob/dev/backend/src/main/java/org/cms/PharmacyStockManagement/Controllers/StockController.java"
    click ScheduleCtrl "https://github.com/dilansriyantha/clinic-management-system/blob/dev/backend/src/main/java/org/cms/ScheduleManagement/Controllers/ScheduleController.java"
    click UserCtrl "https://github.com/dilansriyantha/clinic-management-system/blob/dev/backend/src/main/java/org/cms/Users/Controllers/UserController.java"
    click DashboardCtrl "https://github.com/dilansriyantha/clinic-management-system/blob/dev/backend/src/main/java/org/cms/Dashboard/Controllers/DashboardController.java"
    click Security "https://github.com/dilansriyantha/clinic-management-system/blob/dev/backend/src/main/java/org/cms/Configurations/SecurityConfig.java"
    click Security "https://github.com/dilansriyantha/clinic-management-system/blob/dev/backend/src/main/java/org/cms/Configurations/JwtAuthFilter.java"
    click Security "https://github.com/dilansriyantha/clinic-management-system/blob/dev/backend/src/main/java/org/cms/Configurations/JwtService.java"
    click Security "https://github.com/dilansriyantha/clinic-management-system/blob/dev/backend/src/main/java/org/cms/Configurations/ApplicationConfiguration.java"
    click Repositories "https://github.com/dilansriyantha/clinic-management-system/blob/dev/backend/src/main/java/org/cms/**/Repositories/*.java"
    click Models "https://github.com/dilansriyantha/clinic-management-system/blob/dev/backend/src/main/java/org/cms/**/Models/*.java"
    click Services "https://github.com/dilansriyantha/clinic-management-system/blob/dev/backend/src/main/java/org/cms/**/Services/*.java"
    click Main "https://github.com/dilansriyantha/clinic-management-system/blob/dev/backend/src/main/java/org/cms/Main.java"
    click Pom "https://github.com/dilansriyantha/clinic-management-system/blob/dev/backend/pom.xml"

    %% Click Events - Database
    click Database "https://github.com/dilansriyantha/clinic-management-system/tree/dev/database/Dockerfile"
    click Database "https://github.com/dilansriyantha/clinic-management-system/blob/dev/database/init.sql"
    click Database "https://github.com/dilansriyantha/clinic-management-system/blob/dev/docker-compose.yml"

    %% Click Events - File Storage
    click FileStore "https://github.com/dilansriyantha/clinic-management-system/tree/dev/InvoiceFiles/"

    %% Click Events - Utilities
    click InvGen "https://github.com/dilansriyantha/clinic-management-system/blob/dev/packages/InvoiceGenerator/api.js"
    click InvGen "https://github.com/dilansriyantha/clinic-management-system/blob/dev/packages/InvoiceGenerator/bin/invgen.jar"
    click PrintHandler "https://github.com/dilansriyantha/clinic-management-system/blob/dev/packages/PrintJobHandler/api.js"
    click PrintHandler "https://github.com/dilansriyantha/clinic-management-system/blob/dev/packages/PrintJobHandler/bin/PrintJobHandler/bin/Debug/PrintJobHandler.exe"
    click BackupSched "https://github.com/dilansriyantha/clinic-management-system/blob/dev/packages/BackupScheduler/bin/BackupScheduler/BackupScheduler.sln"
    click BackupSched "https://github.com/dilansriyantha/clinic-management-system/blob/dev/packages/BackupScheduler/bin/BackupScheduler/Program.cs"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#1e75ff,color:#000;
    classDef backend fill:#d4edda,stroke:#28a745,color:#000;
    classDef database fill:#ffe5b4,stroke:#ff8c00,color:#000;
    classDef utility fill:#e2e3e5,stroke:#6c757d,color:#000;
```
