# huyg17082006/ctumedic architecture

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

- Interactive diagram: https://gitdiagram.com/huyg17082006/ctumedic
- Repository: https://github.com/huyg17082006/ctumedic

## Overview

CTUMedic is a role-based clinic portal for patients, doctors, and managers. Its central workflow is role-aware page routing, followed by appointment booking or management; appointment APIs validate patient access and normalize requested slots before database operations. Separate capabilities cover account access and profiles, doctor discovery, appointment lifecycle actions, and manager administration of doctors and patients. The graph reflects the routing and dependencies visible in the excerpts and source index; frontend-to-API wiring is not shown, so those links are omitted.

Main entry points: [`index.php`](https://github.com/huyg17082006/ctumedic/blob/main/index.php) (Role page router), [`backend/api/appointments`](https://github.com/huyg17082006/ctumedic/tree/main/backend/api/appointments) (Appointment endpoints), [`backend/middleware`](https://github.com/huyg17082006/ctumedic/tree/main/backend/middleware) (Role authorization), [`backend/database.php`](https://github.com/huyg17082006/ctumedic/blob/main/backend/database.php) (Clinic database)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web experience"]
  node_router["Role page router<br/>[index.php]"]
  node_auth_views["Sign-in and registration"]
  node_patient_views["Patient workspace"]
  node_doctor_views["Doctor workspace<br/>[doctors.php]"]
  node_manager_views["Manager workspace"]
  node_appointment_ui["Appointment interface"]
  node_profile_ui["Account and history views"]
  node_pagination["Pagination<br/>[pagination.php]"]
  node_schedule_ui["Schedule periods"]
  node_base["Shared app setup<br/>[BASE.php]"]
end

subgraph group_accounts["Accounts and access"]
  node_account_api["Account endpoints"]
  node_auth_guard["Session authorization<br/>[auth.php]"]
  node_role_guards["Role authorization"]
end

subgraph group_appointments["Appointments"]
  node_appointment_api["Appointment endpoints"]
  node_doctor_discovery["Doctor discovery"]
end

subgraph group_administration["Clinic administration"]
  node_management_api["Management endpoints"]
end

subgraph group_data["Data and scheduling"]
  node_slot_rules["Slot validation"]
  node_database[("Clinic database<br/>[database.php]")]
end

node_user(("Portal user"))

node_user -->|"opens portal"| node_router
node_router -->|"routes to"| node_auth_views
node_router -->|"routes to"| node_patient_views
node_router -->|"routes to"| node_doctor_views
node_router -->|"routes to"| node_manager_views
node_router -->|"loads"| node_base
node_account_api -->|"requires"| node_auth_guard
node_role_guards -->|"checks session"| node_auth_guard
node_management_api -->|"requires manager"| node_role_guards
node_appointment_api -->|"reads and writes"| node_database
node_appointment_api -->|"validates slots"| node_slot_rules
node_appointment_api -->|"requires patient"| node_role_guards
node_doctor_discovery -->|"queries doctors"| node_database
node_management_api -->|"manages records"| node_database
node_appointment_ui -->|"renders slots"| node_schedule_ui
node_manager_views -->|"uses pagination"| node_pagination

click node_router "https://github.com/huyg17082006/ctumedic/blob/main/index.php"
click node_auth_views "https://github.com/huyg17082006/ctumedic/tree/main/frontend/views/authentication"
click node_patient_views "https://github.com/huyg17082006/ctumedic/tree/main/frontend/views/patients"
click node_doctor_views "https://github.com/huyg17082006/ctumedic/blob/main/frontend/views/doctors/doctors.php"
click node_manager_views "https://github.com/huyg17082006/ctumedic/tree/main/frontend/views/management"
click node_appointment_ui "https://github.com/huyg17082006/ctumedic/tree/main/frontend/components/appointment"
click node_profile_ui "https://github.com/huyg17082006/ctumedic/tree/main/frontend/views/shared"
click node_pagination "https://github.com/huyg17082006/ctumedic/blob/main/frontend/components/pagination.php"
click node_schedule_ui "https://github.com/huyg17082006/ctumedic/blob/main/frontend/components/schedule_periods.php"
click node_account_api "https://github.com/huyg17082006/ctumedic/tree/main/backend/api/accounts"
click node_auth_guard "https://github.com/huyg17082006/ctumedic/blob/main/backend/middleware/auth.php"
click node_role_guards "https://github.com/huyg17082006/ctumedic/tree/main/backend/middleware"
click node_appointment_api "https://github.com/huyg17082006/ctumedic/tree/main/backend/api/appointments"
click node_doctor_discovery "https://github.com/huyg17082006/ctumedic/tree/main/backend/api/doctors"
click node_slot_rules "https://github.com/huyg17082006/ctumedic/blob/main/backend/helpers/appointment_schedule.php"
click node_management_api "https://github.com/huyg17082006/ctumedic/tree/main/backend/api/management"
click node_database "https://github.com/huyg17082006/ctumedic/blob/main/backend/database.php"
click node_base "https://github.com/huyg17082006/ctumedic/blob/main/BASE.php"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_router,node_auth_views,node_patient_views,node_doctor_views,node_manager_views,node_appointment_ui,node_profile_ui,node_pagination,node_schedule_ui,node_base,node_user toneBlue
class node_account_api,node_auth_guard,node_role_guards toneAmber
class node_appointment_api,node_doctor_discovery toneMint
class node_management_api toneRose
class node_slot_rules,node_database toneIndigo
```

## Components

### Web experience

- [Role page router](https://github.com/huyg17082006/ctumedic/blob/main/index.php): `index.php`
- [Sign-in and registration](https://github.com/huyg17082006/ctumedic/tree/main/frontend/views/authentication): `frontend/views/authentication`
- [Patient workspace](https://github.com/huyg17082006/ctumedic/tree/main/frontend/views/patients): `frontend/views/patients`
- [Doctor workspace](https://github.com/huyg17082006/ctumedic/blob/main/frontend/views/doctors/doctors.php): `frontend/views/doctors/doctors.php`
- [Manager workspace](https://github.com/huyg17082006/ctumedic/tree/main/frontend/views/management): `frontend/views/management`
- [Appointment interface](https://github.com/huyg17082006/ctumedic/tree/main/frontend/components/appointment): `frontend/components/appointment`
- [Account and history views](https://github.com/huyg17082006/ctumedic/tree/main/frontend/views/shared): `frontend/views/shared`
- [Pagination](https://github.com/huyg17082006/ctumedic/blob/main/frontend/components/pagination.php): `frontend/components/pagination.php`
- [Schedule periods](https://github.com/huyg17082006/ctumedic/blob/main/frontend/components/schedule_periods.php): `frontend/components/schedule_periods.php`
- [Shared app setup](https://github.com/huyg17082006/ctumedic/blob/main/BASE.php): `BASE.php`

### Accounts and access

- [Account endpoints](https://github.com/huyg17082006/ctumedic/tree/main/backend/api/accounts): `backend/api/accounts`
- [Session authorization](https://github.com/huyg17082006/ctumedic/blob/main/backend/middleware/auth.php): `backend/middleware/auth.php`
- [Role authorization](https://github.com/huyg17082006/ctumedic/tree/main/backend/middleware): `backend/middleware`

### Appointments

- [Appointment endpoints](https://github.com/huyg17082006/ctumedic/tree/main/backend/api/appointments): `backend/api/appointments`
- [Doctor discovery](https://github.com/huyg17082006/ctumedic/tree/main/backend/api/doctors): `backend/api/doctors`

### Clinic administration

- [Management endpoints](https://github.com/huyg17082006/ctumedic/tree/main/backend/api/management): `backend/api/management`

### Data and scheduling

- [Slot validation](https://github.com/huyg17082006/ctumedic/blob/main/backend/helpers/appointment_schedule.php): `backend/helpers/appointment_schedule.php`
- [Clinic database](https://github.com/huyg17082006/ctumedic/blob/main/backend/database.php): `backend/database.php`

### Other components

- **Portal user**

## Connections

- Portal user → Role page router: opens portal (evidence: `index.php`)
- Role page router → Sign-in and registration: routes to (evidence: `index.php`)
- Role page router → Patient workspace: routes to (evidence: `index.php`)
- Role page router → Doctor workspace: routes to (evidence: `index.php`)
- Role page router → Manager workspace: routes to (evidence: `index.php`)
- Role page router → Shared app setup: loads (evidence: `index.php`)
- Account endpoints → Session authorization: requires (evidence: `backend/api/accounts/personal_profile.php`)
- Role authorization → Session authorization: checks session (evidence: `backend/middleware/manager.php`)
- Management endpoints → Role authorization: requires manager (evidence: `backend/api/management/manager_add_doctor.php`)
- Appointment endpoints → Clinic database: reads and writes (evidence: `backend/api/appointments/create_appointment.php`)
- Appointment endpoints → Slot validation: validates slots (evidence: `backend/api/appointments/create_appointment.php`)
- Appointment endpoints → Role authorization: requires patient (evidence: `backend/api/appointments/create_appointment.php`)
- Doctor discovery → Clinic database: queries doctors (evidence: `backend/api/doctors/get_available_doctors_for_booking.php`)
- Management endpoints → Clinic database: manages records (evidence: `backend/api/management/manager_add_doctor.php`)
- Appointment interface → Schedule periods: renders slots (evidence: `frontend/components/appointment/reschedule_modal.php`)
- Manager workspace → Pagination: uses pagination (evidence: `frontend/views/management/tabs/doctors.php`)
