An open API service indexing awesome lists of open source software.

https://github.com/joshbaneycs/stock-tracker

My first attempt at making a Dockerized stock platform with Golang backend and ReackJS frontend
https://github.com/joshbaneycs/stock-tracker

Last synced: 11 months ago
JSON representation

My first attempt at making a Dockerized stock platform with Golang backend and ReackJS frontend

Awesome Lists containing this project

README

          

# πŸ“ˆ Stock Tracker

A full-stack, real-time stock tracking and alerting web application built with **React**, **Go**, **Python**, and **MySQL** β€” fully containerized with **Docker**. Users can register, select up to 50 stocks, view live graphing and history, set alerts, and customize their settings.

---

## πŸ“ Project Directory Structure

stock-tracker/
β”œβ”€β”€ backend/
β”‚ β”œβ”€β”€ main.go
β”‚ β”œβ”€β”€ handlers/
β”‚ β”œβ”€β”€ models/
β”‚ β”œβ”€β”€ middleware/
β”‚ β”œβ”€β”€ utils/
β”‚ β”œβ”€β”€ stock_fetcher.py
β”‚ β”œβ”€β”€ requirements.txt
β”‚ └── go.mod
β”‚
β”œβ”€β”€ frontend/
β”‚ β”œβ”€β”€ public/
β”‚ β”œβ”€β”€ src/
β”‚ β”‚ β”œβ”€β”€ pages/
β”‚ β”‚ β”œβ”€β”€ components/
β”‚ β”‚ └── index.js
β”‚ β”œβ”€β”€ Dockerfile
β”‚ └── package.json
β”‚
β”œβ”€β”€ db/
β”‚ └── schema.sql
β”œβ”€β”€ .env
β”œβ”€β”€ docker-compose.yml
└── README.md

---

🧠 Backend Stack

- **Language:** Go (Golang)
- **Framework:** `gin-gonic`
- **Authentication:** JWT (stored in client storage)
- **Email Alerts:** SMTP via `net/smtp`
- **Data Fetching:** Calls a Python script (`stock_fetcher.py`) using `os/exec`
- **Python Dependencies:** `yfinance`, `pandas`, `numpy`
- **Database:** MySQL 8.x via GORM ORM

🎨 Frontend Stack

- **Library:** React (with React Router v6)
- **Graphing:** Chart.js via `react-chartjs-2`
- **API:** Axios for HTTP requests
- **Styling:** CSS modules + responsive layout
- **Background:** [particles.js](https://vincentgarreau.com/particles.js/)
- **Session:** JWT stored in `localStorage`

βš™οΈ Technology Stack

- **Frontend:** React + Chart.js
- **Backend:** Go + Python
- **Database:** MySQL
- **Containerization:** Docker
- **Email + Alerts:** SMTP
- **Currency Conversion:** exchangerate.host
- **Reverse Proxy (optional):** Nginx

---

## πŸ› οΈ Installation Guide

### Prerequisites

- [Docker](https://www.docker.com/products/docker-desktop)
- [Docker Compose](https://docs.docker.com/compose/)
- (Optional) Python installed locally for testing `stock_fetcher.py`

---

### 1. Clone the Repository

```bash
git clone https://github.com/JoshBaneyCS/stock-tracker.git
cd stock-tracker
```
### 2. Setup Environment Variables
Create a .env file in the project root:

```.env
PORT=8080
DB_HOST=db
DB_PORT=3306
DB_USER=root
DB_PASS=password
DB_NAME=stocktracker

JWT_SECRET=supersecretjwtkey
EMAIL_USER=your_email@gmail.com
EMAIL_PASS=your_email_password
```
### 3. Build and Run!
```bash
docker-compose up --build
```
This will:

Build and run the Go backend + Python inside 1 container

Serve the React frontend via Nginx on port 3000

Set up a MySQL database and schema

### 4. Open in Browser
Frontend: http://localhost:3000 (Or whatever you have your port mapped to)

Backend API: http://localhost:8080 (Or whatever you have your port mapped to)

## πŸ” Default Routes

Method Endpoint Description
POST /register Register a new user
POST /login Login and get JWT
GET /api/favorites Get user’s saved stocks
POST /api/favorites Save user’s selected stocks
GET /api/stocks Fetch live stock data
GET /api/settings Get user profile/settings
POST /api/settings Update name, email, etc.
POST /api/alerts Create price alert
GET /api/alerts View all alerts
DELETE /api/alerts/:id Delete alert

JWT must be sent as a Bearer token in Authorization headers for protected endpoints.

## πŸ“§ Features

- βœ… User authentication (JWT-based login/register)
- βœ… Select up to 50 favorite stocks
- βœ… Market index toggle support (e.g., S&P 500)
- βœ… Real-time stock graphing (using Chart.js)
- βœ… Custom color-coded lines per stock
- βœ… Search bar to quickly find stocks
- βœ… Historical data box (market cap, high/low, etc.)
- βœ… Auto-refresh every 5 minutes
- βœ… Email alerts when price reaches or falls below threshold
- βœ… Currency conversion via exchangerate.host
- βœ… Customizable account settings (name, email, password, currency)
- βœ… IP address is logged on login and registration
- βœ… Dockerized with flexible port management via `.env`
- βœ… Front page includes `particles.js` animated background and logo

## πŸ” Security Notes

- Passwords are hashed securely using **bcrypt**
- JWTs are used for stateless authentication
- Frontend stores JWT in `localStorage`
- CSRF is avoided by using token-only auth
- SMTP email alerts use secure environment variables

## πŸ§ͺ Development Notes

To test the Python stock data script locally:
```bash
cd backend
pip install -r requirements.txt
python3 stock_fetcher.py AAPL TSLA
```

This will return a JSON response for the given stock tickers.

## πŸ“œ License

This project is licensed under the MIT License. You may use, modify, and distribute it freely, with proper attribution.