# tgt073/tfg architecture

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

- Interactive diagram: https://gitdiagram.com/tgt073/tfg
- Repository: https://github.com/tgt073/tfg

## Overview

##### Project Type and Purpose
- This is a full‑stack web application (“TFG”) that provides movie recommendations.
- Backend: Python + Flask, several recommendation‑engine modules.
- Frontend: Jinja2 templates + static assets (CSS, images).
- Persistence: two SQLite databases (movies_genre.db, users.db).
- Auxiliary scripts: Evaluacion.py and ProbarSVD.py for evaluating algorithms offline.

##### Top‑Level Components
A. Web Client (Browser)
- Renders HTML from `templates/` (index.html, login.html, dashboard.html, movie_detail.html, search_results.html, registrer.html).
- Loads static assets from `static/style.css` and `static/imgs/`.

B. Flask Application (app2.py)
- Entry point: defines routes (`/`, `/login`, `/register`, `/dashboard`, `/movie/<id>`, `/search`, etc.).
- Uses Flask, Jinja2, and SQLite (`sqlite3` or an ORM).
- Imports recommendation modules from `RecomendadoresPruebas/`.
- Manages user sessions and form submissions.

C. Recommendation Engine Modules (`RecomendadoresPruebas/`)
- Contenido.py – Content‑based filtering.
- Items.py – Item‑based collaborative filtering.
- Usuarios.py – User‑based collaborative filtering.
- Modelo.py – Core model utilities (data loading, similarity metrics).
- Hybrid.py – Combines results from multiple recommenders.

D. Databases (`database/`)
- movies_genre.db – movie metadata, genres.
- users.db – user profiles, ratings.

E. Evaluation & Experimentation Scripts
- Evaluacion.py – runs offline tests, computes accuracy metrics.
- ProbarSVD.py – tests SVD‑based recommender performance.

F. Configuration & Dependencies
- `.env` – environment variables (e.g. Flask secret key, DB paths).
- requirements.txt – Flask, Jinja2, numpy, pandas, scikit‑learn, etc.
- `.gitattributes`, `.idea` (IDE settings).

##### Relationships & Data Flows
1. User action in Browser → HTTP request to Flask (app2.py).
2. Flask route handler → queries SQLite DB (users.db or movies_genre.db).
3. For recommendations, route calls one or more functions in RecomendadoresPruebas modules:
– e.g. `Usuarios.get_recommendations(user_id)` or
`Hybrid.combine([...])`.
4. Modules in `RecomendadoresPruebas` → internally load data from DB via Modelo.py utilities.
5. Recommendation results returned to Flask → passed into Jinja2 templates → rendered HTML.
6. Static assets served alongside HTML.
7. Evaluation scripts (`Evaluacion.py`, `ProbarSVD.py`) run offline: import modules from `RecomendadoresPruebas`, load DBs, output metrics to console or files.

##### Execution Flow (Numbered Sequence)
1. User navigates to `/login` → app2.py renders `templates/login.html`.
2. On login POST → app2.py validates against `users.db`.
3. Successful login → redirect to `/dashboard`.
4. app2.py calls `Hybrid.recommend_for(user_id)` → internally calls Contenido, Items, Usuarios modules → each loads data via Modelo → queries DBs.
5. Combined recommendations returned → passed to `dashboard.html`.
6. User clicks on a movie → GET `/movie/<id>` → app2.py loads details from `movies_genre.db` → renders `movie_detail.html`.
7. Search flow similarly handled via a search route + `search_results.html`.

##### Bringing It All Together
- Sketch four horizontal layers:
1. Client Layer (Browser)
2. Presentation Layer (Flask/app2.py + templates + static)
3. Business Logic Layer (RecomendadoresPruebas modules)
4. Data Layer (SQLite DBs)

