How dlabbate/stock-dashboard works
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).