# galsakuri/stock-market-viewer-gui-api architecture

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

- Interactive diagram: https://gitdiagram.com/galsakuri/stock-market-viewer-gui-api
- Repository: https://github.com/galsakuri/stock-market-viewer-gui-api

## Overview

##### Project type and purpose
- This is a lightweight desktop GUI application (Tkinter-based) whose sole purpose is:
- To fetch and display a 6-month history chart of a stock’s daily closing price.
- To fetch and display the 5 most recent news headlines for that ticker (clickable to open the browser).
- It relies on two external REST APIs: AlphaVantage (stock data) and NewsAPI (news headlines).

##### File structure
- At the top level we have just:
- README.md
- Stock Market main.py
- All code lives in a single script; there are no subdirectories for modules or assets.
- No build scripts or config files beyond the API-key placeholders inside the main.py.

##### README for additional insights
- The README specifies:
- Python 3.9+
- Dependencies: requests, pandas, matplotlib, and tkinter (part of stdlib).
- Rate limits for each API.
- Setup instructions (where to insert API keys), installation, and how to run the script.

a. Main components
1. User Interface (Tkinter)
- Input field for ticker symbol
- “Search” button
- Chart area (matplotlib embedded)
- News list (clickable items)
2. Controller / Orchestrator (in the same script)
- Receives UI events (e.g., Search clicked)
- Calls data-fetching functions
- Updates UI with results
3. Data-Fetch Layer
- StockDataFetcher (requests → AlphaVantage)
- NewsDataFetcher (requests → NewsAPI)
4. Data Processing
- pandas DataFrame transformation for charting
5. Chart Renderer
- matplotlib Figure/Canvas embedded into Tkinter
6. External Services
- AlphaVantage REST API
- NewsAPI REST API
b. Relationships & interactions
- UI “Search” event → Controller
- Controller → StockDataFetcher → AlphaVantage → JSON
- Controller → NewsDataFetcher → NewsAPI → JSON
- Controller → pandas transforms stock JSON → DataFrame
- Controller → matplotlib renders chart from DataFrame
- Controller → UI updates chart and news list
- UI news-item click → open default web browser to news URL
c. Architectural patterns & design principles
- MVC-like separation (View: Tkinter, Controller: event handlers, Model: fetched data)
- Single responsibility per component (fetching stock vs. fetching news vs. rendering chart)
- Synchronous, linear flow (no async/threading)
d. Key technologies
- Python 3.9+
- Tkinter (UI)
- requests (HTTP calls)
- pandas (data processing)
- matplotlib (plotting)
- webbrowser (open URLs)

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Local Application"
        direction TB
        UI["User Interface (Tkinter)"]:::ui
        Controller["Controller/Orchestrator"]:::core
        StockFetcher["StockDataFetcher"]:::core
        NewsFetcher["NewsDataFetcher"]:::core
        DataProcessor["Data Processing (pandas)"]:::core
        ChartRenderer["Chart Renderer (matplotlib)"]:::core
    end

    subgraph "External Services"
        direction TB
        AlphaVantage["AlphaVantage REST API"]:::external
        NewsAPI["NewsAPI REST API"]:::external
        Browser["Default Web Browser"]:::external
    end

    Docs["External Services Documentation (README.md)"]:::external

    UI -->|"1. Search clicked"| Controller
    Controller -->|"2. Request ticker JSON"| StockFetcher
    StockFetcher -->|"3. HTTP JSON"| AlphaVantage
    AlphaVantage -->|"4. JSON response"| StockFetcher
    StockFetcher -->|"5. Data JSON"| Controller

    Controller -->|"6. Request headlines JSON"| NewsFetcher
    NewsFetcher -->|"7. HTTP JSON"| NewsAPI
    NewsAPI -->|"8. JSON response"| NewsFetcher
    NewsFetcher -->|"9. Data JSON"| Controller

    Controller -->|"10. JSON→DataFrame"| DataProcessor
    DataProcessor -->|"11. DataFrame"| Controller

    Controller -->|"12. Plot DataFrame"| ChartRenderer
    ChartRenderer -->|"13. Chart image"| UI

    Controller -->|"14. Populate news list"| UI
    UI -->|"15. open URL"| Browser

    Docs

    click UI "https://github.com/galsakuri/stock-market-viewer-gui-api/blob/main/Stock Market main.py"
    click Controller "https://github.com/galsakuri/stock-market-viewer-gui-api/blob/main/Stock Market main.py"
    click StockFetcher "https://github.com/galsakuri/stock-market-viewer-gui-api/blob/main/Stock Market main.py"
    click NewsFetcher "https://github.com/galsakuri/stock-market-viewer-gui-api/blob/main/Stock Market main.py"
    click DataProcessor "https://github.com/galsakuri/stock-market-viewer-gui-api/blob/main/Stock Market main.py"
    click ChartRenderer "https://github.com/galsakuri/stock-market-viewer-gui-api/blob/main/Stock Market main.py"
    click Docs "https://github.com/galsakuri/stock-market-viewer-gui-api/blob/main/README.md"

    classDef ui fill:#D6EAF8,stroke:#1B4F72,stroke-width:2px
    classDef core fill:#D5F5E3,stroke:#145A32,stroke-width:2px
    classDef external fill:#FAD7A0,stroke:#7D6608,stroke-width:2px
```
