# kanishk1420/stockviz-real-time-stock-market architecture

> Architecture diagram of the GitHub repository kanishk1420/stockviz-real-time-stock-market, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kanishk1420/stockviz-real-time-stock-market
- Repository: https://github.com/kanishk1420/stockviz-real-time-stock-market

## Overview

1. StockViz is a two-tier application: a React frontend for interactive visualization and a FastAPI backend that serves market data and real-time updates.

2. The frontend lives under `frontend/src` and is organized around a single trading dashboard. `App.js` composes the main UI, while `components/` contains the visible pieces: `Navbar` for market indices, `TradingInterface` for the charting and controls area, and `ChartTypeSelector` for switching chart modes.

3. The frontend’s architecture is client-driven and stateful. It uses React hooks for local state, then pulls data through `services/Api.js`, which is the boundary between UI and backend communication. The README indicates both REST and WebSocket usage, so the frontend likely mixes initial HTTP fetches with a persistent streaming channel for live updates.

4. The backend is under `backend/api` and is the central integration layer. `main.py` is the FastAPI entry point, while `data_fetcher.py` handles retrieving stock data from `yfinance`. This backend is the place where external market data is normalized before being exposed to clients.

5. Real-time delivery is a key architectural feature. The backend provides WebSocket support for pushing stock price updates to connected clients, and the frontend is built to subscribe to a chosen symbol and timeframe, then merge incremental updates into its existing chart state.

6. Technical analysis is separated into its own backend subsystem at `backend/indicators/technical_analysis.py`. That module uses TA-Lib to compute indicators and chart-friendly derived series, keeping indicator logic out of the UI and out of the data-fetching layer.

7. Local persistence is handled by SQLite. The repository includes `backend/stock_data.db` and `backend/stocks.db`, and `backend/database/init_db.py` suggests a database initialization/migration step. This implies the backend can cache or persist market data locally rather than relying only on live API calls.

8. The main data flow is: external market source (`yfinance`) → backend fetch/processing → optional SQLite storage/caching → FastAPI REST/WebSocket endpoints → React service layer → chart and market UI components. That flow is what an architecture diagram should emphasize.

9. The frontend’s presentation stack is React plus Tailwind CSS and Recharts. Tailwind drives layout/styling, while Recharts is the chart rendering layer for line, bar, and candlestick visualizations, with responsive behavior and tooltip-driven interaction.

10. Operationally, the project is intended to run as two separately started processes in development: the backend via Uvicorn/FastAPI and the frontend via the React dev server. There is no sign of a monolithic server-side-rendered app; instead, the frontend and backend are cleanly separated by API and WebSocket boundaries.

