Architecture Overview
Architecture Overview
Section titled “Architecture Overview”TradeX is built as a microservices architecture, with each service handling a specific domain.
System Architecture
Section titled “System Architecture”┌─────────────┐ ┌─────────────┐ ┌─────────────┐│ Frontend │────▶│ Backend │────▶│ Services ││ (Next.js) │ │ (Hono) │ │ (Microsvcs) │└─────────────┘ └─────────────┘ └─────────────┘ │ ▼ ┌─────────────┐ │ Database │ │ (MongoDB) │ └─────────────┘Core Components
Section titled “Core Components”Frontend
Section titled “Frontend”- Next.js Application: User interface and client console
- WebSocket Client: Real-time data streaming
Backend Services
Section titled “Backend Services”- Market Data Service: Market data ingestion and distribution
- Order Service: Order management and execution
- Auth Service: Authentication and authorization
- User Service: User profile management
- Wallet Service: Wallet operations and balance tracking
- Metadata Service: Trading symbols and configuration
Infrastructure
Section titled “Infrastructure”- MongoDB: Primary database
- PostgreSQL: Relational data storage
- Redis: Caching and session management
- Kafka: Event streaming and messaging
- gRPC: Inter-service communication
Data Flow
Section titled “Data Flow”- Market Data: External exchanges → Market Data Service → WebSocket/Kafka → Clients
- Orders: Client → Order Service → Matching Engine → Execution
- Authentication: Client → Auth Service → JWT Token → Service Access
For detailed data flows, see the Data Flow documentation.
Service Communication
Section titled “Service Communication”Services communicate via:
- REST APIs: External client access
- gRPC: Internal service-to-service communication
- Kafka: Event-driven messaging
- WebSocket: Real-time client updates
For detailed communication patterns, see the Communication Patterns documentation.
Key Services
Section titled “Key Services”Market Data Service
Section titled “Market Data Service”Real-time market data ingestion, processing, and distribution via WebSocket and REST APIs.
Order Service
Section titled “Order Service”Order management, validation, and lifecycle handling with integration to matching engine.
Matching Engine
Section titled “Matching Engine”High-performance order matching and trade execution engine built in Rust.
Metadata Service
Section titled “Metadata Service”Canonical reference data store for instruments, configuration, and trading rules.
Auth Service
Section titled “Auth Service”User authentication, JWT token management, and API key management.
User Service
Section titled “User Service”User profile management, preferences, and KYC workflows.
Wallet Service
Section titled “Wallet Service”Balance management, deposits, withdrawals, and transaction history.
Position Service
Section titled “Position Service”Position tracking, risk calculations, and position limit enforcement.
Backend Service
Section titled “Backend Service”API aggregation layer providing unified access to multiple services.
Infrastructure Components
Section titled “Infrastructure Components”Databases
Section titled “Databases”- MongoDB: Document storage for user data and preferences
- PostgreSQL: Relational data for transactions and configuration
- TimescaleDB: Time-series data for market data
- ClickHouse: Analytics and historical data storage
Caching
Section titled “Caching”- Redis: In-memory caching and session management
Messaging
Section titled “Messaging”- Kafka: Event streaming and asynchronous messaging
- Schema Registry: Avro schema management for Kafka events
Observability
Section titled “Observability”- Prometheus: Metrics collection
- Grafana: Metrics visualization
- OpenTelemetry: Distributed tracing