TradeX is a full-stack trading simulation built as a Bun + Turborepo monorepo. It pairs a Next.js trading dashboard with a Hono API, PostgreSQL persistence, Redis-backed order books, and Socket.IO streams for live market depth and candlestick updates.
- Limit and market order placement with basic order matching
- Redis-backed bid/ask order book with live depth broadcasts
- Real-time candlestick chart updates over Socket.IO
- Authenticated user accounts with signed HTTP-only cookie sessions
- Portfolio dashboard for cash, holdings, active orders, and trade history
- PostgreSQL schema and migrations managed with Drizzle ORM
- Shared TypeScript, ESLint, and UI packages across the monorepo
| Layer | Tools |
|---|---|
| Monorepo | Bun workspaces, Turborepo |
| Frontend | Next.js 16, React 19, Tailwind CSS 4, TanStack Query, Zustand |
| Backend | Bun, Hono, Socket.IO, Zod, JWT, bcrypt |
| Data | PostgreSQL, Drizzle ORM, Redis |
| Charts | lightweight-charts, Recharts |
apps/
frontend/ Next.js web app and trading dashboard
backend/ Hono API, matching logic, sockets, database access
packages/
ui/ Shared React UI primitives
eslint-config/
typescript-config/- Bun 1.3+
- PostgreSQL
- Redis
bun installCreate apps/backend/.env:
DATABASE_URL=postgres://USER:PASSWORD@localhost:5432/tradex
REDIS_URL=redis://localhost:6379
JWT_SECRET=replace-with-a-long-random-secret
PORT=8080
NODE_ENV=developmentCreate apps/frontend/.env.local:
NEXT_PUBLIC_API_URL=http://localhost:8080
NEXT_PUBLIC_WS_URL=http://localhost:8080cd apps/backend
bun run db:migrateFrom the repository root:
bun run devThe frontend runs on http://localhost:3000 and the backend defaults to http://localhost:8080.
bun run dev # Start all apps through Turborepo
bun run build # Build all workspaces
bun run lint # Run lint checks
bun run check-types # Run TypeScript checks
docker run -d --name redis -p 6379:6379 redis:latest # spin dockerBackend-specific commands:
cd apps/backend
bun run db:gen # Generate Drizzle migrations
bun run db:migrate # Apply migrations
bun run db:studio # Open Drizzle Studio| Method | Route | Description |
|---|---|---|
POST |
/auth/signup |
Create an account with starter cash and stock |
POST |
/auth/login |
Authenticate and set session cookie |
GET |
/auth/logout |
Clear session cookie |
GET |
/user |
Return the current portfolio profile |
GET |
/user/transactions |
Return trade history |
POST |
/trade/makeorder |
Place a limit or market order |
GET |
/trade/depth |
Return current bid/ask depth |
GET |
/trade/chart |
Return recent candlestick data |
GET |
/trade/myorders |
Return the authenticated user's open orders |
POST |
/trade/cancelorder |
Cancel an open order |
Socket.IO is served from the backend port.
| Event | Payload |
|---|---|
depth |
Current asks and bids arrays |
chart |
Recent OHLC candle array |
Before opening a PR or presenting the project, run:
bun run lint
bun run check-typesThis is a trading simulator for engineering and product demonstration. It is not connected to live brokerage infrastructure and should not be used for real-money trading.
