# 13felixlopez/proyectoofi architecture

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

- Interactive diagram: https://gitdiagram.com/13felixlopez/proyectoofi
- Repository: https://github.com/13felixlopez/proyectoofi

## Overview

1. **Repository shape**
   - This is a **Windows desktop application** built in **C# WinForms** on **.NET Framework 4.8**.
   - The solution centers on `ProyectoOFI`, with a smaller companion `Datos` project in the solution. The functional architecture is inside `ProyectoOFI`.

2. **Top-level architecture**
   - The codebase follows a classic **3-layer pattern**:
     - **UI layer**: WinForms forms and user controls.
     - **Business layer**: `ProyectoOFI/Logica` classes (`L*`).
     - **Data access layer**: `ProyectoOFI/Datos` classes (`D*`).
   - The UI does not appear to talk directly to SQL Server; it goes through `Logica`, which in turn uses `Datos`.

3. **Application entry and shell**
   - `Program.cs` starts the app.
   - `Login` is the first functional gate: it checks connectivity and user credentials.
   - `FrmConexionIP` is the fallback/admin screen for configuring the SQL connection if the connection test fails.
   - `FrmMenu` is the main shell/orchestrator after authentication; it routes users into functional modules.

4. **Security and session flow**
   - User authentication and authorization are handled through `Usuario/`, `Logica/LUsuarios.cs`, `Logica/LPermisos.cs`, and the corresponding data classes.
   - The menu loads permissions and adjusts access based on role; the README indicates an **admin vs restricted-permission** path.
   - Password and sensitive values are handled with crypto helpers in `Logica/AES.cs`, `Encrip.cs`, and `Desencryptacion.cs`.

5. **Data access and persistence boundary**
   - `ProyectoOFI/Datos/` contains the SQL-facing classes such as `DRecepcion`, `DControlPatio`, `DAlmacen`, `DCompraD`, `DUsuarios`, `DReporte`, etc.
   - This layer is tied to **SQL Server** and appears to rely heavily on **stored procedures**.
   - The database scripts `CoffeeTech.sql` and `Ultima.sql` are part of the repo, indicating the schema and procedural database logic are versioned alongside the app.

6. **Core operational domain: coffee flow**
   - The application tracks the operational lifecycle of coffee lots/tickets across these main business areas:
     - **Recepción / Transferencia**
     - **Control Patio / secado natural**
     - **Secado Mecánico (SM)**
     - **Análisis / Catación**
     - **Almacén / Bodega / Compra directa**
     - **Reportería**
     - **Configuración y catálogos**
   - The central data object is a **ticket/lote**, which moves through these stages and accumulates operational and quality records.

7. **Reception and ticket intake**
   - `Recepcion/` handles the initial capture of incoming tickets/lotes and transfer/consolidation workflows.
   - Subforms like `AddEditTicket`, `Consolidar`, and `Transferencia` suggest the entry point for a lot into the system.
   - The flow is: validate input → persist reception data → update lot status so downstream modules can consume it.

8. **Drying and patio operations**
   - `ControlPatio/` models natural drying workflows and patio management.
   - `SM/` contains the mechanical drying subsystem, with separate forms for entities such as guadiolas, tolvas, verticales, PS/POA, and related operations.
   - These modules are operationally similar: select lot/subprocess → record process event → save state and history in the database.

9. **Quality analysis**
   - `Analisis/` handles samples and cupping/catation.
   - The main artifacts are sample registration and quality assessment, which are then linked back to the lot/ticket.
   - This subsystem contributes quality metrics used later by reporting and operational decisions.

10. **Storage, movement, and purchase**
   - `Almacen/` and `Compras/` represent inventory/storage and direct purchase workflows.
   - `Otros/` contains many supporting master-data forms: clients, providers, locations, varieties, qualities, turns, materials, damages, areas, etc.
   - These screens act as configuration and reference-data boundaries for the operational modules.

