# rickypega/docuhuella architecture

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

- Interactive diagram: https://gitdiagram.com/rickypega/docuhuella
- Repository: https://github.com/rickypega/docuhuella

## Overview

1. **Overall shape**
DocuHuella is a PHP/MySQL MVC application for veterinary record management. The main request path is: browser → front controller/routing → role-specific controller → model → MySQL database → view render. The codebase is split by responsibility rather than by technical layer only, which makes it easy to map the app into domain areas.

2. **Entry point and routing**
`index.php` is the application entry point, and `routes/web.php` likely defines the request-to-controller mapping. The root `.htaccess` suggests clean URLs and Apache-based front-controller routing. This means the architecture depends on Apache/XAMPP or equivalent hosting, with PHP handling server-side rendering.

3. **Shared infrastructure**
`config/db.php` centralizes the database connection, using PDO as described in the README. `config/auth_check.php` is the main access-control boundary, enforcing login/role checks before protected actions run. This is the key security layer separating public pages from authenticated modules.

4. **Role-based application boundaries**
The repository is organized around four user domains:
- `superadmin/` for system administration and catalog management
- `admin/` for clinic/admin operations
- `veterinario/` for clinical workflow
- `cuidador/` for pet-owner/caregiver features  
This is the strongest architectural boundary in the app; each role has its own controller set and views, and likely its own dashboard/home page.

5. **Core domain model**
The `models/` folder holds the domain entities and persistence logic. The main business objects are:
- identity/access: `Usuario`, `Rol`, `Administrador`, `Veterinario`, `Cuidador`
- clinical workflow: `Mascota`, `Cita`, `Consulta`, `Expediente`, `Nota`, `Vacuna`, `Vacunacion`
- reference data: `Clinica`, `Especie`, `Raza`, `Color`, `Especialidad`  
These models represent the data graph for the diagram: users own or manage pets; pets have appointments, consultations, notes, and vaccination records; vets and admins operate within clinic context.

6. **Clinical workflow subsystem**
The veterinarian area (`controllers/veterinario/`, `views/veterinario/`) is centered on day-to-day medical operations: `citas`, `consultas`, `pacientes`, `paciente_ver`, and `vacunas`. This is where most write-heavy clinical data flows happen, especially from appointments into consultation records and then into the pet’s expediente/history.

7. **Caregiver subsystem**
The caregiver module (`controllers/cuidador/`, `views/cuidador/`) handles pet ownership and self-service features like viewing a dashboard, managing `mascota`, and `mis_mascotas`. The shared view includes modal fragments such as `modal_registrar_mascota`, which suggests that caregivers can submit pet data through in-page forms rather than separate admin workflows.

8. **Administration and reporting**
The admin and superadmin areas separate operational administration from system-wide configuration. `controllers/admin/` includes clinic management, vet registration, dashboard, and reports. `controllers/superadmin/` adds administrator management, catalog maintenance, dashboards, and reporting. The reporting subsystem likely aggregates monthly clinical or operational statistics and may generate documents via FPDF.

9. **Reusable UI composition**
`layouts/header.php` and `layouts/footer.php` provide the shared shell for pages, while `views/includes/` contains reusable fragments like profile and notes modals. This indicates a server-rendered UI with shared partials rather than a SPA. Page composition is view-driven, with controllers assembling the data and selecting the correct template.

10. **Document generation and file assets**
`libs/fpdf.php` and the bundled font files show that PDF generation is embedded in the app, most likely for reports and clinical outputs. Static assets live under `public/`, including CSS and uploads. The upload structure is domain-specific: `public/uploads/pets` and `public/uploads/consultas` separate pet images or documents from consultation attachments.

11. **Database and initialization**
`DocuhuellaDB.sql` is the schema/data seed source. The README also references an initialization step that creates default roles and a master account, so the system expects a populated database before first use. The application is therefore database-first: schema, seed data, then runtime behavior.

12. **Deployment/runtime constraints**
The stack is standard LAMP/XAMPP-style PHP with MySQL, and the README shows local and hosted deployment targets. The architecture assumes Apache URL rewriting and server-side sessions/auth, not client-side routing. For an architecture diagram, the main external dependencies to show are Apache/PHP runtime, MySQL database, and file storage under `public/uploads`.

