A real-time trading platform for London Metal Exchange base metals, demonstrating modern full-stack development with React and Node.js.
https://trading-platform-production-3db5.up.railway.app
| Document | Description |
|---|---|
| REQUIREMENTS.md | Business requirements, user flows with diagrams, technical decisions |
| ARCHITECTURE.md | System architecture, data flow diagrams, deployment details |
| PROJECT_STRUCTURE.md | Folder structure, naming conventions, file organization |
# Install dependencies
pnpm install
# Setup database
pnpm run db:generate
pnpm run db:migrate
pnpm run db:seed
# Start development servers
pnpm run dev- Frontend: http://localhost:5173
- Backend: http://localhost:3001
| Technology | Purpose | Why This Choice |
|---|---|---|
| React 18 | UI Framework | Industry standard, demonstrates component architecture |
| TypeScript | Type Safety | Catches errors at compile time, self-documenting code |
| TanStack Query | Server State | Handles caching, background refetching, optimistic updates |
| TailwindCSS | Styling | Rapid prototyping, consistent design system |
| Recharts | Data Visualization | Composable charts for portfolio allocation |
| Vite | Build Tool | Fast HMR, optimized production builds |
| Technology | Purpose | Why This Choice |
|---|---|---|
| Fastify | HTTP Server | High performance, TypeScript-first, plugin ecosystem |
| WebSocket | Real-time Updates | Sub-second price updates without polling |
| Drizzle ORM | Database | Type-safe queries, lightweight, excellent DX |
| SQLite | Database | Zero-config, portable, sufficient for demo scale |
| Zod | Validation | Runtime validation with TypeScript inference |
βββ packages/
β βββ shared/ # Types, schemas, constants (used by both)
β βββ server/ # Fastify REST + WebSocket API
β βββ client/ # React SPA
β βββ server-java/ # (Placeholder) Spring Boot alternative
Why Monorepo? Shared types between frontend and backend eliminate API contract drift and enable end-to-end type safety.
src/features/
βββ trading/
β βββ api/ # React Query hooks
β βββ components/ # Feature-specific UI
β βββ hooks/ # Custom hooks
βββ portfolio/
βββ ...
Scales better than grouping by file type. Each feature is self-contained.
Routes β Services β Database
- Routes: HTTP/validation only
- Services: Business logic, reusable across routes
- Database: Drizzle schema + queries
βββββββββββ WebSocket βββββββββββ
β Client ββββββββββββββββββΊβ Server β
βββββββββββ βββββββββββ
β β
β React Query β Price Service
β (cache sync) β (simulation)
βΌ βΌ
UI Updates Broadcast to all clients
Price updates flow via WebSocket, React Query cache is updated, UI re-renders automatically.
The API contract is documented separately, allowing the backend to be reimplemented in any language (Java/Spring Boot scaffold included) while the frontend remains unchanged.
| Feature | Implementation |
|---|---|
| Live Price Grid | WebSocket subscription, flash animations on price change |
| Trade Execution | Form validation, optimistic updates, position recalculation |
| Portfolio View | Positions table, P&L calculation, allocation pie chart |
| Connection Status | Visual indicator, automatic reconnection with backoff |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/prices |
All current metal prices |
| GET | /api/trades |
Trade history |
| POST | /api/trades |
Execute a trade |
| GET | /api/positions |
Current holdings |
| GET | /api/positions/summary |
Portfolio summary |
| Event | Direction | Description |
|---|---|---|
PRICE_SNAPSHOT |
Server β Client | Initial prices on connect |
PRICE_UPDATE |
Server β Client | Single price change |
TRADE_EXECUTED |
Server β Client | Trade confirmation |
PING/PONG |
Bidirectional | Heartbeat |
Metal exchange/
βββ README.md # This file
βββ REQUIREMENTS.md # Domain research & requirements gathering
βββ package.json # Root workspace config
βββ pnpm-workspace.yaml
βββ packages/
β βββ shared/ # Shared types & validation
β β βββ src/
β β βββ constants/ # Metal definitions
β β βββ types/ # TypeScript interfaces
β β βββ schemas/ # Zod validation schemas
β βββ server/ # Node.js backend
β β βββ src/
β β βββ db/ # Drizzle schema & migrations
β β βββ services/ # Business logic
β β βββ routes/ # REST endpoints
β β βββ websocket/ # Real-time handler
β βββ client/ # React frontend
β β βββ src/
β β βββ api/ # Axios, React Query, WebSocket
β β βββ components/ # Shared UI components
β β βββ features/ # Feature modules
β β βββ layouts/ # Page layouts
β βββ server-java/ # (Future) Spring Boot backend
βββ docs/ # Detailed technical docs (reference)
pnpm run dev # Start all services
pnpm run build # Production build
pnpm run db:seed # Seed sample data
pnpm run typecheck # Type checking- Authentication (JWT)
- Order book depth visualization
- Historical price charts (candlestick)
- Trade blotter with filtering
- Java/Spring Boot backend implementation