# dlabbate/stock-dashboard architecture

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

- Interactive diagram: https://gitdiagram.com/dlabbate/stock-dashboard
- Repository: https://github.com/dlabbate/stock-dashboard

## Overview

##### Project Type and Purpose
- This is a single‐page front‐end application (React) that visualizes stock data by querying the Finnhub API.
- The app’s goal is to let users search stocks, view quotes and details, filter historical chart data, and toggle light/dark themes.

##### File Structure Analysis
Top-level files
- package.json, package-lock.json
- postcss.config.js, tailwind.config.js (CSS tooling and Tailwind setup)
- public/index.html (static host entry)
- src/ (application code)

Inside src/
- index.js, App.js, App.css – entry point and root component
- assets/ – images and GIFs used in README
- constants/ – configuration (API key, base URLs) and mock data
- context/ – React Context providers for stock data and theme state
- components/ – presentational and container components (Dashboard, Search, Chart, etc.)
- utils/api/stock-api.js – service layer calling Finnhub REST endpoints
- utils/helpers/date-helper.js – utility for date formatting
- setupTests.js, reportWebVitals.js, App.test.js – test and performance instrumentation

##### Key Architectural Patterns
- Component-based UI (React components per feature)
- State management via React Context (StockContext, ThemeContext)
- Service layer abstraction for external API calls
- Styling via TailwindCSS and CSS modules

##### Main System Components
A. Browser / Client
B. React App Shell
1. Public Host (static server / CDN) serving index.html, JS bundles, CSS
2. Root React (index.js → App.js)
C. Presentation Layer (components/)
- Header, Overview, Dashboard, Details, Chart, Card, Search, SearchResults, ThemeIcon, ChartFilter
D. State Management Layer (context/)
- ThemeContext (light/dark toggle)
- StockContext (current symbol, quote data, historical data, search results)
E. Service Layer (utils/api/)
- stock-api.js (fetchSymbol, fetchQuote, fetchHistoricalData)
F. External Service
- Finnhub REST API (authentication via API key in config.js)
G. Asset Layer
- Static assets (public/*, src/assets)

##### Relationships and Data Flow
2. Components dispatch context actions via StockContext or ThemeContext.
3. StockContext uses stock-api.js to call Finnhub API.
4. API returns JSON (quotes, details, historical).
5. Context updates state → triggers re-render of components (charts, cards).

## Diagram (Mermaid)

```mermaid
flowchart TB
    UserBrowser["User / Browser"]:::external
    StaticHost["Static Host / CDN"]:::external

    UserBrowser -->|"request assets"| StaticHost
    StaticHost -->|"serves index.html, JS, CSS"| ReactApp

    subgraph "React App (SPA)"
        subgraph "Presentation Layer"
            Header["Header"]:::component
            Overview["Overview"]:::component
            Dashboard["Dashboard"]:::component
            Details["Details"]:::component
            Chart["Chart"]:::component
            ChartFilter["ChartFilter"]:::component
            Card["Card"]:::component
            Search["Search"]:::component
            SearchResults["SearchResults"]:::component
            ThemeIcon["ThemeIcon"]:::component
        end
        subgraph "State Management Layer"
            ThemeContext["ThemeContext"]:::context
            StockContext["StockContext"]:::context
        end
        subgraph "Service Layer"
            StockAPI["stock-api.js"]:::service
        end
    end

    Search -->|"dispatch search"| StockContext
    ChartFilter -->|"dispatch filter"| StockContext
    ThemeIcon -->|"dispatch theme toggle"| ThemeContext

    StockContext -->|"calls fetch methods"| StockAPI
    ThemeContext -->|"theme updates"| Header

    StockAPI -->|"REST call"| FinnhubAPI
    FinnhubAPI["Finnhub REST API"]:::external
    FinnhubAPI -->|"JSON response"| StockAPI

    StockAPI -->|"update state"| StockContext
    StockContext -->|"state update"| Chart

    dateHelper["date-helper.js"]:::helper
    config["config.js"]:::helper
    mock["mock.js"]:::helper
    assets["assets/"]:::helper

    dateHelper -->|"formats dates"| StockAPI
    config -->|"provides API key & URLs"| StockAPI
    mock -->|"fallback data"| StockAPI
    assets -->|"static images/GIFs"| Header

    click StaticHost "https://github.com/dlabbate/stock-dashboard/blob/master/public/index.html"
    click Header "https://github.com/dlabbate/stock-dashboard/blob/master/src/components/Header.js"
    click Overview "https://github.com/dlabbate/stock-dashboard/blob/master/src/components/Overview.js"
    click Dashboard "https://github.com/dlabbate/stock-dashboard/blob/master/src/components/Dashboard.js"
    click Details "https://github.com/dlabbate/stock-dashboard/blob/master/src/components/Details.js"
    click Chart "https://github.com/dlabbate/stock-dashboard/blob/master/src/components/Chart.js"
    click ChartFilter "https://github.com/dlabbate/stock-dashboard/blob/master/src/components/ChartFilter.js"
    click Card "https://github.com/dlabbate/stock-dashboard/blob/master/src/components/Card.js"
    click Search "https://github.com/dlabbate/stock-dashboard/blob/master/src/components/Search.js"
    click SearchResults "https://github.com/dlabbate/stock-dashboard/blob/master/src/components/SearchResults.js"
    click ThemeIcon "https://github.com/dlabbate/stock-dashboard/blob/master/src/components/ThemeIcon.js"
    click ThemeContext "https://github.com/dlabbate/stock-dashboard/blob/master/src/context/ThemeContext.js"
    click StockContext "https://github.com/dlabbate/stock-dashboard/blob/master/src/context/StockContext.js"
    click StockAPI "https://github.com/dlabbate/stock-dashboard/blob/master/src/utils/api/stock-api.js"
    click dateHelper "https://github.com/dlabbate/stock-dashboard/blob/master/src/utils/helpers/date-helper.js"
    click config "https://github.com/dlabbate/stock-dashboard/blob/master/src/constants/config.js"
    click mock "https://github.com/dlabbate/stock-dashboard/blob/master/src/constants/mock.js"
    click assets "https://github.com/dlabbate/stock-dashboard/tree/master/src/assets/"
    click ReactApp "https://github.com/dlabbate/stock-dashboard/blob/master/src/index.js"
    click ReactApp "https://github.com/dlabbate/stock-dashboard/blob/master/src/App.js"

    classDef component fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef context fill:#98FB98,stroke:#000,stroke-width:1px
    classDef service fill:#FFA500,stroke:#000,stroke-width:1px
    classDef external fill:#DDA0DD,stroke:#000,stroke-width:1px
    classDef helper fill:#E0E0E0,stroke:#000,stroke-width:1px
```
