# carlosdgiron/php-clinica architecture

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

- Interactive diagram: https://gitdiagram.com/carlosdgiron/php-clinica
- Repository: https://github.com/carlosdgiron/php-clinica

## Overview

#### Purpose and deployment
This is a Dockerized PHP clinic-management application. It serves a browser UI and an internal same-server API for clinical, operational, inventory, and access-management workflows. Apache rewrite/configuration establishes the public boundary and forwards requests to the PHP front controller: `Dockerfile`, `apache2-custom.conf`, `public/index.php`.

#### Application entry and routing
`public/index.php` boots the custom framework. The routing layer maps requests to resource controllers, while the base controller loads models and middleware. This is a conventional controller/model/view structure rather than a separate API service.
Paths: `public/index.php`, `app/libraries/Core.php`, `app/config/RouteMap.php`.

#### Authentication and authorization boundary
Login is a distinct flow; protected controller operations pass through token validation middleware. Authorization domain data is modeled around users, roles, permissions, employees, and positions.
Paths: `app/Controllers/LoginController.php`, `app/middleware/AuthMiddleware.php`, `app/Models/MiddlewareModel.php`.

#### Clinical-care domain
Patient management is central, with linked diagnosis and examination records. These controllers/models form the clinical-record flow: UI/API requests create or query patient data and associated diagnoses/exams through the database layer.
Paths: `app/Controllers/PatientController.php`, `app/Controllers/PatientDiagnosisController.php`, `app/Controllers/PatientExamController.php`.

#### Facilities and staffing domain
Room state is separated into rooms, availability, assignments, and history, supporting operational tracking of patient/staff placement and occupancy over time. Branch and employee resources define the organizational context.
Paths: `app/Controllers/RoomController.php`, `app/Controllers/RoomAssignmentController.php`, `app/Controllers/RoomHistoryController.php`.

#### Pharmacy and commercial domain
Medicine, supplier, batch, inventory, sales, and sale-detail resources provide the medication lifecycle: supplies/batches feed inventory, and sales with line details consume or report on stock. Medicine images are public static assets.
Paths: `app/Controllers/MedicineController.php`, `app/Controllers/InventoryController.php`, `app/Controllers/SaleController.php`.

#### Data, views, and browser client
Models access the configured database through a shared database abstraction. PHP views render the application shell/templates; JavaScript dynamically loads feature modules and calls the internal API. The home feature also has a local cached news payload, suggesting an external news integration configured server-side.
Paths: `app/libraries/Database.php`, `app/config/Database.php`, `app/Views/Template/Header.php`, `public/js/services/apiService.js`, `app/storage/cache/news.json`.

#### Primary request flow
Browser requests enter Apache and `public/index.php`, then `Core` resolves routes to controllers. Controllers apply auth where required, invoke entity models/database access, and return data or render views. Client modules use `apiService` for authenticated API calls and update the browser UI.
Paths: `app/libraries/Core.php`, `app/libraries/Controllers.php`, `public/js/moduleLoader.js`.

