# danielayala-06/proyecto-de-innovacion architecture

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

- Interactive diagram: https://gitdiagram.com/danielayala-06/proyecto-de-innovacion
- Repository: https://github.com/danielayala-06/proyecto-de-innovacion

## Overview

1. **Overall shape**
   - This is a **CodeIgniter 4 / PHP 8.2** monolith with a layered backend and a browser-based frontend.
   - The main business domains are **cotizaciones, contratos, clientes, paquetes, pagos, promociones, personas/usuarios**, and supporting academic entities like **colegios, estudiantes y apoderados**.

2. **Request entry and HTTP boundary**
   - All web traffic enters through **`public/index.php`**.
   - The app exposes both **HTML pages** and **REST-style API endpoints**.
   - Apache rewrite rules are handled by the `.htaccess` files in `public/` and `app/`.

3. **Routing and cross-cutting controls**
   - **`app/Config/Routes.php`** defines the HTTP surface.
   - **`app/Filters/AuthFilter.php`** is the key access-control boundary, likely protecting authenticated areas and API routes.
   - Other CI4 configs in `app/Config/` control environment bootstrapping, sessions, security, CORS, validation, logging, and database connectivity.

4. **Backend layering**
   - The repository follows a clear pipeline:
     - **Controllers** receive requests and orchestrate responses.
     - **Services** hold domain logic.
     - **Models** access the database.
     - **Transformers** shape API responses into JSON-friendly output.
   - This separation is explicit in the folders `app/Controllers`, `app/Services`, `app/Models`, and `app/Transformers`.

5. **Domain controllers**
   - There are standard UI controllers such as **`ClienteController`**, **`ContratoController`**, **`CotizacionController`**, **`PaqueteController`**, **`CalendarioController`**, and **`AuthController`**.
   - API controllers live under **`app/Controllers/Api`** and mirror core business areas: **ClientesApi, ContratosApi, CotizacionesApi, PagosApi, PaquetesApi, PromocionesApi, ReniecApi**.
   - The presence of **ReniecApi** suggests integration with an external identity/document lookup service.

6. **Business services**
   - Domain logic is concentrated in feature-specific services:
     - **ClienteService**
     - **ContratoService**
     - **CotizacionService**
     - **PagoService**
     - **PaqueteService**
     - **PromocionService**
   - These services form the main boundary between HTTP controllers and persistence, especially for operations that combine multiple tables or business rules.

7. **Persistence model and schema**
   - Data is persisted in **MySQL** through CodeIgniter models such as `ClientesModel`, `ContratosModel`, `CotizacionesModel`, `PagosModel`, `PaquetesModel`, `UsuariosModel`, etc.
   - The schema is managed with many migrations covering:
     - identity and authorization: **Personas, Usuarios, Roles, Permisos, RolesPermisos**
     - commercial operations: **Clientes, Cotizaciones, CotizacionesDetalles, Contratos, Pagos**
     - products and offers: **Productos, Paquetes, PaquetesProductos, ReglasPaquetes, PromocionesEscolares**
     - supporting entities: **Colegios, Estudiantes, Apoderados, SesionesFotograficas, FormasPago**
   - Seeders provide initial/reference data for these tables.

8. **Response formatting**
   - API output is normalized through **Transformers** for each major domain: `ClienteTransformer`, `ContratoTransformer`, `CotizacionTransformer`, `PagoTransformer`, `PaqueteTransformer`, `PromocionTransformer`.
   - This means the API boundary is intentionally decoupled from raw model structure and can enforce consistent response shapes.

9. **Frontend structure**
   - The browser UI is server-rendered with **CodeIgniter Views** for pages like login, clientes, contratos, cotizaciones, paquetes, calendario, and PDF output.
   - The frontend also has a **modular JavaScript layer** under `public/js/modules`, organized by domain:
     - `cotizaciones`
     - `contratos`
     - `paquetes`
   - Each module is split into state, UI, events, form/manager files, indicating a client-side interaction layer that talks to the backend APIs.

