Component Architecture
Exchange Web uses a modular component architecture with clear separation of concerns. Components are organized by feature and responsibility.Main Components
The application consists of five main top-level components:SwapInterface
Order entry interface for buying/selling
TradeInterface
Trading view with chart and order book
Depth
Order book and recent trades display
MarketBar
Market information and price ticker
NetBar
Network status and user information
SwapInterface Component
The SwapInterface provides order entry functionality with support for limit and market orders.Key Features
- Buy/Sell mode toggle
- Order type selection (Limit/Market)
- Real-time fee calculation
- Position sizing
- Price integration from context
Component Interface
State Management
From apps/web/src/components/SwapInterface.tsx:7-17:Order Creation
From apps/web/src/components/SwapInterface.tsx:29-62:TradeInterface Component
A composition component that combines the trading chart and order book display.Component Code
From apps/web/src/components/TradeInterface.tsx:1-12:Layout
- Desktop: Side-by-side layout (3:1 ratio)
- Mobile: Stacked layout
- Chart Area: Fixed 600px height
- Depth Area: Responsive height
Depth Component
Manages order book and recent trades with real-time WebSocket updates.Props Interface
State from Context
From apps/web/src/components/Depth.tsx:14-22:WebSocket Integration
The component registers callbacks for depth and trade updates: From apps/web/src/components/Depth.tsx:24-96:Tab Interface
From apps/web/src/components/Depth.tsx:11-12:- Order Book: Live bid/ask ladder
- Recent Trades: Trade history stream
MarketBar Component
Displays current market information and statistics.Context Integration
From apps/web/src/components/MarketBar.tsx:6-8:Data Fetching
From apps/web/src/components/MarketBar.tsx:10-18:Displayed Information
- Current price
- 24h price change percentage
- 24h trading volume
- 24h high/low prices
- Market pair (SOL/USDC)
Component Composition
Components follow React best practices:Props Pattern
Context Consumption
All major components consume TradesContext:TypeScript Interfaces
From apps/web/src/utils/types.ts:Trade Interface
Trade Interface
Depth Interface
Depth Interface
CreateOrder Interface
CreateOrder Interface
Ticker Interface
Ticker Interface
Component Lifecycle
Initialization Flow
Cleanup Example
From apps/web/src/components/Depth.tsx:180-192:Next Steps
State Management
Learn how TradesProvider manages global state
WebSocket
Understand real-time data communication