# hayderfino/gestion_documental architecture

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

- Interactive diagram: https://gitdiagram.com/hayderfino/gestion_documental
- Repository: https://github.com/hayderfino/gestion_documental

## Overview

1. **What this system is**
   SGD CAS is a PHP-based institutional document-management system focused on the physical control of expediente loans and returns. Architecturally, it is a custom MVC application rather than a framework-based app, with clear separation between routing, controllers, models, views, and a small service/helper layer.

2. **Request entry and application bootstrap**
   Web traffic enters through Apache with `.htaccess`-driven clean URLs, then reaches `public/index.php` as the public entrypoint. A second root `index.php` appears to act as an application bootstrap/redirect layer. Route definitions live in `routes/web.php`, and the custom router in `app/helpers/Router.php` dispatches requests to controller actions.

3. **Presentation layer**
   The UI is rendered with PHP views under `app/views/`, centered on a shared layout (`app/views/layouts/main.php`) and a login view (`app/views/auth/login.php`). Static behavior and styling are delivered from `public/assets/css/style.css` and `public/assets/js/main.js`. The README indicates a glassmorphism-style interface, but architecturally this is a conventional server-rendered UI with a small amount of client-side interactivity.

4. **Controller layer and use-case boundaries**
   The main business flows are split into controllers: `AuthController`, `DashboardController`, `ExpedienteController`, `PrestamoController`, `UsuarioController`, and `AuditoriaController`. These controllers are the orchestration layer: they handle authentication, dashboard aggregation, expediente management, loan lifecycle, user administration, and audit viewing.

5. **Domain and model layer**
   Core entities are modeled in `app/models/Usuario.php`, `Expediente.php`, and `Prestamo.php`, all built on a shared base model in `app/models/Model.php`. This layer encapsulates record access and entity-level logic, keeping controllers focused on workflow rather than data formatting or persistence details.

6. **Persistence architecture: current JSON store**
   The active runtime data store is file-based JSON under `database/data/`, with separate files for `usuarios`, `expedientes`, `prestamos`, `devoluciones`, `asignaciones`, and `auditoria`. The helper `app/helpers/JsonDB.php` is the key persistence adapter here, and it likely acts as the repository boundary for reading/writing the JSON records.

7. **Persistence architecture: SQL-ready transition path**
   The repository also contains `database/schema.sql` and `app/config/Database.php`, indicating a prepared relational backend using PDO for MySQL/MariaDB. In architectural terms, this is a hybrid persistence design: JSON is the current operational store, while SQL is the normalized target model for a future or optional backend swap.

8. **Loan and return workflow**
   The core business process is a controlled workflow: a Jefe de Línea assigns expedientes, a user can only request loans for assigned expedientes, an administrator approves and records the physical delivery, and the user later reports return details. The administrator then validates the return and either closes the loan or sends it back for correction. This double-verification flow is the main business boundary in the system.

9. **Authorization and access control**
   Access is role-based and assignment-based. The system distinguishes `Administrador`, `Jefe de Línea`, and `Usuario`, and users are restricted to expedientes previously assigned to them. This constraint is central to the architecture because it influences routing, controller authorization checks, and the visible data set in the UI.

10. **Audit and compliance subsystem**
   Audit logging is handled by `app/services/AuditService.php` and persisted in `database/data/auditoria.json`. This subsystem records transactional and metadata changes for traceability and compliance, making it a cross-cutting concern that spans multiple controllers and models rather than a standalone user-facing feature.

11. **Operational and deployment context**
   The system expects a traditional PHP/Apache runtime, with `mod_rewrite` enabled. The repository also includes documentation artifacts under `documentacion/` and institutional reference files under `geenral/`, which support process governance but do not materially change runtime architecture.