- Captures every folder and file in this version of the repo.
- Shows module interactions, data flows, and DB connections.
- Highlights external libraries and configuration.
- Illustrates both the runtime web‑app flow and the offline evaluation processes.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Client Layer"
        Browser["Browser"]:::client
        Templates["templates/"]:::client
        StaticCSS["static/style.css"]:::static
        StaticImgs["static/imgs/"]:::static
    end

    subgraph "Presentation Layer"
        App["app2.py"]:::presentation
        Env[".env"]:::presentation
        Req["requirements.txt"]:::presentation
        Gitattributes[".gitattributes"]:::presentation
        Idea[".idea"]:::presentation
        Readme["README.md"]:::presentation
    end

    subgraph "Business Logic Layer"
        subgraph "RecomendadoresPruebas/"
            Contenido["Contenido.py"]:::business
            Items["Items.py"]:::business
            Usuarios["Usuarios.py"]:::business
            Modelo["Modelo.py"]:::business
            Hybrid["Hybrid.py"]:::business
        end
    end

    subgraph "Data Layer"
        DB1["movies_genre.db"]:::data
        DB2["users.db"]:::data
    end

    subgraph "Offline Evaluation"
        Eval["Evaluacion.py"]:::eval
        SVD["ProbarSVD.py"]:::eval
    end

    Browser -->|"HTTPRequest"| App
    App -->|"renders"| Templates
    App -->|"serves"| StaticCSS
    App -->|"serves"| StaticImgs
    App -->|"callsImport"| Contenido
    App -->|"callsImport"| Items
    App -->|"callsImport"| Usuarios
    App -->|"callsImport"| Hybrid
    Contenido -->|"uses"| Modelo
    Items -->|"uses"| Modelo
    Usuarios -->|"uses"| Modelo
    Hybrid -->|"combinesResults"| Contenido
    Hybrid -->|"combinesResults"| Items
    Hybrid -->|"combinesResults"| Usuarios
    App -->|"query_user_ratings()"| DB2
    App -->|"query_movie_data()"| DB1
    Modelo -->|"loadsData"| DB1
    Modelo -->|"loadsData"| DB2
    Eval -->|"importsModules"| Contenido
    Eval -->|"importsModules"| Items
    Eval -->|"importsModules"| Usuarios
    Eval -->|"importsModules"| Hybrid
    Eval -->|"readsDB"| DB1
    Eval -->|"readsDB"| DB2
    SVD -->|"importsModel"| Modelo
    SVD -->|"readsDB"| DB1

    click Templates "https://github.com/tgt073/tfg/tree/main/templates/"
    click StaticCSS "https://github.com/tgt073/tfg/blob/main/static/style.css"
    click StaticImgs "https://github.com/tgt073/tfg/tree/main/static/imgs/"
    click App "https://github.com/tgt073/tfg/blob/main/app2.py"
    click RecomendadoresPruebas "https://github.com/tgt073/tfg/tree/main/RecomendadoresPruebas/"
    click Contenido "https://github.com/tgt073/tfg/blob/main/RecomendadoresPruebas/Contenido.py"
    click Items "https://github.com/tgt073/tfg/blob/main/RecomendadoresPruebas/Items.py"
    click Usuarios "https://github.com/tgt073/tfg/blob/main/RecomendadoresPruebas/Usuarios.py"
    click Modelo "https://github.com/tgt073/tfg/blob/main/RecomendadoresPruebas/Modelo.py"
    click Hybrid "https://github.com/tgt073/tfg/blob/main/RecomendadoresPruebas/Hybrid.py"
    click DB1 "https://github.com/tgt073/tfg/blob/main/database/movies_genre.db"
    click DB2 "https://github.com/tgt073/tfg/blob/main/database/users.db"
    click Eval "https://github.com/tgt073/tfg/blob/main/Evaluacion.py"
    click SVD "https://github.com/tgt073/tfg/blob/main/ProbarSVD.py"
    click Env "https://github.com/tgt073/tfg/blob/main/.env"
    click Req "https://github.com/tgt073/tfg/blob/main/requirements.txt"
    click Gitattributes "https://github.com/tgt073/tfg/blob/main/.gitattributes"
    click Idea "https://github.com/tgt073/tfg/blob/main/.idea"
    click Readme "https://github.com/tgt073/tfg/blob/main/README.md"

    classDef client fill:#cfc,stroke:#393
    classDef presentation fill:#ccf,stroke:#339
    classDef business fill:#fc8,stroke:#f60
    classDef data fill:#ccf,stroke:#369
    classDef static fill:#ddd,stroke:#999
    classDef eval stroke-dasharray:5 5,fill:#f9f,stroke:#f66
```
