# mroblesdev/pos-cdp-lite architecture

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

- Interactive diagram: https://gitdiagram.com/mroblesdev/pos-cdp-lite
- Repository: https://github.com/mroblesdev/pos-cdp-lite

## Overview

1. **Application type and runtime boundary**  
   This is a **CodeIgniter 4 PHP application** for a point-of-sale system. The runtime entrypoint is `public/index.php`, with Apache rewrite rules in `public/.htaccess` and app-specific rewrite support in `app/.htaccess`. The app persists business data in **MySQL** and stores runtime artifacts in `writable/` (logs, cache, sessions, uploads).

2. **Framework vs. application code**  
   The repo is split into the CodeIgniter framework (`system/`) and the business application (`app/`). The architectural diagram should treat `app/` as the custom POS layer on top of CI4, while `system/` is the reusable framework runtime providing routing, request/response handling, sessions, validation, database access, and views.

3. **Request handling pipeline**  
   Incoming HTTP requests flow through CI4 boot/configuration (`app/Config/*`, especially `Routes.php`, `Filters.php`, `Services.php`, `Database.php`) and then into controller actions. The app uses an `AuthFilter` to guard protected pages, so authenticated access is a key boundary between public login traffic and the internal POS modules.

4. **Authentication and session state**  
   `app/Controllers/Login.php` is the primary public entry point for users. Successful login likely creates session state through CI4’s session subsystem, and subsequent requests are allowed through `app/Filters/AuthFilter.php`. The application’s stateful behavior depends on session management plus user records in `UsuariosModel`.

5. **Core POS modules**  
   The main business subsystems are organized by controller:  
   - `Inicio` for the dashboard/home screen  
   - `Productos` for catalog management  
   - `Ventas` for sales workflow, sale history, cancellations, and ticketing  
   - `Caja` for cash register / checkout state  
   - `Configuracion` for system settings  
   - `Reportes` for sales and product reports  
   These controllers are backed by matching views under `app/Views/` and models under `app/Models/`.

6. **Data model and persistence**  
   Persistence is centered on a small transactional schema managed by migrations and seeders. The key domain entities are: `usuarios`, `productos`, `configuracion`, `temporal_caja`, `ventas`, `detalle_venta`, and `vista_ventas`. Migrations in `app/Database/Migrations/` define schema evolution, while seeders in `app/Database/Seeds/` provide bootstrap data such as default users and configuration. A full SQL snapshot is also included at `app/Database/pos-cdp-lite.sql`.

7. **Sales flow and transactional boundary**  
   The sales subsystem appears to use a multi-step flow: a cash register state is stored in `TemporalCajaModel`, sales headers in `VentasModel`, and line items in `DetalleVentasModel`. This implies a transactional boundary where product selection, checkout, and ticket generation are tightly coupled to database writes. Historical sales and cancellations are handled from the `Ventas` controller and related views.

8. **Reporting and document generation**  
   Reports and printable artifacts are a distinct subsystem. `app/Controllers/Reportes.php` serves report views, and `app/ThirdParty/Fpdf/` provides PDF generation for tickets and reports via custom templates like `PlantillaVentas.php` and `PlantillaProductos.php`. `NumerosALetras.php` supports converting amounts to text, which is typically used in printable documents.

9. **Presentation layer**  
   The UI is built with server-rendered views under `app/Views/`, organized by module and shared layout. Shared shell components live in `app/Views/plantilla/` (`layout.php`, `menu.php`), while module views live under `productos/`, `ventas/`, `reportes/`, and `configuracion/`. Front-end assets in `public/assets/`, `public/css/`, and `public/js/` include DataTables and jQuery UI, indicating table-heavy admin screens and interactive forms.

10. **Cross-cutting framework services**  
   CI4 configuration files under `app/Config/` define the app’s security, session, database, validation, and routing behavior. Language files in `app/Language/` support localized validation messages in English and Spanish. The presence of standard CI4 filters, security, and validation layers means these concerns are handled centrally rather than inside each controller.

