# blitzbugg/hms architecture

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

- Interactive diagram: https://gitdiagram.com/blitzbugg/hms
- Repository: https://github.com/blitzbugg/hms

## Overview

##### Project type and purpose
- This is a full-stack web application—specifically a Hospital Management System (HMS) built on a LAMP stack (HTML/CSS/JS front-end, PHP back-end, MySQL database).
- It handles patient/appointment management, medical records, billing, and separate user roles (Admin, Doctor, Patient).

##### File structure
- Top-level PHP entry points: index.php, account.php, adminlogin.php, doctorlogin.php, patientlogin.php.
- Role-specific directories:
- admin/ (admin dashboard, approval, reporting, slot management)
- doctor/ (appointment handling, discharge, patient view)
- patient/ (book/cancel appointments, invoice generation)
- / holds shared logic (DB connection, common header).
- css/, img/ store static assets.
- sql/hms.sql defines database schema.

##### Key insights from the README
- Three user roles with distinct modules.
- Emphasis on scheduling, records, billing.
- Technology: front-end (HTML/CSS/JS), back-end (PHP), DB (MySQL).

##### Main components
a. Presentation Layer (Client browser)
- UI pages for Admin, Doctor, Patient (served as PHP-rendered HTML + CSS + JS).
b. Application Layer (Web Server + PHP)
- Authentication & Session Management (login, logout scripts).
- Role Modules:
– Admin Module (slot management, user/patient management, billing, reports)
– Doctor Module (appointment handling, medical records, discharge)
– Patient Module (booking, profile, invoices)
- Shared Services: DB Connection (include/connection.php), common header/navbar (include/header.php).
c. Data Layer (MySQL)
- Tables for users, patients, appointments, medical_records, invoices, slots.
d. Optional External Service
- Payment Gateway (if online payment is enabled).

##### Relationships and data flow
- Client → HTTP → Web Server
- Web Server (PHP) → SQL queries → MySQL
- PHP returns HTML/JSON → Client
- For payments: PHP → REST API → Payment Gateway → PHP → MySQL

##### Architectural patterns & design principles
- Three-tier architecture: Presentation / Business Logic / Data.
- Role-based module separation: each user role has its own folder/controller.
- Shared include files for DRY (connection.php, header.php).
- Maintain separation of concerns: CSS/JS in static folders, PHP logic in dedicated directories.

