# keerthuammu/hospital-appointment-booking-system architecture

> Architecture diagram of the GitHub repository keerthuammu/hospital-appointment-booking-system, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-03-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/keerthuammu/hospital-appointment-booking-system
- Repository: https://github.com/keerthuammu/hospital-appointment-booking-system

## Overview

##### What this project is (type + purpose)
**CarePlus Hospital System** is a **small full-stack web application** for **medical appointment scheduling**:
- **Frontend**: static pages (**index.html**, **booking.html**) with **Bootstrap + jQuery/AJAX**.
- **Backend**: **PHP 8** “API endpoints” under `backend/api/`.
- **Database**: **MySQL** with schema in `database/schema.sql`.
- Data flow called out in README: **Load doctors (AJAX)** → **Book (validate in jQuery, persist via PHP/MySQL)** → **Cancel / “My Bookings”**.

##### What the file tree tells you about the architecture
Directories/files to architectural components:

##### Backend (application/API layer)
- `backend/api/get_doctors.php` (read/list doctors for UI)
- `backend/api/book_appointment.php` (create appointment)
- `backend/includes/config.php` (DB connection + constants; should be a shared dependency)

##### Data layer
- `database/schema.sql` (authoritative DB structure)

##### Web Browser (Client)
- Renders `index.html`, `booking.html`
- Runs `js/script.js`
##### Web Server + PHP Runtime (Backend)
- Serves static files (or note: could be Apache/Nginx serving both static + PHP)
- Hosts API endpoints:
- `GET /backend/api/get_doctors.php`
- `POST /backend/api/book_appointment.php`
##### MySQL Database
- Schema from `database/schema.sql`

- **Static Assets Store** (`assets/`, `css/`, `js/`) as a “Static Content” sub-container (even if served by same server)

Decompose the backend container into components:
- **API: Doctor Catalog Endpoint**
- `backend/api/get_doctors.php`
- Depends on `backend/includes/config.php`
- Reads from `doctors` table (or equivalent)
- **API: Appointment Booking Endpoint**
- `backend/api/book_appointment.php`
- Depends on `backend/includes/config.php`
- Writes to `appointments/bookings` tables (whatever schema defines)
- **Config/DB Connector**
- `backend/includes/config.php`
- Owns DB connection parameters and creates a DB handle

If cancellation exists (“My Bookings” suggests it might), but there’s no endpoint in the tree, represent it as:
- **“Cancel booking” UI flow** calling a **(missing/not yet implemented) endpoint** OR note it as **future work**. Don’t invent files that aren’t present.

##### Relationships & interactions to show (data flows)
Base this strictly on README workflow + the API files you have.

##### `script.js` sends AJAX request to
- `backend/api/get_doctors.php`
3. PHP endpoint queries **MySQL** (or reads `doctors.json` if that’s what implementation does)
##### Returns JSON → browser renders doctor list / available slots

- Browser → get_doctors.php (HTTP GET)
- get_doctors.php → MySQL (SQL SELECT)
- MySQL → get_doctors.php
- get_doctors.php → Browser (JSON)

##### Browser sends AJAX POST to
- `backend/api/book_appointment.php`
4. PHP validates server-side (should be shown as a responsibility even if simple), inserts into **MySQL**
##### Returns success/failure JSON → UI updates

- Browser → book_appointment.php (HTTP POST: patient info, doctor_id, time slot)
- book_appointment.php → MySQL (SQL INSERT)
- book_appointment.php → Browser (JSON response)

##### Flow 3: “My Bookings” / Cancel (if present in UI)
If no endpoint exists, show:
- Browser “My Bookings” UI → (TBD API) → MySQL

##### C4 L1 (Context): User ↔ CarePlus ↔ MySQL
2. **C4 L2 (Container)**: Browser (HTML/JS/CSS) ↔ PHP API (two endpoints + config) ↔ MySQL (+ optional JSON files)
- “Load doctors”
- “Book appointment”

These three views together will be the most accurate representation of what the repository actually implements, while still being detailed and decomposed into many components.

## Diagram (Mermaid)

