Skip to content

KrishKyada/TradeX

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

13 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

MERN Portfolio Tracker โ€“ Stocks & Crypto Dashboard

A modern portfolio tracking dashboard built using the MERN stack. Users can track crypto and stock holdings, view real-time prices, charts, profit/loss analytics, and manage their portfolio in a clean admin-style UI.


โญ Features

๐Ÿ” User Authentication

  • Register and login system
  • JWT-based authentication
  • Protected backend routes
  • Password encryption with Bcrypt

๐Ÿ“Š Dashboard Analytics

  • Total investment value
  • Current portfolio value
  • Total profit/loss calculation
  • Number of holdings
  • BTC hourly price chart
  • Recent activities widget
  • Portfolio performance metrics

๐Ÿ’น Live Price Fetching

  • Crypto prices from CoinGecko API
  • Stock prices from Finnhub API
  • Auto-updating P/L calculations
  • Real-time market data refresh
  • Multiple asset support

๐Ÿ“ Portfolio Management

  • Add stocks or crypto assets
  • Enter buy price & quantity
  • Delete assets
  • View detailed portfolio table
  • Edit asset details
  • Track investment history

๐ŸŽจ Modern UI / Layout

  • Fixed sidebar navigation
  • Dark neon theme
  • Responsive grid design
  • Recharts line & area charts
  • Smooth animations
  • Mobile-friendly interface

๐Ÿ›  Tech Stack

Frontend

  • React 18 (Vite)
  • Axios
  • Recharts
  • Custom CSS
  • Responsive Design

Backend

  • Node.js
  • Express.js
  • MongoDB Atlas
  • Mongoose ODM
  • JWT Authentication
  • Bcrypt Hashing
  • CoinGecko API
  • Finnhub API

๐Ÿ“ Project Structure

MERN-Portfolio-Tracker/
โ”œโ”€โ”€ client/
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”œโ”€โ”€ components/
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ Sidebar.jsx
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ Header.jsx
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ PortfolioTable.jsx
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ ChartWidget.jsx
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ StatCard.jsx
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ ...
โ”‚   โ”‚   โ”œโ”€โ”€ pages/
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ Dashboard.jsx
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ Portfolio.jsx
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ AddAsset.jsx
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ Login.jsx
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ Register.jsx
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ ...
โ”‚   โ”‚   โ”œโ”€โ”€ layout/
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ MainLayout.jsx
โ”‚   โ”‚   โ”œโ”€โ”€ App.jsx
โ”‚   โ”‚   โ””โ”€โ”€ main.jsx
โ”‚   โ”œโ”€โ”€ public/
โ”‚   โ”œโ”€โ”€ index.html
โ”‚   โ”œโ”€โ”€ package.json
โ”‚   โ”œโ”€โ”€ vite.config.js
โ”‚   โ””โ”€โ”€ .env
โ”œโ”€โ”€ server/
โ”‚   โ”œโ”€โ”€ controllers/
โ”‚   โ”‚   โ”œโ”€โ”€ authController.js
โ”‚   โ”‚   โ”œโ”€โ”€ portfolioController.js
โ”‚   โ”‚   โ”œโ”€โ”€ priceController.js
โ”‚   โ”‚   โ””โ”€โ”€ chartController.js
โ”‚   โ”œโ”€โ”€ routes/
โ”‚   โ”‚   โ”œโ”€โ”€ auth.js
โ”‚   โ”‚   โ”œโ”€โ”€ portfolio.js
โ”‚   โ”‚   โ”œโ”€โ”€ prices.js
โ”‚   โ”‚   โ””โ”€โ”€ charts.js
โ”‚   โ”œโ”€โ”€ models/
โ”‚   โ”‚   โ”œโ”€โ”€ User.js
โ”‚   โ”‚   โ”œโ”€โ”€ Portfolio.js
โ”‚   โ”‚   โ””โ”€โ”€ Activity.js
โ”‚   โ”œโ”€โ”€ middleware/
โ”‚   โ”‚   โ”œโ”€โ”€ authMiddleware.js
โ”‚   โ”‚   โ””โ”€โ”€ errorHandler.js
โ”‚   โ”œโ”€โ”€ config/
โ”‚   โ”‚   โ””โ”€โ”€ db.js
โ”‚   โ”œโ”€โ”€ index.js
โ”‚   โ”œโ”€โ”€ package.json
โ”‚   โ””โ”€โ”€ .env
โ”œโ”€โ”€ README.md
โ””โ”€โ”€ .gitignore

๐Ÿš€ Installation & Setup