##### Technologies, frameworks, libraries
- Apache (or Nginx) with PHP interpreter
- MySQL / MariaDB
- HTML5, CSS3 (with separate CSS files per module), vanilla JavaScript
- Folders act as micro-controllers for each user role.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        direction TB
        AdminUI["Admin UI"]:::presentation
        DoctorUI["Doctor UI"]:::presentation
        PatientUI["Patient UI"]:::presentation
        StaticAssets["Global Static Assets"]:::presentation
    end

    %% Application Layer
    subgraph "Application Server"
        direction TB
        %% Authentication Service
        subgraph "Authentication & Session Management"
            direction TB
            AdminLogin["adminlogin.php"]:::application
            DoctorLogin["doctorlogin.php"]:::application
            PatientLogin["patientlogin.php"]:::application
            AccountActions["account.php"]:::application
            AdminLogout["admin/logout.php"]:::application
            DoctorLogout["doctor/logout.php"]:::application
            PatientLogout["patient/logout.php"]:::application
        end

        %% Shared Services
        subgraph "Shared Services"
            direction TB
            DBConn["include/connection.php"]:::application
            HeaderNav["include/header.php"]:::application
        end

        %% Admin Module
        subgraph "Admin Module"
            direction TB
            AdminApply["admin/apply.php"]:::application
            AdminAjaxApprove["admin/ajax_approve.php"]:::application
            AdminAjaxReject["admin/ajax_reject.php"]:::application
            AdminAjaxJobReq["admin/ajax_job_request.php"]:::application
            AdminJobReq["admin/job_request.php"]:::application
            AdminReport["admin/report.php"]:::application
            AdminIncome["admin/income.php"]:::application
            AdminPatientMgmt["admin/patient.php"]:::application
            AdminProfile["admin/profile.php"]:::application
            AdminEdit["admin/edit.php"]:::application
            AdminView["admin/view.php"]:::application
            AdminDoctorMgmt["admin/doctor.php"]:::application
        end

        %% Doctor Module
        subgraph "Doctor Module"
            direction TB
            DrAppointment["doctor/appointment.php"]:::application
            DrDischarge["doctor/discharge.php"]:::application
            DrPatientView["doctor/patient.php"]:::application
            DrProfile["doctor/profile.php"]:::application
            DrView["doctor/view.php"]:::application
        end

        %% Patient Module
        subgraph "Patient Module"
            direction TB
            PtAppointment["patient/appointment.php"]:::application
            PtGenerateInv["patient/generate_invoice.php"]:::application
            PtInvoiceView["patient/invoice.php"]:::application
            PtProfile["patient/profile.php"]:::application
            PtView["patient/view.php"]:::application
        end
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        MySQLDB["MySQL Database"]:::database
        Schema["sql/hms.sql"]:::database
    end

    %% External Services
    subgraph "External Services"
        direction TB
        PaymentGateway["Payment Gateway"]:::external
    end

    %% Connections: Presentation to Auth & Modules
    AdminUI -->|"HTTP GET/POST"| AdminLogin
    AdminUI -->|"HTTP GET/POST"| AdminModule
    DoctorUI -->|"HTTP GET/POST"| DoctorLogin
    DoctorUI -->|"HTTP GET/POST"| DrAppointment
    PatientUI -->|"HTTP GET/POST"| PatientLogin
    PatientUI -->|"HTTP GET/POST"| PtAppointment
    StaticAssets --> AdminUI
    StaticAssets --> DoctorUI
    StaticAssets --> PatientUI

    %% Auth to Modules and Shared
    AdminLogin -->|Validate| DBConn
    DoctorLogin -->|Validate| DBConn
    PatientLogin -->|Validate| DBConn
    AccountActions -->|Session| DBConn

    %% Modules to Shared Services
    AdminModule -->|Uses| DBConn
    DoctorModule -->|Uses| DBConn
    PatientModule -->|Uses| DBConn
    AdminModule -->|Render| HeaderNav
    DoctorModule -->|Render| HeaderNav
    PatientModule -->|Render| HeaderNav

    %% Modules to Database
    AdminModule -->|"SQL SELECT/INSERT"| MySQLDB
    DoctorModule -->|"SQL SELECT/INSERT"| MySQLDB
    PatientModule -->|"SQL SELECT/INSERT"| MySQLDB
    Schema --> MySQLDB

    %% Payment flow
    PtGenerateInv -->|"REST API"| PaymentGateway
    PaymentGateway -->|"Callback"| PtGenerateInv
    PaymentGateway -->|"Log"| MySQLDB

    %% Click Events
    click AdminUI "https://github.com/blitzbugg/hms/blob/master/admin/index.php"
    click DoctorUI "https://github.com/blitzbugg/hms/blob/master/doctor/index.php"
    click PatientUI "https://github.com/blitzbugg/hms/blob/master/patient/index.php"
    click StaticAssets "https://github.com/blitzbugg/hms/tree/master/css/"
    click AdminLogin "https://github.com/blitzbugg/hms/blob/master/adminlogin.php"
    click DoctorLogin "https://github.com/blitzbugg/hms/blob/master/doctorlogin.php"
    click PatientLogin "https://github.com/blitzbugg/hms/blob/master/patientlogin.php"
    click AccountActions "https://github.com/blitzbugg/hms/blob/master/account.php"
    click AdminLogout "https://github.com/blitzbugg/hms/blob/master/admin/logout.php"
    click DoctorLogout "https://github.com/blitzbugg/hms/blob/master/doctor/logout.php"
    click PatientLogout "https://github.com/blitzbugg/hms/blob/master/patient/logout.php"
    click DBConn "https://github.com/blitzbugg/hms/blob/master/include/connection.php"
    click HeaderNav "https://github.com/blitzbugg/hms/blob/master/include/header.php"
    click AdminApply "https://github.com/blitzbugg/hms/blob/master/admin/apply.php"
    click AdminAjaxApprove "https://github.com/blitzbugg/hms/blob/master/admin/ajax_approve.php"
    click AdminAjaxReject "https://github.com/blitzbugg/hms/blob/master/admin/ajax_reject.php"
    click AdminAjaxJobReq "https://github.com/blitzbugg/hms/blob/master/admin/ajax_job_request.php"
    click AdminJobReq "https://github.com/blitzbugg/hms/blob/master/admin/job_request.php"
    click AdminReport "https://github.com/blitzbugg/hms/blob/master/admin/report.php"
    click AdminIncome "https://github.com/blitzbugg/hms/blob/master/admin/income.php"
    click AdminPatientMgmt "https://github.com/blitzbugg/hms/blob/master/admin/patient.php"
    click AdminProfile "https://github.com/blitzbugg/hms/blob/master/admin/profile.php"
    click AdminEdit "https://github.com/blitzbugg/hms/blob/master/admin/edit.php"
    click AdminView "https://github.com/blitzbugg/hms/blob/master/admin/view.php"
    click AdminDoctorMgmt "https://github.com/blitzbugg/hms/blob/master/admin/doctor.php"
    click DrAppointment "https://github.com/blitzbugg/hms/blob/master/doctor/appointment.php"
    click DrDischarge "https://github.com/blitzbugg/hms/blob/master/doctor/discharge.php"
    click DrPatientView "https://github.com/blitzbugg/hms/blob/master/doctor/patient.php"
    click DrProfile "https://github.com/blitzbugg/hms/blob/master/doctor/profile.php"
    click DrView "https://github.com/blitzbugg/hms/blob/master/doctor/view.php"
    click PtAppointment "https://github.com/blitzbugg/hms/blob/master/patient/appointment.php"
    click PtGenerateInv "https://github.com/blitzbugg/hms/blob/master/patient/generate_invoice.php"
    click PtInvoiceView "https://github.com/blitzbugg/hms/blob/master/patient/invoice.php"
    click PtProfile "https://github.com/blitzbugg/hms/blob/master/patient/profile.php"
    click PtView "https://github.com/blitzbugg/hms/blob/master/patient/view.php"
    click Schema "https://github.com/blitzbugg/hms/blob/master/sql/hms.sql"

    %% Styles
    classDef presentation fill:#ADD8E6,stroke:#000
    classDef application fill:#90EE90,stroke:#000
    classDef database fill:#FFA500,stroke:#000
    classDef external fill:#D3D3D3,stroke:#000
```
