# isoledadss/sis-rev-ops architecture

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

- Interactive diagram: https://gitdiagram.com/isoledadss/sis-rev-ops
- Repository: https://github.com/isoledadss/sis-rev-ops

## Overview

1. **High-level shape**
   This repository is a single-process Streamlit application with a shared PostgreSQL backend. There is no separate API service: `app.py` drives the UI, and the functional modules implement the business workflows directly against the database.

2. **Entry point and navigation**
   `app.py` is the orchestration layer. It handles login, role-based access, and tab/routing logic for the main user flows: carga, bandeja, precios, asignaciones, reportes, métricas, and administración.

3. **Configuration and runtime boundaries**
   `config.py` centralizes environment-driven settings, credentials, and domain mappings. The app depends on `.env` variables for DB access and user/admin lists, so secrets are kept out of source control. This makes configuration a clear boundary between code and deployment environment.

4. **Persistence layer**
   `db.py` is the data-access and lifecycle core. It manages PostgreSQL connections/pooling, schema creation or migrations at startup, and database logging. The README indicates the schema is created automatically into about 12 tables, including contracts, operations, assignments, aliases, and audit/history tables.

5. **Shared domain utilities**
   `helpers.py` holds cross-cutting business utilities: conversions, alias resolution, and user/contract mapping logic. This module is the main shared dependency used by multiple features to keep classification and normalization consistent.

6. **Operation ingestion**
   `carga.py` owns import of CPASVTAS Excel files via `openpyxl`/pandas-style parsing. Its output is persisted operations plus load records in `cargas`, and it likely feeds downstream review and reporting tables. This is the first major inbound data flow from external files into PostgreSQL.

7. **Review workflow**
   `bandeja.py` implements the contract-based review queue. It is the operational control plane: multiuser locking, review callbacks, and auto-close when a contract is completed. It reads/writes contract and operation state, so it sits between the imported data and finalized operational records.

8. **Price enrichment**
   `precios.py` is the market-data enrichment boundary. It integrates with Yahoo Finance via `yahooquery` and also consumes local Vector analítico files for debt instruments. It updates or supplements instrument pricing data used by review, metrics, and reporting.

9. **Mass assignments**
   `asignaciones.py` handles batch assignment workflows for purchases, including participation percentages and risk validations. It writes assignment entities and links them back to operations/cargas, making it a separate business process from the review queue even though both touch the same core data.

10. **Reporting and analytics**
    `reportes.py` produces per-contract reports and Excel exports, while `metricas.py` builds the dashboard with Plotly and generates PDF/email outputs via ReportLab and `.eml` files. These modules are read-heavy consumers of the operational database, with export as the main outbound flow.

11. **Administration and audit**
    `admin.py` groups operational tooling: database backup, operation search, alias management, and audit-log access. It depends on the same PostgreSQL core plus `pg_dump` for backups, making administration an internal tooling subsystem rather than a separate service.

12. **Data model and traceability**
    The schema design emphasizes traceability: `operacion_historial` captures field-level changes, `audit_log` records security and maintenance events, and alias/assignment tables preserve lineage across enrichment and workflow steps. This makes the database the central system of record for both state and auditability.

13. **Main data flow**
    The typical end-to-end path is: external Excel or reference files enter through `carga.py` or `precios.py`, records are normalized with `helpers.py`, persisted through `db.py`, reviewed in `bandeja.py`, enriched or assigned via `precios.py` and `asignaciones.py`, and finally surfaced in `reportes.py`, `metricas.py`, or `admin.py`.

14. **Primary architectural boundary**
    The key boundary in this repo is not frontend/backend, but **UI orchestration vs. domain modules vs. PostgreSQL persistence**. Streamlit provides the presentation layer, the feature modules implement business logic, and PostgreSQL holds state, audit history, and workflow coordination.

