A production-ready fullstack application for predicting stock prices and analyzing market sentiment.
- Stock Price Display: View historical price data for various stocks
- Price Predictions: ML-based predictions for 1 hour, 1 day, and 1 week timeframes
- Market Sentiment Analysis: Uses Alpha Vantage API to analyze sentiment for stocks
- Real-time Data: Fetches latest stock data from Yahoo Finance API
- Production Ready: Docker support, monitoring, logging, and security features
- Frontend: React + Vite + Tailwind CSS
- Backend: FastAPI (Python)
- ML Model: LightGBM for stock price prediction
- Data Sources: Yahoo Finance API for stock data, Alpha Vantage API for sentiment
- Database: PostgreSQL (production) / SQLite (development)
- Caching: Redis
- Monitoring: Prometheus metrics
- Deployment: Docker + Docker Compose
- Docker and Docker Compose
- Python 3.11+ (for local development)
- Node.js 18+ (for local development)
- Clone the repository:
git clone https://github.com/hectar-glitches/stock-predictor-fullstack.git
cd stock-predictor-fullstack- Configure environment:
# Copy and edit the environment file
cp backend/.env.example backend/.env
# Edit backend/.env with your API keys and configuration- Deploy with Docker:
./deploy.sh- Access the application:
- Frontend: http://localhost:3000
- Backend API: http://localhost:8000
- API Documentation: http://localhost:8000/docs
- Metrics: http://localhost:8000/metrics
- Navigate to the backend directory:
cd backend- Create virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- Install dependencies:
pip install -r requirements.txt- Configure environment:
cp .env.example .env
# Edit .env file with your configuration- Run the development server:
uvicorn app:app --reload- Navigate to the frontend directory:
cd frontend- Install dependencies:
npm install- Start the development server:
npm run devdocker-compose up --builddocker-compose up -ddocker-compose logs -f [service-name]docker-compose downdocker-compose build [service-name]GET /health- Application health status
GET /top-stocks- Get top 10 stocks dataGET /stock-stats?symbol={SYMBOL}&days={DAYS}- Get stock statisticsGET /stock-data?symbol={SYMBOL}&days={DAYS}- Get historical stock dataGET /indexes- Get market indexes (DOW, S&P 500)
POST /predict- Generate stock price predictions
GET /metrics- Prometheus metrics
# API Keys
ALPHA_VANTAGE_API_KEY=your_key_here
# Model Configuration
MODEL_N_ESTIMATORS=100
MODEL_LEARNING_RATE=0.05
MODEL_MAX_DEPTH=5
# Cache Configuration
CACHE_TTL_MINUTES=15
STOCK_CACHE_SIZE=100
# Logging
LOG_LEVEL=INFO
# Server Configuration
PORT=8000
HOST=0.0.0.0
CORS_ORIGINS=["http://localhost:5173", "http://localhost:3000"]
# Database (for production)
DATABASE_URL=postgresql://user:password@db:5432/stockpredictor
# Security
SECRET_KEY=your-secret-key-here
RATE_LIMIT_PER_MINUTE=60
# Environment
ENVIRONMENT=productionThe application exposes Prometheus metrics at /metrics endpoint:
- HTTP request counts and durations
- Error rates
- Custom business metrics
Structured logging with configurable levels:
- JSON format in production
- Console format in development
- Request/response logging
- Error tracking
- Application health endpoint:
/health - Docker health checks configured
- Database connectivity checks
- Rate limiting on all endpoints
- CORS configuration
- Security headers (HSTS, XSS protection, etc.)
- Input validation and sanitization
- Error handling without information leakage
- Non-root Docker containers
- Configure production environment variables
- Run
./deploy.shfor automated deployment - Set up reverse proxy (Nginx configuration included)
- Configure SSL certificates
- Set up monitoring and alerting
- Build Docker images
- Deploy to container orchestration platform (Kubernetes, ECS, etc.)
- Configure load balancer
- Set up database and Redis instances
- Configure monitoring and logging
cd backend
python -m pytest tests/cd frontend
npm testWhen running in development mode, interactive API documentation is available at:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
- Port conflicts: Make sure ports 3000, 8000, 5432, and 6379 are available
- API key errors: Ensure Alpha Vantage API key is properly configured
- Docker issues: Restart Docker daemon and try again
- Memory issues: Increase Docker memory allocation for large datasets
Check application logs for detailed error information:
docker-compose logs -f backend
docker-compose logs -f frontendFor support and questions, please open an issue in the GitHub repository.
npm run dev
- Access the application at
http://localhost:5173
- Alpha Vantage API: For sentiment analysis, get a free API key from Alpha Vantage and update it in
frontend/src/App.jsx
If the chart is not displaying, ensure:
- The backend
/stock-ohlcendpoint is returning data - The data has
dateandclosefields (lowercase) - CORS is properly configured for the frontend origin
If sentiment analysis is not displaying:
- Check you have a valid Alpha Vantage API key and you're hiding it when you publish.
- Check the browser console for API error messages
- Note that Alpha Vantage has rate limits for free accounts (typically 5 calls per minute)