Main entry points: [`app/libraries/Controllers.php`](https://github.com/carlosdgiron/php-clinica/blob/main/app/libraries/Controllers.php) (Base controller), [`app/libraries/Database.php`](https://github.com/carlosdgiron/php-clinica/blob/main/app/libraries/Database.php) (Database abstraction), [`app/libraries/Core.php`](https://github.com/carlosdgiron/php-clinica/blob/main/app/libraries/Core.php) (Core router), [`apache2-custom.conf`](https://github.com/carlosdgiron/php-clinica/blob/main/apache2-custom.conf) (Apache public boundary)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_edge["Web boundary"]
  node_browser(("Browser UI<br/>browser client"))
  node_apache{{"Apache public boundary<br/>web server"}}
  node_front["PHP front controller<br/>application entry<br/>[index.php]"]
end

subgraph group_app["PHP application"]
  node_core["Core router<br/>framework router<br/>[Core.php]"]
  node_routes["Route map<br/>route definitions<br/>[RouteMap.php]"]
  node_controllers["Base controller<br/>controller base<br/>[Controllers.php]"]
  node_auth["Auth middleware<br/>token validation<br/>[AuthMiddleware.php]"]
  node_login["Login flow<br/>authentication controller"]
end

subgraph group_domains["Business domains"]
  node_access["Access management<br/>authorization models"]
  node_clinical["Clinical records<br/>patient controllers"]
  node_facilities["Rooms and assignments<br/>operations controllers<br/>[RoomController.php]"]
  node_pharmacy["Pharmacy and sales<br/>commercial controllers"]
end

subgraph group_data["Data and presentation"]
  node_database[("Database abstraction<br/>database access layer<br/>[Database.php]")]
  node_dbconfig["Database configuration<br/>connection configuration<br/>[Database.php]"]
  node_views["PHP templates<br/>server-rendered views<br/>[Header.php]"]
  node_modules["Feature module loader<br/>browser module loader<br/>[moduleLoader.js]"]
  node_api["API service<br/>authenticated API client<br/>[apiService.js]"]
  node_news["Cached news payload<br/>local cache<br/>[news.json]"]
end

node_browser -->|"HTTP requests"| node_apache
node_apache -->|"rewrites"| node_front
node_front -->|"boots"| node_core
node_core -->|"resolves routes from"| node_routes
node_core -->|"dispatches to"| node_controllers
node_controllers -->|"protects operations with"| node_auth
node_controllers -->|"serves"| node_login
node_auth -->|"validates against"| node_access
node_controllers -->|"handles"| node_clinical
node_controllers -->|"handles"| node_facilities
node_controllers -->|"handles"| node_pharmacy
node_clinical -->|"persists records"| node_database
node_facilities -->|"persists state"| node_database
node_pharmacy -->|"manages stock and sales"| node_database
node_access -->|"reads authorization data"| node_database
node_database -->|"uses connection settings"| node_dbconfig
node_controllers -->|"renders"| node_views
node_browser -->|"loads"| node_modules
node_modules -->|"uses"| node_api
node_api -->|"internal API calls"| node_apache
node_controllers -.->|"reads cached home news"| node_news

click node_apache "https://github.com/carlosdgiron/php-clinica/blob/main/apache2-custom.conf"
click node_front "https://github.com/carlosdgiron/php-clinica/blob/main/public/index.php"
click node_core "https://github.com/carlosdgiron/php-clinica/blob/main/app/libraries/Core.php"
click node_routes "https://github.com/carlosdgiron/php-clinica/blob/main/app/config/RouteMap.php"
click node_controllers "https://github.com/carlosdgiron/php-clinica/blob/main/app/libraries/Controllers.php"
click node_auth "https://github.com/carlosdgiron/php-clinica/blob/main/app/middleware/AuthMiddleware.php"
click node_login "https://github.com/carlosdgiron/php-clinica/blob/main/app/Controllers/LoginController.php"
click node_access "https://github.com/carlosdgiron/php-clinica/blob/main/app/Models/MiddlewareModel.php"
click node_clinical "https://github.com/carlosdgiron/php-clinica/blob/main/app/Controllers/PatientController.php"
click node_facilities "https://github.com/carlosdgiron/php-clinica/blob/main/app/Controllers/RoomController.php"
click node_pharmacy "https://github.com/carlosdgiron/php-clinica/blob/main/app/Controllers/MedicineController.php"
click node_database "https://github.com/carlosdgiron/php-clinica/blob/main/app/libraries/Database.php"
click node_dbconfig "https://github.com/carlosdgiron/php-clinica/blob/main/app/config/Database.php"
click node_views "https://github.com/carlosdgiron/php-clinica/blob/main/app/Views/Template/Header.php"
click node_modules "https://github.com/carlosdgiron/php-clinica/blob/main/public/js/moduleLoader.js"
click node_api "https://github.com/carlosdgiron/php-clinica/blob/main/public/js/services/apiService.js"
click node_news "https://github.com/carlosdgiron/php-clinica/blob/main/app/storage/cache/news.json"

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_browser,node_apache,node_front toneBlue
class node_core,node_routes,node_controllers,node_auth,node_login toneAmber
class node_access,node_clinical,node_facilities,node_pharmacy toneMint
class node_database,node_dbconfig,node_views,node_modules,node_api,node_news toneRose
```

## Components

### Web boundary

- **Browser UI**: browser client
- [Apache public boundary](https://github.com/carlosdgiron/php-clinica/blob/main/apache2-custom.conf): web server · Rewrite rules forward application requests to the front controller. · `apache2-custom.conf`
- [PHP front controller](https://github.com/carlosdgiron/php-clinica/blob/main/public/index.php): application entry · `public/index.php`

### PHP application

- [Core router](https://github.com/carlosdgiron/php-clinica/blob/main/app/libraries/Core.php): framework router · `app/libraries/Core.php`
- [Route map](https://github.com/carlosdgiron/php-clinica/blob/main/app/config/RouteMap.php): route definitions · `app/config/RouteMap.php`
- [Base controller](https://github.com/carlosdgiron/php-clinica/blob/main/app/libraries/Controllers.php): controller base · Loads models and middleware for resource controllers. · `app/libraries/Controllers.php`
- [Auth middleware](https://github.com/carlosdgiron/php-clinica/blob/main/app/middleware/AuthMiddleware.php): token validation · `app/middleware/AuthMiddleware.php`
- [Login flow](https://github.com/carlosdgiron/php-clinica/blob/main/app/Controllers/LoginController.php): authentication controller · `app/Controllers/LoginController.php`

### Business domains

- [Access management](https://github.com/carlosdgiron/php-clinica/blob/main/app/Models/MiddlewareModel.php): authorization models · Users, roles, permissions, employees, and positions. · `app/Models/MiddlewareModel.php`
- [Clinical records](https://github.com/carlosdgiron/php-clinica/blob/main/app/Controllers/PatientController.php): patient controllers · Patient records with diagnosis and examination flows. · `app/Controllers/PatientController.php`
- [Rooms and assignments](https://github.com/carlosdgiron/php-clinica/blob/main/app/Controllers/RoomController.php): operations controllers · Room state, placement, and occupancy history. · `app/Controllers/RoomController.php`
- [Pharmacy and sales](https://github.com/carlosdgiron/php-clinica/blob/main/app/Controllers/MedicineController.php): commercial controllers · Medicine, inventory, batches, suppliers, sales, and sale details. · `app/Controllers/MedicineController.php`

### Data and presentation

- [Database abstraction](https://github.com/carlosdgiron/php-clinica/blob/main/app/libraries/Database.php): database access layer · `app/libraries/Database.php`
- [Database configuration](https://github.com/carlosdgiron/php-clinica/blob/main/app/config/Database.php): connection configuration · `app/config/Database.php`
- [PHP templates](https://github.com/carlosdgiron/php-clinica/blob/main/app/Views/Template/Header.php): server-rendered views · `app/Views/Template/Header.php`
- [Feature module loader](https://github.com/carlosdgiron/php-clinica/blob/main/public/js/moduleLoader.js): browser module loader · `public/js/moduleLoader.js`
- [API service](https://github.com/carlosdgiron/php-clinica/blob/main/public/js/services/apiService.js): authenticated API client · `public/js/services/apiService.js`
- [Cached news payload](https://github.com/carlosdgiron/php-clinica/blob/main/app/storage/cache/news.json): local cache · Cached home-feature news integration data. · `app/storage/cache/news.json`

## Connections

- Browser UI → Apache public boundary: HTTP requests
- Apache public boundary → PHP front controller: rewrites
- PHP front controller → Core router: boots
- Core router → Route map: resolves routes from
- Core router → Base controller: dispatches to
- Base controller → Auth middleware: protects operations with
- Base controller → Login flow: serves
- Auth middleware → Access management: validates against
- Base controller → Clinical records: handles
- Base controller → Rooms and assignments: handles
- Base controller → Pharmacy and sales: handles
- Clinical records → Database abstraction: persists records
- Rooms and assignments → Database abstraction: persists state
- Pharmacy and sales → Database abstraction: manages stock and sales
- Access management → Database abstraction: reads authorization data
- Database abstraction → Database configuration: uses connection settings
- Base controller → PHP templates: renders
- Browser UI → Feature module loader: loads
- Feature module loader → API service: uses
- API service → Apache public boundary: internal API calls
- Base controller → Cached news payload: reads cached home news