10. **Client-server interaction**
   - JavaScript API wrappers in `public/js/api/` call the backend endpoints for each domain.
   - Shared utilities in `public/js/utils/` handle HTTP, alerts, and formatting.
   - This creates a clean flow: **UI module → API wrapper → controller/API → service → model → database**, with transformers shaping the response on the way back.

11. **Authentication and session handling**
   - Authentication is centered around `AuthController`, filtered routes, session config, and the `Usuarios`/`Roles`/`Permisos` schema.
   - The architecture suggests role-based access control rather than a flat login-only system.

12. **Reporting and document generation**
   - There is a dedicated **PDF view** at `app/Views/pdf/contrato.php`, plus contract styling in `public/css/contrato_styles.css`.
   - This indicates at least one document-generation path for contract output, separate from normal page rendering.

13. **Operational and developer tooling**
   - **Composer** manages PHP dependencies.
   - **Spark** is used for migrations, seeding, and local serving.
   - The `tests/` tree includes CI4 support fixtures plus database, session, and unit tests, showing the project is structured for framework-level testing.

14. **Architecture summary for diagramming**
   - The main diagram should show three major zones:
     - **Browser/UI**: server-rendered views plus modular JS calling APIs.
     - **Application layer**: controllers, auth filter, services, transformers.
     - **Data layer**: models, migrations, seeders, MySQL.
   - External dependencies are limited but important: **MySQL** for persistence and **RENIEC** for identity-related lookup/integration.

