Skip to main content

Introduction

Exchange Web is a modern, real-time crypto trading frontend built with React, TypeScript, and Vite. The application provides a professional trading interface with live order books, price charts, and instant trade execution.

Monorepo Structure

The project uses a Turborepo monorepo structure with Yarn workspaces:
exchange-web/
├── apps/
│   └── web/              # Main trading application
├── packages/
│   ├── ui/               # Shared UI components
│   ├── eslint-config/    # Shared ESLint configuration
│   └── typescript-config/ # Shared TypeScript configuration
└── turbo.json            # Turborepo configuration

Apps Directory

  • web: The primary trading interface application built with React + Vite

Packages Directory

  • ui: Reusable UI components (buttons, cards, etc.)
  • eslint-config: Shared linting rules
  • typescript-config: Shared TypeScript compiler settings

Technology Stack

React 18

Modern React with hooks for component logic

TypeScript

Type-safe development with full type coverage

Vite

Fast build tool and dev server

React Router

Client-side routing with react-router-dom v6

Key Dependencies

{
  "react": "^18.3.1",
  "react-router-dom": "^6.26.2",
  "lightweight-charts": "^4.2.1",
  "axios": "^1.7.7",
  "sonner": "^1.5.0"
}

Application Structure

apps/web/src/
├── components/           # React components
│   ├── SwapInterface.tsx
│   ├── TradeInterface.tsx
│   ├── Depth.tsx
│   ├── MarketBar.tsx
│   ├── NetBar.tsx
│   ├── depth/
│   └── trade_interface/
├── pages/               # Page components
│   └── Trade.tsx
├── state/               # State management
│   └── TradesProvider.tsx
├── utils/               # Utilities
│   ├── ws_manager.ts    # WebSocket manager
│   ├── chart_manager.ts # Chart management
│   ├── requests.ts      # API requests
│   └── types.ts         # TypeScript types
├── App.tsx              # Root component
└── main.tsx             # Application entry

Component Hierarchy

The application follows a clear component hierarchy:

Root Level

App.tsx wraps the entire application with:
  • TradesProvider for global state
  • BrowserRouter for routing
  • Toast notifications via Sonner
  • Vercel Analytics

Page Level

Trade.tsx (apps/web/src/pages/Trade.tsx:32-49) composes the main trading interface:
<div className="grid grid-cols-1 lg:grid-cols-[4fr_1fr] gap-2 mt-5 lg:mt-0">
  <div className="order-2 lg:order-1">
    <TradeInterface market={market as string} />
  </div>
  <div className="order-1 lg:order-2">
    <SwapInterface market={market as string} />
  </div>
</div>

Data Flow Architecture

1

WebSocket Connection

WsManager establishes connection to exchange backend
2

Event Subscription

Components subscribe to depth/trade events via callbacks
3

State Updates

WebSocket messages update TradesProvider context state
4

UI Rendering

Components consume context and re-render with new data

Data Flow Diagram

Routing

The application uses react-router-dom v6 for client-side routing:
<Routes>
  <Route path="/trade/:market" element={<Trade />} />
  <Route path="*" element={<Navigate to="/trade/SOL_USDC" />} />
</Routes>
  • Primary route: /trade/:market (e.g., /trade/SOL_USDC)
  • Fallback: Redirects all unknown routes to SOL_USDC market
  • Market parameter extracted with useParams() hook

Real-Time Updates

The application is designed for real-time trading with:

WebSocket Connection

Persistent connection to exchange backend

Live Order Book

Real-time bid/ask updates

Trade Stream

Instant trade notifications

Price Ticker

Live price and stats updates

Performance Considerations

Optimization Strategies

  • Singleton Pattern: WsManager uses singleton to maintain single WebSocket connection
  • Message Buffering: Messages buffered until connection established
  • Selective Updates: Components only re-render when relevant state changes
  • Context Optimization: TradesProvider exposes granular setters to minimize re-renders

Next Steps

Components

Explore component structure and composition

State Management

Learn about TradesProvider and context usage

WebSocket

Understand real-time communication

Build docs developers (and LLMs) love