11. **Operational and deployment boundaries**  
   The app is designed to be deployed either through Apache or via `php spark serve` during development. `env`/`.env` controls environment-specific settings such as `baseURL` and MySQL credentials. Runtime write paths are isolated in `writable/`, which is important for logs, session persistence, cache, and uploaded files.

12. **Testing and maintenance surface**  
   The repository includes CI4 test scaffolding under `tests/`, covering unit, database, and session examples. That suggests the architecture is already partitioned enough to support framework-level and domain-level testing, even though the main app is relatively compact.

Main entry points: [`app/Config/Routes.php`](https://github.com/mroblesdev/pos-cdp-lite/blob/main/app/Config/Routes.php) (Routes), [`app/Filters/AuthFilter.php`](https://github.com/mroblesdev/pos-cdp-lite/blob/main/app/Filters/AuthFilter.php) (Auth guard), [`app/Controllers/Ventas.php`](https://github.com/mroblesdev/pos-cdp-lite/blob/main/app/Controllers/Ventas.php) (Sales), [`app/Controllers/Login.php`](https://github.com/mroblesdev/pos-cdp-lite/blob/main/app/Controllers/Login.php) (Login)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime"]
  node_public_index["Front controller<br/>entrypoint<br/>[index.php]"]
  node_public_htaccess["Web rewrite<br/>apache rewrite<br/>[.htaccess]"]
  node_app_htaccess["App rewrite<br/>apache rewrite<br/>[.htaccess]"]
  node_writable_state[("Writable state<br/>runtime storage")]
end

subgraph group_app["POS App"]
  node_routes["Routes<br/>routing config<br/>[Routes.php]"]
  node_filters["Filters<br/>security config<br/>[Filters.php]"]
  node_services["Services<br/>service config<br/>[Services.php]"]
  node_db_config["Database config<br/>db config<br/>[Database.php]"]
  node_login["Login<br/>auth controller<br/>[Login.php]"]
  node_auth_filter{{"Auth guard<br/>auth filter<br/>[AuthFilter.php]"}}
  node_inicio["Home<br/>dashboard controller<br/>[Inicio.php]"]
  node_productos["Products<br/>catalog controller<br/>[Productos.php]"]
  node_ventas["Sales<br/>[Ventas.php]"]
  node_caja["Cash desk<br/>checkout controller<br/>[Caja.php]"]
  node_configuracion["Settings<br/>[Configuracion.php]"]
  node_reportes["Reports<br/>report controller<br/>[Reportes.php]"]
end

subgraph group_data["Data"]
  node_usuarios_model[("Users model<br/>[UsuariosModel.php]")]
  node_productos_model[("Products model<br/>[ProductosModel.php]")]
  node_ventas_model[("Sales model<br/>[VentasModel.php]")]
  node_detalle_model[("Line items<br/>model")]
  node_caja_model[("Caja state<br/>model")]
  node_config_model[("Config model")]
  node_usuarios_migration["Usuarios schema<br/>migration"]
  node_ventas_migration["Ventas schema<br/>migration"]
  node_seeders["Seed data<br/>bootstrap data<br/>[CargaSeeder.php]"]
  node_sql_snapshot["SQL snapshot<br/>schema dump<br/>[pos-cdp-lite.sql]"]
end

subgraph group_ui["Presentation"]
  node_views["Views<br/>presentation"]
  node_layout["Layout<br/>shared shell<br/>[layout.php]"]
  node_menu["Menu<br/>shared nav<br/>[menu.php]"]
  node_login_view["Login view<br/>auth screen<br/>[login.php]"]
  node_assets["Assets<br/>[styles.css]"]
  node_fpdf["PDF engine<br/>third-party library<br/>[Fpdf.php]"]
  node_n2l["Numbers to words<br/>helper library<br/>[NumerosALetras.php]"]
end

node_system["CI4 runtime<br/>framework<br/>[CodeIgniter.php]"]

node_public_htaccess -->|"rewrites to"| node_public_index
node_app_htaccess -->|"supports routing"| node_public_index
node_public_index -->|"boots"| node_system
node_public_index -->|"loads"| node_routes
node_routes -->|"public route"| node_login
node_routes -->|"protected route"| node_inicio
node_routes -->|"protected route"| node_productos
node_routes -->|"protected route"| node_ventas
node_routes -->|"protected route"| node_caja
node_routes -->|"protected route"| node_configuracion
node_routes -->|"protected route"| node_reportes
node_filters -->|"registers"| node_auth_filter
node_auth_filter -->|"allows public access"| node_login
node_auth_filter -->|"protects"| node_inicio
node_auth_filter -->|"protects"| node_productos
node_auth_filter -->|"protects"| node_ventas
node_auth_filter -->|"protects"| node_caja
node_auth_filter -->|"protects"| node_configuracion
node_auth_filter -->|"protects"| node_reportes
node_login -->|"verifies user"| node_usuarios_model
node_login -->|"uses"| node_services
node_login -->|"writes session/logs"| node_writable_state
node_login -->|"renders"| node_login_view
node_inicio -->|"renders"| node_views
node_productos -->|"reads/writes"| node_productos_model
node_productos -->|"renders"| node_views
node_ventas -->|"persists header"| node_ventas_model
node_ventas -->|"persists items"| node_detalle_model
node_ventas -->|"uses register state"| node_caja_model
node_ventas -->|"generates tickets"| node_fpdf
node_ventas -->|"formats amounts"| node_n2l
node_ventas -->|"renders"| node_views
node_caja -->|"updates state"| node_caja_model
node_caja -->|"renders"| node_views
node_configuracion -->|"updates settings"| node_config_model
node_configuracion -->|"renders"| node_views
node_reportes -->|"queries sales"| node_ventas_model
node_reportes -->|"queries products"| node_productos_model
node_reportes -->|"exports pdf"| node_fpdf
node_reportes -->|"renders"| node_views
node_views -->|"uses shell"| node_layout
node_views -->|"uses nav"| node_menu
node_views -->|"loads"| node_assets
node_system -->|"provides db layer"| node_db_config
node_system -->|"provides services"| node_services
node_system -->|"provides filter runtime"| node_filters
node_system -->|"uses runtime storage"| node_writable_state
node_usuarios_migration -->|"defines schema for"| node_usuarios_model

click node_public_index "https://github.com/mroblesdev/pos-cdp-lite/blob/main/public/index.php"
click node_public_htaccess "https://github.com/mroblesdev/pos-cdp-lite/blob/main/public/.htaccess"
click node_app_htaccess "https://github.com/mroblesdev/pos-cdp-lite/blob/main/app/.htaccess"
click node_routes "https://github.com/mroblesdev/pos-cdp-lite/blob/main/app/Config/Routes.php"
click node_filters "https://github.com/mroblesdev/pos-cdp-lite/blob/main/app/Config/Filters.php"
click node_services "https://github.com/mroblesdev/pos-cdp-lite/blob/main/app/Config/Services.php"
click node_db_config "https://github.com/mroblesdev/pos-cdp-lite/blob/main/app/Config/Database.php"
click node_login "https://github.com/mroblesdev/pos-cdp-lite/blob/main/app/Controllers/Login.php"
click node_auth_filter "https://github.com/mroblesdev/pos-cdp-lite/blob/main/app/Filters/AuthFilter.php"
click node_inicio "https://github.com/mroblesdev/pos-cdp-lite/blob/main/app/Controllers/Inicio.php"
click node_productos "https://github.com/mroblesdev/pos-cdp-lite/blob/main/app/Controllers/Productos.php"
click node_ventas "https://github.com/mroblesdev/pos-cdp-lite/blob/main/app/Controllers/Ventas.php"
click node_caja "https://github.com/mroblesdev/pos-cdp-lite/blob/main/app/Controllers/Caja.php"
click node_configuracion "https://github.com/mroblesdev/pos-cdp-lite/blob/main/app/Controllers/Configuracion.php"
click node_reportes "https://github.com/mroblesdev/pos-cdp-lite/blob/main/app/Controllers/Reportes.php"
click node_usuarios_model "https://github.com/mroblesdev/pos-cdp-lite/blob/main/app/Models/UsuariosModel.php"
click node_productos_model "https://github.com/mroblesdev/pos-cdp-lite/blob/main/app/Models/ProductosModel.php"
click node_ventas_model "https://github.com/mroblesdev/pos-cdp-lite/blob/main/app/Models/VentasModel.php"
click node_detalle_model "https://github.com/mroblesdev/pos-cdp-lite/blob/main/app/Models/DetalleVentasModel.php"
click node_caja_model "https://github.com/mroblesdev/pos-cdp-lite/blob/main/app/Models/TemporalCajaModel.php"
click node_config_model "https://github.com/mroblesdev/pos-cdp-lite/blob/main/app/Models/ConfiguracionModel.php"
click node_usuarios_migration "https://github.com/mroblesdev/pos-cdp-lite/blob/main/app/Database/Migrations/2024-01-30-144522_Usuarios.php"
click node_ventas_migration "https://github.com/mroblesdev/pos-cdp-lite/blob/main/app/Database/Migrations/2024-02-06-204639_Ventas.php"
click node_seeders "https://github.com/mroblesdev/pos-cdp-lite/blob/main/app/Database/Seeds/CargaSeeder.php"
click node_sql_snapshot "https://github.com/mroblesdev/pos-cdp-lite/blob/main/app/Database/pos-cdp-lite.sql"
click node_layout "https://github.com/mroblesdev/pos-cdp-lite/blob/main/app/Views/plantilla/layout.php"
click node_menu "https://github.com/mroblesdev/pos-cdp-lite/blob/main/app/Views/plantilla/menu.php"
click node_login_view "https://github.com/mroblesdev/pos-cdp-lite/blob/main/app/Views/login.php"
click node_assets "https://github.com/mroblesdev/pos-cdp-lite/blob/main/public/css/styles.css"
click node_fpdf "https://github.com/mroblesdev/pos-cdp-lite/blob/main/app/ThirdParty/Fpdf/Fpdf.php"
click node_n2l "https://github.com/mroblesdev/pos-cdp-lite/blob/main/app/ThirdParty/NumerosALetras.php"
click node_system "https://github.com/mroblesdev/pos-cdp-lite/blob/main/system/CodeIgniter.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_public_index,node_public_htaccess,node_app_htaccess,node_writable_state toneBlue
class node_routes,node_filters,node_services,node_db_config,node_login,node_auth_filter,node_inicio,node_productos,node_ventas,node_caja,node_configuracion,node_reportes toneAmber
class node_usuarios_model,node_productos_model,node_ventas_model,node_detalle_model,node_caja_model,node_config_model,node_usuarios_migration,node_ventas_migration,node_seeders,node_sql_snapshot toneMint
class node_views,node_layout,node_menu,node_login_view,node_assets,node_fpdf,node_n2l toneRose
class node_system toneNeutral
```

## Components

### Runtime

HTTP entrypoints and writable deployment state

- [Front controller](https://github.com/mroblesdev/pos-cdp-lite/blob/main/public/index.php): entrypoint · Main HTTP entrypoint for the application · `public/index.php`
- [Web rewrite](https://github.com/mroblesdev/pos-cdp-lite/blob/main/public/.htaccess): apache rewrite · Apache rewrite rules for public routing · `public/.htaccess`
- [App rewrite](https://github.com/mroblesdev/pos-cdp-lite/blob/main/app/.htaccess): apache rewrite · Application-level rewrite support · `app/.htaccess`
- **Writable state**: runtime storage · Logs, cache, sessions, and uploads

### POS App

Custom CodeIgniter 4 application layer for the point-of-sale domain

- [Routes](https://github.com/mroblesdev/pos-cdp-lite/blob/main/app/Config/Routes.php): routing config · URL-to-controller mapping · `app/Config/Routes.php`
- [Filters](https://github.com/mroblesdev/pos-cdp-lite/blob/main/app/Config/Filters.php): security config · Request filters including auth boundary · `app/Config/Filters.php`
- [Services](https://github.com/mroblesdev/pos-cdp-lite/blob/main/app/Config/Services.php): service config · Framework service wiring for app behavior · `app/Config/Services.php`
- [Database config](https://github.com/mroblesdev/pos-cdp-lite/blob/main/app/Config/Database.php): db config · MySQL connection and persistence settings · `app/Config/Database.php`
- [Login](https://github.com/mroblesdev/pos-cdp-lite/blob/main/app/Controllers/Login.php): auth controller · Public authentication entrypoint · `app/Controllers/Login.php`
- [Auth guard](https://github.com/mroblesdev/pos-cdp-lite/blob/main/app/Filters/AuthFilter.php): auth filter · Protects authenticated POS pages · `app/Filters/AuthFilter.php`
- [Home](https://github.com/mroblesdev/pos-cdp-lite/blob/main/app/Controllers/Inicio.php): dashboard controller · Dashboard and landing screen · `app/Controllers/Inicio.php`
- [Products](https://github.com/mroblesdev/pos-cdp-lite/blob/main/app/Controllers/Productos.php): catalog controller · Product catalog management · `app/Controllers/Productos.php`
- [Sales](https://github.com/mroblesdev/pos-cdp-lite/blob/main/app/Controllers/Ventas.php): sales controller · Checkout, history, cancellations, and tickets · `app/Controllers/Ventas.php`
- [Cash desk](https://github.com/mroblesdev/pos-cdp-lite/blob/main/app/Controllers/Caja.php): checkout controller · Register state and checkout workflow · `app/Controllers/Caja.php`
- [Settings](https://github.com/mroblesdev/pos-cdp-lite/blob/main/app/Controllers/Configuracion.php): settings controller · System configuration management · `app/Controllers/Configuracion.php`
- [Reports](https://github.com/mroblesdev/pos-cdp-lite/blob/main/app/Controllers/Reportes.php): report controller · Sales and product reporting · `app/Controllers/Reportes.php`

### Data

Database schema, seed data, and persistence models

- [Users model](https://github.com/mroblesdev/pos-cdp-lite/blob/main/app/Models/UsuariosModel.php): model · User persistence and login lookup · `app/Models/UsuariosModel.php`
- [Products model](https://github.com/mroblesdev/pos-cdp-lite/blob/main/app/Models/ProductosModel.php): model · Product catalog persistence · `app/Models/ProductosModel.php`
- [Sales model](https://github.com/mroblesdev/pos-cdp-lite/blob/main/app/Models/VentasModel.php): model · Sales header persistence · `app/Models/VentasModel.php`
- [Line items](https://github.com/mroblesdev/pos-cdp-lite/blob/main/app/Models/DetalleVentasModel.php): model · Sale detail persistence · `app/Models/DetalleVentasModel.php`
- [Caja state](https://github.com/mroblesdev/pos-cdp-lite/blob/main/app/Models/TemporalCajaModel.php): model · Temporary cash register state · `app/Models/TemporalCajaModel.php`
- [Config model](https://github.com/mroblesdev/pos-cdp-lite/blob/main/app/Models/ConfiguracionModel.php): model · Application settings persistence · `app/Models/ConfiguracionModel.php`
- [Usuarios schema](https://github.com/mroblesdev/pos-cdp-lite/blob/main/app/Database/Migrations/2024-01-30-144522_Usuarios.php): migration · Database migration for users · `app/Database/Migrations/2024-01-30-144522_Usuarios.php`
- [Ventas schema](https://github.com/mroblesdev/pos-cdp-lite/blob/main/app/Database/Migrations/2024-02-06-204639_Ventas.php): migration · Database migration for sales and details · `app/Database/Migrations/2024-02-06-204639_Ventas.php`
- [Seed data](https://github.com/mroblesdev/pos-cdp-lite/blob/main/app/Database/Seeds/CargaSeeder.php): bootstrap data · Initial users, configuration, and sample data · `app/Database/Seeds/CargaSeeder.php`
- [SQL snapshot](https://github.com/mroblesdev/pos-cdp-lite/blob/main/app/Database/pos-cdp-lite.sql): schema dump · Full MySQL snapshot of the POS schema · `app/Database/pos-cdp-lite.sql`

### Presentation

Server-rendered views, shared layout, and public assets

- **Views**: presentation · Server-rendered UI templates
- [Layout](https://github.com/mroblesdev/pos-cdp-lite/blob/main/app/Views/plantilla/layout.php): shared shell · Common page chrome and menu · `app/Views/plantilla/layout.php`
- [Menu](https://github.com/mroblesdev/pos-cdp-lite/blob/main/app/Views/plantilla/menu.php): shared nav · Shared navigation component · `app/Views/plantilla/menu.php`
- [Login view](https://github.com/mroblesdev/pos-cdp-lite/blob/main/app/Views/login.php): auth screen · Rendered login form · `app/Views/login.php`
- [Assets](https://github.com/mroblesdev/pos-cdp-lite/blob/main/public/css/styles.css): static assets · CSS, JavaScript, DataTables, and jQuery UI · `public/css/styles.css`
- [PDF engine](https://github.com/mroblesdev/pos-cdp-lite/blob/main/app/ThirdParty/Fpdf/Fpdf.php): third-party library · Ticket and report PDF generation · `app/ThirdParty/Fpdf/Fpdf.php`
- [Numbers to words](https://github.com/mroblesdev/pos-cdp-lite/blob/main/app/ThirdParty/NumerosALetras.php): helper library · Converts amounts for printable documents · `app/ThirdParty/NumerosALetras.php`

### Other components

- [CI4 runtime](https://github.com/mroblesdev/pos-cdp-lite/blob/main/system/CodeIgniter.php): framework · Reusable CodeIgniter 4 framework layer · `system/CodeIgniter.php`

## Connections

- Web rewrite → Front controller: rewrites to
- App rewrite → Front controller: supports routing
- Front controller → CI4 runtime: boots
- Front controller → Routes: loads
- Routes → Login: public route
- Routes → Home: protected route
- Routes → Products: protected route
- Routes → Sales: protected route
- Routes → Cash desk: protected route
- Routes → Settings: protected route
- Routes → Reports: protected route
- Filters → Auth guard: registers
- Auth guard → Login: allows public access
- Auth guard → Home: protects
- Auth guard → Products: protects
- Auth guard → Sales: protects
- Auth guard → Cash desk: protects
- Auth guard → Settings: protects
- Auth guard → Reports: protects
- Login → Users model: verifies user
- Login → Services: uses
- Login → Writable state: writes session/logs
- Login → Login view: renders
- Home → Views: renders
- Products → Products model: reads/writes
- Products → Views: renders
- Sales → Sales model: persists header
- Sales → Line items: persists items
- Sales → Caja state: uses register state
- Sales → PDF engine: generates tickets
- Sales → Numbers to words: formats amounts
- Sales → Views: renders
- Cash desk → Caja state: updates state
- Cash desk → Views: renders
- Settings → Config model: updates settings
- Settings → Views: renders
- Reports → Sales model: queries sales
- Reports → Products model: queries products
- Reports → PDF engine: exports pdf
- Reports → Views: renders
- Views → Layout: uses shell
- Views → Menu: uses nav
- Views → Assets: loads
- CI4 runtime → Database config: provides db layer
- CI4 runtime → Services: provides services
- CI4 runtime → Filters: provides filter runtime
- CI4 runtime → Writable state: uses runtime storage
- Usuarios schema → Users model: defines schema for