11. **Reporting and analytics**
   - `Reportes/` is the read-heavy side of the system: dashboard, ticket reports, histories, lot listings, digitization, and tender/processing views.
   - Reporting reads aggregated operational data from SQL Server and presents it in forms or exportable views.
   - This is the main consumer of the historical trail produced by all operational modules.

12. **Cross-cutting services**
   - `Log.cs` plus the README indicate errors are written to `C:\Log\logerror.txt`.
   - `Services/ApiService.cs` provides optional HTTP integration, including an endpoint named `/api/ExcelLotesExcelCP`, which suggests export or sync support for patio/lot Excel workflows.
   - The app also has form-level support for Excel import/export in several modules, indicating file-based interchange alongside the SQL backend.

13. **Configuration and environment**
   - `App.config` and the connection-setup screen imply runtime configuration is essential to startup.
   - The connection string is described as being stored in `ConnectionString.xml` and protected with AES-based encryption.
   - Operationally, the app depends on a reachable SQL Server instance before the main login flow can succeed.

14. **How to draw the architecture**
   - Draw the **UI layer** as a set of module forms under `Login`/`FrmMenu`.
   - Place **`Logica`** as the mediator/business boundary between UI and persistence.
   - Place **`Datos` + SQL Server** as the persistence boundary, with stored procedures as the main database interaction mechanism.
   - Show two side channels: **encrypted connection/configuration** and **file-based logging**, plus a small **HTTP API integration** for Excel-related exchange.

