# dagus21/proyecto_apg architecture

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

- Interactive diagram: https://gitdiagram.com/dagus21/proyecto_apg
- Repository: https://github.com/dagus21/proyecto_apg

## Overview

##### Project type and purpose
- Proyecto APG is a monolithic, full-stack web application built with Flask.
- Purpose: Provide modular, reusable authentication features (login, registration, email verification, password recovery).

##### High-level file-structure analysis
- **app.py**: Main Flask application entrypoint. Likely registers Blueprints for each feature.
- **Clases_Base/**: Core data-access layer (DB connection & generic CRUD for user details).
- **Gestion_y_Autenticacion_Login/**: Blueprint handling login, registration, change-password and email verification. Contains its own `main.py`, business logic (`GestionLogin.py`), static assets, templates, and tests.
- **Recuperacion_y_Cambio_Contrasena/**: Blueprint for password recovery and reset. Includes `main.py`, helpers, templates, and tests.
- **Front/** + **static/** + **templates/**: Shared CSS, JS, and base/layout HTML templates used across all modules.
- **log.py**: Centralized logging setup (outputs to `APG.log` or `sistema.log`).
- **.env** & **requirements.txt**: Environment and dependency definitions.
- **tests** & **allure-results**: Pytest test suites and Allure reports (not part of runtime, but useful to show CI/testing layer).

##### Key README insights
- Modular, “feature-oriented” architecture. Each major function (login, recovery) is a self-contained Flask Blueprint with its own assets & tests.
- Uses Flask, SQLAlchemy (via psycopg2), bcrypt for password hashing, flask-mail for email, pytest + allure-pytest for testing & reporting.

##### Main components
a. Client Layer
- Web browser (end user)
- Delivers HTTP(S) requests, renders HTML/CSS/JS
b. Presentation/Web Layer
- Flask App (app.py)
- Blueprints:
– Gestion_y_Autenticacion_Login
– Recuperacion_y_Cambio_Contrasena
- Shared Front assets (Front/, static/, templates/)
c. Business Logic Layer
- GestionLogin.py & helpers.py (module-specific controllers/services)
- Clases_Base (Conexion_Data_Base, Crud_Usuario_Detalle)
- log.py for logging events
d. Data Layer
- PostgreSQL (accessed via SQLAlchemy/psycopg2)
e. External Services
- SMTP Mail Server (flask-mail) for verification & recovery emails
- Optional: CI/Test Runner producing Allure reports

##### Relationships & data flows
- Browser → Flask App (HTTP request)
- Flask App routes to correct Blueprint → invokes module controller (`main.py` → `GestionLogin` or `helpers`)
- Controller → Clases_Base → SQLAlchemy → PostgreSQL (DB queries)
- Controller → flask-mail → SMTP (send email)
- Controller → Renders Jinja2 templates → returns HTML to browser
- log.py intercepts key events → writes to log files
- pytest runners → exercise each module’s tests → produce Allure JSON → served by Allure UI

##### Architectural patterns & design principles
- Modular/Feature-Oriented: each functional area is a self-contained Blueprint.
- Layered Architecture: Presentation (Flask + static/templates) → Business Logic (controllers, services) → Data Access (Clases_Base) → Data Store (PostgreSQL).
- Separation of Concerns:
- Static vs. Template assets separated per module & shared layer.
- Tests co-located with modules.
- Logging abstracted to log.py.
- Reusability: Common templates and static files in `Front/`, `static/`, `templates/`.

##### Detail level
- Reusable modules: Front, static, templates
- Tests & CI only if diagramming testing architecture (optional inset)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    Browser["Web Browser"]:::client

    %% Web & Presentation Layer
    subgraph "Web & Presentation Layer"
        App["app.py\n(Flask App)"]:::web
        subgraph "Gestion_y_Autenticacion_Login"
            GLoginMain["main.py\n(Blueprint Routes)"]:::web
            GLoginLogic["GestionLogin.py\n(Business Logic)"]:::biz
            GLoginStatic["static/"]:::asset
            GLoginTemplates["templates/"]:::asset
        end
        subgraph "Recuperacion_y_Cambio_Contrasena"
            RecMain["main.py\n(Blueprint Routes)"]:::web
            RecHelpers["helpers.py\n(Services)"]:::biz
            RecTemplates["templates/"]:::asset
        end
        FrontAssets["Front/\n(Shared CSS & Templates)"]:::asset
        StaticGlobal["static/\n(Global Static Assets)"]:::asset
        TemplatesGlobal["templates/\n(Global Templates)"]:::asset
    end

    %% Business Logic & Data Access Layer
    subgraph "Business Logic & Data Access Layer"
        ClasesBase["Clases_Base/"]:::data
        ConnDB["Conexion_Data_Base.py"]:::data
        CrudUser["Crud_Usuario_Detalle.py"]:::data
        LogModule["log.py"]:::biz
    end

    %% Data Layer & External Services
    subgraph "Data Layer & External Services"
        Postgres["PostgreSQL"]:::storage
        SMTP["SMTP Mail Server"]:::external
    end

    %% Connections
    Browser -->|"HTTP(S) Request"| App
    App -->|"routes to"| GLoginMain
    App -->|"routes to"| RecMain
    App -->|"serves assets/templates"| FrontAssets
    App -->|"serves assets/templates"| StaticGlobal
    App -->|"serves assets/templates"| TemplatesGlobal
    App -->|"logging calls"| LogModule

    GLoginMain -->|"calls"| GLoginLogic
    GLoginLogic -->|"queries via SQLAlchemy"| ConnDB
    ConnDB -->|"connects to"| Postgres
    GLoginLogic -->|"sends email via"| SMTP
    GLoginMain -->|"renders templates"| GLoginTemplates
    GLoginMain -->|"serves static"| GLoginStatic

    RecMain -->|"calls"| RecHelpers
    RecHelpers -->|"queries via SQLAlchemy"| ConnDB
    RecHelpers -->|"sends email via"| SMTP
    RecMain -->|"renders templates"| RecTemplates

    LogModule -->|"writes to"| LogModule

    %% Click Events
    click App "https://github.com/dagus21/proyecto_apg/blob/main/app.py"
    click GLoginMain "https://github.com/dagus21/proyecto_apg/blob/main/Gestion_y_Autenticacion_Login/main.py"
    click GLoginLogic "https://github.com/dagus21/proyecto_apg/blob/main/Gestion_y_Autenticacion_Login/GestionLogin.py"
    click GLoginStatic "https://github.com/dagus21/proyecto_apg/tree/main/Gestion_y_Autenticacion_Login/static/"
    click GLoginTemplates "https://github.com/dagus21/proyecto_apg/tree/main/Gestion_y_Autenticacion_Login/templates/"
    click RecMain "https://github.com/dagus21/proyecto_apg/blob/main/Recuperacion_y_Cambio_Contrasena/main.py"
    click RecHelpers "https://github.com/dagus21/proyecto_apg/blob/main/Recuperacion_y_Cambio_Contrasena/helpers.py"
    click RecTemplates "https://github.com/dagus21/proyecto_apg/tree/main/Recuperacion_y_Cambio_Contrasena/templates/"
    click ConnDB "https://github.com/dagus21/proyecto_apg/blob/main/Clases_Base/Conexion_Data_Base.py"
    click CrudUser "https://github.com/dagus21/proyecto_apg/blob/main/Clases_Base/Crud_Usuario_Detalle.py"
    click FrontAssets "https://github.com/dagus21/proyecto_apg/tree/main/Front/"
    click StaticGlobal "https://github.com/dagus21/proyecto_apg/tree/main/static/"
    click TemplatesGlobal "https://github.com/dagus21/proyecto_apg/tree/main/templates/"
    click LogModule "https://github.com/dagus21/proyecto_apg/blob/main/log.py"

    %% Styles
    classDef client fill:#D3BFFE,stroke:#6F42C1,color:#000;
    classDef web fill:#BEE3F8,stroke:#3182CE,color:#000;
    classDef biz fill:#FED7AA,stroke:#DD6B20,color:#000;
    classDef data fill:#C6F6D5,stroke:#38A169,color:#000;
    classDef storage fill:#9AE6B4,stroke:#2F855A,color:#000;
    classDef external fill:#E2E8F0,stroke:#A0AEC0,color:#000;
    classDef asset fill:#F0FFF4,stroke:#38A169,color:#000;
```
