How kanishk1420/stockviz-real-time-stock-market works
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: App.js App · main.py FastAPI App · data_fetcher.py Data Fetcher · TradingInterface.js Trading Interface
Components 14
Frontend
React UI, charting, and client-side data access.
- App · Composes the main dashboard and overall client state.
frontend/src/App.js - Navbar · Displays market indices and top-level market context.
frontend/src/components/Navbar.js - Trading Interface · Main charting and controls area for symbol and timeframe interaction.
frontend/src/components/TradingInterface.js - Chart Selector · Switches between chart modes such as line, bar, and candlestick.
frontend/src/components/ChartTypeSelector.js - Api Service · Boundary for REST calls and WebSocket interaction with the backend.
frontend/src/services/Api.js - Recharts · Renders the interactive market charts used by the dashboard.
- Tailwind CSS · Provides utility-driven layout and visual styling.
frontend/tailwind.config.js
Backend
FastAPI services for market data, streaming, and indicators.
- FastAPI App · Starts the backend and exposes HTTP and WebSocket endpoints.
backend/api/main.py - Data Fetcher · Retrieves external stock data from yfinance and prepares it for serving.
backend/api/data_fetcher.py - Technical Analysis · Computes indicators and derived series with TA-Lib.
backend/indicators/technical_analysis.py - DB Init · Initializes or prepares the local SQLite schema.
backend/database/init_db.py
Storage
Local SQLite databases used for persistence or caching.
- stock_data.db · Local market data store used for persistence or caching.
backend/stock_data.db - stocks.db · Additional local SQLite database for stock-related storage.
backend/stocks.db
Other components
- yfinance · Upstream market data provider used by the backend.
Connections 17
- 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.