# gody19/hospital architecture

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

- Interactive diagram: https://gitdiagram.com/gody19/hospital
- Repository: https://github.com/gody19/hospital

## Overview

#### Purpose and Runtime
MediCare is a framework-free PHP 8 MVC application for hospital operations: patient and doctor management, appointment scheduling, prescriptions, dashboard metrics, and reports. It runs behind Apache with `mod_rewrite`, serving the front controller at `public/index.php`; the project root rewrite supports XAMPP-style deployment via `.htaccess`.

#### Application Bootstrap and Routing
`public/index.php` is the HTTP entry point and loads application initialization from `app/bootstrap.php`. Bootstrap/configuration establish the application environment, database settings, and controller dispatch conventions. Controllers are the request boundary:
- `app/Controllers/AuthController.php`
- `app/Controllers/AppointmentController.php`
- `app/Controllers/ReportController.php`

Requests are routed to controller actions, which enforce authorization, validate input, invoke models, and render PHP views.

#### MVC Domain Modules
The principal business modules are organized around hospital entities:
- Patients: `app/Controllers/PatientController.php`, `app/Models/Patient.php`, `app/Views/patients/index.php`
- Doctors: `app/Controllers/DoctorController.php`, `app/Models/Doctor.php`, `app/Views/doctors/form.php`
- Appointments: `app/Controllers/AppointmentController.php`, `app/Models/Appointment.php`, `app/Views/appointments/_table.php`
- Prescriptions: `app/Controllers/PrescriptionController.php`, `app/Models/Prescription.php`, `app/Views/prescriptions/show.php`

The controller → model → view boundary keeps SQL/data access out of templates and places request orchestration in controllers.

#### Core Platform Services
Shared application behavior resides in `app/Core`:
- Database abstraction and base persistence model: `app/Core/Database.php`, `app/Core/Model.php`
- Controller base/rendering behavior: `app/Core/Controller.php`
- Session/login authorization: `app/Core/Auth.php`
- CSRF protection and request validation: `app/Core/Csrf.php`, `app/Core/Validator.php`
- Sensitive-field encryption and audit activity recording: `app/Core/Crypto.php`, `app/Core/Audit.php`

These services form the main security and persistence boundary used by domain controllers/models.

#### Data and Security Flow
Browser requests pass through Apache and the public front controller, then into authenticated controller actions. Mutating actions should flow through CSRF validation and input validation before model persistence. Models use the shared database layer to access MySQL/MariaDB. Sensitive records can be encrypted through `Crypto`; decryption depends on the environment-specific `APP_KEY`, so key retention is required to recover existing data. Audit logging captures material application activity.

#### Persistence and External Dependencies
The sole operational datastore is MySQL/MariaDB. Schema and bootstrap data are supplied by:
- `database/schema.sql`
- `database/create_user.sql`
- `database/seed_demo.php`

Database credentials and application key are environment-provided via `.env` based on `.env.example`, with PHP OpenSSL required for key generation/encryption. No external API, queue, or cloud service dependency is indicated.

#### Presentation and Reporting
Server-rendered PHP templates share the primary layout at `app/Views/layouts/main.php`. Dashboard and reporting are separate read-oriented flows:
- `app/Controllers/DashboardController.php`, `app/Views/dashboard/index.php`
- `app/Controllers/ReportController.php`, `app/Views/reports/index.php`

Static browser assets are delivered from `public/assets/css/app.css` and `public/assets/js/app.js`.