Main entry points: [`app/helpers/Router.php`](https://github.com/hayderfino/gestion_documental/blob/main/app/helpers/Router.php) (Router), [`app/views/layouts/main.php`](https://github.com/hayderfino/gestion_documental/blob/main/app/views/layouts/main.php) (Main layout), [`app/controllers/Controller.php`](https://github.com/hayderfino/gestion_documental/blob/main/app/controllers/Controller.php) (Base controller), [`app/controllers/AuthController.php`](https://github.com/hayderfino/gestion_documental/blob/main/app/controllers/AuthController.php) (Auth)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_entry["Entry & Routing"]
  node_node_htaccess[".htaccess<br/>rewrite rules<br/>[.htaccess]"]
  node_node_public_index["Public entry<br/>web entrypoint<br/>[index.php]"]
  node_node_root_index["Bootstrap<br/>[index.php]"]
  node_node_routes["Web routes<br/>route definitions<br/>[web.php]"]
end

subgraph group_group_app["Application Layer"]
  node_node_router["Router<br/>dispatch helper<br/>[Router.php]"]
  node_node_controller_base["Base controller<br/>mvc base<br/>[Controller.php]"]
  node_node_auth_ctrl["Auth<br/>controller<br/>[AuthController.php]"]
  node_node_dash_ctrl["Dashboard<br/>controller"]
  node_node_expediente_ctrl["Expedientes<br/>controller"]
  node_node_prestamo_ctrl["Préstamos<br/>controller"]
  node_node_usuario_ctrl["Usuarios<br/>controller"]
  node_node_auditoria_ctrl["Auditoría<br/>controller"]
  node_node_audit_service["Audit service<br/>[AuditService.php]"]
end

subgraph group_group_domain["Domain Models"]
  node_node_model_base["Base model<br/>domain base<br/>[Model.php]"]
  node_node_usuario_model["Usuario<br/>entity model<br/>[Usuario.php]"]
  node_node_expediente_model["Expediente<br/>entity model<br/>[Expediente.php]"]
  node_node_prestamo_model["Préstamo<br/>entity model<br/>[Prestamo.php]"]
end

subgraph group_group_persistence["Persistence"]
  node_node_jsondb[("JsonDB<br/>file-store adapter<br/>[JsonDB.php]")]
  node_node_db_config[("DB config<br/>pdo config<br/>[Database.php]")]
  node_node_schema["schema.sql<br/>sql schema<br/>[schema.sql]"]
  node_node_json_data[("JSON data<br/>data files")]
end

subgraph group_group_ui["Presentation"]
  node_node_layout["Main layout<br/>view layout<br/>[main.php]"]
  node_node_login_view["Login view<br/>[login.php]"]
  node_node_css["Stylesheet<br/>asset css<br/>[style.css]"]
  node_node_js["Client JS<br/>asset js<br/>[main.js]"]
end

subgraph group_group_docs["Documentation"]
  node_node_readme["README<br/>documentation<br/>[README.md]"]
  node_node_doc_dir["Docs<br/>documentation"]
  node_node_reference_dir["References<br/>institutional docs"]
end

node_node_htaccess -->|"rewrites to"| node_node_public_index
node_node_public_index -->|"boots"| node_node_root_index
node_node_root_index -->|"loads"| node_node_routes
node_node_routes -->|"dispatches via"| node_node_router
node_node_router -->|"invokes"| node_node_auth_ctrl
node_node_router -->|"invokes"| node_node_dash_ctrl
node_node_router -->|"invokes"| node_node_expediente_ctrl
node_node_router -->|"invokes"| node_node_prestamo_ctrl
node_node_router -->|"invokes"| node_node_usuario_ctrl
node_node_router -->|"invokes"| node_node_auditoria_ctrl
node_node_controller_base -->|"base for"| node_node_auth_ctrl
node_node_controller_base -->|"base for"| node_node_dash_ctrl
node_node_controller_base -->|"base for"| node_node_expediente_ctrl
node_node_controller_base -->|"base for"| node_node_prestamo_ctrl
node_node_controller_base -->|"base for"| node_node_usuario_ctrl
node_node_controller_base -->|"base for"| node_node_auditoria_ctrl
node_node_auth_ctrl -->|"uses"| node_node_usuario_model
node_node_dash_ctrl -->|"reads"| node_node_expediente_model
node_node_expediente_ctrl -->|"manages"| node_node_expediente_model
node_node_prestamo_ctrl -->|"manages"| node_node_prestamo_model
node_node_usuario_ctrl -->|"manages"| node_node_usuario_model
node_node_auditoria_ctrl -->|"reads via"| node_node_audit_service
node_node_audit_service -->|"writes"| node_node_jsondb
node_node_model_base -->|"persists through"| node_node_jsondb
node_node_usuario_model -->|"extends"| node_node_model_base
node_node_expediente_model -->|"extends"| node_node_model_base
node_node_prestamo_model -->|"extends"| node_node_model_base
node_node_jsondb -->|"stores in"| node_node_json_data
node_node_db_config -->|"pairs with"| node_node_schema
node_node_layout -->|"styles with"| node_node_css
node_node_layout -->|"enhanced by"| node_node_js
node_node_auth_ctrl -->|"renders"| node_node_login_view
node_node_dash_ctrl -->|"renders"| node_node_layout
node_node_expediente_ctrl -->|"renders"| node_node_layout
node_node_prestamo_ctrl -->|"renders"| node_node_layout
node_node_usuario_ctrl -->|"renders"| node_node_layout
node_node_auditoria_ctrl -->|"renders"| node_node_layout
node_node_readme -.->|"documents"| node_node_doc_dir
node_node_readme -.->|"references"| node_node_reference_dir

click node_node_htaccess "https://github.com/hayderfino/gestion_documental/blob/main/.htaccess"
click node_node_public_index "https://github.com/hayderfino/gestion_documental/blob/main/public/index.php"
click node_node_root_index "https://github.com/hayderfino/gestion_documental/blob/main/index.php"
click node_node_routes "https://github.com/hayderfino/gestion_documental/blob/main/routes/web.php"
click node_node_router "https://github.com/hayderfino/gestion_documental/blob/main/app/helpers/Router.php"
click node_node_controller_base "https://github.com/hayderfino/gestion_documental/blob/main/app/controllers/Controller.php"
click node_node_auth_ctrl "https://github.com/hayderfino/gestion_documental/blob/main/app/controllers/AuthController.php"
click node_node_dash_ctrl "https://github.com/hayderfino/gestion_documental/blob/main/app/controllers/DashboardController.php"
click node_node_expediente_ctrl "https://github.com/hayderfino/gestion_documental/blob/main/app/controllers/ExpedienteController.php"
click node_node_prestamo_ctrl "https://github.com/hayderfino/gestion_documental/blob/main/app/controllers/PrestamoController.php"
click node_node_usuario_ctrl "https://github.com/hayderfino/gestion_documental/blob/main/app/controllers/UsuarioController.php"
click node_node_auditoria_ctrl "https://github.com/hayderfino/gestion_documental/blob/main/app/controllers/AuditoriaController.php"
click node_node_audit_service "https://github.com/hayderfino/gestion_documental/blob/main/app/services/AuditService.php"
click node_node_model_base "https://github.com/hayderfino/gestion_documental/blob/main/app/models/Model.php"
click node_node_usuario_model "https://github.com/hayderfino/gestion_documental/blob/main/app/models/Usuario.php"
click node_node_expediente_model "https://github.com/hayderfino/gestion_documental/blob/main/app/models/Expediente.php"
click node_node_prestamo_model "https://github.com/hayderfino/gestion_documental/blob/main/app/models/Prestamo.php"
click node_node_jsondb "https://github.com/hayderfino/gestion_documental/blob/main/app/helpers/JsonDB.php"
click node_node_db_config "https://github.com/hayderfino/gestion_documental/blob/main/app/config/Database.php"
click node_node_schema "https://github.com/hayderfino/gestion_documental/blob/main/database/schema.sql"
click node_node_json_data "https://github.com/hayderfino/gestion_documental/tree/main/database/data"
click node_node_layout "https://github.com/hayderfino/gestion_documental/blob/main/app/views/layouts/main.php"
click node_node_login_view "https://github.com/hayderfino/gestion_documental/blob/main/app/views/auth/login.php"
click node_node_css "https://github.com/hayderfino/gestion_documental/blob/main/public/assets/css/style.css"
click node_node_js "https://github.com/hayderfino/gestion_documental/blob/main/public/assets/js/main.js"
click node_node_readme "https://github.com/hayderfino/gestion_documental/blob/main/README.md"
click node_node_doc_dir "https://github.com/hayderfino/gestion_documental/tree/main/documentacion"
click node_node_reference_dir "https://github.com/hayderfino/gestion_documental/tree/main/geenral"

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_node_htaccess,node_node_public_index,node_node_root_index,node_node_routes toneBlue
class node_node_router,node_node_controller_base,node_node_auth_ctrl,node_node_dash_ctrl,node_node_expediente_ctrl,node_node_prestamo_ctrl,node_node_usuario_ctrl,node_node_auditoria_ctrl,node_node_audit_service toneAmber
class node_node_model_base,node_node_usuario_model,node_node_expediente_model,node_node_prestamo_model toneMint
class node_node_jsondb,node_node_db_config,node_node_schema,node_node_json_data toneRose
class node_node_layout,node_node_login_view,node_node_css,node_node_js toneIndigo
class node_node_readme,node_node_doc_dir,node_node_reference_dir toneTeal
```

## Components

### Entry & Routing

HTTP entrypoints, rewrite rules, and route dispatch.

- [.htaccess](https://github.com/hayderfino/gestion_documental/blob/main/.htaccess): rewrite rules · Apache rewrite and access behavior for clean URLs. · `.htaccess`
- [Public entry](https://github.com/hayderfino/gestion_documental/blob/main/public/index.php): web entrypoint · Public-facing PHP entrypoint for requests. · `public/index.php`
- [Bootstrap](https://github.com/hayderfino/gestion_documental/blob/main/index.php): app bootstrap · Root-level bootstrap or redirect layer. · `index.php`
- [Web routes](https://github.com/hayderfino/gestion_documental/blob/main/routes/web.php): route definitions · Maps application URLs to controller actions. · `routes/web.php`

### Application Layer

Controllers, helpers, services, and shared MVC base code.

- [Router](https://github.com/hayderfino/gestion_documental/blob/main/app/helpers/Router.php): dispatch helper · Custom request dispatcher for controller routing. · `app/helpers/Router.php`
- [Base controller](https://github.com/hayderfino/gestion_documental/blob/main/app/controllers/Controller.php): mvc base · Shared controller behavior and common plumbing. · `app/controllers/Controller.php`
- [Auth](https://github.com/hayderfino/gestion_documental/blob/main/app/controllers/AuthController.php): controller · Login and session access flow. · `app/controllers/AuthController.php`
- [Dashboard](https://github.com/hayderfino/gestion_documental/blob/main/app/controllers/DashboardController.php): controller · Dashboard aggregation and landing data. · `app/controllers/DashboardController.php`
- [Expedientes](https://github.com/hayderfino/gestion_documental/blob/main/app/controllers/ExpedienteController.php): controller · Expediente management and assignment flow. · `app/controllers/ExpedienteController.php`
- [Préstamos](https://github.com/hayderfino/gestion_documental/blob/main/app/controllers/PrestamoController.php): controller · Loan, delivery, and return workflow. · `app/controllers/PrestamoController.php`
- [Usuarios](https://github.com/hayderfino/gestion_documental/blob/main/app/controllers/UsuarioController.php): controller · User administration and role management. · `app/controllers/UsuarioController.php`
- [Auditoría](https://github.com/hayderfino/gestion_documental/blob/main/app/controllers/AuditoriaController.php): controller · Audit log viewing and traceability. · `app/controllers/AuditoriaController.php`
- [Audit service](https://github.com/hayderfino/gestion_documental/blob/main/app/services/AuditService.php): service · Cross-cutting audit event recording. · `app/services/AuditService.php`

### Domain Models

Core business entities and shared model base.

- [Base model](https://github.com/hayderfino/gestion_documental/blob/main/app/models/Model.php): domain base · Shared model behavior for data access. · `app/models/Model.php`
- [Usuario](https://github.com/hayderfino/gestion_documental/blob/main/app/models/Usuario.php): entity model · User entity and persistence logic. · `app/models/Usuario.php`
- [Expediente](https://github.com/hayderfino/gestion_documental/blob/main/app/models/Expediente.php): entity model · Expediente entity and persistence logic. · `app/models/Expediente.php`
- [Préstamo](https://github.com/hayderfino/gestion_documental/blob/main/app/models/Prestamo.php): entity model · Loan entity and persistence logic. · `app/models/Prestamo.php`

### Persistence

Current JSON store and SQL-ready database path.

- [JsonDB](https://github.com/hayderfino/gestion_documental/blob/main/app/helpers/JsonDB.php): file-store adapter · JSON persistence adapter for operational data. · `app/helpers/JsonDB.php`
- [DB config](https://github.com/hayderfino/gestion_documental/blob/main/app/config/Database.php): pdo config · Relational database connection configuration. · `app/config/Database.php`
- [schema.sql](https://github.com/hayderfino/gestion_documental/blob/main/database/schema.sql): sql schema · Normalized relational schema for database-backed use. · `database/schema.sql`
- [JSON data](https://github.com/hayderfino/gestion_documental/tree/main/database/data): data files · Runtime data files for users, expedientes, loans, returns, assignments, and audit. · `database/data`

### Presentation

Server-rendered views and public assets.

- [Main layout](https://github.com/hayderfino/gestion_documental/blob/main/app/views/layouts/main.php): view layout · Shared server-rendered page shell. · `app/views/layouts/main.php`
- [Login view](https://github.com/hayderfino/gestion_documental/blob/main/app/views/auth/login.php): view · Authentication screen rendered by PHP. · `app/views/auth/login.php`
- [Stylesheet](https://github.com/hayderfino/gestion_documental/blob/main/public/assets/css/style.css): asset css · Application styling for the UI. · `public/assets/css/style.css`
- [Client JS](https://github.com/hayderfino/gestion_documental/blob/main/public/assets/js/main.js): asset js · Small client-side interactivity layer. · `public/assets/js/main.js`

### Documentation

Operational and institutional reference material.

- [README](https://github.com/hayderfino/gestion_documental/blob/main/README.md): documentation · Project overview and usage notes. · `README.md`
- [Docs](https://github.com/hayderfino/gestion_documental/tree/main/documentacion): documentation · System documentation and diagrams. · `documentacion`
- [References](https://github.com/hayderfino/gestion_documental/tree/main/geenral): institutional docs · Policy and reference documents supporting operations. · `geenral`

## Connections

- .htaccess → Public entry: rewrites to · Apache routes clean URLs into the public entrypoint.
- Public entry → Bootstrap: boots · Public entry uses the root bootstrap layer.
- Bootstrap → Web routes: loads · Bootstrap loads route definitions.
- Web routes → Router: dispatches via · Routes are executed through the custom router.
- Router → Auth: invokes · Router dispatches authentication actions.
- Router → Dashboard: invokes · Router dispatches dashboard actions.
- Router → Expedientes: invokes · Router dispatches expediente actions.
- Router → Préstamos: invokes · Router dispatches loan and return actions.
- Router → Usuarios: invokes · Router dispatches user administration actions.
- Router → Auditoría: invokes · Router dispatches audit views.
- Base controller → Auth: base for · Shared controller behavior.
- Base controller → Dashboard: base for · Shared controller behavior.
- Base controller → Expedientes: base for · Shared controller behavior.
- Base controller → Préstamos: base for · Shared controller behavior.
- Base controller → Usuarios: base for · Shared controller behavior.
- Base controller → Auditoría: base for · Shared controller behavior.
- Auth → Usuario: uses · Authentication depends on user records.
- Dashboard → Expediente: reads · Dashboard aggregates expediente state.
- Expedientes → Expediente: manages · Controller orchestrates expediente operations.
- Préstamos → Préstamo: manages · Controller orchestrates loan lifecycle.
- Usuarios → Usuario: manages · Controller orchestrates user administration.
- Auditoría → Audit service: reads via · Audit view is backed by audit logging.
- Audit service → JsonDB: writes · Audit events are persisted through the JSON store.
- Base model → JsonDB: persists through · Shared model layer uses the JSON adapter.
- Usuario → Base model: extends · User model builds on the shared base.
- Expediente → Base model: extends · Expediente model builds on the shared base.
- Préstamo → Base model: extends · Loan model builds on the shared base.
- JsonDB → JSON data: stores in · Operational records live in JSON files.
- DB config → schema.sql: pairs with · PDO configuration matches the relational schema.
- Main layout → Stylesheet: styles with · Shared layout uses application CSS.
- Main layout → Client JS: enhanced by · Shared layout uses client-side behavior.
- Auth → Login view: renders · Authentication controller serves the login screen.
- Dashboard → Main layout: renders · Dashboard content is wrapped in the main layout.
- Expedientes → Main layout: renders · Expediente screens use the shared layout.
- Préstamos → Main layout: renders · Loan screens use the shared layout.
- Usuarios → Main layout: renders · User admin screens use the shared layout.
- Auditoría → Main layout: renders · Audit screens use the shared layout.
- README → Docs: documents · Project documentation supplements the README.
- README → References: references · Repository includes institutional reference material.
