A real-time P&L monitoring and risk dashboard for CFD traders built with modern web technologies.
Replace with actual screenshot after deployment
- Framework: Next.js 14 with App Router
- Language: TypeScript
- Styling: Tailwind CSS
- Charts: Recharts
- Animations: Framer Motion
- Icons: Lucide React
- Font: Geist (Vercel)
✨ Live Features:
- Live PNL Ticker — Real-time P&L with delta and percentage changes, animated with Framer Motion
- Trading Volume Chart — Rolling 60-second volume history with Recharts area chart and live data updates
- Asset Exposure Heatmap — Risk-scored CFD assets grouped by category (Forex, Indices, Crypto, Commodities)
- Threat Alert Feed — Real-time alert stream with severity levels (low/medium/high/critical) and pulsing critical alerts
- Top Traders Table — Sortable trader leaderboard with PNL, volume, risk scores, and trade counts
- Time Range Filter — Switch between 1m, 5m, 1h, 1d views
- Live Clock — Real-time display with pulsing "Live" badge
🎨 Design:
- Dark theme with glassmorphism effects
- Smooth animations and transitions using Framer Motion
- Fully responsive (mobile, tablet, desktop)
- Error boundaries on each panel for resilience
- Loading skeletons for smooth initial load
- Color-coded risk indicators (green/yellow/orange/red)
- Node.js 18+
- npm or yarn
-
Clone the repository:
git clone https://github.com/your-username/pnl-dashboard.git cd pnl-dashboard -
Install dependencies:
npm install
-
Run the development server:
npm run dev
-
Open in browser:
http://localhost:3000
Next.js 14 with App Router provides:
- Server Components by default — Cleaner data fetching patterns for future API integration
- Built-in optimization — Automatic code splitting, image optimization, and font optimization
use clientdirective — Seamless client-side interactivity without context hell- Zero-config deployment — Native Vercel integration with environment variables and edge functions
Recharts was chosen for charting because:
- Lightweight and composable — Build complex charts from simple components
- TailwindCSS-friendly — Easy to style with custom colors and dark backgrounds
- React-native — Built specifically for React with hooks support
- Responsive by default — ResponsiveContainer automatically adapts to parent width
- Animation support — Built-in SVG animations for data changes
The dashboard uses setInterval to simulate real-time updates via:
useLivePNL— Updates PNL every 800ms with ±0.5% fluctuationsuseVolumeHistory— Appends volume tick every 1 second, keeps last 60useAlertFeed— Fires random alerts every 3-8 secondsuseExposure— Recalculates risk scores every 5 seconds
This was chosen for the demo because:
- ✅ No backend required for prototyping
- ✅ Demonstrates real-time UI patterns clearly
- ✅ Easy to replace with actual WebSocket in production
To replace mock data with real WebSocket streams in production:
// hooks/useRealPNL.ts
export function useRealPNL() {
const [pnl, setPnl] = useState<LivePNL>({...});
useEffect(() => {
const ws = new WebSocket(process.env.NEXT_PUBLIC_WS_URL);
ws.onmessage = (event) => {
const data = JSON.parse(event.data);
setPnl({
totalPNL: data.pnl,
delta: data.delta,
percentChange: data.percentChange,
});
};
return () => ws.close();
}, []);
return pnl;
}Then update components to use useRealPNL instead of useLivePNL.
- WebSocket Integration — Replace
setIntervalwith live broker data via WebSocket (e.g., Interactive Brokers, Alpaca, Kraken) - Server-Sent Events (SSE) — Alternative to WebSocket for one-way data streams (simpler firewall-friendly option)
- Data Persistence — Store trade history and alerts in PostgreSQL for analytics
- NextAuth.js — OAuth2 authentication (Google, GitHub) or broker credentials
- User Profiles — Save dashboard preferences, watchlists, alert thresholds per trader
- Role-based Access — Admin dashboard for supervising multiple traders
- Alpaca API — Real stock/crypto trading data
- Interactive Brokers — Institutional CFD data integration
- Real trade execution — Place, modify, and cancel trades from dashboard
- Historical Charts — Multi-day/month candle charts with technical analysis overlays
- Performance Analytics — Win rate, Sharpe ratio, max drawdown, risk metrics
- Predictive Alerts — ML-based anomaly detection for unusual market conditions
- Trade Journal — Annotate trades with screenshots, reasoning, lessons learned
pnl-dashboard/
├── app/
│ ├── layout.tsx # Root layout with metadata
│ ├── page.tsx # Main dashboard page
│ └── globals.css # Global styles & CSS variables
├── components/
│ ├── Header.tsx # Dashboard header with live clock
│ ├── TimeRangeFilter.tsx # Time range selector
│ ├── PNLTicker.tsx # Live P&L display
│ ├── VolumeChart.tsx # Trading volume chart
│ ├── ExposureHeatmap.tsx # Risk heatmap
│ ├── AlertFeed.tsx # Alert stream
│ ├── TradersTable.tsx # Trader leaderboard
│ ├── Skeleton.tsx # Loading skeletons
│ └── ErrorBoundary.tsx # Error handling
├── hooks/
│ ├── useLivePNL.ts # Real-time PNL updates
│ ├── useVolumeHistory.ts # Volume chart data
│ ├── useAlertFeed.ts # Alert generation
│ └── useExposure.ts # Asset exposure simulation
├── data/
│ ├── mockTraders.ts # 10 demo traders
│ └── mockAssets.ts # 12 CFD assets
├── types/
│ └── index.ts # TypeScript interfaces
└── README.md # This file
The easiest way to deploy is using the Vercel Platform from the creators of Next.js.
Steps:
-
Push code to GitHub:
git init git add . git commit -m "Initial commit" git remote add origin https://github.com/your-username/pnl-dashboard.git git branch -M main git push -u origin main
-
Import to Vercel:
- Go to vercel.com
- Click "Add New" → "Project"
- Select "Import Git Repository"
- Paste your GitHub repo URL
- Click "Import"
-
Configure (Optional):
- No environment variables needed — The dashboard works with mock data out of the box
- Framework: Next.js is auto-detected
- Root directory: ./
-
Deploy:
- Click "Deploy"
- Wait for build to complete (~2 min)
- Your dashboard is live at
https://your-project.vercel.app
That's it! Vercel automatically:
- ✅ Installs dependencies
- ✅ Builds Next.js app
- ✅ Deploys globally with CDN
- ✅ Sets up HTTPS
- ✅ Auto-redeploys on git push
- useMemo — Memoized chart data transformations to prevent unnecessary recalculations
- Framer Motion — Optimized animations using
AnimatePresenceand layout IDs - Error Boundaries — Prevent cascade failures from crashing entire dashboard
- Skeleton Loading — Smooth perceived performance with placeholder content
- TailwindCSS — Purged unused styles in production build
- Chrome/Edge 90+
- Firefox 88+
- Safari 14+
- Mobile browsers (iOS Safari 14+, Chrome Mobile)
MIT License — See LICENSE file for details
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Commit changes:
git commit -m 'Add amazing feature' - Push to branch:
git push origin feature/amazing-feature - Open a Pull Request
For issues or questions, please open a GitHub issue or email: support@example.com
Built with ❤️ by Your Name