# deepcodeview/stock_historic_data architecture

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

- Interactive diagram: https://gitdiagram.com/deepcodeview/stock_historic_data
- Repository: https://github.com/deepcodeview/stock_historic_data

## Overview

##### Main components
- Web Server / Application Logic: The Python files (app.py, app1.py, data_to_db_hist.py, data_to_db_live.py) suggest that the project’s backend logic is implemented in Flask (or a similar Python web framework). This is responsible for routing, data processing, and serving the appropriate web pages.
- Databases: There are multiple database files (historic.db, historic_database.db, live_database.db) indicating that the application interacts with at least two databases – one for historic data and another for live data.
- Frontend: The static templates in the “templates” directory (chart.html, chart_live.html, chart_new.html, chart_only_live.html) and the static CSS file illustrate that the frontend is rendered server-side and is geared towards different types of chart visualizations.
- External Data and Workflows: There is a “currency_list” directory and additional support scripts/notebooks (exp.ipynb) which might be used for preprocessing or additional data feeds. Also, note the GitHub workflows for linting (pylint.yml) which indicate quality checks in the development process.

##### Understand relationships and interactions
- Routing: The app routes include “/” for historic visualization, “/live” for live data and insertion of new records, and “/onlylive” for tick-by-tick data. These routes are defined in the Flask app(s), and each route is responsible for rendering the appropriate webpage and connecting to the corresponding database.
- Data Flow: The backend scripts (data_to_db_hist.py and data_to_db_live.py) likely manage the ingestion of data into their respective SQLite databases. The live data route also visualizes this data in real time.
- Static/Dynamic Content: The static directory and templates are used to serve the visual components, with CSS for styling.

##### Architectural Patterns and Design Principles
- MVC-like Separation: Though not a strict MVC implementation, there is a separation between the business logic (Python files managing routes and database interactions) and presentation (HTML templates with static styling).
- Modularity: The project separates concerns – one set of scripts handles historic data while another handles live updates.
- Data Persistence: Using SQLite databases for persistence of live and historic data.

##### Relevant Technologies
- Python as the programming language.
- Flask (or a similar microframework) for the web application logic.
- SQLite for database management.
- HTML/CSS for rendering the visualization on the front end.
- Jupyter Notebook (exp.ipynb) suggests an exploration or analytical component.

## Diagram (Mermaid)

```mermaid
flowchart TD
    C["Client: Web Browser"]:::client

    subgraph "Backend"
        F["Flask Web Server"]:::backend
        R1["Route: '/' (Historic)"]:::backend
        R2["Route: '/live' (Live)"]:::backend
        R3["Route: '/onlylive' (OnlyLive)"]:::backend
        HIngest["Historic Data Ingestion"]:::backend
        LIngest["Live Data Ingestion"]:::backend
    end

    subgraph "Databases"
        HDB1["Historic DB (historic.db)"]:::database
        HDB2["Historic DB (historic_database.db)"]:::database
        LDB["Live Database (live_database.db)"]:::database
    end

    subgraph "Frontend"
        TChart["Template: Chart.html"]:::frontend
        TChartLive["Template: Chart_live.html"]:::frontend
        TChartNew["Template: Chart_new.html"]:::frontend
        TChartOnlyLive["Template: Chart_only_live.html"]:::frontend
        CSS["Static Assets (CSS)"]:::frontend
    end

    subgraph "External & Workflows"
        Currency["Currency List Data"]:::external
        Notebook["Jupyter Notebook (exp.ipynb)"]:::external
        Quality["Quality Checks (pylint.yml)"]:::external
    end

    %% Client to Backend
    C --> F

    %% Backend Routes
    F --> R1
    F --> R2
    F --> R3
    F --> CSS

    %% Historic Route Flow
    R1 --> HIngest
    HIngest --> HDB1
    HIngest --> HDB2
    HDB1 --> TChart
    HDB2 --> TChart
    TChart --> C

    %% Live Route Flow
    R2 --> LIngest
    LIngest --> LDB
    LDB --> TChartLive
    LDB --> TChartNew
    TChartLive --> C
    TChartNew --> C

    %% OnlyLive Route Flow
    R3 --> LDB
    LDB --> TChartOnlyLive
    TChartOnlyLive --> C

    %% External Data Connections
    Currency --> HIngest
    Currency --> LIngest
    Notebook --> F
    Quality --> F

    %% Click Events
    click F "https://github.com/deepcodeview/stock_historic_data/blob/main/app.py"
    click F "https://github.com/deepcodeview/stock_historic_data/blob/main/app1.py"
    click HIngest "https://github.com/deepcodeview/stock_historic_data/blob/main/data_to_db_hist.py"
    click LIngest "https://github.com/deepcodeview/stock_historic_data/blob/main/data_to_db_live.py"
    click HDB1 "https://github.com/deepcodeview/stock_historic_data/blob/main/historic.db"
    click HDB2 "https://github.com/deepcodeview/stock_historic_data/blob/main/historic_database.db"
    click LDB "https://github.com/deepcodeview/stock_historic_data/blob/main/live_database.db"
    click TChart "https://github.com/deepcodeview/stock_historic_data/blob/main/templates/chart.html"
    click TChartLive "https://github.com/deepcodeview/stock_historic_data/blob/main/templates/chart_live.html"
    click TChartNew "https://github.com/deepcodeview/stock_historic_data/blob/main/templates/chart_new.html"
    click TChartOnlyLive "https://github.com/deepcodeview/stock_historic_data/blob/main/templates/chart_only_live.html"
    click CSS "https://github.com/deepcodeview/stock_historic_data/blob/main/static/style.css"
    click Currency "https://github.com/deepcodeview/stock_historic_data/tree/main/currency_list"
    click Notebook "https://github.com/deepcodeview/stock_historic_data/blob/main/exp.ipynb"
    click Quality "https://github.com/deepcodeview/stock_historic_data/blob/main/.github/workflows/pylint.yml"

    %% Style Classes
    classDef client fill:#AED581,stroke:#333,stroke-width:2px;
    classDef backend fill:#64B5F6,stroke:#333,stroke-width:2px;
    classDef database fill:#E57373,stroke:#333,stroke-width:2px;
    classDef frontend fill:#FFCC80,stroke:#333,stroke-width:2px;
    classDef external fill:#D7CCC8,stroke:#333,stroke-width:2px;
```