Prerequisites

  • Node.js (v14 or higher)
  • npm or yarn
  • MongoDB Atlas Account (free tier)
  • Finnhub API Key (free tier)
  • Git

Step 1: Clone Repository

git clone https://github.com/KrishKyada/stocks-portfolio-tracker.git
cd mern-portfolio-tracker

Step 2: Install Backend Dependencies

cd server
npm install

Step 3: Install Frontend Dependencies

cd ../client
npm install

Step 4: Setup Environment Variables

Create .env file in the server folder:

PORT=5000
NODE_ENV=development
MONGO_URI=mongodb+srv://username:password@cluster.mongodb.net/portfolio-tracker
JWT_SECRET=your_super_secret_jwt_key_here
FINNHUB_KEY=your_finnhub_api_key_here

Get these values:

Step 5: Start Backend Server

cd server
npm run dev

Backend runs at: http://localhost:5000

Step 6: Start Frontend Server

In a new terminal:

cd client
npm run dev

Frontend runs at: http://localhost:5173

Step 7: Access Application

Open browser and go to http://localhost:5173


๐Ÿ“ก API Routes

Authentication Routes

POST   /api/auth/register
POST   /api/auth/login
POST   /api/auth/logout
GET    /api/auth/profile

Portfolio Routes

GET    /api/portfolio
POST   /api/portfolio/add
PUT    /api/portfolio/:id
DELETE /api/portfolio/:id

Price Routes

GET    /api/prices/crypto/:symbol
GET    /api/prices/stock/:symbol
GET    /api/prices/multiple

Chart Routes

GET    /api/chart/btc-24h
GET    /api/chart/portfolio

๐Ÿ” Authentication

  • Registration: Create account with email & password
  • Password Hashing: Bcrypt encryption for security
  • JWT Token: Issued upon successful login
  • Protected Routes: Token required for API access
  • Token Storage: Stored in localStorage

๐Ÿ’พ Database Schema

User Model

{
  _id: ObjectId,
  name: String,
  email: String (unique),
  password: String (hashed),
  createdAt: Date,
  updatedAt: Date
}

Portfolio Model

{
  _id: ObjectId,
  userId: ObjectId,
  assetName: String,
  assetType: String (crypto/stock),
  symbol: String,
  quantity: Number,
  buyPrice: Number,
  currentPrice: Number,
  totalInvested: Number,
  currentValue: Number,
  profitLoss: Number,
  createdAt: Date,
  updatedAt: Date
}

๐ŸŽจ Key Components

Pages

  • Dashboard - Analytics overview
  • Portfolio - Holdings management
  • Add Asset - New investment form
  • Login - User authentication
  • Register - Account creation

Components

  • Sidebar Navigation
  • Header/Navbar
  • Portfolio Table
  • Chart Widgets
  • Statistics Cards
  • Forms (Add/Edit/Delete)

๐Ÿ”ฎ Future Improvements

  • Watchlist feature
  • WebSocket real-time updates
  • Export data to CSV/PDF
  • More chart types (candlestick, MA)
  • Multi-theme support
  • Performance alerts
  • Portfolio comparisons
  • Dividend tracking
  • Tax reports generation
  • Mobile app (iOS/Android)
  • Social sharing features
  • AI recommendations

๐Ÿ› Troubleshooting

Port Already in Use

lsof -i :5000
kill -9 <PID>

MongoDB Connection Error

  • Verify MONGO_URI in .env
  • Check MongoDB Atlas IP whitelist
  • Ensure cluster is active

API Key Issues

  • Verify Finnhub API key
  • Check rate limits
  • Confirm .env variables are set

CORS Issues

  • Add frontend URL to CORS whitelist
  • Check Axios configuration

๐Ÿ“ Available Scripts

Frontend

npm run dev          # Start dev server
npm run build        # Build for production
npm run preview      # Preview production build

Backend

npm run dev          # Start with nodemon
npm start            # Start server

๐Ÿค Contributing

  1. Fork the repository
  2. Create feature branch (git checkout -b feature/AmazingFeature)
  3. Commit changes (git commit -m 'Add AmazingFeature')
  4. Push to branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

๐Ÿ“„ License

This project is licensed under the MIT License - see LICENSE file for details.


๐Ÿ“ง Support

For issues and questions:

  • Open a GitHub issue
  • Check existing issues for solutions
  • Provide detailed bug reports

๐ŸŒŸ Acknowledgments

  • CoinGecko API
  • Finnhub API
  • MongoDB
  • React Community
  • Express.js

Author : Krish Kyada

โญ If you found this helpful, please star the repository!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors