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.
- Register and login system
- JWT-based authentication
- Protected backend routes
- Password encryption with Bcrypt
- Total investment value
- Current portfolio value
- Total profit/loss calculation
- Number of holdings
- BTC hourly price chart
- Recent activities widget
- Portfolio performance metrics
- Crypto prices from CoinGecko API
- Stock prices from Finnhub API
- Auto-updating P/L calculations
- Real-time market data refresh
- Multiple asset support
- Add stocks or crypto assets
- Enter buy price & quantity
- Delete assets
- View detailed portfolio table
- Edit asset details
- Track investment history
- Fixed sidebar navigation
- Dark neon theme
- Responsive grid design
- Recharts line & area charts
- Smooth animations
- Mobile-friendly interface
- React 18 (Vite)
- Axios
- Recharts
- Custom CSS
- Responsive Design
- Node.js
- Express.js
- MongoDB Atlas
- Mongoose ODM
- JWT Authentication
- Bcrypt Hashing
- CoinGecko API
- Finnhub API
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
- Node.js (v14 or higher)
- npm or yarn
- MongoDB Atlas Account (free tier)
- Finnhub API Key (free tier)
- Git
git clone https://github.com/KrishKyada/stocks-portfolio-tracker.git
cd mern-portfolio-trackercd server
npm installcd ../client
npm installCreate .env file in the server folder:
PORT=5000
NODE_ENV=development
MONGO_URI=mongodb+srv://username:[email protected]/portfolio-tracker
JWT_SECRET=your_super_secret_jwt_key_here
FINNHUB_KEY=your_finnhub_api_key_hereGet these values:
- MONGO_URI: MongoDB Atlas
- FINNHUB_KEY: Finnhub
- JWT_SECRET: Any random secure string
cd server
npm run devBackend runs at: http://localhost:5000
In a new terminal:
cd client
npm run devFrontend runs at: http://localhost:5173
Open browser and go to http://localhost:5173
POST /api/auth/register
POST /api/auth/login
POST /api/auth/logout
GET /api/auth/profile
GET /api/portfolio
POST /api/portfolio/add
PUT /api/portfolio/:id
DELETE /api/portfolio/:id
GET /api/prices/crypto/:symbol
GET /api/prices/stock/:symbol
GET /api/prices/multiple
GET /api/chart/btc-24h
GET /api/chart/portfolio
- 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
{
_id: ObjectId,
name: String,
email: String (unique),
password: String (hashed),
createdAt: Date,
updatedAt: Date
}{
_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
}- Dashboard - Analytics overview
- Portfolio - Holdings management
- Add Asset - New investment form
- Login - User authentication
- Register - Account creation
- Sidebar Navigation
- Header/Navbar
- Portfolio Table
- Chart Widgets
- Statistics Cards
- Forms (Add/Edit/Delete)
- 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
lsof -i :5000
kill -9 <PID>- Verify MONGO_URI in .env
- Check MongoDB Atlas IP whitelist
- Ensure cluster is active
- Verify Finnhub API key
- Check rate limits
- Confirm .env variables are set
- Add frontend URL to CORS whitelist
- Check Axios configuration
npm run dev # Start dev server
npm run build # Build for production
npm run preview # Preview production buildnpm run dev # Start with nodemon
npm start # Start server- Fork the repository
- Create feature branch (
git checkout -b feature/AmazingFeature) - Commit changes (
git commit -m 'Add AmazingFeature') - Push to branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see LICENSE file for details.
For issues and questions:
- Open a GitHub issue
- Check existing issues for solutions
- Provide detailed bug reports
- CoinGecko API
- Finnhub API
- MongoDB
- React Community
- Express.js
Author : Krish Kyada
⭐ If you found this helpful, please star the repository!