Main entry points: [`app/Controllers/AppointmentController.php`](https://github.com/gody19/hospital/blob/main/app/Controllers/AppointmentController.php) (Domain controllers), [`app/Core/Database.php`](https://github.com/gody19/hospital/blob/main/app/Core/Database.php) (Model and database layer), [`app/bootstrap.php`](https://github.com/gody19/hospital/blob/main/app/bootstrap.php) (Bootstrap), [`app/Views/layouts/main.php`](https://github.com/gody19/hospital/blob/main/app/Views/layouts/main.php) (PHP views and layout)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web Runtime"]
  node_apache{{"Apache + rewrite<br/>web server<br/>[.htaccess]"}}
  node_front["Front controller<br/>PHP entry point<br/>[index.php]"]
end

subgraph group_mvc["MVC Application"]
  node_bootstrap["Bootstrap<br/>initialization<br/>[bootstrap.php]"]
  node_controllers["Domain controllers<br/>request orchestration"]
  node_dashboard["Dashboard flow<br/>read controller"]
  node_reports["Reporting flow<br/>read controller"]
  node_patients["Patients<br/>domain module<br/>[Patient.php]"]
  node_doctors["Doctors<br/>domain module<br/>[Doctor.php]"]
  node_appointments["Appointments<br/>domain module<br/>[Appointment.php]"]
  node_prescriptions["Prescriptions<br/>domain module<br/>[Prescription.php]"]
end

subgraph group_core["Core Services"]
  node_auth["Auth and session<br/>security service<br/>[Auth.php]"]
  node_request_security["CSRF and validation<br/>request security<br/>[Csrf.php]"]
  node_persistence[("Model and database layer<br/>persistence abstraction<br/>[Database.php]")]
  node_crypto_audit["Crypto and audit<br/>security service<br/>[Crypto.php]"]
end

subgraph group_data["Data &amp; Environment"]
  node_environment["Environment secrets<br/>environment configuration<br/>[.env.example]"]
  node_database[("MySQL / MariaDB<br/>operational datastore<br/>[schema.sql]")]
end

subgraph group_ui["Presentation"]
  node_views["PHP views and layout<br/>server-rendered UI<br/>[main.php]"]
  node_assets["Static assets<br/>browser assets<br/>[app.js]"]
end

node_apache -->|"rewrites requests"| node_front
node_front -->|"loads"| node_bootstrap
node_bootstrap -->|"dispatches"| node_controllers
node_bootstrap -->|"dispatches"| node_dashboard
node_bootstrap -->|"dispatches"| node_reports
node_controllers -->|"authorizes"| node_auth
node_controllers -->|"validates mutations"| node_request_security
node_controllers -->|"manages"| node_patients
node_controllers -->|"manages"| node_doctors
node_controllers -->|"schedules"| node_appointments
node_controllers -->|"manages"| node_prescriptions
node_patients -->|"persists through"| node_persistence
node_doctors -->|"persists through"| node_persistence
node_appointments -->|"persists through"| node_persistence
node_prescriptions -->|"persists through"| node_persistence
node_dashboard -->|"reads metrics"| node_persistence
node_reports -->|"reads report data"| node_persistence
node_persistence -->|"queries"| node_database
node_environment -.->|"configures"| node_bootstrap
node_environment -.->|"provides APP_KEY"| node_crypto_audit
node_patients -.->|"protects activity"| node_crypto_audit
node_prescriptions -.->|"protects activity"| node_crypto_audit
node_controllers -->|"renders"| node_views
node_dashboard -->|"renders"| node_views
node_reports -->|"renders"| node_views
node_views -->|"loads"| node_assets

click node_apache "https://github.com/gody19/hospital/blob/main/.htaccess"
click node_front "https://github.com/gody19/hospital/blob/main/public/index.php"
click node_bootstrap "https://github.com/gody19/hospital/blob/main/app/bootstrap.php"
click node_controllers "https://github.com/gody19/hospital/blob/main/app/Controllers/AppointmentController.php"
click node_dashboard "https://github.com/gody19/hospital/blob/main/app/Controllers/DashboardController.php"
click node_reports "https://github.com/gody19/hospital/blob/main/app/Controllers/ReportController.php"
click node_patients "https://github.com/gody19/hospital/blob/main/app/Models/Patient.php"
click node_doctors "https://github.com/gody19/hospital/blob/main/app/Models/Doctor.php"
click node_appointments "https://github.com/gody19/hospital/blob/main/app/Models/Appointment.php"
click node_prescriptions "https://github.com/gody19/hospital/blob/main/app/Models/Prescription.php"
click node_auth "https://github.com/gody19/hospital/blob/main/app/Core/Auth.php"
click node_request_security "https://github.com/gody19/hospital/blob/main/app/Core/Csrf.php"
click node_persistence "https://github.com/gody19/hospital/blob/main/app/Core/Database.php"
click node_crypto_audit "https://github.com/gody19/hospital/blob/main/app/Core/Crypto.php"
click node_environment "https://github.com/gody19/hospital/blob/main/.env.example"
click node_database "https://github.com/gody19/hospital/blob/main/database/schema.sql"
click node_views "https://github.com/gody19/hospital/blob/main/app/Views/layouts/main.php"
click node_assets "https://github.com/gody19/hospital/blob/main/public/assets/js/app.js"

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_apache,node_front toneBlue
class node_bootstrap,node_controllers,node_dashboard,node_reports,node_patients,node_doctors,node_appointments,node_prescriptions toneAmber
class node_auth,node_request_security,node_persistence,node_crypto_audit toneMint
class node_environment,node_database toneRose
class node_views,node_assets toneIndigo
```

## Components

### Web Runtime

- [Apache + rewrite](https://github.com/gody19/hospital/blob/main/.htaccess): web server · Routes requests to the public front controller. · `.htaccess`
- [Front controller](https://github.com/gody19/hospital/blob/main/public/index.php): PHP entry point · `public/index.php`

### MVC Application

- [Bootstrap](https://github.com/gody19/hospital/blob/main/app/bootstrap.php): initialization · Loads environment, database settings, and dispatch conventions. · `app/bootstrap.php`
- [Domain controllers](https://github.com/gody19/hospital/blob/main/app/Controllers/AppointmentController.php): request orchestration · Authorize requests, validate input, invoke models, and render views. · `app/Controllers/AppointmentController.php`
- [Dashboard flow](https://github.com/gody19/hospital/blob/main/app/Controllers/DashboardController.php): read controller · `app/Controllers/DashboardController.php`
- [Reporting flow](https://github.com/gody19/hospital/blob/main/app/Controllers/ReportController.php): read controller · `app/Controllers/ReportController.php`
- [Patients](https://github.com/gody19/hospital/blob/main/app/Models/Patient.php): domain module · `app/Models/Patient.php`
- [Doctors](https://github.com/gody19/hospital/blob/main/app/Models/Doctor.php): domain module · `app/Models/Doctor.php`
- [Appointments](https://github.com/gody19/hospital/blob/main/app/Models/Appointment.php): domain module · `app/Models/Appointment.php`
- [Prescriptions](https://github.com/gody19/hospital/blob/main/app/Models/Prescription.php): domain module · `app/Models/Prescription.php`

### Core Services

- [Auth and session](https://github.com/gody19/hospital/blob/main/app/Core/Auth.php): security service · `app/Core/Auth.php`
- [CSRF and validation](https://github.com/gody19/hospital/blob/main/app/Core/Csrf.php): request security · Protects mutating requests before persistence. · `app/Core/Csrf.php`
- [Model and database layer](https://github.com/gody19/hospital/blob/main/app/Core/Database.php): persistence abstraction · `app/Core/Database.php`
- [Crypto and audit](https://github.com/gody19/hospital/blob/main/app/Core/Crypto.php): security service · Encrypts sensitive fields and records material activity. · `app/Core/Crypto.php`

### Data & Environment

- [Environment secrets](https://github.com/gody19/hospital/blob/main/.env.example): environment configuration · Supplies database credentials and APP_KEY. · `.env.example`
- [MySQL / MariaDB](https://github.com/gody19/hospital/blob/main/database/schema.sql): operational datastore · `database/schema.sql`

### Presentation

- [PHP views and layout](https://github.com/gody19/hospital/blob/main/app/Views/layouts/main.php): server-rendered UI · Templates render through the shared primary layout. · `app/Views/layouts/main.php`
- [Static assets](https://github.com/gody19/hospital/blob/main/public/assets/js/app.js): browser assets · `public/assets/js/app.js`

## Connections

- Apache + rewrite → Front controller: rewrites requests
- Front controller → Bootstrap: loads
- Bootstrap → Domain controllers: dispatches
- Bootstrap → Dashboard flow: dispatches
- Bootstrap → Reporting flow: dispatches
- Domain controllers → Auth and session: authorizes
- Domain controllers → CSRF and validation: validates mutations
- Domain controllers → Patients: manages
- Domain controllers → Doctors: manages
- Domain controllers → Appointments: schedules
- Domain controllers → Prescriptions: manages
- Patients → Model and database layer: persists through
- Doctors → Model and database layer: persists through
- Appointments → Model and database layer: persists through
- Prescriptions → Model and database layer: persists through
- Dashboard flow → Model and database layer: reads metrics
- Reporting flow → Model and database layer: reads report data
- Model and database layer → MySQL / MariaDB: queries
- Environment secrets → Bootstrap: configures
- Environment secrets → Crypto and audit: provides APP_KEY
- Patients → Crypto and audit: protects activity
- Prescriptions → Crypto and audit: protects activity
- Domain controllers → PHP views and layout: renders
- Dashboard flow → PHP views and layout: renders
- Reporting flow → PHP views and layout: renders
- PHP views and layout → Static assets: loads