Main entry points: [`app/Controllers/Api/ClientesApi.php`](https://github.com/danielayala-06/proyecto-de-innovacion/blob/main/app/Controllers/Api/ClientesApi.php) (API controllers), [`app/Models/ClientesModel.php`](https://github.com/danielayala-06/proyecto-de-innovacion/blob/main/app/Models/ClientesModel.php) (Models), [`app/Config/Routes.php`](https://github.com/danielayala-06/proyecto-de-innovacion/blob/main/app/Config/Routes.php) (Routes), [`app/Controllers/ClienteController.php`](https://github.com/danielayala-06/proyecto-de-innovacion/blob/main/app/Controllers/ClienteController.php) (UI controllers)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["Browser/UI"]
  node_views["Views<br/>[index.php]"]
  node_js_modules["JS modules<br/>client modules"]
  node_js_api["JS API<br/>client API<br/>[contrato.api.js]"]
  node_http_utils["HTTP utils<br/>client utils<br/>[http.js]"]
end

subgraph group_app["Application"]
  node_auth_filter{{"Auth filter<br/>access control<br/>[AuthFilter.php]"}}
  node_auth_controller["Auth<br/>ui controller<br/>[AuthController.php]"]
  node_ui_controllers["UI controllers<br/>page controllers"]
  node_api_controllers["API controllers<br/>[ClientesApi.php]"]
  node_cliente_service["Cliente service<br/>domain service<br/>[ClienteService.php]"]
  node_contrato_service["Contrato service<br/>domain service"]
  node_cotizacion_service["Cotización service<br/>domain service"]
  node_pago_service["Pago service<br/>domain service<br/>[PagoService.php]"]
  node_paquete_service["Paquete service<br/>domain service<br/>[PaqueteService.php]"]
  node_promocion_service["Promoción service<br/>domain service"]
  node_transformers["Transformers<br/>response shaping"]
end

subgraph group_data["Data"]
  node_models[("Models<br/>[ClientesModel.php]")]
  node_migrations["Migrations<br/>schema history"]
  node_seeders["Seeders<br/>reference data<br/>[DatabaseSeeder.php]"]
end

subgraph group_infra["Infrastructure"]
  node_public_index["index.php<br/>entrypoint<br/>[index.php]"]
  node_routes["Routes<br/>routing<br/>[Routes.php]"]
  node_reniec_api(("RENIEC<br/>external service<br/>[ReniecApi.php]"))
  node_mysql[("MySQL<br/>database")]
end

node_public_index -->|"bootstraps"| node_routes
node_routes -->|"guards"| node_auth_filter
node_routes -->|"maps"| node_auth_controller
node_routes -->|"maps"| node_ui_controllers
node_routes -->|"maps"| node_api_controllers
node_auth_controller -->|"renders"| node_views
node_ui_controllers -->|"renders"| node_views
node_ui_controllers -->|"serves"| node_js_modules
node_js_modules -->|"calls"| node_js_api
node_js_api -->|"requests"| node_api_controllers
node_api_controllers -->|"orchestrates"| node_cliente_service
node_api_controllers -->|"orchestrates"| node_contrato_service
node_api_controllers -->|"orchestrates"| node_cotizacion_service
node_api_controllers -->|"orchestrates"| node_pago_service
node_api_controllers -->|"orchestrates"| node_paquete_service
node_api_controllers -->|"orchestrates"| node_promocion_service
node_cliente_service -->|"reads/writes"| node_models
node_contrato_service -->|"reads/writes"| node_models
node_cotizacion_service -->|"reads/writes"| node_models
node_pago_service -->|"reads/writes"| node_models
node_paquete_service -->|"reads/writes"| node_models
node_promocion_service -->|"reads/writes"| node_models
node_api_controllers -->|"formats"| node_transformers
node_transformers -.->|"separates"| node_views
node_models -->|"persists to"| node_mysql
node_migrations -->|"defines schema"| node_mysql
node_seeders -->|"loads data"| node_mysql
node_api_controllers -.->|"integrates"| node_reniec_api
node_ui_controllers -->|"protected by"| node_auth_filter

click node_public_index "https://github.com/danielayala-06/proyecto-de-innovacion/blob/main/public/index.php"
click node_routes "https://github.com/danielayala-06/proyecto-de-innovacion/blob/main/app/Config/Routes.php"
click node_auth_filter "https://github.com/danielayala-06/proyecto-de-innovacion/blob/main/app/Filters/AuthFilter.php"
click node_auth_controller "https://github.com/danielayala-06/proyecto-de-innovacion/blob/main/app/Controllers/AuthController.php"
click node_ui_controllers "https://github.com/danielayala-06/proyecto-de-innovacion/blob/main/app/Controllers/ClienteController.php"
click node_api_controllers "https://github.com/danielayala-06/proyecto-de-innovacion/blob/main/app/Controllers/Api/ClientesApi.php"
click node_cliente_service "https://github.com/danielayala-06/proyecto-de-innovacion/blob/main/app/Services/Clientes/ClienteService.php"
click node_contrato_service "https://github.com/danielayala-06/proyecto-de-innovacion/blob/main/app/Services/Contratos/ContratoService.php"
click node_cotizacion_service "https://github.com/danielayala-06/proyecto-de-innovacion/blob/main/app/Services/Cotizaciones/CotizacionService.php"
click node_pago_service "https://github.com/danielayala-06/proyecto-de-innovacion/blob/main/app/Services/Pagos/PagoService.php"
click node_paquete_service "https://github.com/danielayala-06/proyecto-de-innovacion/blob/main/app/Services/Paquetes/PaqueteService.php"
click node_promocion_service "https://github.com/danielayala-06/proyecto-de-innovacion/blob/main/app/Services/Promociones/PromocionService.php"
click node_transformers "https://github.com/danielayala-06/proyecto-de-innovacion/blob/main/app/Transformers/ClienteTransformer.php"
click node_models "https://github.com/danielayala-06/proyecto-de-innovacion/blob/main/app/Models/ClientesModel.php"
click node_migrations "https://github.com/danielayala-06/proyecto-de-innovacion/blob/main/app/Database/Migrations/2026-05-07-035257_Personas.php"
click node_seeders "https://github.com/danielayala-06/proyecto-de-innovacion/blob/main/app/Database/Seeds/DatabaseSeeder.php"
click node_views "https://github.com/danielayala-06/proyecto-de-innovacion/blob/main/app/Views/contratos/index.php"
click node_js_modules "https://github.com/danielayala-06/proyecto-de-innovacion/blob/main/public/js/modules/contratos/contrato.manager.js"
click node_js_api "https://github.com/danielayala-06/proyecto-de-innovacion/blob/main/public/js/api/contrato.api.js"
click node_http_utils "https://github.com/danielayala-06/proyecto-de-innovacion/blob/main/public/js/utils/http.js"
click node_reniec_api "https://github.com/danielayala-06/proyecto-de-innovacion/blob/main/app/Controllers/Api/ReniecApi.php"

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_views,node_js_modules,node_js_api,node_http_utils toneBlue
class node_auth_filter,node_auth_controller,node_ui_controllers,node_api_controllers,node_cliente_service,node_contrato_service,node_cotizacion_service,node_pago_service,node_paquete_service,node_promocion_service,node_transformers toneAmber
class node_models,node_migrations,node_seeders toneMint
class node_public_index,node_routes,node_reniec_api,node_mysql toneRose
```

## Components

### Browser/UI

Server-rendered views and client-side modules

- [Views](https://github.com/danielayala-06/proyecto-de-innovacion/blob/main/app/Views/contratos/index.php): server views · Login, clientes, contratos, cotizaciones, paquetes, calendario, PDF · `app/Views/contratos/index.php`
- [JS modules](https://github.com/danielayala-06/proyecto-de-innovacion/blob/main/public/js/modules/contratos/contrato.manager.js): client modules · Domain UI state, events, forms, and managers · `public/js/modules/contratos/contrato.manager.js`
- [JS API](https://github.com/danielayala-06/proyecto-de-innovacion/blob/main/public/js/api/contrato.api.js): client API · Browser wrappers for backend endpoints · `public/js/api/contrato.api.js`
- [HTTP utils](https://github.com/danielayala-06/proyecto-de-innovacion/blob/main/public/js/utils/http.js): client utils · Shared request, alert, and formatting helpers · `public/js/utils/http.js`

### Application

HTTP boundary, routing, controllers, filters, services, and transformers

- [Auth filter](https://github.com/danielayala-06/proyecto-de-innovacion/blob/main/app/Filters/AuthFilter.php): access control · Protects authenticated routes and APIs · `app/Filters/AuthFilter.php`
- [Auth](https://github.com/danielayala-06/proyecto-de-innovacion/blob/main/app/Controllers/AuthController.php): ui controller · Login and session entry · `app/Controllers/AuthController.php`
- [UI controllers](https://github.com/danielayala-06/proyecto-de-innovacion/blob/main/app/Controllers/ClienteController.php): page controllers · Clientes, contratos, cotizaciones, paquetes, calendario · `app/Controllers/ClienteController.php`
- [API controllers](https://github.com/danielayala-06/proyecto-de-innovacion/blob/main/app/Controllers/Api/ClientesApi.php): api controllers · Clientes, contratos, cotizaciones, pagos, paquetes, promociones, Reniec · `app/Controllers/Api/ClientesApi.php`
- [Cliente service](https://github.com/danielayala-06/proyecto-de-innovacion/blob/main/app/Services/Clientes/ClienteService.php): domain service · Cliente business rules · `app/Services/Clientes/ClienteService.php`
- [Contrato service](https://github.com/danielayala-06/proyecto-de-innovacion/blob/main/app/Services/Contratos/ContratoService.php): domain service · Contract orchestration · `app/Services/Contratos/ContratoService.php`
- [Cotización service](https://github.com/danielayala-06/proyecto-de-innovacion/blob/main/app/Services/Cotizaciones/CotizacionService.php): domain service · Quotation workflow · `app/Services/Cotizaciones/CotizacionService.php`
- [Pago service](https://github.com/danielayala-06/proyecto-de-innovacion/blob/main/app/Services/Pagos/PagoService.php): domain service · Payment logic · `app/Services/Pagos/PagoService.php`
- [Paquete service](https://github.com/danielayala-06/proyecto-de-innovacion/blob/main/app/Services/Paquetes/PaqueteService.php): domain service · Package and bundle rules · `app/Services/Paquetes/PaqueteService.php`
- [Promoción service](https://github.com/danielayala-06/proyecto-de-innovacion/blob/main/app/Services/Promociones/PromocionService.php): domain service · School promotion rules · `app/Services/Promociones/PromocionService.php`
- [Transformers](https://github.com/danielayala-06/proyecto-de-innovacion/blob/main/app/Transformers/ClienteTransformer.php): response shaping · Normalizes API payloads · `app/Transformers/ClienteTransformer.php`

### Data

Persistence, migrations, and seed data

- [Models](https://github.com/danielayala-06/proyecto-de-innovacion/blob/main/app/Models/ClientesModel.php): persistence models · CI4 models for core domains · `app/Models/ClientesModel.php`
- [Migrations](https://github.com/danielayala-06/proyecto-de-innovacion/blob/main/app/Database/Migrations/2026-05-07-035257_Personas.php): schema history · Database schema evolution · `app/Database/Migrations/2026-05-07-035257_Personas.php`
- [Seeders](https://github.com/danielayala-06/proyecto-de-innovacion/blob/main/app/Database/Seeds/DatabaseSeeder.php): reference data · Initial and fixture data · `app/Database/Seeds/DatabaseSeeder.php`

### Infrastructure

Framework config, public entrypoint, and external integrations

- [index.php](https://github.com/danielayala-06/proyecto-de-innovacion/blob/main/public/index.php): entrypoint · HTTP front controller · `public/index.php`
- [Routes](https://github.com/danielayala-06/proyecto-de-innovacion/blob/main/app/Config/Routes.php): routing · Defines web and API surface · `app/Config/Routes.php`
- [RENIEC](https://github.com/danielayala-06/proyecto-de-innovacion/blob/main/app/Controllers/Api/ReniecApi.php): external service · External identity lookup integration · `app/Controllers/Api/ReniecApi.php`
- **MySQL**: database · Primary relational datastore

## Connections

- index.php → Routes: bootstraps · Front controller hands off to route resolution
- Routes → Auth filter: guards · Applies access control to protected surfaces
- Routes → Auth: maps · Routes login and session endpoints
- Routes → UI controllers: maps · Routes browser-facing pages
- Routes → API controllers: maps · Routes REST-style endpoints
- Auth → Views: renders · Login page and session-related views
- UI controllers → Views: renders · Server-side page rendering
- UI controllers → JS modules: serves · Pages load modular client scripts
- JS modules → JS API: calls · UI modules invoke domain API wrappers
- JS API → API controllers: requests · Browser requests reach backend APIs
- API controllers → Cliente service: orchestrates · Clientes API delegates business logic
- API controllers → Contrato service: orchestrates · Contratos API delegates business logic
- API controllers → Cotización service: orchestrates · Cotizaciones API delegates business logic
- API controllers → Pago service: orchestrates · Pagos API delegates business logic
- API controllers → Paquete service: orchestrates · Paquetes API delegates business logic
- API controllers → Promoción service: orchestrates · Promociones API delegates business logic
- Cliente service → Models: reads/writes · Services coordinate persistence through models
- Contrato service → Models: reads/writes · Services coordinate persistence through models
- Cotización service → Models: reads/writes · Services coordinate persistence through models
- Pago service → Models: reads/writes · Services coordinate persistence through models
- Paquete service → Models: reads/writes · Services coordinate persistence through models
- Promoción service → Models: reads/writes · Services coordinate persistence through models
- API controllers → Transformers: formats · API responses are normalized before returning
- Transformers → Views: separates · Keeps API shapes distinct from page templates
- Models → MySQL: persists to · CI4 models store domain data in MySQL
- Migrations → MySQL: defines schema · Schema evolution targets the same database
- Seeders → MySQL: loads data · Reference and initial data populate tables
- API controllers → RENIEC: integrates · RENIEC lookup is exposed as an API boundary
- UI controllers → Auth filter: protected by · Authenticated pages are filtered at entry
