# ldgss/laudos architecture

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

- Interactive diagram: https://gitdiagram.com/ldgss/laudos
- Repository: https://github.com/ldgss/laudos

## Overview

##### Project type and purpose
- This is a full‑stack, monolithic web application (“sistema de laudos”) built with Python and Flask.
- Its purpose is to manage “laudos” (reports) for mercadería and hojalata, including access control, blocking/unblocking, inventory, labeling, reporting, etc.

##### File structure
- Top‑level entrypoint: app.py
- “routes/” directory: each module is a controller (Flask blueprint) for one domain (acceso, mercaderia, hojalata, etc.).
- “models/” directory: each file encapsulates data access for a domain entity (mod_login, mod_reporte, mod_insumos, etc.).
- “static/” and “templates/”: frontend assets (CSS, JS, images, sound) and Jinja2 templates for each view.
- “db/db.py”: database connection logic (PostgreSQL via psycopg2 and/or SQL‑Server via msodbcsql).
- “utils/”: helpers and token utilities.
- Config/backups in “db/” and tests in “tests/”.

##### Extract README insights
- Stack: Python, Flask, PostgreSQL, SQL‑Server (via ODBC driver).
- Development: VS Code, Git branching strategy.

##### Components
a. Client Layer
- Web Browser
- Static assets: CSS, JavaScript, images, sounds
b. Web Server Layer
- Flask App (app.py)
- Blueprints/Routes (routes/*.py) – handle HTTP requests, authentication, authorization
- Template Engine (Jinja2) renders HTML
c. Business Logic Layer
- Models (models/*.py) – ORM/data‑access modules
- Utility modules (utils/helpers.py, utils/tokens.py)
d. Data Layer
- Primary Database: PostgreSQL
- External Data Source: SQL‑Server (ODBC driver msodbcsql)
- DB backups stored under “db/”
e. Infrastructure & Dev
- Version Control (Git)
- Local Dev Environment (VS Code, Python interpreter)

##### Relationships and interactions
- Browser → (HTTP GET/POST) → Flask Routes
- Routes → Models → Database(s)
- Models → (SQL via psycopg2/ODBC) → PostgreSQL / SQL‑Server
- Routes → Templates & Static → Browser
- Utilities invoked by controllers and models
- Tests hitting Routes/Models directly

##### Architectural patterns and design principles
- MVC (Model‑View‑Controller) separation
- Blueprint‑based modularization for domain separation
- Single codebase → monolith, no microservices
- Layered architecture: Presentation → Application → Data

##### Essential elements
- Client vs. Server vs. Database
- Internal modules vs. external services
- Callouts for special modules (e.g., utils/tokens for JWT or session management)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Layer
    subgraph "Client Layer"
        direction TB
        Browser["Web Browser"]:::client
        Static["Static Assets"]:::client
        Templates["Jinja2 Templates"]:::client
    end

    %% Web Server Layer
    subgraph "Web Server Layer"
        direction TB
        App["Flask App<br/>(app.py)"]:::server
        TemplateEngine["Template Engine<br/>(Jinja2)"]:::server
        subgraph "Blueprints / Routes"
            direction TB
            Index["routes/index.py"]:::server
            Login["routes/login.py"]:::server
            Acceso["routes/acceso.py"]:::server
            Errors["routes/errors.py"]:::server
            Mercaderia["routes/mercaderia.py"]:::server
            Hojalata["routes/hojalata.py"]:::server
            Bloqueos["routes/bloqueos.py"]:::server
            Reporte["routes/reporte.py"]:::server
            OtherRoutes["routes/*.py"]:::server
        end
    end

    %% Business Logic Layer
    subgraph "Business Logic Layer"
        direction TB
        subgraph "Models / Data Access"
            direction TB
            ModLogin["models/mod_login.py"]:::server
            ModAcceso["models/mod_acceso.py"]:::server
            ModMerc["models/mod_mercaderia.py"]:::server
            ModHoj["models/mod_hojalata.py"]:::server
            ModBloq["models/mod_bloqueos.py"]:::server
            ModRep["models/mod_reporte.py"]:::server
            ModInsumos["models/mod_insumos.py"]:::server
            ModMater["models/mod_materia.py"]:::server
            ModReac["models/mod_reacondicionado.py"]:::server
            ModAnu["models/mod_anulacion.py"]:::server
            ModCorr["models/mod_correccion.py"]:::server
            ModUbic["models/mod_ubicaciones.py"]:::server
            OtherModels["models/*.py"]:::server
        end
        subgraph "Utilities"
            direction TB
            Helpers["utils/helpers.py"]:::util
            Tokens["utils/tokens.py"]:::util
        end
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        DBConn["db/db.py"]:::data
        Postgres["PostgreSQL"]:::data
        SQLServer["SQL‑Server<br>(msodbcsql)"]:::data
        Backups["db backups"]:::data
        Driver["blob/msodbcsql.msi"]:::data
    end

    %% Infrastructure & Dev
    subgraph "Infrastructure & Dev"
        direction TB
        Git["Git (Version Control)"]:::infra
        VSCode["VS Code"]:::infra
        Requirements["requirements.txt"]:::infra
        Readme["README.md"]:::infra
        Gitignore[".gitignore"]:::infra
        Tests["tests/tests.py"]:::infra
    end

    %% Connections
    Browser -->|HTTP GET/POST| App
    Static --> Browser
    Templates --> Browser
    App -->|loads blueprints| Index
    App --> Login
    App --> Acceso
    App --> Errors
    App --> Mercaderia
    App --> Hojalata
    App --> Bloqueos
    App --> Reporte
    App --> OtherRoutes
    Index -->|calls| ModLogin
    Login -->|auth flows| ModLogin
    Acceso -->|access control| ModAcceso
    Mercaderia -->|CRUD| ModMerc
    Hojalata -->|CRUD| ModHoj
    Bloqueos -->|block/unblock| ModBloq
    Reporte -->|generate reports| ModRep
    OtherRoutes --> OtherModels

    %% Routes render templates/static
    Index -->|render| TemplateEngine
    Login -->|render| TemplateEngine
    Acceso -->|render| TemplateEngine
    Mercaderia -->|render| TemplateEngine
    Hojalata -->|render| TemplateEngine
    Bloqueos -->|render| TemplateEngine
    Reporte -->|render| TemplateEngine

    %% Models to DB
    ModLogin -->|SQL| DBConn
    OtherModels -->|SQL| DBConn
    ModAcceso --> DBConn
    ModMerc --> DBConn
    ModHoj --> DBConn
    ModBloq --> DBConn
    ModRep --> DBConn

    DBConn -->|psycopg2| Postgres
    DBConn -->|ODBC| SQLServer
    DBConn -->|backup/restore| Backups
    DBConn --> Driver

    %% Utilities usage
    Index --> Helpers
    Login --> Tokens
    ModLogin --> Helpers
    OtherModels --> Helpers

    %% Tests
    Tests -->|tests routes| Index
    Tests -->|tests models| ModLogin

    %% Infra interactions
    Git -.->|push/pull| App
    VSCode -.-> App
    VSCode -.-> OtherModels
    VSCode -.-> DBConn

    %% Click Events
    click Static "https://github.com/ldgss/laudos/tree/main/static/"
    click Templates "https://github.com/ldgss/laudos/tree/main/templates/"
    click App "https://github.com/ldgss/laudos/blob/main/app.py"
    click Index "https://github.com/ldgss/laudos/blob/main/routes/index.py"
    click Login "https://github.com/ldgss/laudos/blob/main/routes/login.py"
    click Acceso "https://github.com/ldgss/laudos/blob/main/routes/acceso.py"
    click Errors "https://github.com/ldgss/laudos/blob/main/routes/errors.py"
    click Mercaderia "https://github.com/ldgss/laudos/blob/main/routes/mercaderia.py"
    click Hojalata "https://github.com/ldgss/laudos/blob/main/routes/hojalata.py"
    click Bloqueos "https://github.com/ldgss/laudos/blob/main/routes/bloqueos.py"
    click Reporte "https://github.com/ldgss/laudos/blob/main/routes/reporte.py"
    click OtherRoutes "https://github.com/ldgss/laudos/tree/main/routes/"
    click ModLogin "https://github.com/ldgss/laudos/blob/main/models/mod_login.py"
    click ModAcceso "https://github.com/ldgss/laudos/blob/main/models/mod_acceso.py"
    click ModMerc "https://github.com/ldgss/laudos/blob/main/models/mod_mercaderia.py"
    click ModHoj "https://github.com/ldgss/laudos/blob/main/models/mod_hojalata.py"
    click ModBloq "https://github.com/ldgss/laudos/blob/main/models/mod_bloqueos.py"
    click ModRep "https://github.com/ldgss/laudos/blob/main/models/mod_reporte.py"
    click ModInsumos "https://github.com/ldgss/laudos/blob/main/models/mod_insumos.py"
    click ModMater "https://github.com/ldgss/laudos/blob/main/models/mod_materia.py"
    click ModReac "https://github.com/ldgss/laudos/blob/main/models/mod_reacondicionado.py"
    click ModAnu "https://github.com/ldgss/laudos/blob/main/models/mod_anulacion.py"
    click ModCorr "https://github.com/ldgss/laudos/blob/main/models/mod_correccion.py"
    click ModUbic "https://github.com/ldgss/laudos/blob/main/models/mod_ubicaciones.py"
    click OtherModels "https://github.com/ldgss/laudos/tree/main/models/"
    click Helpers "https://github.com/ldgss/laudos/blob/main/utils/helpers.py"
    click Tokens "https://github.com/ldgss/laudos/blob/main/utils/tokens.py"
    click DBConn "https://github.com/ldgss/laudos/blob/main/db/db.py"
    click Backups "https://github.com/ldgss/laudos/tree/main/db/db backup 20241120/"
    click Driver "https://github.com/ldgss/laudos/blob/main/blob/msodbcsql.msi"
    click Tests "https://github.com/ldgss/laudos/blob/main/tests/tests.py"
    click Requirements "https://github.com/ldgss/laudos/blob/main/requirements.txt"
    click Readme "https://github.com/ldgss/laudos/blob/main/README.md"
    click Gitignore "https://github.com/ldgss/laudos/blob/main/.gitignore"

    %% Styles
    classDef client fill:#D0E6FF,stroke:#0366d6,color:#0366d6
    classDef server fill:#DFFFE0,stroke:#28a745,color:#155724
    classDef data fill:#FFF5B1,stroke:#DAA520,color:#8B4513
    classDef util fill:#EDEDED,stroke:#6a737d,color:#24292e
    classDef infra fill:#F0F0F0,stroke:#444,color:#555
```