Main entry points: [`app.py`](https://github.com/isoledadss/sis-rev-ops/blob/main/app.py) (Main app), [`db.py`](https://github.com/isoledadss/sis-rev-ops/blob/main/db.py) (Database core), [`bandeja.py`](https://github.com/isoledadss/sis-rev-ops/blob/main/bandeja.py) (Bandeja), [`carga.py`](https://github.com/isoledadss/sis-rev-ops/blob/main/carga.py) (Carga)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_presentation["Presentation"]
  node_app["Main app<br/>streamlit entry<br/>[app.py]"]
end

subgraph group_workflows["Workflows"]
  node_carga["Carga<br/>ingestion<br/>[carga.py]"]
  node_bandeja["Bandeja<br/>review queue<br/>[bandeja.py]"]
  node_precios["Precios<br/>pricing enrichment<br/>[precios.py]"]
  node_asignaciones["Asignaciones<br/>batch workflow<br/>[asignaciones.py]"]
  node_reportes["Reportes<br/>report export<br/>[reportes.py]"]
  node_metricas["Métricas<br/>analytics dashboard<br/>[metricas.py]"]
  node_admin["Admin<br/>ops tools<br/>[admin.py]"]
end

subgraph group_data["Data Layer"]
  node_config["Config<br/>settings<br/>[config.py]"]
  node_db[("Database core<br/>postgres access<br/>[db.py]")]
  node_helpers["Helpers<br/>domain utils<br/>[helpers.py]"]
end

subgraph group_external["External Systems"]
  node_postgres[("PostgreSQL<br/>system of record")]
  node_excel["Excel files<br/>input source"]
  node_market["Market data<br/>external source"]
  node_exports["Exports<br/>output files"]
end

node_app -->|"loads settings"| node_config
node_app -->|"opens data access"| node_db
node_app -->|"routes to"| node_carga
node_app -->|"routes to"| node_bandeja
node_app -->|"routes to"| node_precios
node_app -->|"routes to"| node_asignaciones
node_app -->|"routes to"| node_reportes
node_app -->|"routes to"| node_metricas
node_app -->|"routes to"| node_admin
node_carga -->|"imports"| node_excel
node_carga -->|"normalizes with"| node_helpers
node_carga -->|"persists loads"| node_db
node_bandeja -->|"classifies with"| node_helpers
node_bandeja -->|"reads/writes workflow"| node_db
node_precios -->|"fetches pricing"| node_market
node_precios -->|"resolves aliases"| node_helpers
node_precios -->|"updates prices"| node_db
node_asignaciones -->|"validates mappings"| node_helpers
node_asignaciones -->|"stores assignments"| node_db
node_reportes -->|"reads operations"| node_db
node_reportes -->|"generates reports"| node_exports
node_metricas -->|"reads metrics"| node_db
node_metricas -->|"generates dashboards"| node_exports
node_admin -->|"administers"| node_db
node_admin -->|"backup via pg_dump"| node_postgres
node_db -->|"connects to"| node_postgres
node_helpers -->|"supports consistent state"| node_postgres
node_carga -->|"feeds reviewed operations"| node_bandeja
node_bandeja -->|"finalized data to reports"| node_reportes
node_bandeja -->|"feeds dashboards"| node_metricas
node_asignaciones -->|"feeds summaries"| node_reportes

click node_app "https://github.com/isoledadss/sis-rev-ops/blob/main/app.py"
click node_config "https://github.com/isoledadss/sis-rev-ops/blob/main/config.py"
click node_db "https://github.com/isoledadss/sis-rev-ops/blob/main/db.py"
click node_helpers "https://github.com/isoledadss/sis-rev-ops/blob/main/helpers.py"
click node_carga "https://github.com/isoledadss/sis-rev-ops/blob/main/carga.py"
click node_bandeja "https://github.com/isoledadss/sis-rev-ops/blob/main/bandeja.py"
click node_precios "https://github.com/isoledadss/sis-rev-ops/blob/main/precios.py"
click node_asignaciones "https://github.com/isoledadss/sis-rev-ops/blob/main/asignaciones.py"
click node_reportes "https://github.com/isoledadss/sis-rev-ops/blob/main/reportes.py"
click node_metricas "https://github.com/isoledadss/sis-rev-ops/blob/main/metricas.py"
click node_admin "https://github.com/isoledadss/sis-rev-ops/blob/main/admin.py"

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_app toneBlue
class node_carga,node_bandeja,node_precios,node_asignaciones,node_reportes,node_metricas,node_admin toneAmber
class node_config,node_db,node_helpers toneMint
class node_postgres,node_excel,node_market,node_exports toneRose
```

## Components

### Presentation

Streamlit entry point and user navigation

- [Main app](https://github.com/isoledadss/sis-rev-ops/blob/main/app.py): streamlit entry · Login, role gating, and tab routing for the whole application · `app.py`

### Workflows

Business modules for ingestion, review, pricing, assignments, and admin

- [Carga](https://github.com/isoledadss/sis-rev-ops/blob/main/carga.py): ingestion · Imports CPASVTAS Excel files and persists load records · `carga.py`
- [Bandeja](https://github.com/isoledadss/sis-rev-ops/blob/main/bandeja.py): review queue · Contract review workflow with locking, callbacks, and auto-close · `bandeja.py`
- [Precios](https://github.com/isoledadss/sis-rev-ops/blob/main/precios.py): pricing enrichment · Updates instrument pricing from market and local reference inputs · `precios.py`
- [Asignaciones](https://github.com/isoledadss/sis-rev-ops/blob/main/asignaciones.py): batch workflow · Handles purchase assignments, participation percentages, and risk checks · `asignaciones.py`
- [Reportes](https://github.com/isoledadss/sis-rev-ops/blob/main/reportes.py): report export · Builds per-contract reports and Excel outputs · `reportes.py`
- [Métricas](https://github.com/isoledadss/sis-rev-ops/blob/main/metricas.py): analytics dashboard · Dashboards and PDF/email style outputs for operational metrics · `metricas.py`
- [Admin](https://github.com/isoledadss/sis-rev-ops/blob/main/admin.py): ops tools · Backup, search, alias management, and audit-log access · `admin.py`

### Data Layer

Shared persistence, configuration, and domain utilities

- [Config](https://github.com/isoledadss/sis-rev-ops/blob/main/config.py): settings · Environment-driven settings, credentials, and domain mappings · `config.py`
- [Database core](https://github.com/isoledadss/sis-rev-ops/blob/main/db.py): postgres access · Connection handling, schema lifecycle, and database logging · `db.py`
- [Helpers](https://github.com/isoledadss/sis-rev-ops/blob/main/helpers.py): domain utils · Shared normalization, alias resolution, and mapping logic · `helpers.py`

### External Systems

Non-repository dependencies and data sources

- **PostgreSQL**: system of record · Central relational store for contracts, operations, assignments, aliases, and audit history
- **Excel files**: input source · Imported CPASVTAS and reference spreadsheets
- **Market data**: external source · Yahoo Finance and local Vector analítico inputs for pricing
- **Exports**: output files · Generated Excel, PDF, and .eml artifacts

## Connections

- Main app → Config: loads settings
- Main app → Database core: opens data access
- Main app → Carga: routes to
- Main app → Bandeja: routes to
- Main app → Precios: routes to
- Main app → Asignaciones: routes to
- Main app → Reportes: routes to
- Main app → Métricas: routes to
- Main app → Admin: routes to
- Carga → Excel files: imports
- Carga → Helpers: normalizes with
- Carga → Database core: persists loads
- Bandeja → Helpers: classifies with
- Bandeja → Database core: reads/writes workflow
- Precios → Market data: fetches pricing
- Precios → Helpers: resolves aliases
- Precios → Database core: updates prices
- Asignaciones → Helpers: validates mappings
- Asignaciones → Database core: stores assignments
- Reportes → Database core: reads operations
- Reportes → Exports: generates reports
- Métricas → Database core: reads metrics
- Métricas → Exports: generates dashboards
- Admin → Database core: administers
- Admin → PostgreSQL: backup via pg_dump
- Database core → PostgreSQL: connects to
- Helpers → PostgreSQL: supports consistent state
- Carga → Bandeja: feeds reviewed operations
- Bandeja → Reportes: finalized data to reports
- Bandeja → Métricas: feeds dashboards
- Asignaciones → Reportes: feeds summaries
