- Frontend (Landing Page): https://trading-frontend-rose.vercel.app
- Dashboard (Trading App): https://trading-dashboard-opal.vercel.app
- Backend API: https://trading-platform-mern.vercel.app
A full-stack simulated stock trading platform built with the MERN stack (MongoDB, Express.js, React.js, Node.js). This project demonstrates modern web development practices including user authentication, real-time data visualization, and comprehensive testing.
- User Authentication: Secure signup/login with JWT tokens and bcrypt password hashing
- Portfolio Management: Track holdings, positions, and order history
- Live Stock Simulation: Real-time price fluctuations using custom API
- Interactive Charts: Dynamic doughnut charts showing margin utilization (Chart.js)
- Order Execution: Buy/sell stocks with automatic portfolio updates
- TradingView Integration: Professional stock charts with technical indicators
- Full CRUD Operations: Create, Read, Update, Delete for all entities
- RESTful API: Clean, scalable backend architecture
- Responsive Design: Works seamlessly across devices
- Automated Testing: Jest unit tests for API endpoints
- State Management: React hooks for efficient state handling
- React.js (v19.2.3) - UI framework
- React Router - Client-side routing
- Axios - HTTP client
- Chart.js - Data visualization
- React Icons - Icon library
- React Toastify - Notifications
- Node.js - Runtime environment
- Express.js - Web framework
- MongoDB - Database
- Mongoose - ODM
- JWT - Authentication
- bcrypt - Password hashing
- Jest - Testing framework
- Supertest - HTTP assertions
stockproject/
βββ frontend/ # Marketing website
β βββ src/
β β βββ home/ # Landing page
β β βββ signup/ # Auth pages
β β βββ ...
β βββ package.json
β
βββ dashboard/ # Trading dashboard
β βββ src/
β β βββ components/
β β β βββ Holdings.js
β β β βββ Positions.js
β β β βββ Orders.js
β β β βββ WatchList.js
β β β βββ Summary.js
β β β βββ ...
β β βββ data/
β βββ package.json
β
βββ backend/ # API server
βββ Models/
β βββ User.js
β βββ Holding.js
β βββ Position.js
β βββ Order.js
βββ index.js
βββ api.test.js
βββ package.json
- Node.js (v14 or higher)
- MongoDB (running locally or MongoDB Atlas)
- npm or yarn
- Clone the repository
git clone https://github.com/vivekyadav-3/trading-platform-mern.git
cd trading-platform-mern- Install dependencies
# Install backend dependencies
cd backend
npm install
# Install dashboard dependencies
cd ../dashboard
npm install
# Install frontend dependencies
cd ../frontend
npm install- Environment Setup
Create .env files in each directory:
backend/.env
PORT=3002
MONGO_URL=mongodb://localhost:27017/stockproject
TOKEN_KEY=your_secret_key_heredashboard/.env
PORT=3001- Start MongoDB
# Make sure MongoDB is running
mongod- Seed the Database (First time only)
# Navigate to http://localhost:3002/addHoldings after starting the backendOpen 3 separate terminals:
Terminal 1 - Backend
cd backend
npm start
# Runs on http://localhost:3002Terminal 2 - Dashboard
cd dashboard
npm start
# Runs on http://localhost:3001Terminal 3 - Frontend
cd frontend
npm start
# Runs on http://localhost:3000Run backend tests:
cd backend
npm testTest Results:
Test Suites: 1 passed, 1 total
Tests: 6 passed, 6 total
POST /signup- Register new userPOST /login- User login
GET /allStocks- Get live stock pricesGET /allHoldings- Get user holdingsGET /allPositions- Get user positionsGET /allOrders- Get order history
POST /newOrder- Place buy/sell orderGET /addHoldings- Seed initial data (dev only)
- User registers with email, username, and password
- Password is hashed using bcrypt (12 rounds)
- JWT token generated and stored in HTTP-only cookie
- Protected routes verify token before granting access
- Custom algorithm simulates price fluctuations (Β±1%)
- No external API dependencies = 100% reliability
- Prices update on each request
- Supports 15+ stocks including INFY, TCS, RELIANCE, MRF
- Buy: Increases quantity or creates new holding
- Sell: Decreases quantity or removes holding if qty = 0
- Real-time P&L calculation
- Margin tracking with visual charts
- Fetches live holdings data
- Calculates total investment vs available margin
- Updates chart automatically on trades
- Doughnut chart with 70% cutout for modern look
- Password hashing with bcrypt
- JWT-based authentication
- HTTP-only cookies
- CORS configuration
- Environment variable protection
- Input validation
- Real-time WebSocket updates
- Advanced charting (candlestick, line charts)
- Portfolio analytics dashboard
- Trade history export (CSV/PDF)
- Email notifications
- Mobile app (React Native)
- Integration with real stock APIs
- Paper trading competitions
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License.
Vivek Yadav
- GitHub: @vivekyadav-3
- Inspired by Zerodha Kite platform
- TradingView for chart widgets
- Chart.js for data visualization
- MongoDB for database solution
β If you found this project helpful, please give it a star!