# cyam12/ropusac_2026 architecture

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

- Interactive diagram: https://gitdiagram.com/cyam12/ropusac_2026
- Repository: https://github.com/cyam12/ropusac_2026

## Overview

#### Purpose and Runtime
ROPUSAC is a server-rendered Flask business-management system for users, suppliers, customers, products, sale prices, quotations, sales, and electronic receipts. The executable entry point is `run.py`; application setup and extensions are centralized in `app/__init__.py` and `app/extensiones.py`. It runs on Python/Flask with Bootstrap templates.

#### HTTP Application Boundary
Route modules form the primary controller layer, separating workflows by role and domain. Authentication starts in `app/rutas/autenticacion.py`; the landing/dashboard flow is in `app/rutas/dashboard.py`. Role-specific route partitions support administrator, commercial area, and seller experiences, e.g. `app/rutas/administrador.py`, `app/rutas/productos_comercial.py`, and `app/rutas/productos_vendedor.py`. HTML is rendered from corresponding template trees under `app/plantillas/`.

#### Identity, Roles, and Authorization
Users, roles, permissions, and role-permission assignments define access control: `app/modelos/usuario.py`, `app/modelos/rol.py`, and `app/modelos/permiso.py`. Route-level authorization behavior is likely enforced through reusable decorators in `app/utilidades/decoradores.py`. This establishes a boundary between authentication/authorization and domain routes, with distinct UIs for administrator, commercial, and seller roles.

#### Commercial Master Data and Pricing
Products and suppliers are managed through dedicated models and route surfaces: `app/modelos/producto.py`, `app/modelos/proveedor.py`, and `app/rutas/productos.py`. Product pricing is tracked historically through `app/modelos/historial_precio_base.py` and `app/modelos/historial_precio_venta.py`, exposed in pricing route modules such as `app/rutas/precios_venta.py`. Product image and import capabilities are represented by `app/modelos/imagen_producto.py` and `app/modelos/importacion_producto.py`.

#### Customer-to-Document Transaction Flow
The core commercial flow begins with customer records (`app/modelos/cliente.py`), creates quotations with line items (`app/modelos/cotizacion.py`, `app/modelos/detalle_cotizacion.py`), and tracks quotation status transitions (`app/modelos/historial_estado_cotizacion.py`). Sales and their lines are persisted in `app/modelos/venta.py` and `app/modelos/detalle_venta.py`; electronic receipts are represented by `app/modelos/boleta.py`. Seller quotation and receipt workflows are handled by `app/rutas/cotizaciones_vendedor.py` and `app/rutas/boletas_vendedor.py`.

#### Persistence and Operational Audit
PostgreSQL is accessed via SQLAlchemy, with schema evolution managed by Flask-Migrate/Alembic. The canonical migration chain is under `migrations/versions/`, beginning at `migrations/versions/0001_baseline_ropusac.py`; a legacy/initial SQL schema also exists at `SQL/esquema_inicial_ropusac.sql`. Operational/API activity is modeled separately via `app/modelos/bitacora_operacion.py` and `app/modelos/registro_api.py`, indicating auditability around business actions and integrations.

#### Integrations and Deployment
External-service adapters are isolated under `app/servicios/`: electronic invoicing through `app/servicios/nubefact.py`, email through `app/servicios/correo.py`, PDF quotation generation through `app/servicios/pdf_cotizacion.py`, and product-image hosting through `app/servicios/imgbb.py`. Additional API, geocoding, and exchange-rate integrations appear in `app/servicios/apis_net.py`, `app/servicios/geoapify.py`, and `app/servicios/exchange_rate.py`; integration endpoints are grouped in `app/rutas/integraciones.py`. Credentials and database configuration are environment-driven via `.env.example` and `config.py`. Deployment targets are Render for the Flask application and Neon PostgreSQL for persistence.

