# amircp/investingpy architecture

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

- Interactive diagram: https://gitdiagram.com/amircp/investingpy
- Repository: https://github.com/amircp/investingpy

## Overview

##### Project Type and Purpose
- This is a lightweight Python package (library) whose sole responsibility is to fetch the last 30 days of historical data from Investing.com for various financial instruments.
- It uses Selenium WebDriver to drive a headless browser, scrape the page, parse the table, and return the result as a pandas DataFrame.

##### File Structure
- Top-level files:
- `datafeed.py` – core module exposing `get_investing_last30days_data()`.
- `__init__.py` – makes the folder a Python package.
- `requirements.txt` – lists Selenium, pandas, and other dependencies.
- `README.md` – documents usage.
- No subdirectories—this is a single-module library.

##### Extract Key Components & Roles
- User Application / Script: the consumer code that imports your package.
- datafeed Module: contains the API function and internal helpers.
- Selenium WebDriver: third-party component (e.g., ChromeDriver/GeckoDriver).
- Investing.com Website: external service providing the data.
- Parser & DataFrame: internal logic to transform raw HTML into a pandas DataFrame.

##### Interactions & Data Flow
1. Consumer calls `get_investing_last30days_data(symbol, category)`.
2. datafeed module spins up a Selenium WebDriver instance.
3. WebDriver navigates to the correct Investing.com URL.
4. Investing.com responds with HTML (sometimes slow or blocked).
5. datafeed parses the HTML table (e.g., via BeautifulSoup or Selenium APIs).
6. Parsed rows are assembled into a pandas DataFrame.
7. DataFrame is returned to the consumer code.
8. WebDriver is shut down/teardown.

##### Architectural Patterns
- Single-module library pattern: clear separation between public API (`get_investing_last30days_data`) and internal helpers (browser setup, parsing).
- Dependency-injection point: ability to pass custom WebDriver instance (future enhancement).
- Error-handling/timeouts around slow or blocked requests to Investing.com.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Main flow
    User["User Script<br/>(Consumer Code)"]:::user
    subgraph "datafeed.py (Internal Module)"
        API["API Layer<br/>get_investing_last30days_data()"]:::internal
        Parser["Parser/Transformer<br/>(HTML → DataFrame)"]:::internal
    end
    Selenium["Selenium WebDriver"]:::thirdparty
    Investing["Investing.com<br/>(External Service)"]:::external
    Pandas["pandas DataFrame"]:::thirdparty

    %% Packaging and Project Files
    subgraph "Project Structure"
        Init["__init__.py"]:::internal
        Requirements["requirements.txt"]:::manifest
        Readme["README.md"]:::docs
        Venv["pyvenv.cfg"]:::manifest
        Gitignore[".gitignore"]:::manifest
    end

    subgraph "Deployment"
        PyPI["PyPI Package"]:::deployment
    end

    %% Connections
    User -->|invoke API| API
    API -->|drive browser| Selenium
    Selenium -->|HTTP GET / HTML| Investing
    Investing -->|HTML content| Parser
    API -->|teardown WebDriver| Selenium
    Parser -->|parse table| Pandas
    Pandas -->|return DataFrame| User
    API -->|package for distribution| PyPI

    %% Click Events
    click API "https://github.com/amircp/investingpy/blob/master/datafeed.py"
    click Parser "https://github.com/amircp/investingpy/blob/master/datafeed.py"
    click Init "https://github.com/amircp/investingpy/blob/master/__init__.py"
    click Requirements "https://github.com/amircp/investingpy/blob/master/requirements.txt"
    click Readme "https://github.com/amircp/investingpy/blob/master/README.md"
    click Venv "https://github.com/amircp/investingpy/blob/master/pyvenv.cfg"
    click Gitignore "https://github.com/amircp/investingpy/blob/master/.gitignore"

    %% Styling
    classDef user fill:#D5E8D4,stroke:#82B366,color:#000;
    classDef internal fill:#DAE8FC,stroke:#6C8EBF,color:#000;
    classDef thirdparty fill:#E1D5E7,stroke:#9673A6,color:#000;
    classDef external fill:#F8CECC,stroke:#B85450,color:#000;
    classDef manifest fill:#FFF2CC,stroke:#D6B656,color:#000;
    classDef docs fill:#F5F5F5,stroke:#CCCCCC,color:#000;
    classDef deployment fill:#E2EFDA,stroke:#6AA84F,color:#000;
```
