Skip to content

TheHackerFromMars/Wealth_Pulse_Dashboard

Repository files navigation

Portfolio Analytics Dashboard

image image

A full-stack portfolio analytics application with a React TypeScript frontend and Python FastAPI backend.

πŸš€ Features

Frontend (React + TypeScript)

  • Portfolio Overview Cards - Total value, gains/losses, holdings count, risk level
  • Asset Allocation Charts - Interactive pie charts for sector and market cap distribution
  • Holdings Table - Sortable, searchable table with all portfolio positions
  • Performance Chart - Timeline comparison vs Nifty 50 and Gold benchmarks
  • Top Performers - Best and worst performing stocks with insights

Backend (Python FastAPI)

  • 4 REST API Endpoints matching the assignment requirements exactly
  • Excel Data Integration - Reads portfolio data from provided Excel file
  • Real-time Calculations - Gain/loss, percentages, allocations computed on-the-fly
  • Type Safety - Pydantic models for request/response validation
  • Auto-generated API Docs - Interactive Swagger UI at /docs

πŸ“Š API Endpoints

Endpoint Description Returns
GET /api/portfolio/holdings Complete holdings with calculations List of enriched stock positions
GET /api/portfolio/allocation Sector & market cap distribution Percentage breakdowns with counts
GET /api/portfolio/performance Historical timeline vs benchmarks Performance data with returns
GET /api/portfolio/summary Key portfolio metrics Overview with top/worst performers

πŸ› οΈ Technology Stack

Frontend

  • React 18 with TypeScript for type safety
  • Vite for fast development and building
  • Shadcn/ui + Tailwind CSS for modern, responsive design
  • Recharts for interactive data visualizations
  • TanStack Query for efficient API state management
  • React Router for navigation

Backend

  • Python 3.12 with FastAPI for high-performance APIs
  • JSON-based data pipeline for optimal performance (Excel β†’ JSON β†’ API)
  • Automatic data import from Excel with timestamped backups
  • In-memory caching for sub-millisecond API responses
  • Pydantic for data validation and serialization
  • Uvicorn as ASGI server with auto-reload

🚦 Quick Start

Prerequisites

  • Node.js 18+ (for frontend)
  • Python 3.12+ (for backend)

1. Setup & Run Backend (Python FastAPI)

# Navigate to backend directory
cd backend

# Install Python dependencies (virtual environment already configured)
pip install -r requirements.txt

# Import Excel data to JSON (first time or after Excel updates)
python import_data.py

# Start the API server
python run.py

Backend will run on: http://localhost:8000

2. Setup & Run Frontend (React)

# Navigate to frontend directory
cd frontend

# Install frontend dependencies
npm install

# Start the development server  
npm run dev

Frontend will run on: http://localhost:8080

3. Test Integration

# Run the integration test script
chmod +x test-integration.sh
./test-integration.sh

4. Update Data (When Excel File Changes)

# Complete data update workflow
cd backend
./update_data.sh

This will:

  1. Import latest Excel data to JSON
  2. Reload API server cache
  3. Validate all endpoints

πŸ“ Project Structure

wealth-pulse-dash/
β”œβ”€β”€ frontend/                    # React TypeScript Frontend
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/dashboard/    # Dashboard components
β”‚   β”‚   β”œβ”€β”€ api/portfolio.ts         # API client
β”‚   β”‚   β”œβ”€β”€ pages/Index.tsx          # Main dashboard page
β”‚   β”‚   └── ...
β”‚   β”œβ”€β”€ package.json
β”‚   └── vite.config.ts
β”œβ”€β”€ backend/                     # Python FastAPI Backend
β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”œβ”€β”€ main.py                  # FastAPI application
β”‚   β”‚   β”œβ”€β”€ models.py                # Pydantic models
β”‚   β”‚   β”œβ”€β”€ data_service.py          # JSON processing logic
β”‚   β”‚   └── __init__.py
β”‚   β”œβ”€β”€ data/
β”‚   β”‚   β”œβ”€β”€ portfolio_data.json      # Generated JSON cache
β”‚   β”‚   β”œβ”€β”€ Sample Portfolio Dataset for Assignment.xlsx
β”‚   β”‚   └── backups/                 # Timestamped backups
β”‚   β”œβ”€β”€ requirements.txt
β”‚   β”œβ”€β”€ run.py                       # Server startup
β”‚   └── README.md
└── start-dev.sh                     # Development startup script

πŸ“ˆ Data Source

The application reads portfolio data from Sample Portfolio Dataset for Assignment.xlsx with the following sheets:

  • Holdings - Stock positions with quantities, prices, sectors
  • Historical_Performance - Timeline data for performance charts
  • Summary - Portfolio overview metrics
  • Sector_Allocation - Sector distribution data
  • Market_Cap - Market cap allocation data
  • Top_Performers - Best/worst performing stocks

πŸ”§ Development

Frontend Development

cd frontend
npm run dev     # Start with hot reload
npm run build   # Production build
npm run preview # Preview production build

Backend Development

python run.py   # Start with auto-reload
# API will automatically restart when code changes

Adding New Features

  1. Backend: Add new endpoints in backend/app/main.py, models in backend/app/models.py
  2. Frontend: Add API calls in frontend/src/api/portfolio.ts, components in frontend/src/components/

🌟 Key Features Implemented

βœ… Backend Requirements Met

  • All 4 required API endpoints implemented exactly as specified
  • Data calculations (gain/loss, percentages) working correctly
  • Error handling with proper HTTP status codes
  • CORS enabled for frontend integration
  • Clean, documented code structure

βœ… Frontend Requirements Met

  • Portfolio overview cards with color-coded gains/losses
  • Interactive asset allocation visualizations
  • Sortable, searchable holdings table
  • Performance comparison charts with hover effects
  • Top performers section with insights
  • Responsive design for mobile/desktop
  • Loading states and error handling

πŸš€ Deployment Ready

The application is architected for easy deployment:

  • Backend: Can be deployed to any platform supporting Python (Heroku, Railway, DigitalOcean, etc.)
  • Frontend: Can be deployed to static hosting (Vercel, Netlify, GitHub Pages, etc.)
  • Environment Variables: Backend URL configurable via frontend environment

πŸ§ͺ Testing

  • Integration test script validates all API endpoints
  • Frontend automatically handles API failures gracefully
  • Type safety ensures data consistency between frontend/backend

Portfolio Analytics Dashboard - Built with modern web technologies for optimal performance and user experience.

  • Edit files directly within the Codespace and commit and push your changes once you're done.

What technologies are used for this project?

This project is built with:

  • Vite
  • TypeScript
  • React
  • shadcn-ui
  • Tailwind CSS