Main entry points: [`app/rutas/administrador.py`](https://github.com/cyam12/ropusac_2026/blob/main/app/rutas/administrador.py) (Role and domain routes), [`app/__init__.py`](https://github.com/cyam12/ropusac_2026/blob/main/app/__init__.py) (App setup), [`app/rutas/cotizaciones_vendedor.py`](https://github.com/cyam12/ropusac_2026/blob/main/app/rutas/cotizaciones_vendedor.py) (Seller documents), [`app/rutas/autenticacion.py`](https://github.com/cyam12/ropusac_2026/blob/main/app/rutas/autenticacion.py) (Authentication)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Flask runtime"]
  node_entry["Application entry<br/>Python entry point<br/>[run.py]"]
  node_app_factory["App setup<br/>Flask application<br/>[__init__.py]"]
  node_extensions["Extensions<br/>[extensiones.py]"]
end

subgraph group_web["HTTP and UI"]
  node_auth_routes["Authentication<br/>route controller<br/>[autenticacion.py]"]
  node_domain_routes["Role and domain routes<br/>route controllers<br/>[administrador.py]"]
  node_seller_documents["Seller documents<br/>route controllers"]
  node_templates["Server-rendered UI<br/>Bootstrap templates"]
end

subgraph group_domain["Business domain"]
  node_authorization["Identity and access control<br/>user, role, permission models<br/>[usuario.py]"]
  node_auth_decorators["Authorization decorators<br/>route guards<br/>[decoradores.py]"]
  node_catalog["Catalog and suppliers<br/>product master data<br/>[producto.py]"]
  node_pricing["Sale pricing<br/>price history"]
  node_quotations["Quotations<br/>quotation aggregate<br/>[cotizacion.py]"]
  node_sales["Sales and receipts<br/>sales aggregate<br/>[venta.py]"]
end

subgraph group_data["Persistence and audit"]
  node_database[("Neon PostgreSQL<br/>PostgreSQL database")]
  node_migrations["Schema migrations<br/>Flask-Migrate / Alembic"]
  node_audit["Operational audit<br/>operation and API logs"]
end

subgraph group_integrations["External services"]
  node_business_services{{"Document services<br/>Nubefact, email, PDF<br/>[nubefact.py]"}}
  node_external_apis{{"External API adapters<br/>image, geo, exchange APIs<br/>[apis_net.py]"}}
end

node_entry -->|"starts"| node_app_factory
node_app_factory -->|"initializes"| node_extensions
node_app_factory -->|"registers"| node_auth_routes
node_app_factory -->|"registers"| node_domain_routes
node_app_factory -->|"registers"| node_seller_documents
node_auth_routes -->|"authenticates"| node_authorization
node_domain_routes -->|"guards with"| node_auth_decorators
node_auth_decorators -->|"checks"| node_authorization
node_auth_routes -->|"renders"| node_templates
node_domain_routes -->|"renders"| node_templates
node_seller_documents -->|"renders"| node_templates
node_domain_routes -->|"manages"| node_catalog
node_domain_routes -->|"maintains"| node_pricing
node_seller_documents -->|"creates and updates"| node_quotations
node_seller_documents -->|"records"| node_sales
node_quotations -.->|"converts to"| node_sales
node_catalog -->|"persists"| node_database
node_authorization -->|"persists"| node_database
node_quotations -->|"persists"| node_database
node_sales -->|"persists"| node_database
node_migrations -->|"evolves schema"| node_database
node_domain_routes -.->|"records activity"| node_audit
node_seller_documents -->|"generates and sends"| node_business_services
node_business_services -.->|"logs API activity"| node_audit
node_domain_routes -->|"uses"| node_external_apis

click node_entry "https://github.com/cyam12/ropusac_2026/blob/main/run.py"
click node_app_factory "https://github.com/cyam12/ropusac_2026/blob/main/app/__init__.py"
click node_extensions "https://github.com/cyam12/ropusac_2026/blob/main/app/extensiones.py"
click node_auth_routes "https://github.com/cyam12/ropusac_2026/blob/main/app/rutas/autenticacion.py"
click node_domain_routes "https://github.com/cyam12/ropusac_2026/blob/main/app/rutas/administrador.py"
click node_seller_documents "https://github.com/cyam12/ropusac_2026/blob/main/app/rutas/cotizaciones_vendedor.py"
click node_authorization "https://github.com/cyam12/ropusac_2026/blob/main/app/modelos/usuario.py"
click node_auth_decorators "https://github.com/cyam12/ropusac_2026/blob/main/app/utilidades/decoradores.py"
click node_catalog "https://github.com/cyam12/ropusac_2026/blob/main/app/modelos/producto.py"
click node_pricing "https://github.com/cyam12/ropusac_2026/blob/main/app/modelos/historial_precio_venta.py"
click node_quotations "https://github.com/cyam12/ropusac_2026/blob/main/app/modelos/cotizacion.py"
click node_sales "https://github.com/cyam12/ropusac_2026/blob/main/app/modelos/venta.py"
click node_migrations "https://github.com/cyam12/ropusac_2026/blob/main/migrations/versions/0001_baseline_ropusac.py"
click node_audit "https://github.com/cyam12/ropusac_2026/blob/main/app/modelos/bitacora_operacion.py"
click node_business_services "https://github.com/cyam12/ropusac_2026/blob/main/app/servicios/nubefact.py"
click node_external_apis "https://github.com/cyam12/ropusac_2026/blob/main/app/servicios/apis_net.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_entry,node_app_factory,node_extensions toneBlue
class node_auth_routes,node_domain_routes,node_seller_documents,node_templates toneAmber
class node_authorization,node_auth_decorators,node_catalog,node_pricing,node_quotations,node_sales toneMint
class node_database,node_migrations,node_audit toneRose
class node_business_services,node_external_apis toneIndigo
```

## Components

### Flask runtime

- [Application entry](https://github.com/cyam12/ropusac_2026/blob/main/run.py): Python entry point · `run.py`
- [App setup](https://github.com/cyam12/ropusac_2026/blob/main/app/__init__.py): Flask application · Centralizes application initialization and extensions. · `app/__init__.py`
- [Extensions](https://github.com/cyam12/ropusac_2026/blob/main/app/extensiones.py): SQLAlchemy and Flask extensions · `app/extensiones.py`

### HTTP and UI

- [Authentication](https://github.com/cyam12/ropusac_2026/blob/main/app/rutas/autenticacion.py): route controller · `app/rutas/autenticacion.py`
- [Role and domain routes](https://github.com/cyam12/ropusac_2026/blob/main/app/rutas/administrador.py): route controllers · Administrator, commercial, seller, product, dashboard, and integration workflows. · `app/rutas/administrador.py`
- [Seller documents](https://github.com/cyam12/ropusac_2026/blob/main/app/rutas/cotizaciones_vendedor.py): route controllers · Quotation and receipt workflows for sellers. · `app/rutas/cotizaciones_vendedor.py`
- **Server-rendered UI**: Bootstrap templates

### Business domain

- [Identity and access control](https://github.com/cyam12/ropusac_2026/blob/main/app/modelos/usuario.py): user, role, permission models · `app/modelos/usuario.py`
- [Authorization decorators](https://github.com/cyam12/ropusac_2026/blob/main/app/utilidades/decoradores.py): route guards · `app/utilidades/decoradores.py`
- [Catalog and suppliers](https://github.com/cyam12/ropusac_2026/blob/main/app/modelos/producto.py): product master data · Products, suppliers, images, imports, and price history. · `app/modelos/producto.py`
- [Sale pricing](https://github.com/cyam12/ropusac_2026/blob/main/app/modelos/historial_precio_venta.py): price history · `app/modelos/historial_precio_venta.py`
- [Quotations](https://github.com/cyam12/ropusac_2026/blob/main/app/modelos/cotizacion.py): quotation aggregate · Quotation lines and status history. · `app/modelos/cotizacion.py`
- [Sales and receipts](https://github.com/cyam12/ropusac_2026/blob/main/app/modelos/venta.py): sales aggregate · Sales, line items, and electronic receipts. · `app/modelos/venta.py`

### Persistence and audit

- **Neon PostgreSQL**: PostgreSQL database
- [Schema migrations](https://github.com/cyam12/ropusac_2026/blob/main/migrations/versions/0001_baseline_ropusac.py): Flask-Migrate / Alembic · `migrations/versions/0001_baseline_ropusac.py`
- [Operational audit](https://github.com/cyam12/ropusac_2026/blob/main/app/modelos/bitacora_operacion.py): operation and API logs · `app/modelos/bitacora_operacion.py`

### External services

- [Document services](https://github.com/cyam12/ropusac_2026/blob/main/app/servicios/nubefact.py): Nubefact, email, PDF · Electronic invoicing, email delivery, and quotation PDFs. · `app/servicios/nubefact.py`
- [External API adapters](https://github.com/cyam12/ropusac_2026/blob/main/app/servicios/apis_net.py): image, geo, exchange APIs · `app/servicios/apis_net.py`

## Connections

- Application entry → App setup: starts
- App setup → Extensions: initializes
- App setup → Authentication: registers
- App setup → Role and domain routes: registers
- App setup → Seller documents: registers
- Authentication → Identity and access control: authenticates
- Role and domain routes → Authorization decorators: guards with
- Authorization decorators → Identity and access control: checks
- Authentication → Server-rendered UI: renders
- Role and domain routes → Server-rendered UI: renders
- Seller documents → Server-rendered UI: renders
- Role and domain routes → Catalog and suppliers: manages
- Role and domain routes → Sale pricing: maintains
- Seller documents → Quotations: creates and updates
- Seller documents → Sales and receipts: records
- Quotations → Sales and receipts: converts to
- Catalog and suppliers → Neon PostgreSQL: persists
- Identity and access control → Neon PostgreSQL: persists
- Quotations → Neon PostgreSQL: persists
- Sales and receipts → Neon PostgreSQL: persists
- Schema migrations → Neon PostgreSQL: evolves schema
- Role and domain routes → Operational audit: records activity
- Seller documents → Document services: generates and sends
- Document services → Operational audit: logs API activity
- Role and domain routes → External API adapters: uses
