Skip to content

Modern React + FastAPI Stock Analysis Dashboard with AI predictions, forecasting algorithms, and international market support

License

Notifications You must be signed in to change notification settings

DataVisuals/stocks-react-dashboard

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

4 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ“ˆ Stock Analysis Dashboard - React Edition

License: MIT React FastAPI TypeScript Python Tailwind CSS

A modern, responsive stock analysis and forecasting dashboard built with React and FastAPI. This is a React-based clone of the original Streamlit application with enhanced UI/UX and better performance.

๐Ÿš€ Features

  • ๐Ÿ“ˆ Interactive Stock Charts: Real-time stock price visualization with candlestick charts and moving averages
  • ๐Ÿ”ฎ Advanced Forecasting: Multiple forecasting algorithms including:
    • Linear Regression
    • Polynomial Regression
    • Moving Average
    • ARIMA
    • Facebook Prophet
    • Support Vector Regression
  • ๐Ÿ“ฐ Real-time News: Latest news articles related to selected stocks
  • ๐ŸŽจ Modern Dark Theme: Beautiful, responsive UI with Tailwind CSS
  • ๐Ÿ“Š Key Metrics: Current price, 52-week high/low, volume, and forecast predictions
  • ๐Ÿ” Smart Search: Search by ticker symbol or company name with autocomplete
  • ๐Ÿ“ฑ Responsive Design: Works perfectly on desktop, tablet, and mobile devices

๐Ÿ—๏ธ Architecture

  • Frontend: React 18 + TypeScript + Tailwind CSS + Chart.js
  • Backend: FastAPI + Python 3.8+
  • Data Source: Yahoo Finance (yfinance)
  • Caching: DuckDB for efficient data caching
  • Charts: Chart.js with react-chartjs-2

๐Ÿ“ฆ Installation

Prerequisites

  • Node.js 16+ and npm
  • Python 3.8+
  • pip

Backend Setup

  1. Navigate to the backend directory:
cd backend
  1. Create a virtual environment:
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
  1. Install dependencies:
pip install -r requirements.txt
  1. Start the FastAPI server:
python main.py

The backend will be available at http://localhost:8000

Frontend Setup

  1. Navigate to the frontend directory:
cd frontend
  1. Install dependencies:
npm install
  1. Start the development server:
npm start

The frontend will be available at http://localhost:3000

๐Ÿš€ Quick Start

  1. Start the backend server (from the backend directory):
python main.py
  1. Start the frontend development server (from the frontend directory):
npm start
  1. Open your browser and navigate to http://localhost:3000

  2. Search for a stock using the search bar or click on popular stocks

  3. Explore the features:

    • View interactive price charts
    • Switch between different forecasting methods
    • Read the latest news
    • Analyze key metrics

๐Ÿ“Š API Endpoints

The FastAPI backend provides the following endpoints:

  • POST /api/search - Search for stock tickers
  • POST /api/stock-data - Get stock data and metrics
  • POST /api/forecast - Get price forecasts
  • POST /api/news - Get news articles
  • GET /api/health - Health check

๐ŸŽจ UI Components

  • StockSearch: Smart search with autocomplete and popular stocks
  • StockChart: Interactive price charts with moving averages
  • ForecastChart: Forecast visualization with multiple algorithms
  • StockMetrics: Key performance indicators
  • NewsSection: News articles with external links

๐Ÿ”ง Configuration

Backend Configuration

  • Cache Duration: Modify CACHE_DURATION_HOURS and CACHE_DURATION_DAYS in main.py
  • Market Hours: Update MARKET_HOURS for different exchanges
  • API Rate Limits: Adjust timeout and retry settings

Frontend Configuration

  • API Base URL: Update API_BASE_URL in src/services/api.ts
  • Theme Colors: Modify tailwind.config.js for custom colors
  • Chart Options: Customize chart appearance in component files

๐Ÿ“ฑ Responsive Design

The application is fully responsive and works on:

  • Desktop: Full-featured experience with sidebar and main content
  • Tablet: Optimized layout with collapsible sidebar
  • Mobile: Stacked layout with touch-friendly controls

๐Ÿš€ Deployment

Backend Deployment

  1. Using Docker:
# Create Dockerfile in backend directory
FROM python:3.9-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
CMD ["python", "main.py"]
  1. Using cloud platforms:
    • Heroku
    • Railway
    • DigitalOcean App Platform
    • AWS Elastic Beanstalk

Frontend Deployment

  1. Build for production:
npm run build
  1. Deploy to:
    • Vercel
    • Netlify
    • AWS S3 + CloudFront
    • GitHub Pages

๐Ÿ” Development

Project Structure

Stocks-React/
โ”œโ”€โ”€ backend/
โ”‚   โ”œโ”€โ”€ main.py              # FastAPI application
โ”‚   โ”œโ”€โ”€ requirements.txt     # Python dependencies
โ”‚   โ””โ”€โ”€ stock_cache.db      # DuckDB cache (auto-created)
โ”œโ”€โ”€ frontend/
โ”‚   โ”œโ”€โ”€ public/
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”œโ”€โ”€ components/      # React components
โ”‚   โ”‚   โ”œโ”€โ”€ services/        # API services
โ”‚   โ”‚   โ”œโ”€โ”€ types.ts         # TypeScript types
โ”‚   โ”‚   โ””โ”€โ”€ App.tsx          # Main app component
โ”‚   โ”œโ”€โ”€ package.json
โ”‚   โ””โ”€โ”€ tailwind.config.js
โ””โ”€โ”€ README.md

Adding New Features

  1. New Forecasting Method:

    • Add function in backend/main.py
    • Update frontend dropdown options
    • Add method to API service
  2. New Chart Type:

    • Create new component in src/components/
    • Import Chart.js plugins as needed
    • Add to main App component
  3. New Data Source:

    • Add API endpoint in backend/main.py
    • Create service function in src/services/api.ts
    • Update types in src/types.ts

๐Ÿ› Troubleshooting

Common Issues

  1. CORS Errors: Ensure backend is running on port 8000 and frontend on port 3000
  2. Chart Not Rendering: Check if Chart.js plugins are properly registered
  3. API Timeout: Increase timeout in src/services/api.ts
  4. Build Errors: Clear node_modules and reinstall dependencies

Debug Mode

Enable debug logging by setting environment variables:

# Backend
export DEBUG=1
python main.py

# Frontend
export REACT_APP_DEBUG=1
npm start

๐Ÿ“„ License

This project is for educational and informational purposes only. Stock market investments carry risk, and past performance does not guarantee future results. Always consult with a financial advisor before making investment decisions.

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

๐Ÿ“ž Support

For questions or issues:

  1. Check the troubleshooting section
  2. Search existing issues
  3. Create a new issue with detailed description

Note: This application is for educational purposes only. Always verify data accuracy and consult financial professionals before making investment decisions.