# leoulgirma/scrape-exchange-rates architecture

> Architecture diagram of the GitHub repository leoulgirma/scrape-exchange-rates, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-02-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/leoulgirma/scrape-exchange-rates
- Repository: https://github.com/leoulgirma/scrape-exchange-rates

## Overview

##### Main Components
- Data Scraper Module: Components like currency_scraper.py and get-rate.py are responsible for fetching and/or updating exchange rate data.
- Database Layer: The SQLite database (currency_exchange.db), along with db_setup.py, read.py, and write.py, represent the data persistence layer. This layer handles storing, updating, and retrieving the exchange rate data.
- API/Backend: The Flask API application (app.py) serves as the entry point for accessing the statistics derived from the stored data.
- Data Processing/Visualization: Scripts like exchange_rate_plot.py, rate_plotly.py, and possibly CurrencyExchange.py seem designed for processing data or generating visualizations (with tables.html as a possible rendered output).

##### Relationships & Interactions
- The Data Scraper fetches exchange rate information from external sources and writes these values into the SQLite database.
- The Database Layer is interfaced both by the scraper (writing/updating data) and by the backend API (reading data to expose endpoints with statistics).
- The API layer (Flask in app.py) retrieves data from the SQLite database when endpoints are called, likely processing data or calling visualization scripts to generate statistics.
- Visualization scripts might be invoked internally by the API or as standalone scripts to generate data plots or HTML tables that display trends or statistics.

##### Architectural Patterns & Design Principles
- Modular Separation: Each major functionality (data scraping, database management, API presentation, and visualization) is separated by individual scripts. This design promotes simplicity and clarity.
- RESTful API Design: The Flask application is set up as an API endpoint that provides access to various statistics about exchange rates.
- Lightweight Data Persistence: Using an SQLite database suits the scale of this project, emphasizing ease of setup and maintenance.
- Reusability: The existence of separate modules (read.py, write.py, db_setup.py) indicates a design choice that favors code reuse rather than monolithic scripts.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Data Scraper Modules
    subgraph "Data Scraper"
        DC1["currency_scraper.py"]
        DC2["get-rate.py"]
    end

    %% Database Layer
    subgraph "Database Layer"
        DB1["currency_exchange.db"]
        DB2["db_setup.py"]
        DB3["read.py"]
        DB4["write.py"]
    end

    %% API Backend
    subgraph "API Backend"
        API["app.py"]
    end

    %% Visualization Modules
    subgraph "Visualization Modules"
        V1["exchange_rate_plot.py"]
        V2["rate_plotly.py"]
        V3["CurrencyExchange.py"]
        V4["tables.html"]
    end

    %% Interactions
    DC1 -->|"scrapes&writes"| DB4
    DC2 -->|"scrapes&writes"| DB4
    DB3 -->|"retrieves"| API
    API -->|"generatesStats"| V1
    API -->|"generatesStats"| V2
    API -->|"generatesStats"| V3
    API -->|"rendersOutput"| V4

    %% Click Events
    click DC1 "https://github.com/leoulgirma/scrape-exchange-rates/blob/master/currency_scraper.py"
    click DC2 "https://github.com/leoulgirma/scrape-exchange-rates/blob/master/get-rate.py"
    click DB1 "https://github.com/leoulgirma/scrape-exchange-rates/blob/master/currency_exchange.db"
    click DB2 "https://github.com/leoulgirma/scrape-exchange-rates/blob/master/db_setup.py"
    click DB3 "https://github.com/leoulgirma/scrape-exchange-rates/blob/master/read.py"
    click DB4 "https://github.com/leoulgirma/scrape-exchange-rates/blob/master/write.py"
    click API "https://github.com/leoulgirma/scrape-exchange-rates/blob/master/app.py"
    click V1 "https://github.com/leoulgirma/scrape-exchange-rates/blob/master/exchange_rate_plot.py"
    click V2 "https://github.com/leoulgirma/scrape-exchange-rates/blob/master/rate_plotly.py"
    click V3 "https://github.com/leoulgirma/scrape-exchange-rates/blob/master/CurrencyExchange.py"
    click V4 "https://github.com/leoulgirma/scrape-exchange-rates/blob/master/tables.html"

    %% Styles
    classDef scraper fill:#a1cfff,stroke:#333,stroke-width:2px;
    classDef database fill:#caffca,stroke:#333,stroke-width:2px;
    classDef api fill:#ffd8b1,stroke:#333,stroke-width:2px;
    classDef visualization fill:#ffc0cb,stroke:#333,stroke-width:2px;

    class DC1,DC2 scraper;
    class DB1,DB2,DB3,DB4 database;
    class API api;
    class V1,V2,V3,V4 visualization;
```