13. **Suggested diagram boundaries**
A clean diagram would have four major zones:
- **Presentation layer:** `views/`, `layouts/`, public CSS/assets
- **Application layer:** controllers grouped by role plus auth checks
- **Domain/data layer:** models
- **Infrastructure:** MySQL, uploads filesystem, FPDF library  
The most important data flows are login/authentication, pet registration, consultation/vaccination recording, and report generation.

Main entry points: [`routes/web.php`](https://github.com/rickypega/docuhuella/blob/main/routes/web.php) (Web routes), [`layouts/header.php`](https://github.com/rickypega/docuhuella/blob/main/layouts/header.php) (Shared layout), [`config/db.php`](https://github.com/rickypega/docuhuella/blob/main/config/db.php) (DB config), [`controllers/admin/Dashboardcontroller.php`](https://github.com/rickypega/docuhuella/blob/main/controllers/admin/Dashboardcontroller.php) (Admin area)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entry & Routing"]
  node_index(("Front controller<br/>entrypoint<br/>[index.php]"))
  node_routes["Web routes<br/>routing<br/>[web.php]"]
end

subgraph group_app["Application Layer"]
  node_auth["Auth check<br/>security<br/>[auth_check.php]"]
  node_admin_ctrl["Admin area<br/>controller bundle"]
  node_superadmin_ctrl["Superadmin area<br/>controller bundle"]
  node_vet_ctrl["Vet area<br/>controller bundle"]
  node_care_ctrl["Caregiver area<br/>controller bundle"]
  node_core_ctrl["Shared controllers<br/>controller bundle"]
end

subgraph group_domain["Domain & Data"]
  node_db[("DB config<br/>infrastructure<br/>[db.php]")]
  node_usuario["Usuario<br/>identity model<br/>[Usuario.php]"]
  node_personas["Roles<br/>identity models<br/>[Administrador.php]"]
  node_clinic_models["Clinic models<br/>reference model set<br/>[Clinica.php]"]
  node_patient_models["Patient records<br/>clinical model set<br/>[Mascota.php]"]
  node_schema["DB schema<br/>sql seed<br/>[DocuhuellaDB.sql]"]
end

subgraph group_uiinfra["UI & Infrastructure"]
  node_layout["Shared layout<br/>view shell<br/>[header.php]"]
  node_public_views["Public views<br/>pages<br/>[home.php]"]
  node_role_views["Role views<br/>pages<br/>[dashboard.php]"]
  node_partials["View partials<br/>[modal_perfil.php]"]
  node_pdf_lib["PDF library<br/>reporting lib<br/>[fpdf.php]"]
  node_storage[("Uploads<br/>file storage")]
end

node_index -->|"dispatches"| node_routes
node_routes -->|"guards"| node_auth
node_routes -->|"admin requests"| node_admin_ctrl
node_routes -->|"superadmin requests"| node_superadmin_ctrl
node_routes -->|"vet requests"| node_vet_ctrl
node_routes -->|"caregiver requests"| node_care_ctrl
node_routes -->|"shared actions"| node_core_ctrl
node_admin_ctrl -->|"queries"| node_db
node_superadmin_ctrl -->|"queries"| node_db
node_vet_ctrl -->|"queries"| node_db
node_care_ctrl -->|"queries"| node_db
node_core_ctrl -->|"queries"| node_db
node_db -.->|"defined by"| node_schema
node_admin_ctrl -->|"renders"| node_layout
node_superadmin_ctrl -->|"renders"| node_layout
node_vet_ctrl -->|"renders"| node_layout
node_care_ctrl -->|"renders"| node_layout
node_layout -->|"wraps"| node_public_views
node_layout -->|"wraps"| node_role_views
node_role_views -.->|"includes"| node_partials
node_core_ctrl -->|"manages"| node_usuario
node_core_ctrl -->|"manages"| node_personas
node_admin_ctrl -->|"administers"| node_clinic_models
node_superadmin_ctrl -->|"administers"| node_clinic_models
node_vet_ctrl -->|"operates on"| node_patient_models
node_care_ctrl -->|"views"| node_patient_models
node_patient_models -.->|"uploads"| node_storage
node_superadmin_ctrl -->|"reports"| node_pdf_lib
node_admin_ctrl -->|"reports"| node_pdf_lib

click node_index "https://github.com/rickypega/docuhuella/blob/main/index.php"
click node_routes "https://github.com/rickypega/docuhuella/blob/main/routes/web.php"
click node_auth "https://github.com/rickypega/docuhuella/blob/main/config/auth_check.php"
click node_db "https://github.com/rickypega/docuhuella/blob/main/config/db.php"
click node_admin_ctrl "https://github.com/rickypega/docuhuella/blob/main/controllers/admin/Dashboardcontroller.php"
click node_superadmin_ctrl "https://github.com/rickypega/docuhuella/blob/main/controllers/superadmin/DashboardController.php"
click node_vet_ctrl "https://github.com/rickypega/docuhuella/blob/main/controllers/veterinario/VeterinarioController.php"
click node_care_ctrl "https://github.com/rickypega/docuhuella/blob/main/controllers/cuidador/CuidadorController.php"
click node_core_ctrl "https://github.com/rickypega/docuhuella/blob/main/controllers/UsuariosController.php"
click node_usuario "https://github.com/rickypega/docuhuella/blob/main/models/Usuario.php"
click node_personas "https://github.com/rickypega/docuhuella/blob/main/models/Administrador.php"
click node_clinic_models "https://github.com/rickypega/docuhuella/blob/main/models/Clinica.php"
click node_patient_models "https://github.com/rickypega/docuhuella/blob/main/models/Mascota.php"
click node_layout "https://github.com/rickypega/docuhuella/blob/main/layouts/header.php"
click node_public_views "https://github.com/rickypega/docuhuella/blob/main/views/home.php"
click node_role_views "https://github.com/rickypega/docuhuella/blob/main/views/veterinario/dashboard.php"
click node_partials "https://github.com/rickypega/docuhuella/blob/main/views/includes/modal_perfil.php"
click node_pdf_lib "https://github.com/rickypega/docuhuella/blob/main/libs/fpdf.php"
click node_storage "https://github.com/rickypega/docuhuella/tree/main/public/uploads/consultas"
click node_schema "https://github.com/rickypega/docuhuella/blob/main/DocuhuellaDB.sql"

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_index,node_routes toneBlue
class node_auth,node_admin_ctrl,node_superadmin_ctrl,node_vet_ctrl,node_care_ctrl,node_core_ctrl toneAmber
class node_db,node_usuario,node_personas,node_clinic_models,node_patient_models,node_schema toneMint
class node_layout,node_public_views,node_role_views,node_partials,node_pdf_lib,node_storage toneRose
```

## Components

### Entry & Routing

Front controller and route definitions for request dispatch.

- [Front controller](https://github.com/rickypega/docuhuella/blob/main/index.php): entrypoint · Bootstraps the app and starts request handling. · `index.php`
- [Web routes](https://github.com/rickypega/docuhuella/blob/main/routes/web.php): routing · Maps incoming URLs to application controllers. · `routes/web.php`

### Application Layer

Shared auth plus role-specific controllers and page orchestration.

- [Auth check](https://github.com/rickypega/docuhuella/blob/main/config/auth_check.php): security · Session and role gate for protected actions. · `config/auth_check.php`
- [Admin area](https://github.com/rickypega/docuhuella/blob/main/controllers/admin/Dashboardcontroller.php): controller bundle · Clinic admin dashboard, vets, and reports. · `controllers/admin/Dashboardcontroller.php`
- [Superadmin area](https://github.com/rickypega/docuhuella/blob/main/controllers/superadmin/DashboardController.php): controller bundle · System administration, catalogs, dashboards, and reports. · `controllers/superadmin/DashboardController.php`
- [Vet area](https://github.com/rickypega/docuhuella/blob/main/controllers/veterinario/VeterinarioController.php): controller bundle · Clinical workflow for appointments, consultations, patients, and vaccines. · `controllers/veterinario/VeterinarioController.php`
- [Caregiver area](https://github.com/rickypega/docuhuella/blob/main/controllers/cuidador/CuidadorController.php): controller bundle · Owner self-service for pets and dashboard views. · `controllers/cuidador/CuidadorController.php`
- [Shared controllers](https://github.com/rickypega/docuhuella/blob/main/controllers/UsuariosController.php): controller bundle · Cross-cutting controllers for profiles, users, notes, and registration. · `controllers/UsuariosController.php`

### Domain & Data

Models and database schema for the clinical record system.

- [DB config](https://github.com/rickypega/docuhuella/blob/main/config/db.php): infrastructure · Central PDO/MySQL connection setup. · `config/db.php`
- [Usuario](https://github.com/rickypega/docuhuella/blob/main/models/Usuario.php): identity model · Base account and access identity. · `models/Usuario.php`
- [Roles](https://github.com/rickypega/docuhuella/blob/main/models/Administrador.php): identity models · Administrator, veterinarian, and caregiver role entities. · `models/Administrador.php`
- [Clinic models](https://github.com/rickypega/docuhuella/blob/main/models/Clinica.php): reference model set · Clinic, specialty, species, breed, and color reference data. · `models/Clinica.php`
- [Patient records](https://github.com/rickypega/docuhuella/blob/main/models/Mascota.php): clinical model set · Pets, appointments, consultations, expediente, notes, and vaccinations. · `models/Mascota.php`
- [DB schema](https://github.com/rickypega/docuhuella/blob/main/DocuhuellaDB.sql): sql seed · Schema and seed data for the application database. · `DocuhuellaDB.sql`

### UI & Infrastructure

Shared templates, server-rendered views, uploads, and PDF support.

- [Shared layout](https://github.com/rickypega/docuhuella/blob/main/layouts/header.php): view shell · Common header and footer for server-rendered pages. · `layouts/header.php`
- [Public views](https://github.com/rickypega/docuhuella/blob/main/views/home.php): pages · Home, login, registration, privacy, and terms pages. · `views/home.php`
- [Role views](https://github.com/rickypega/docuhuella/blob/main/views/veterinario/dashboard.php): pages · Admin, veterinarian, caregiver, and superadmin screens. · `views/veterinario/dashboard.php`
- [View partials](https://github.com/rickypega/docuhuella/blob/main/views/includes/modal_perfil.php): partials · Reusable modal and notes fragments. · `views/includes/modal_perfil.php`
- [PDF library](https://github.com/rickypega/docuhuella/blob/main/libs/fpdf.php): reporting lib · Embedded FPDF engine and bundled fonts for report output. · `libs/fpdf.php`
- [Uploads](https://github.com/rickypega/docuhuella/tree/main/public/uploads/consultas): file storage · Filesystem storage for pet and consultation uploads. · `public/uploads/consultas`

## Connections

- Front controller → Web routes: dispatches · Front controller hands off to route definitions.
- Web routes → Auth check: guards · Protected routes pass through role checks.
- Web routes → Admin area: admin requests · Admin URLs dispatch to the admin controller set.
- Web routes → Superadmin area: superadmin requests · System admin URLs dispatch to the superadmin controller set.
- Web routes → Vet area: vet requests · Clinical workflow URLs dispatch to veterinary controllers.
- Web routes → Caregiver area: caregiver requests · Owner self-service URLs dispatch to caregiver controllers.
- Web routes → Shared controllers: shared actions · Common pages and cross-cutting actions route to shared controllers.
- Admin area → DB config: queries · Admin features read and write through the database connection.
- Superadmin area → DB config: queries · Superadmin features read and write through the database connection.
- Vet area → DB config: queries · Veterinary workflow persists clinical records in MySQL.
- Caregiver area → DB config: queries · Caregiver actions read and update pet data.
- Shared controllers → DB config: queries · Shared controllers access users, profiles, and notes data.
- DB config → DB schema: defined by · Runtime schema is created from the SQL dump.
- Admin area → Shared layout: renders · Controllers assemble views through the shared page shell.
- Superadmin area → Shared layout: renders · Controllers assemble views through the shared page shell.
- Vet area → Shared layout: renders · Controllers assemble views through the shared page shell.
- Caregiver area → Shared layout: renders · Controllers assemble views through the shared page shell.
- Shared layout → Public views: wraps · Shared header/footer frame the public pages.
- Shared layout → Role views: wraps · Shared header/footer frame the role-specific pages.
- Role views → View partials: includes · Role views reuse modal and notes fragments.
- Shared controllers → Usuario: manages · User and profile actions center on account identity.
- Shared controllers → Roles: manages · Registration and profile flows bind to role entities.
- Admin area → Clinic models: administers · Admin screens manage clinic and catalog reference data.
- Superadmin area → Clinic models: administers · System configuration maintains catalogs and clinic data.
- Vet area → Patient records: operates on · Clinical screens create and update patient record data.
- Caregiver area → Patient records: views · Caregivers inspect and submit pet information.
- Patient records → Uploads: uploads · Pet photos and clinical attachments live in filesystem storage.
- Superadmin area → PDF library: reports · Report generation uses the bundled PDF engine.
- Admin area → PDF library: reports · Operational reports can be rendered as PDFs.