Main entry points: [`ProyectoOFI/FrmMenu.cs`](https://github.com/13felixlopez/proyectoofi/blob/master/ProyectoOFI/FrmMenu.cs) (Main menu), [`ProyectoOFI/Logica/LRecepcion.cs`](https://github.com/13felixlopez/proyectoofi/blob/master/ProyectoOFI/Logica/LRecepcion.cs) (Logica), [`ProyectoOFI/Login.cs`](https://github.com/13felixlopez/proyectoofi/blob/master/ProyectoOFI/Login.cs) (Login), [`ProyectoOFI/Reportes/Dashboard.cs`](https://github.com/13felixlopez/proyectoofi/blob/master/ProyectoOFI/Reportes/Dashboard.cs) (Reportes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["UI layer"]
  node_program(("Program<br/>startup<br/>[Program.cs]"))
  node_login["Login<br/>auth gate<br/>[Login.cs]"]
  node_conexion["Connection setup<br/>config screen<br/>[FrmConexionIP.cs]"]
  node_menu["Main menu<br/>shell<br/>[FrmMenu.cs]"]
  node_recepcion["Recepción<br/>ticket intake<br/>[Transferencia.cs]"]
  node_patio["Control patio<br/>drying ops<br/>[CUControlPatio.cs]"]
  node_sm["Secado mecánico<br/>drying ops<br/>[SecadoMecanico.cs]"]
  node_analisis["Análisis<br/>quality<br/>[Catacion.cs]"]
  node_almacen["Almacén<br/>inventory<br/>[Almacen.cs]"]
  node_compras["Compras<br/>procurement<br/>[ComprasDirectas.cs]"]
  node_reportes["Reportes<br/>reporting<br/>[Dashboard.cs]"]
  node_catalogos["Catálogos<br/>master data<br/>[FrmConfig.cs]"]
  node_usuario["Usuario<br/>account<br/>[FrmPerfil.cs]"]
end

subgraph group_biz["Business layer"]
  node_logica{{"Logica<br/>service layer<br/>[LRecepcion.cs]"}}
  node_lseguridad{{"Seguridad<br/>authn/authz<br/>[LUsuarios.cs]"}}
  node_lopers{{"Permisos<br/>access control<br/>[LPermisos.cs]"}}
  node_ldomain{{"Operaciones<br/>domain services<br/>[LControlPatio.cs]"}}
end

subgraph group_data["Data layer"]
  node_datoslib[("Datos<br/>sql gateway")]
  node_sqlserver[("SQL Server<br/>persistence")]
end

subgraph group_cross["Cross-cutting"]
  node_configsec["Config crypto<br/>encrypted config<br/>[AES.cs]"]
  node_logger["Logger<br/>file log<br/>[Log.cs]"]
  node_apisvc["API service<br/>http integration<br/>[ApiService.cs]"]
end

node_program -->|"starts"| node_login
node_login -->|"fallback"| node_conexion
node_login -->|"authenticates"| node_menu
node_menu -->|"opens"| node_recepcion
node_menu -->|"opens"| node_patio
node_menu -->|"opens"| node_sm
node_menu -->|"opens"| node_analisis
node_menu -->|"opens"| node_almacen
node_menu -->|"opens"| node_compras
node_menu -->|"opens"| node_reportes
node_menu -->|"opens"| node_catalogos
node_menu -->|"opens"| node_usuario
node_recepcion -->|"uses"| node_logica
node_patio -->|"uses"| node_logica
node_sm -->|"uses"| node_logica
node_analisis -->|"uses"| node_logica
node_almacen -->|"uses"| node_logica
node_compras -->|"uses"| node_logica
node_reportes -->|"reads via"| node_logica
node_catalogos -->|"uses"| node_logica
node_usuario -->|"uses"| node_lseguridad
node_menu -->|"enforces"| node_lopers
node_logica -->|"calls"| node_datoslib
node_lseguridad -->|"calls"| node_datoslib
node_lopers -->|"calls"| node_datoslib
node_datoslib -->|"persists to"| node_sqlserver
node_configsec -.->|"protects"| node_conexion
node_logger -.->|"records"| node_login
node_apisvc -.->|"integrates"| node_reportes

click node_program "https://github.com/13felixlopez/proyectoofi/blob/master/ProyectoOFI/Program.cs"
click node_login "https://github.com/13felixlopez/proyectoofi/blob/master/ProyectoOFI/Login.cs"
click node_conexion "https://github.com/13felixlopez/proyectoofi/blob/master/ProyectoOFI/FrmConexionIP.cs"
click node_menu "https://github.com/13felixlopez/proyectoofi/blob/master/ProyectoOFI/FrmMenu.cs"
click node_recepcion "https://github.com/13felixlopez/proyectoofi/blob/master/ProyectoOFI/Recepcion/Transferencia.cs"
click node_patio "https://github.com/13felixlopez/proyectoofi/blob/master/ProyectoOFI/ControlPatio/CUControlPatio.cs"
click node_sm "https://github.com/13felixlopez/proyectoofi/blob/master/ProyectoOFI/SM/SecadoMecanico.cs"
click node_analisis "https://github.com/13felixlopez/proyectoofi/blob/master/ProyectoOFI/Analisis/Catacion.cs"
click node_almacen "https://github.com/13felixlopez/proyectoofi/blob/master/ProyectoOFI/Almacen/Almacen.cs"
click node_compras "https://github.com/13felixlopez/proyectoofi/blob/master/ProyectoOFI/Compras/ComprasDirectas.cs"
click node_reportes "https://github.com/13felixlopez/proyectoofi/blob/master/ProyectoOFI/Reportes/Dashboard.cs"
click node_catalogos "https://github.com/13felixlopez/proyectoofi/blob/master/ProyectoOFI/Otros/FrmConfig.cs"
click node_usuario "https://github.com/13felixlopez/proyectoofi/blob/master/ProyectoOFI/Usuario/FrmPerfil.cs"
click node_logica "https://github.com/13felixlopez/proyectoofi/blob/master/ProyectoOFI/Logica/LRecepcion.cs"
click node_lseguridad "https://github.com/13felixlopez/proyectoofi/blob/master/ProyectoOFI/Logica/LUsuarios.cs"
click node_lopers "https://github.com/13felixlopez/proyectoofi/blob/master/ProyectoOFI/Logica/LPermisos.cs"
click node_ldomain "https://github.com/13felixlopez/proyectoofi/blob/master/ProyectoOFI/Logica/LControlPatio.cs"
click node_configsec "https://github.com/13felixlopez/proyectoofi/blob/master/ProyectoOFI/Logica/AES.cs"
click node_logger "https://github.com/13felixlopez/proyectoofi/blob/master/ProyectoOFI/Log.cs"
click node_apisvc "https://github.com/13felixlopez/proyectoofi/blob/master/ProyectoOFI/Services/ApiService.cs"

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_program,node_login,node_conexion,node_menu,node_recepcion,node_patio,node_sm,node_analisis,node_almacen,node_compras,node_reportes,node_catalogos,node_usuario toneBlue
class node_logica,node_lseguridad,node_lopers,node_ldomain toneAmber
class node_datoslib,node_sqlserver toneMint
class node_configsec,node_logger,node_apisvc toneRose
```

## Components

### UI layer

WinForms screens and module forms

- [Program](https://github.com/13felixlopez/proyectoofi/blob/master/ProyectoOFI/Program.cs): startup · Application entry point · `ProyectoOFI/Program.cs`
- [Login](https://github.com/13felixlopez/proyectoofi/blob/master/ProyectoOFI/Login.cs): auth gate · First functional gate for connectivity and credentials · `ProyectoOFI/Login.cs`
- [Connection setup](https://github.com/13felixlopez/proyectoofi/blob/master/ProyectoOFI/FrmConexionIP.cs): config screen · Fallback screen for SQL connection configuration · `ProyectoOFI/FrmConexionIP.cs`
- [Main menu](https://github.com/13felixlopez/proyectoofi/blob/master/ProyectoOFI/FrmMenu.cs): shell · Primary application shell and module router · `ProyectoOFI/FrmMenu.cs`
- [Recepción](https://github.com/13felixlopez/proyectoofi/blob/master/ProyectoOFI/Recepcion/Transferencia.cs): ticket intake · Incoming ticket and transfer workflows · `ProyectoOFI/Recepcion/Transferencia.cs`
- [Control patio](https://github.com/13felixlopez/proyectoofi/blob/master/ProyectoOFI/ControlPatio/CUControlPatio.cs): drying ops · Natural drying and patio management · `ProyectoOFI/ControlPatio/CUControlPatio.cs`
- [Secado mecánico](https://github.com/13felixlopez/proyectoofi/blob/master/ProyectoOFI/SM/SecadoMecanico.cs): drying ops · Mechanical drying workflows and equipment screens · `ProyectoOFI/SM/SecadoMecanico.cs`
- [Análisis](https://github.com/13felixlopez/proyectoofi/blob/master/ProyectoOFI/Analisis/Catacion.cs): quality · Sampling and cupping/catation screens · `ProyectoOFI/Analisis/Catacion.cs`
- [Almacén](https://github.com/13felixlopez/proyectoofi/blob/master/ProyectoOFI/Almacen/Almacen.cs): inventory · Storage and warehouse operations · `ProyectoOFI/Almacen/Almacen.cs`
- [Compras](https://github.com/13felixlopez/proyectoofi/blob/master/ProyectoOFI/Compras/ComprasDirectas.cs): procurement · Direct purchase workflows · `ProyectoOFI/Compras/ComprasDirectas.cs`
- [Reportes](https://github.com/13felixlopez/proyectoofi/blob/master/ProyectoOFI/Reportes/Dashboard.cs): reporting · Dashboard, histories, lot views, and digitation · `ProyectoOFI/Reportes/Dashboard.cs`
- [Catálogos](https://github.com/13felixlopez/proyectoofi/blob/master/ProyectoOFI/Otros/FrmConfig.cs): master data · Reference-data maintenance screens · `ProyectoOFI/Otros/FrmConfig.cs`
- [Usuario](https://github.com/13felixlopez/proyectoofi/blob/master/ProyectoOFI/Usuario/FrmPerfil.cs): account · Profile, recovery, and user-facing account screens · `ProyectoOFI/Usuario/FrmPerfil.cs`

### Business layer

Logica classes coordinating workflows and rules

- [Logica](https://github.com/13felixlopez/proyectoofi/blob/master/ProyectoOFI/Logica/LRecepcion.cs): service layer · Business rules and orchestration boundary · `ProyectoOFI/Logica/LRecepcion.cs`
- [Seguridad](https://github.com/13felixlopez/proyectoofi/blob/master/ProyectoOFI/Logica/LUsuarios.cs): authn/authz · Users, permissions, and encryption helpers · `ProyectoOFI/Logica/LUsuarios.cs`
- [Permisos](https://github.com/13felixlopez/proyectoofi/blob/master/ProyectoOFI/Logica/LPermisos.cs): access control · Role and module permission evaluation · `ProyectoOFI/Logica/LPermisos.cs`
- [Operaciones](https://github.com/13felixlopez/proyectoofi/blob/master/ProyectoOFI/Logica/LControlPatio.cs): domain services · Reception, patio, drying, analysis, storage, and purchase logic · `ProyectoOFI/Logica/LControlPatio.cs`

### Data layer

SQL-facing classes and database boundary

- **Datos**: sql gateway · SQL-facing data access classes
- **SQL Server**: persistence · Stored-procedure-backed database

### Cross-cutting

Security, config, logging, and integration services

- [Config crypto](https://github.com/13felixlopez/proyectoofi/blob/master/ProyectoOFI/Logica/AES.cs): encrypted config · Connection string protection and AES helpers · `ProyectoOFI/Logica/AES.cs`
- [Logger](https://github.com/13felixlopez/proyectoofi/blob/master/ProyectoOFI/Log.cs): file log · Error logging to a local file · `ProyectoOFI/Log.cs`
- [API service](https://github.com/13felixlopez/proyectoofi/blob/master/ProyectoOFI/Services/ApiService.cs): http integration · Optional HTTP integration for Excel exchange · `ProyectoOFI/Services/ApiService.cs`

## Connections

- Program → Login: starts · Launches the application at the login gate
- Login → Connection setup: fallback · Routes to connection setup when SQL connectivity fails
- Login → Main menu: authenticates · On success, opens the main shell
- Main menu → Recepción: opens · Navigates to intake workflows
- Main menu → Control patio: opens · Navigates to patio control
- Main menu → Secado mecánico: opens · Navigates to mechanical drying
- Main menu → Análisis: opens · Navigates to quality analysis
- Main menu → Almacén: opens · Navigates to inventory/storage
- Main menu → Compras: opens · Navigates to direct purchases
- Main menu → Reportes: opens · Navigates to reporting and dashboards
- Main menu → Catálogos: opens · Navigates to master data maintenance
- Main menu → Usuario: opens · Navigates to account/profile features
- Recepción → Logica: uses · Routes ticket intake through business rules
- Control patio → Logica: uses · Sends drying events through business rules
- Secado mecánico → Logica: uses · Sends mechanical drying events through business rules
- Análisis → Logica: uses · Sends sample and catation data through business rules
- Almacén → Logica: uses · Sends storage movements through business rules
- Compras → Logica: uses · Sends purchase workflows through business rules
- Reportes → Logica: reads via · Loads historical and aggregated data through the business layer
- Catálogos → Logica: uses · Maintains reference data through business rules
- Usuario → Seguridad: uses · Account and credential workflows depend on security services
- Main menu → Permisos: enforces · Adjusts access based on loaded permissions
- Logica → Datos: calls · Business logic delegates persistence to data access classes
- Seguridad → Datos: calls · User and permission features persist through data access
- Permisos → Datos: calls · Permission checks query the data layer
- Datos → SQL Server: persists to · SQL Server is the main persistence boundary
- Config crypto → Connection setup: protects · Encrypted connection configuration feeds the setup screen
- Logger → Login: records · Startup and authentication errors are written to local logs
- API service → Reportes: integrates · Supports Excel-related exchange and optional HTTP workflows
