# naoufalelhlou22/medical-appointment architecture

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

- Interactive diagram: https://gitdiagram.com/naoufalelhlou22/medical-appointment
- Repository: https://github.com/naoufalelhlou22/medical-appointment

## Overview

##### Project Type & Purpose
- This is a full-stack web application (“Medical Appointment System”) built with a PHP/MySQL backend and a static HTML/CSS/JavaScript frontend.
- It supports three user roles: Patients (book appointments), Doctors (manage slots), and Admins (dashboard oversight).

##### Key Architectural Layers & Components
A. Client-Side (Frontend)
- Patient UI
– Located under `user/appointment.html` and related assets
– CSS in `assets/css/appointment-page.css`, JS validations in `assets/js/appointment-validation.js`
- Doctor UI
– Static HTML in `doctors/login.html`, `doctors/forget-pass.html`
– CSS in `assets/css/forget-pass.css`, JS in `assets/js/sent-fields.js`
- Admin Dashboard
– PHP pages under `app/dashboard/*.php` (add-appointment, view-appointments, analysis, etc.)
– CSS in `assets/css/admin-login.css`, JS in `assets/js/analytics.js`

B. Server-Side (Backend)
- Public Endpoints (“handler” folder)
– PHP scripts: `handler/fetch_all_appointments.php`, `handler/set_appointment_data.php`, etc.
– Handle CRUD operations, AJAX calls from the frontend
- Core Business Logic (“functions” & “includes”)
– `functions/`: pure PHP helpers (date conversion, database-table fetch, message formatting)
– `includes/`: configuration & shared libraries (`conn_db.php`, `send_notification.php`, `header.php`)
- Authentication & Session Management
– `app/auth.php` for login/session checks
- Dependency Management
– `composer.json` / `vendor/`: any third-party PHP packages

C. Data Layer
- MySQL relational database
– Connection configured in `includes/conn_db.php`
– Tables for users (patients, doctors), appointments, notifications, etc.

D. External Services
- Notification service via `includes/send_notification.php` (email or SMS gateways)
- (Optional) Logging, Monitoring, Backup routines

##### Relationships & Data Flows
1. Browser → Web Server
– Users access static HTML/PHP pages.
2. Frontend → Backend APIs
– Form submissions & AJAX calls from JS (`assets/js/...`) to PHP handlers (`handler/*.php`).
3. Backend → Database
– Handlers use `conn_db.php` to execute SQL queries, fetch/update appointment and user tables.
4. Backend → External Notification
– After insert/update, `send_notification.php` sends emails/SMS to users/doctors.
5. Admin Dashboard ↔ Database ↔ Handlers
– Admin pages (`app/dashboard/*.php`) call the same handlers or directly include functions to manage data and view analytics.

##### Architectural Patterns & Design Principles
- Layered Architecture: Presentation (HTML/CSS/JS) → Application Logic (handler + functions) → Data Persistence (MySQL)
- Separation of Concerns:
- “handler/” only for request handling
- “functions/” purely utility functions
- “includes/” shared configuration and templates
- Role-Based Access: app/auth.php enforces doctor/admin sessions
- Stateless Frontend: page reloads or AJAX, no client-heavy frameworks
- Composer for modular PHP dependencies

