# das1204/a-test-assignment-for-the-ddpp architecture

> Architecture diagram of the GitHub repository das1204/a-test-assignment-for-the-ddpp, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/das1204/a-test-assignment-for-the-ddpp
- Repository: https://github.com/das1204/a-test-assignment-for-the-ddpp

## Overview

##### Main Components
- Data Acquisition & External Services:
- The backend, when launched via app.py, automatically fetches data from external sources such as the official Росстат site (for CPI) and the Bank of Russia (for the key rate and USD exchange rate).
- Web Server / Backend:
- The core application logic resides in files like app.py and functions.py. This is where the routing happens (e.g., the main page “/” and the forecast page “/forecast”) and where external data is integrated.
- Machine Learning Models and Forecasting Engine:
- The “models” directory contains several pre-trained ML models (stored as .pkl files) along with exploratory analysis and testing notebooks (inside models/code). These models are used to predict CPI for six months along with confidence intervals.
- Visualization and Frontend:
- The “static” directory holds interactive HTML graphs and CSS, indicating that Plotly is used for producing interactive charts. The “templates” directory contains HTML templates (base.html, main.html, forecast.html) for rendering the website pages.
- Containerization:
- The Dockerfile encapsulates the entire application, ensuring that all dependencies (as seen in requirements.txt) are installed and the correct Python version is used.

##### Relationships and Interactions
- Data Flow starts from fetching external data -> preprocessing within the backend (functions.py) -> feeding data into ML models -> producing forecasts with confidence intervals -> interactive visualization via Plotly on the web pages.
- The web frontend (HTML templates + static files) interacts with the backend endpoints provided through Flask (or a similar framework, as hinted by the file structure).
- The ML components operate as part of the backend service. The routing in app.py triggers ML inference, and results are passed to the templates for plotting.
- Docker acts as a container that packages the entire flow: data acquisition, backend logic, model inference, and the frontend display.

##### Architectural Patterns and Technologies
- The application follows a typical MVC-like separation:
- “Models”: Pre-built machine learning models and analysis notebooks.
- “Views”: HTML templates in the “templates” directory paired with static assets (CSS, JavaScript/Plotly HTML) in the “static” directory.
- “Controller”: The Python scripts (app.py, functions.py) coordinate data fetching, model predictions, and rendering web pages.
- Technologies:
- Python (>=3.9) forms the backbone.
- Plotly is used for interactive graphs.
- ML libraries include scikit-learn, xgboost, etc., indicated in the README.
- Docker containerization is leveraged for consistency and deployments.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Data Sources
    subgraph "External Data Sources"
        RS["Rosstat Official CPI"]:::externalService
        BoB["Bank of Russia (KeyRate&USDExchange)"]:::externalService
    end

    %% Docker Container encapsulating internal components
    subgraph "Docker Container"
        %% Backend Controller (Flask App)
        subgraph "Backend Controller (Flask App)"
            AP["app.py"]:::backend
            FUNC["functions.py"]:::backend
        end
        
        %% Machine Learning Prediction Engine
        subgraph "Machine Learning Prediction Engine"
            %% Pre-trained ML Models
            subgraph "Pre-trained ML Models"
                M1["01.pkl"]:::ml
                M2["02.pkl"]:::ml
                M3["03.pkl"]:::ml
                M4["03.pkl"]:::ml
            end
            %% ML Analysis Notebooks
            subgraph "ML Analysis Notebooks"
                N1["01.ipynb"]:::analysis
                N2["02.ipynb"]:::analysis
                N3["03.ipynb"]:::analysis
                N4["04.ipynb"]:::analysis
            end
        end
        
        %% Frontend Visualization (Interactive Visualization via Plotly)
        subgraph "Interactive Visualization (Plotly)"
            subgraph "Templates"
                T1["base.html"]:::frontend
                T2["forecast.html"]:::frontend
                T3["main.html"]:::frontend
            end
            subgraph "Static Assets"
                CSS["main.css"]:::frontend
            end
        end
        
        %% Dockerfile for containerization
        D["Dockerfile"]:::docker
    end

    %% Data Flow Connections
    RS -->|"fetch_data"| AP
    BoB -->|"fetch_data"| AP
    AP -->|"process_data"| FUNC
    AP -->|"trigger_forecast"| M1
    M1 -->|"forecast_result"| AP
    AP -->|"render_template"| T1
    AP -->|"render_template"| T2
    AP -->|"render_template"| T3
    AP -->|"serve_static"| CSS

    %% Click Events
    click AP "https://github.com/das1204/a-test-assignment-for-the-ddpp/blob/main/app.py"
    click FUNC "https://github.com/das1204/a-test-assignment-for-the-ddpp/blob/main/functions.py"
    click M1 "https://github.com/das1204/a-test-assignment-for-the-ddpp/blob/main/models/01.pkl"
    click M2 "https://github.com/das1204/a-test-assignment-for-the-ddpp/blob/main/models/02.pkl"
    click M3 "https://github.com/das1204/a-test-assignment-for-the-ddpp/blob/main/models/03.pkl"
    click M4 "https://github.com/das1204/a-test-assignment-for-the-ddpp/blob/main/models/04.pkl"
    click N1 "https://github.com/das1204/a-test-assignment-for-the-ddpp/blob/main/models/code/01.ipynb"
    click N2 "https://github.com/das1204/a-test-assignment-for-the-ddpp/blob/main/models/code/02.ipynb"
    click N3 "https://github.com/das1204/a-test-assignment-for-the-ddpp/blob/main/models/code/03.ipynb"
    click N4 "https://github.com/das1204/a-test-assignment-for-the-ddpp/blob/main/models/code/04.ipynb"
    click T1 "https://github.com/das1204/a-test-assignment-for-the-ddpp/blob/main/templates/base.html"
    click T2 "https://github.com/das1204/a-test-assignment-for-the-ddpp/blob/main/templates/forecast.html"
    click T3 "https://github.com/das1204/a-test-assignment-for-the-ddpp/blob/main/templates/main.html"
    click CSS "https://github.com/das1204/a-test-assignment-for-the-ddpp/blob/main/static/css/main.css"
    click D "https://github.com/das1204/a-test-assignment-for-the-ddpp/tree/main/Dockerfile"

    %% Styles
    classDef externalService fill:#ffcc00,stroke:#000,stroke-width:2px;
    classDef backend fill:#66ccff,stroke:#000,stroke-width:2px;
    classDef ml fill:#ccff99,stroke:#000,stroke-width:2px;
    classDef analysis fill:#aaffaa,stroke:#000,stroke-width:2px;
    classDef frontend fill:#ff9999,stroke:#000,stroke-width:2px;
    classDef docker fill:#cccccc,stroke:#000,stroke-width:2px;
```
