How hayderfino/gestion_documental works
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: Router.php Router · main.php Main layout · Controller.php Base controller · AuthController.php Auth
Components 28
Entry & Routing
HTTP entrypoints, rewrite rules, and route dispatch.
- .htaccess · Apache rewrite and access behavior for clean URLs.
.htaccess - Public entry · Public-facing PHP entrypoint for requests.
public/index.php - Bootstrap · Root-level bootstrap or redirect layer.
index.php - Web routes · Maps application URLs to controller actions.
routes/web.php
Application Layer
Controllers, helpers, services, and shared MVC base code.
- Router · Custom request dispatcher for controller routing.
app/helpers/Router.php - Base controller · Shared controller behavior and common plumbing.
app/controllers/Controller.php - Auth · Login and session access flow.
app/controllers/AuthController.php - Dashboard · Dashboard aggregation and landing data.
app/controllers/DashboardController.php - Expedientes · Expediente management and assignment flow.
app/controllers/ExpedienteController.php - Préstamos · Loan, delivery, and return workflow.
app/controllers/PrestamoController.php - Usuarios · User administration and role management.
app/controllers/UsuarioController.php - Auditoría · Audit log viewing and traceability.
app/controllers/AuditoriaController.php - Audit service · Cross-cutting audit event recording.
app/services/AuditService.php
Domain Models
Core business entities and shared model base.
- Base model · Shared model behavior for data access.
app/models/Model.php - Usuario · User entity and persistence logic.
app/models/Usuario.php - Expediente · Expediente entity and persistence logic.
app/models/Expediente.php - Préstamo · Loan entity and persistence logic.
app/models/Prestamo.php
Persistence
Current JSON store and SQL-ready database path.
- JsonDB · JSON persistence adapter for operational data.
app/helpers/JsonDB.php - DB config · Relational database connection configuration.
app/config/Database.php - schema.sql · Normalized relational schema for database-backed use.
database/schema.sql - JSON data · Runtime data files for users, expedientes, loans, returns, assignments, and audit.
database/data
Presentation
Server-rendered views and public assets.
- Main layout · Shared server-rendered page shell.
app/views/layouts/main.php - Login view · Authentication screen rendered by PHP.
app/views/auth/login.php - Stylesheet · Application styling for the UI.
public/assets/css/style.css - Client JS · Small client-side interactivity layer.
public/assets/js/main.js
Documentation
Operational and institutional reference material.
- README · Project overview and usage notes.
README.md - Docs · System documentation and diagrams.
documentacion - References · Policy and reference documents supporting operations.
geenral
Connections 39
- .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.