a. Main Components:
- Doctor Browser
- Admin Browser
- Web Server (Apache/Nginx + PHP)
- Handler Layer (handler/*.php)
- Business Logic Layer (functions/, includes/)
- MySQL Database
- External Notification Service

c. Technologies & Frameworks:

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        direction TB
        subgraph "Patient UI" 
            direction TB
            PHTML["appointment.html"]:::frontend
            PCSS["appointment-page.css"]:::frontend
            PVALJS["appointment-validation.js"]:::frontend
            PGOJS["appointment-go-to.js"]:::frontend
        end
        subgraph "Doctor UI"
            direction TB
            DHTML1["login.html"]:::frontend
            DHTML2["forget-pass.html"]:::frontend
            DCSS["forget-pass.css"]:::frontend
            DJS["sent-fields.js"]:::frontend
        end
        subgraph "Admin Dashboard UI"
            direction TB
            ADDA["add-appointment.php"]:::frontend
            ANAL["analysis.php"]:::frontend
            ALIST["appointments-list.php"]:::frontend
            EDITA["edit-appointment.php"]:::frontend
            PMGMT["patient-management.php"]:::frontend
            PROF["profile.php"]:::frontend
            VAPP["view-appointments.php"]:::frontend
            ACSS["admin-login.css"]:::frontend
            AJS["analytics.js"]:::frontend
        end
    end

    %% Web Server Layer
    subgraph "Web Server (PHP 7+) " 
        direction TB
        subgraph "API Handler Layer" 
            direction TB
            HFA["fetch_all_appointments.php"]:::backend
            HSA["set_appointment_data.php"]:::backend
            HCA["confirm_appointment.php"]:::backend
            HXA["cancel_appointment.php"]:::backend
            HTD["appointments_today.php"]:::backend
            HLM["last_month_appointments.php"]:::backend
            HLY["last_year_appointments.php"]:::backend
            HSP["fetch_spec_patient.php"]:::backend
            HAP["active_patients.php"]:::backend
            HAA["admin_authentication.php"]:::backend
            HFU["file_upload.php"]:::backend
        end
        subgraph "Business Logic Layer"
            direction TB
            subgraph "Utilities (functions/)" 
                FD1["convert_date_to_months.php"]:::backend
                FD2["fetch_db_tables.php"]:::backend
                FD3["showMessage.php"]:::backend
            end
            subgraph "Includes & Config" 
                IC1["conn_db.php"]:::backend
                IC2["set_table_values.php"]:::backend
                IC3["header.php"]:::backend
                IC4["send_notification.php"]:::backend
            end
        end
        AUTH["auth.php"]:::backend
        DEP["composer.json & vendor/"]:::backend
    end

    DB["MySQL Database"]:::db
    NOTIF["Notification Service"]:::external

    %% Connections
    PHTML -->|AJAX/Forms| HFA
    PCSS -->|style| PHTML
    PVALJS -->|validate| PHTML
    PGOJS -->|navigate| PHTML

    DHTML1 -->|AJAX/Forms| HAA
    DHTML2 -->|AJAX POST| HXA
    DCSS -->|style| DHTML2
    DJS -->|script| DHTML2

    ADDA -->|include/API calls| HSA
    ANAL -->|include/API calls| HLM
    ALIST -->|include/API calls| HFA
    EDITA -->|include/API calls| HSA
    PMGMT -->|include/API calls| HAP
    PROF -->|include/auth| AUTH
    VAPP -->|include/API calls| HFA
    ACSS -->|style| ADDA
    AJS -->|script| ANAL

    %% Server internal flows
    HFA -->|use| FD2
    HSA -->|use| FD2
    HCA -->|use| FD2
    HXA -->|use| FD2
    HTD -->|use| FD2
    HLM -->|use| FD2
    HLY -->|use| FD2
    HSP -->|use| FD2
    HAP -->|use| FD2
    HAA -->|use| IC3
    HFU -->|use| IC2

    FD1 -->|use| IC1
    FD2 -->|use| IC1
    FD3 -->|use| IC3

    IC4 -->|send| NOTIF
    allHandlers-->IC4

    %% Database flows
    subgraph "Data Persistence"
        direction TB
        DB
    end
    FD2 -->|SQL queries| DB
    AUTH -->|session check| DB

    %% Styles
    classDef frontend fill:#BBDEFB,stroke:#1E88E5,color:#0D47A1
    classDef backend fill:#FFE0B2,stroke:#FB8C00,color:#E65100
    classDef db fill:#C8E6C9,stroke:#43A047,color:#1B5E20
    classDef external fill:#E0E0E0,stroke:#9E9E9E,color:#424242

    %% Click Events
    click PHTML "https://github.com/naoufalelhlou22/medical-appointment/blob/main/user/appointment.html"
    click PCSS "https://github.com/naoufalelhlou22/medical-appointment/blob/main/assets/css/appointment-page.css"
    click PVALJS "https://github.com/naoufalelhlou22/medical-appointment/blob/main/assets/js/appointment-validation.js"
    click PGOJS "https://github.com/naoufalelhlou22/medical-appointment/blob/main/assets/js/appointment-go-to.js"
    click DHTML1 "https://github.com/naoufalelhlou22/medical-appointment/blob/main/doctors/login.html"
    click DHTML2 "https://github.com/naoufalelhlou22/medical-appointment/blob/main/doctors/forget-pass.html"
    click DCSS "https://github.com/naoufalelhlou22/medical-appointment/blob/main/assets/css/forget-pass.css"
    click DJS "https://github.com/naoufalelhlou22/medical-appointment/blob/main/assets/js/sent-fields.js"
    click ADDA "https://github.com/naoufalelhlou22/medical-appointment/blob/main/app/dashboard/add-appointment.php"
    click ANAL "https://github.com/naoufalelhlou22/medical-appointment/blob/main/app/dashboard/analysis.php"
    click ALIST "https://github.com/naoufalelhlou22/medical-appointment/blob/main/app/dashboard/appointments-list.php"
    click EDITA "https://github.com/naoufalelhlou22/medical-appointment/blob/main/app/dashboard/edit-appointment.php"
    click PMGMT "https://github.com/naoufalelhlou22/medical-appointment/blob/main/app/dashboard/patient-management.php"
    click PROF "https://github.com/naoufalelhlou22/medical-appointment/blob/main/app/dashboard/profile.php"
    click VAPP "https://github.com/naoufalelhlou22/medical-appointment/blob/main/app/dashboard/view-appointments.php"
    click ACSS "https://github.com/naoufalelhlou22/medical-appointment/blob/main/assets/css/admin-login.css"
    click AJS "https://github.com/naoufalelhlou22/medical-appointment/blob/main/assets/js/analytics.js"
    click HFA "https://github.com/naoufalelhlou22/medical-appointment/blob/main/handler/fetch_all_appointments.php"
    click HSA "https://github.com/naoufalelhlou22/medical-appointment/blob/main/handler/set_appointment_data.php"
    click HCA "https://github.com/naoufalelhlou22/medical-appointment/blob/main/handler/confirm_appointment.php"
    click HXA "https://github.com/naoufalelhlou22/medical-appointment/blob/main/handler/cancel_appointment.php"
    click HTD "https://github.com/naoufalelhlou22/medical-appointment/blob/main/handler/appointments_today.php"
    click HLM "https://github.com/naoufalelhlou22/medical-appointment/blob/main/handler/last_month_appointments.php"
    click HLY "https://github.com/naoufalelhlou22/medical-appointment/blob/main/handler/last_year_appointments.php"
    click HSP "https://github.com/naoufalelhlou22/medical-appointment/blob/main/handler/fetch_spec_patient.php"
    click HAP "https://github.com/naoufalelhlou22/medical-appointment/blob/main/handler/active_patients.php"
    click HAA "https://github.com/naoufalelhlou22/medical-appointment/blob/main/handler/admin_authentication.php"
    click HFU "https://github.com/naoufalelhlou22/medical-appointment/blob/main/handler/file_upload.php"
    click FD1 "https://github.com/naoufalelhlou22/medical-appointment/blob/main/functions/convert_date_to_months.php"
    click FD2 "https://github.com/naoufalelhlou22/medical-appointment/blob/main/functions/fetch_db_tables.php"
    click FD3 "https://github.com/naoufalelhlou22/medical-appointment/blob/main/functions/showMessage.php"
    click IC1 "https://github.com/naoufalelhlou22/medical-appointment/blob/main/includes/conn_db.php"
    click IC2 "https://github.com/naoufalelhlou22/medical-appointment/blob/main/includes/set_table_values.php"
    click IC3 "https://github.com/naoufalelhlou22/medical-appointment/blob/main/includes/header.php"
    click IC4 "https://github.com/naoufalelhlou22/medical-appointment/blob/main/includes/send_notification.php"
    click AUTH "https://github.com/naoufalelhlou22/medical-appointment/blob/main/app/auth.php"
    click DEP "https://github.com/naoufalelhlou22/medical-appointment/blob/main/composer.json"
    click DEP "https://github.com/naoufalelhlou22/medical-appointment/blob/main/composer.lock"
    click DEP "https://github.com/naoufalelhlou22/medical-appointment/tree/main/vendor/"
```