```mermaid
flowchart TD
  %% =========================
  %% C4 L1 - Context Diagram
  %% =========================
  subgraph "C4 L1 — Context: CarePlus Hospital System"
    direction TB
    U["Patient / User"]:::actor
    B0["Web Browser"]:::external
    SYS["CarePlus Hospital System"]:::system
    DB0[("MySQL Database")]:::db

    U -->|"uses"| B0
    B0 -->|"accesses"| SYS
    SYS -->|"stores/retrieves_appointments_and_doctors"| DB0
  end

  %% =========================
  %% C4 L2 - Container Diagram
  %% =========================
  subgraph "C4 L2 — Containers"
    direction TB

    subgraph "Client (Web Browser)"
      direction TB
      PAGES["Browser UI Pages\n(index.html, booking.html)"]:::frontend
      JS["Client Script\n(js/script.js: AJAX + validation + DOM updates)"]:::frontend
      CSS["Frontend Styling\n(css/style.css)"]:::frontend
      ASSETS["Static Assets\n(assets/, assets/doctors/)"]:::static
      MYBOOK["My Bookings / Cancel UI\n(TBD in repo)"]:::optional

      PAGES -.->|"loads"| JS
      PAGES -.->|"loads"| CSS
      PAGES -.->|"loads"| ASSETS
      MYBOOK -.->|"future_UI_flow"| PAGES
    end

    subgraph "Server (Web Server + PHP 8 Runtime)"
      direction TB
      API1["API Endpoint\nGET /backend/api/get_doctors.php"]:::backend
      API2["API Endpoint\nPOST /backend/api/book_appointment.php"]:::backend
      CFG["Shared Backend\nconfig.php (DB connector/constants)"]:::backend
      TBDAPI["TBD Endpoint\n(My Bookings / Cancel)\nnot in repo yet"]:::optional

      API1 -.->|"include/require"| CFG
      API2 -.->|"include/require"| CFG
      TBDAPI -.->|"would_include/require"| CFG
    end

    subgraph "Data Layer"
      direction TB
      DB[("MySQL\n(tables from schema.sql)")]:::db
      SCHEMA["Database Schema\n(database/schema.sql)"]:::doc
      JSOND["Optional Dev/Mock JSON Store\n(doctors.json, bookings.json)"]:::optional

      SCHEMA -.->|"defines_structure_for"| DB
      JSOND -.->|"optional_seed/mock_data"| API1
      JSOND -.->|"optional_seed/mock_data"| API2
    end

    %% Runtime flows (AJAX)
    JS -->|"HTTP_GET_/backend/api/get_doctors.php (JSON)"| API1
    API1 -->|"SQL_SELECT_doctors"| DB
    DB -->|"result_set"| API1
    API1 -->|"JSON_doctor_list"| JS

    JS -->|"HTTP_POST_/backend/api/book_appointment.php (form/JSON)"| API2
    API2 -->|"SQL_INSERT_appointment"| DB
    DB -->|"insert_status"| API2
    API2 -->|"JSON_success/failure"| JS

    %% Future / not implemented
    MYBOOK -.->|"HTTP_TBD"| TBDAPI
    TBDAPI -.->|"SQL_TBD"| DB
  end

  %% =========================
  %% C4 L3 - Component Diagram (PHP container)
  %% =========================
  subgraph "C4 L3 — Components inside PHP Backend"
    direction TB

    subgraph "API Layer (backend/api/)"
      direction TB
      C_GET["Component: Doctor Catalog Endpoint\n(get_doctors.php)"]:::backend
      C_BOOK["Component: Appointment Booking Endpoint\n(book_appointment.php)"]:::backend
      C_TBD["Component: My Bookings / Cancel\n(missing endpoint)"]:::optional
    end

    subgraph "Shared Infrastructure (backend/includes/)"
      direction TB
      C_CFG["Component: Config / DB Connector\n(config.php)"]:::backend
    end

    subgraph "Persistence"
      direction TB
      C_DB[("MySQL Database")]:::db
      C_SCHEMA["schema.sql"]:::doc
      C_JSON["Optional JSON files\n(doctors.json, bookings.json)"]:::optional
    end

    %% Dependencies
    C_GET -.->|"include/require"| C_CFG
    C_BOOK -.->|"include/require"| C_CFG
    C_TBD -.->|"would_include/require"| C_CFG

    %% Data access
    C_GET -->|"SQL_SELECT_doctors"| C_DB
    C_BOOK -->|"SQL_INSERT_booking"| C_DB
    C_TBD -.->|"SQL_TBD"| C_DB

    C_SCHEMA -.->|"defines"| C_DB
    C_JSON -.->|"optional_read"| C_GET
    C_JSON -.->|"optional_read/write"| C_BOOK
  end

  %% =========================
  %% Sequence — Load doctors (AJAX)
  %% =========================
  subgraph "Sequence — Load Doctors (AJAX)"
    direction TB
    S1["Browser loads page + assets"]:::seq
    S2["script.js triggers AJAX GET"]:::seq
    S3["get_doctors.php reads doctors"]:::seq
    S4["MySQL returns rows"]:::seq
    S5["JSON returned; UI renders list"]:::seq

    S1 --> S2 --> S3 --> S4 --> S5
  end

  %% =========================
  %% Sequence — Book appointment (AJAX)
  %% =========================
  subgraph "Sequence — Book Appointment (AJAX)"
    direction TB
    T1["User submits booking form (booking.html)"]:::seq
    T2["script.js validates client-side"]:::seq
    T3["AJAX POST to book_appointment.php"]:::seq
    T4["PHP validates + inserts booking in MySQL"]:::seq
    T5["JSON success/failure; UI updates"]:::seq

    T1 --> T2 --> T3 --> T4 --> T5
  end

  %% =========================
  %% Click Events (from component_mapping)
  %% =========================
  click PAGES "https://github.com/keerthuammu/hospital-appointment-booking-system/blob/main/index.html"
  click PAGES "https://github.com/keerthuammu/hospital-appointment-booking-system/blob/main/booking.html"
  click JS "https://github.com/keerthuammu/hospital-appointment-booking-system/blob/main/js/script.js"
  click CSS "https://github.com/keerthuammu/hospital-appointment-booking-system/blob/main/css/style.css"
  click ASSETS "https://github.com/keerthuammu/hospital-appointment-booking-system/tree/main/assets/"
  click ASSETS "https://github.com/keerthuammu/hospital-appointment-booking-system/tree/main/assets/doctors/"
  click API1 "https://github.com/keerthuammu/hospital-appointment-booking-system/blob/main/backend/api/get_doctors.php"
  click API2 "https://github.com/keerthuammu/hospital-appointment-booking-system/blob/main/backend/api/book_appointment.php"
  click CFG "https://github.com/keerthuammu/hospital-appointment-booking-system/blob/main/backend/includes/config.php"
  click SCHEMA "https://github.com/keerthuammu/hospital-appointment-booking-system/blob/main/database/schema.sql"
  click JSOND "https://github.com/keerthuammu/hospital-appointment-booking-system/blob/main/doctors.json"
  click JSOND "https://github.com/keerthuammu/hospital-appointment-booking-system/blob/main/bookings.json"
  click C_GET "https://github.com/keerthuammu/hospital-appointment-booking-system/blob/main/backend/api/get_doctors.php"
  click C_BOOK "https://github.com/keerthuammu/hospital-appointment-booking-system/blob/main/backend/api/book_appointment.php"
  click C_CFG "https://github.com/keerthuammu/hospital-appointment-booking-system/blob/main/backend/includes/config.php"
  click C_SCHEMA "https://github.com/keerthuammu/hospital-appointment-booking-system/blob/main/database/schema.sql"
  click C_JSON "https://github.com/keerthuammu/hospital-appointment-booking-system/blob/main/doctors.json"

  %% =========================
  %% Styles
  %% =========================
  classDef actor fill:#111827,stroke:#0f172a,color:#ffffff,stroke-width:2px
  classDef external fill:#334155,stroke:#0f172a,color:#ffffff,stroke-width:1.5px
  classDef system fill:#1f2937,stroke:#111827,color:#ffffff,stroke-width:2px
  classDef frontend fill:#2563eb,stroke:#1e3a8a,color:#ffffff,stroke-width:1.5px
  classDef static fill:#1d4ed8,stroke:#1e40af,color:#ffffff,stroke-width:1.5px
  classDef backend fill:#16a34a,stroke:#14532d,color:#ffffff,stroke-width:1.5px
  classDef db fill:#f59e0b,stroke:#92400e,color:#111827,stroke-width:2px
  classDef doc fill:#9ca3af,stroke:#4b5563,color:#111827,stroke-width:1.5px
  classDef optional fill:#e5e7eb,stroke:#6b7280,color:#111827,stroke-width:1.5px,stroke-dasharray: 6 4
  classDef seq fill:#0ea5e9,stroke:#075985,color:#ffffff,stroke-width:1.5px
```
