# lolagj/tfm-sistema-riego-agricola architecture

> Architecture diagram of the GitHub repository lolagj/tfm-sistema-riego-agricola, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-11-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/lolagj/tfm-sistema-riego-agricola
- Repository: https://github.com/lolagj/tfm-sistema-riego-agricola

## Overview

##### Project type and purpose
- This is a full-stack Machine Learning prototype for agricultural irrigation decision support in Andalusia.
- It trains an XGBoost model on agro-climatic data (RIA), versions data/models with DVC, tracks experiments in MLflow, and serves predictions via a Streamlit web UI.

##### File structure
- Top level:
- app.py – Streamlit entry point (frontend).
- src/transform_input.py – input-processing module (backend logic).
- data/ – DVC-managed folders (raw, processed, final).
- notebooks/ – exploratory, preprocessing, modeling notebooks and saved artifacts (.joblib).
- .devcontainer/ – dev environment settings.
- requirements.txt
- DVC config under .dvc outlines remote storage and data versions.
- MLflow isn’t in file tree but is mentioned in README—assume an MLflow tracking server.

##### README for additional insights
- Data source: RIA API (external service).
- Workflow: data collection → cleaning & feature engineering → model training (XGBoost) → model packaging → Streamlit app.
- Technologies: Python, Pandas, scikit-learn, XGBoost, DVC, MLflow, Streamlit.

##### Detail without over-complexity
- Folders (raw, processed, final) as distinct stages in the pipeline.
- Both notebooks (R&D) and production code (src) to demonstrate transition from exploration to deployment.
- DVC and MLflow as first-class architectural blocks, not footnotes.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Sources and Users
    API["RIA API"]:::external
    user["Users (Browser)"]:::external

    %% Data Layer
    subgraph "Data Layer"
        raw["data/raw"]:::storage
        processed["data/processed"]:::storage
        final["data/final"]:::storage
        demo["data/demo_app/df_demo.csv"]:::storage
    end

    %% Data Processing Layer (R&D)
    subgraph "Data Processing Layer (R&D)"
        notebooks1["Comprensión de los datos"]:::compute
        notebooks2["preparacion_datos"]:::compute
    end

    %% Modeling Layer
    subgraph "Modeling Layer"
        train_nb["Modelo.ipynb"]:::compute
        model_art["XGBoost_modelo_final.joblib"]:::storage
        mlflow_client["MLflow Client"]:::service
        mlflow_server["MLflow Server"]:::service
    end

    %% Serving Layer
    subgraph "Serving Layer"
        app["app.py (Streamlit)"]:::app
        transform["src/transform_input.py"]:::compute
    end

    %% Versioning & Tracking
    subgraph "Versioning & Tracking"
        dvc_config[".dvc/config"]:::service
        dvc_ignore[".dvcignore"]:::service
        git["Git Repository"]:::service
    end

    %% Developer Environment
    dev[".devcontainer/devcontainer.json"]:::service

    %% Data Flows
    API -->|"CSV via DVC pull"| raw
    raw -->|"Cleaning & FE"| processed
    processed -->|"Train XGBoost"| train_nb
    train_nb -->|artifact.joblib| model_art
    train_nb -->|"logs metrics"| mlflow_client
    mlflow_client -->|"REST API"| mlflow_server
    model_art -->|"DVC push"| final

    %% Demo Data Usage
    demo -->|"example input"| app

    %% Serving Flows
    user -->|"HTTP request"| app
    app -->|"calls"| transform
    app -->|"loads model.joblib"| final

    %% Versioning & Tracking Flows
    raw -->|"tracked by DVC"| dvc_config
    processed -->|"tracked by DVC"| dvc_config
    final -->|"tracked by DVC"| dvc_config
    notebooks1 -->|"versioned"| git
    notebooks2 -->|"versioned"| git
    train_nb -->|"versioned"| git
    app -->|"versioned"| git
    transform -->|"versioned"| git

    %% Dev Container
    git --> dev

    %% Click Events
    click raw "https://github.com/lolagj/tfm-sistema-riego-agricola/tree/main/data/raw/"
    click processed "https://github.com/lolagj/tfm-sistema-riego-agricola/tree/main/data/processed/"
    click final "https://github.com/lolagj/tfm-sistema-riego-agricola/tree/main/data/final/"
    click demo "https://github.com/lolagj/tfm-sistema-riego-agricola/blob/main/data/demo_app/df_demo.csv"
    click notebooks1 "https://github.com/lolagj/tfm-sistema-riego-agricola/tree/main/notebooks/Comprensión de los datos/"
    click notebooks2 "https://github.com/lolagj/tfm-sistema-riego-agricola/tree/main/notebooks/preparacion_datos/"
    click train_nb "https://github.com/lolagj/tfm-sistema-riego-agricola/blob/main/notebooks/modelado/Modelo.ipynb"
    click model_art "https://github.com/lolagj/tfm-sistema-riego-agricola/blob/main/notebooks/modelado/XGBoost_modelo_final.joblib"
    click app "https://github.com/lolagj/tfm-sistema-riego-agricola/blob/main/app.py"
    click transform "https://github.com/lolagj/tfm-sistema-riego-agricola/blob/main/src/transform_input.py"
    click dvc_config "https://github.com/lolagj/tfm-sistema-riego-agricola/tree/main/.dvc/config"
    click dvc_ignore "https://github.com/lolagj/tfm-sistema-riego-agricola/blob/main/.dvcignore"
    click dev "https://github.com/lolagj/tfm-sistema-riego-agricola/blob/main/.devcontainer/devcontainer.json"

    %% Styles
    classDef external fill:#90cdf4,stroke:#3182ce,color:#1a365d;
    classDef storage fill:#f6e05e,stroke:#dd6b20,color:#4a1b00;
    classDef compute fill:#faf089,stroke:#d69e2e,color:#744210;
    classDef service fill:#c6f6d5,stroke:#38a169,color:#1f3d15;
    classDef app fill:#feb2b2,stroke:#e53e3e,color:#63171b;
```
