A full-stack trading application built as a monorepo using Turborepo. This platform enables users to place market and limit orders, track positions, manage their wallet balance, and view real-time price data with interactive charts.
This project follows a microservices architecture with the following components:
TRADING APP - SIMPLIFIED ARCHITECTURE
βββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββ
β BINANCE β
β (Price Feed) β
ββββββββββ¬βββββββββ
β
βΌ
βββββββββββββββββββ
β PRICE POLLAR β
β (Fetches BTC β
β prices) β
ββββββββββ¬βββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββ
β REDIS β
β (Message Broker - connects all) β
βββββββββββββββββββββ¬ββββββββββββββββββββ
β
ββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββ
β β β
βΌ βΌ βΌ
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β ENGINE β β WS SERVER β β HTTP BACKEND β
β β β β β β
β β’ Process ordersβ β β’ Real-time β β β’ REST API β
β β’ Calculate P&L β β updates to β β β’ Place orders β
β β’ Check TP/SL ββββββββββββΆβ browser β β β’ Auth/Login β
β β β β β β’ User wallet β
ββββββββββ¬βββββββββ ββββββββββ¬βββββββββ ββββββββββ¬βββββββββ
β β β
β β β
βΌ β βΌ
βββββββββββββββββββ β βββββββββββββββββββ
β POSTGRESQL β β β TIMESCALEDB β
β β β β β
β β’ Users β β β β’ Chart candles β
β β’ Orders β β β β’ Price history β
β β’ Wallet balanceβ β β β
βββββββββββββββββββ β βββββββββββββββββββ
β
βΌ
βββββββββββββββββββ
β WEB FRONTEND β
β (Next.js) β
β β
β β’ Trading UI β
β β’ Live charts β
β β’ Place orders β
β β’ View P&L β
βββββββββββββββββββ
β
βΌ
βββββββββββββββββββ
β USER β
β (Browser) β
βββββββββββββββββββ
βββββββββββββββββββββββββββ
HOW IT WORKS
βββββββββββββββββββββββββββ
1. PRICE POLLAR fetches live BTC prices from Binance
2. Prices flow through REDIS to all services
3. USER opens the WEB FRONTEND and sees live prices
4. USER places an order β HTTP BACKEND saves it β ENGINE processes it
5. ENGINE checks Take Profit / Stop Loss on every price tick
6. Updates are pushed to USER via WS SERVER in real-time
| App | Description |
|---|---|
| web | Next.js 15 frontend with React 19, featuring interactive trading charts (Lightweight Charts), order management, and a responsive UI built with Radix UI & Tailwind CSS |
| httpBackend | Express.js REST API handling authentication, order placement, wallet management, and user operations |
| wsServer | WebSocket server for real-time price updates and live order notifications |
| engine | Trading engine that processes orders, manages order books, and calculates P&L |
| pricePollar | Service that polls external price feeds and distributes price data via Redis |
| Package | Description |
|---|---|
| @repo/db | Prisma ORM configuration with PostgreSQL database schema for users and orders |
| @repo/redisclient | Shared Redis client for pub/sub messaging between services |
| @repo/timescaledb | TimescaleDB integration for time-series price data storage |
| @repo/types | Shared TypeScript types and Zod validation schemas |
| @repo/ui | Shared React component library |
| @repo/eslint-config | Shared ESLint configurations |
| @repo/typescript-config | Shared TypeScript configurations |
- Order Management: Place Market and Limit orders with Long/Short positions
- Wallet System: Deposit funds and track balance
- Real-time Updates: Live price feeds via WebSocket connections
- P&L Tracking: Profit and loss calculation for open and closed positions
- Risk Management: Set Take Profit and Stop Loss levels on orders
- Interactive Charts: Real-time trading charts powered by Lightweight Charts
- Authentication: Secure user authentication with JWT tokens
- Frontend: Next.js 15, React 19, Tailwind CSS, Radix UI, Zustand, React Hook Form
- Backend: Express.js, Node.js
- Real-time: WebSocket (ws)
- Database: PostgreSQL with Prisma ORM
- Time-series: TimescaleDB
- Caching/Messaging: Redis
- Validation: Zod
- Build Tool: Turborepo
- Package Manager: pnpm
- Language: TypeScript
- Node.js >= 18
- pnpm 9.0.0+
- PostgreSQL
- Redis
- TimescaleDB (optional, for price history)
-
Clone the repository:
git clone https://github.com/SumitKumar777/TradingApp.git cd TradingApp -
Install dependencies:
pnpm install
-
Set up environment variables:
# Create .env files in respective apps/packages # Required variables: DATABASE_URL="postgresql://..." REDIS_URL="redis://..." JWT_SECRET="your-secret-key"
-
Generate Prisma client:
cd packages/db pnpm prisma generate pnpm prisma db push
Run all apps and packages in development mode:
pnpm devRun a specific app:
# Run only the web frontend
pnpm dev --filter=web
# Run only the HTTP backend
pnpm dev --filter=@repo/httpbackendBuild all apps and packages:
pnpm buildpnpm lintpnpm check-typesTradingApp/
βββ apps/
β βββ web/ # Next.js frontend
β βββ httpBackend/ # REST API server
β βββ wsServer/ # WebSocket server
β βββ engine/ # Trading engine
β βββ pricePollar/ # Price feed service
βββ packages/
β βββ db/ # Prisma database package
β βββ redisClient/ # Redis client
β βββ timescaledb/ # TimescaleDB integration
β βββ types/ # Shared types & validation
β βββ ui/ # UI component library
β βββ eslint-config/ # ESLint configurations
β βββ typescript-config/# TypeScript configurations
βββ turbo.json
βββ package.json
βββ pnpm-workspace.yaml
The application uses the following main entities:
- User: Stores user credentials, email, and wallet balance
- Orders: Tracks all trading orders with status, P&L, entry/exit prices, and risk parameters
The project uses Turborepo for efficient builds with caching. See turbo.json for task configurations.
To enable remote caching with Vercel:
turbo login
turbo linkISC
Sumit Kumar
β Star this repo if you find it useful!