Main entry points: [`frontend/src/App.js`](https://github.com/kanishk1420/stockviz-real-time-stock-market/blob/main/frontend/src/App.js) (App), [`backend/api/main.py`](https://github.com/kanishk1420/stockviz-real-time-stock-market/blob/main/backend/api/main.py) (FastAPI App), [`backend/api/data_fetcher.py`](https://github.com/kanishk1420/stockviz-real-time-stock-market/blob/main/backend/api/data_fetcher.py) (Data Fetcher), [`frontend/src/components/TradingInterface.js`](https://github.com/kanishk1420/stockviz-real-time-stock-market/blob/main/frontend/src/components/TradingInterface.js) (Trading Interface)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_frontend_app["App<br/>React shell<br/>[App.js]"]
  node_frontend_navbar["Navbar<br/>UI component<br/>[Navbar.js]"]
  node_frontend_trade["Trading Interface<br/>UI component"]
  node_frontend_chart_selector["Chart Selector<br/>UI component"]
  node_frontend_api["Api Service<br/>client gateway<br/>[Api.js]"]
  node_frontend_recharts(("Recharts<br/>charting lib"))
  node_frontend_tailwind["Tailwind CSS<br/>styling system<br/>[tailwind.config.js]"]
end

subgraph group_backend["Backend"]
  node_backend_main["FastAPI App<br/>API entrypoint<br/>[main.py]"]
  node_backend_fetcher["Data Fetcher<br/>market ingest<br/>[data_fetcher.py]"]
  node_backend_indicators["Technical Analysis<br/>indicator engine"]
  node_backend_db_init["DB Init<br/>database setup<br/>[init_db.py]"]
end

subgraph group_storage["Storage"]
  node_backend_stock_db[("stock_data.db<br/>sqlite cache<br/>[stock_data.db]")]
  node_backend_stocks_db[("stocks.db<br/>sqlite cache<br/>[stocks.db]")]
end

node_external_yfinance(("yfinance<br/>external source"))

node_frontend_app -->|"composes"| node_frontend_navbar
node_frontend_app -->|"composes"| node_frontend_trade
node_frontend_trade -->|"uses"| node_frontend_chart_selector
node_frontend_trade -->|"renders with"| node_frontend_recharts
node_frontend_app -.->|"styles with"| node_frontend_tailwind
node_frontend_app -->|"fetches via"| node_frontend_api
node_frontend_api -->|"REST/WebSocket"| node_backend_main
node_backend_main -->|"queries"| node_backend_fetcher
node_backend_fetcher -->|"pulls from"| node_external_yfinance
node_backend_main -->|"computes"| node_backend_indicators
node_backend_main -->|"initializes"| node_backend_db_init
node_backend_db_init -->|"prepares"| node_backend_stock_db
node_backend_db_init -->|"prepares"| node_backend_stocks_db
node_backend_fetcher -->|"cache/store"| node_backend_stock_db
node_backend_fetcher -->|"cache/store"| node_backend_stocks_db
node_backend_indicators -.->|"reads/writes"| node_backend_stock_db
node_frontend_api -->|"feeds live state"| node_frontend_trade

click node_frontend_app "https://github.com/kanishk1420/stockviz-real-time-stock-market/blob/main/frontend/src/App.js"
click node_frontend_navbar "https://github.com/kanishk1420/stockviz-real-time-stock-market/blob/main/frontend/src/components/Navbar.js"
click node_frontend_trade "https://github.com/kanishk1420/stockviz-real-time-stock-market/blob/main/frontend/src/components/TradingInterface.js"
click node_frontend_chart_selector "https://github.com/kanishk1420/stockviz-real-time-stock-market/blob/main/frontend/src/components/ChartTypeSelector.js"
click node_frontend_api "https://github.com/kanishk1420/stockviz-real-time-stock-market/blob/main/frontend/src/services/Api.js"
click node_frontend_tailwind "https://github.com/kanishk1420/stockviz-real-time-stock-market/blob/main/frontend/tailwind.config.js"
click node_backend_main "https://github.com/kanishk1420/stockviz-real-time-stock-market/blob/main/backend/api/main.py"
click node_backend_fetcher "https://github.com/kanishk1420/stockviz-real-time-stock-market/blob/main/backend/api/data_fetcher.py"
click node_backend_indicators "https://github.com/kanishk1420/stockviz-real-time-stock-market/blob/main/backend/indicators/technical_analysis.py"
click node_backend_db_init "https://github.com/kanishk1420/stockviz-real-time-stock-market/blob/main/backend/database/init_db.py"
click node_backend_stock_db "https://github.com/kanishk1420/stockviz-real-time-stock-market/blob/main/backend/stock_data.db"
click node_backend_stocks_db "https://github.com/kanishk1420/stockviz-real-time-stock-market/blob/main/backend/stocks.db"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_frontend_app,node_frontend_navbar,node_frontend_trade,node_frontend_chart_selector,node_frontend_api,node_frontend_recharts,node_frontend_tailwind toneBlue
class node_backend_main,node_backend_fetcher,node_backend_indicators,node_backend_db_init toneAmber
class node_backend_stock_db,node_backend_stocks_db toneMint
class node_external_yfinance toneNeutral
```

## Components

### Frontend

React UI, charting, and client-side data access.

- [App](https://github.com/kanishk1420/stockviz-real-time-stock-market/blob/main/frontend/src/App.js): React shell · Composes the main dashboard and overall client state. · `frontend/src/App.js`
- [Navbar](https://github.com/kanishk1420/stockviz-real-time-stock-market/blob/main/frontend/src/components/Navbar.js): UI component · Displays market indices and top-level market context. · `frontend/src/components/Navbar.js`
- [Trading Interface](https://github.com/kanishk1420/stockviz-real-time-stock-market/blob/main/frontend/src/components/TradingInterface.js): UI component · Main charting and controls area for symbol and timeframe interaction. · `frontend/src/components/TradingInterface.js`
- [Chart Selector](https://github.com/kanishk1420/stockviz-real-time-stock-market/blob/main/frontend/src/components/ChartTypeSelector.js): UI component · Switches between chart modes such as line, bar, and candlestick. · `frontend/src/components/ChartTypeSelector.js`
- [Api Service](https://github.com/kanishk1420/stockviz-real-time-stock-market/blob/main/frontend/src/services/Api.js): client gateway · Boundary for REST calls and WebSocket interaction with the backend. · `frontend/src/services/Api.js`
- **Recharts**: charting lib · Renders the interactive market charts used by the dashboard.
- [Tailwind CSS](https://github.com/kanishk1420/stockviz-real-time-stock-market/blob/main/frontend/tailwind.config.js): styling system · Provides utility-driven layout and visual styling. · `frontend/tailwind.config.js`

### Backend

FastAPI services for market data, streaming, and indicators.

- [FastAPI App](https://github.com/kanishk1420/stockviz-real-time-stock-market/blob/main/backend/api/main.py): API entrypoint · Starts the backend and exposes HTTP and WebSocket endpoints. · `backend/api/main.py`
- [Data Fetcher](https://github.com/kanishk1420/stockviz-real-time-stock-market/blob/main/backend/api/data_fetcher.py): market ingest · Retrieves external stock data from yfinance and prepares it for serving. · `backend/api/data_fetcher.py`
- [Technical Analysis](https://github.com/kanishk1420/stockviz-real-time-stock-market/blob/main/backend/indicators/technical_analysis.py): indicator engine · Computes indicators and derived series with TA-Lib. · `backend/indicators/technical_analysis.py`
- [DB Init](https://github.com/kanishk1420/stockviz-real-time-stock-market/blob/main/backend/database/init_db.py): database setup · Initializes or prepares the local SQLite schema. · `backend/database/init_db.py`

### Storage

Local SQLite databases used for persistence or caching.

- [stock_data.db](https://github.com/kanishk1420/stockviz-real-time-stock-market/blob/main/backend/stock_data.db): sqlite cache · Local market data store used for persistence or caching. · `backend/stock_data.db`
- [stocks.db](https://github.com/kanishk1420/stockviz-real-time-stock-market/blob/main/backend/stocks.db): sqlite cache · Additional local SQLite database for stock-related storage. · `backend/stocks.db`

### Other components

- **yfinance**: external source · Upstream market data provider used by the backend.

## Connections

- App → Navbar: composes · App assembles the market header UI.
- App → Trading Interface: composes · App mounts the main trading workspace.
- Trading Interface → Chart Selector: uses · Trading interface lets users switch chart modes.
- Trading Interface → Recharts: renders with · Charts are drawn through the Recharts visualization layer.
- App → Tailwind CSS: styles with · Global UI styling is handled via Tailwind utilities.
- App → Api Service: fetches via · Client state and data requests flow through the API service.
- Api Service → FastAPI App: REST/WebSocket · Frontend communicates with the backend over HTTP and streaming updates.
- FastAPI App → Data Fetcher: queries · API routes delegate market-data retrieval to the fetcher.
- Data Fetcher → yfinance: pulls from · Market data originates from yfinance.
- FastAPI App → Technical Analysis: computes · Backend enriches market data with technical indicators.
- FastAPI App → DB Init: initializes · Startup can prepare local persistence structures.
- DB Init → stock_data.db: prepares · Database initialization targets the local SQLite store.
- DB Init → stocks.db: prepares · Database initialization may also touch the secondary SQLite store.
- Data Fetcher → stock_data.db: cache/store · Fetched market data can be cached or persisted locally.
- Data Fetcher → stocks.db: cache/store · Fetched market data can be cached or persisted locally.
- Technical Analysis → stock_data.db: reads/writes · Indicator processing can operate on locally stored series.
- Api Service → Trading Interface: feeds live state · Streaming updates are merged into the chart and controls state.
