# marketcalls/tradingview-yahoo-finance architecture

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

- Interactive diagram: https://gitdiagram.com/marketcalls/tradingview-yahoo-finance
- Repository: https://github.com/marketcalls/tradingview-yahoo-finance

## Overview

##### Project type and purpose
- This is a full-stack web application whose purpose is to display real-time stock charts (using TradingView’s lightweight-charts.js) with data fetched from Yahoo Finance, alongside watchlist management stored in a local database.
- The README confirms features (chart analysis, watchlist CRUD, theme toggles) and tech stack (Flask, SQLAlchemy/SQLite, Tailwind CSS, DaisyUI, JavaScript).

##### File structure
- Top level:
- app.py – main Flask web server (routes, business logic).
- models.py – SQLAlchemy ORM models for persisting watchlist symbols.
- requirements.txt – dependency list (Flask, SQLAlchemy, yfinance, etc.).
- Directories:
- templates/index.html – Jinja2 template rendering the initial page.
- static/main.js – frontend logic (fetch from backend, initialize charts, update UI).
- There’s no separate “frontend” folder; Flask serves both HTML and JS/CSS, but logically they form the client-side component.

##### README for additional insights
- Backend dependencies: Flask (web framework), SQLAlchemy (ORM), yfinance (data).
- Frontend uses Tailwind CSS + DaisyUI (styling) and lightweight-charts.js (charting).
- Persistence via SQLite.
- No external authentication or message queues; single-process design.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Side
    subgraph "Client (Browser)" 
        direction TB
        BrowserUI["Browser UI"]:::frontend
        Index["templates/index.html"]:::frontend
        MainJS["static/main.js"]:::frontend
        ChartLib["lightweight-charts.js"]:::frontend
    end

    %% Server Side
    subgraph "Server (Backend)" 
        direction TB
        Flask["app.py (Flask Server)"]:::backend
        Models["models.py (ORM Models)"]:::backend
        Req["requirements.txt"]:::backend
        DB[(SQLite Database)]:::db
        YF["Yahoo Finance API"]:::external
    end

    %% Data Flow
    BrowserUI -->|HTTP GET /| Flask
    Flask -->|Render with Jinja2| Index
    Index -->|HTML/CSS/JS delivered| BrowserUI

    BrowserUI -->|Load JS| MainJS
    MainJS -->|Init Charts| ChartLib

    MainJS -->|AJAX GET fetch_chart_data| Flask
    Flask -->|yfinance library calls| YF
    YF -->|Price data| Flask
    Flask -->|JSON chart data| MainJS

    BrowserUI -->|AJAX POST add_symbol| Flask
    Flask -->|SQLAlchemy CRUD| DB
    DB -->|Watchlist data| Flask
    Flask -->|JSON response| MainJS

    %% Click Events
    click Index "https://github.com/marketcalls/tradingview-yahoo-finance/blob/main/templates/index.html"
    click MainJS "https://github.com/marketcalls/tradingview-yahoo-finance/blob/main/static/main.js"
    click Flask "https://github.com/marketcalls/tradingview-yahoo-finance/blob/main/app.py"
    click Models "https://github.com/marketcalls/tradingview-yahoo-finance/blob/main/models.py"
    click Req "https://github.com/marketcalls/tradingview-yahoo-finance/blob/main/requirements.txt"

    %% Styles
    classDef frontend fill:#CFE2FF,stroke:#0B5394,stroke-width:1px
    classDef backend fill:#D9EAD3,stroke:#274E13,stroke-width:1px
    classDef db fill:#FFE599,stroke:#815500,stroke-width:1px
    classDef external fill:#CCCCCC,stroke:#666666,stroke-width:1px
```
