Local Development
This guide provides step-by-step instructions for setting up the TradeX platform for local development.
Prerequisites
Section titled “Prerequisites”- Docker and Docker Compose for infrastructure
- Node.js 18+ and Bun for TypeScript services
- Go 1.25+ for Go services
- Python 3.10+ and uv for Python services
- Rust (latest stable) for matching engine
- PostgreSQL 14+ (or use Docker)
- MongoDB (or use Docker)
- Redis (or use Docker)
- Kafka (or use Docker)
Quick Start
Section titled “Quick Start”1. Clone Repository
Section titled “1. Clone Repository”git clone https://github.com/your-org/tradex.gitcd tradex2. Start Infrastructure
Section titled “2. Start Infrastructure”cd infradocker-compose up -dThis starts:
- PostgreSQL
- MongoDB
- Redis
- Kafka cluster
- Schema Registry
- Zookeeper
3. Initialize Services
Section titled “3. Initialize Services”# Run initialization script./init.sh4. Start Services
Section titled “4. Start Services”Each service can be started individually:
# Market Data Service (Go)cd apps/marketdata-servicemake run
# Order Service (TypeScript)cd apps/order-servicebun run dev
# Auth Service (Python)cd apps/auth-serviceuv run uvicorn app.main:app --reload
# User Service (Python)cd apps/user-serviceuv run uvicorn app.main:app --reload
# Wallet Service (Python)cd apps/wallet-serviceuv run python -m app.main
# Metadata Service (Go)cd apps/metadata-servicemake run
# Matching Engine (Rust)cd apps/matching-engine-rustcargo run
# Backend Service (TypeScript)cd apps/backendbun run devService-Specific Setup
Section titled “Service-Specific Setup”Market Data Service
Section titled “Market Data Service”cd apps/marketdata-service
# Install dependenciesmake deps
# Apply database schemamake atlas-schema-apply
# Generate SQLc codemake sqlc-generate
# Generate Avro codemake avro-generate
# Run servicemake runOrder Service
Section titled “Order Service”cd apps/order-service
# Install dependenciesbun install
# Run database migrationsbun run migrate
# Run servicebun run devPython Services (Auth, User, Wallet)
Section titled “Python Services (Auth, User, Wallet)”cd apps/auth-service # or user-service, wallet-service
# Install dependenciesuv sync
# Setup environmentcp sample.env .env# Edit .env with your configuration
# Run migrationsalembic upgrade head
# Run serviceuv run uvicorn app.main:app --reloadMetadata Service
Section titled “Metadata Service”cd apps/metadata-service
# Install dependenciesgo mod download
# Generate protobuf codebuf generate
# Run migrationsmake migrate
# Run servicemake runMatching Engine
Section titled “Matching Engine”cd apps/matching-engine-rust
# Buildcargo build
# Runcargo runEnvironment Configuration
Section titled “Environment Configuration”Service Environment Variables
Section titled “Service Environment Variables”Each service has a sample.env file. Copy and configure:
cp sample.env .env# Edit .env with your local configurationCommon Variables
Section titled “Common Variables”# DatabasePOSTGRES_URL=postgres://user:pass@localhost:5432/tradexMONGODB_URL=mongodb://localhost:27017/tradex
# RedisREDIS_URL=redis://localhost:6379
# KafkaKAFKA_BROKERS=localhost:9092,localhost:9093,localhost:9094SCHEMA_REGISTRY_URL=http://localhost:8081
# Service URLsAUTH_SERVICE_URL=http://localhost:8000ORDER_SERVICE_URL=http://localhost:3000# ... etcDatabase Setup
Section titled “Database Setup”PostgreSQL
Section titled “PostgreSQL”# Create databasescreatedb tradexcreatedb marketdatacreatedb metadatacreatedb authcreatedb usercreatedb wallet
# Run migrations for each servicecd apps/marketdata-service && make migratecd apps/metadata-service && make migratecd apps/auth-service && alembic upgrade head# ... etcMongoDB
Section titled “MongoDB”MongoDB is typically auto-configured via Docker. For manual setup:
# MongoDB is ready after Docker Compose starts# No additional setup neededKafka Setup
Section titled “Kafka Setup”Register Schemas
Section titled “Register Schemas”# Register all schemas./shared/scripts/kafka/schema/push.sh \ shared/kafka-schema/engine/engine.event.v1.avsc \ engine.event.v1-value
# Repeat for all schemasCreate Topics
Section titled “Create Topics”Topics are typically created automatically. For manual creation:
docker exec -it tradex-kafka-1-dev kafka-topics --create \ --topic engine.event.v1 \ --bootstrap-server kafka-1:29092 \ --replication-factor 3 \ --partitions 3Development Tools
Section titled “Development Tools”Code Formatting
Section titled “Code Formatting”# Format all codenpx ultracite format
# Lint all codenpx ultracite lintType Checking
Section titled “Type Checking”# TypeScript servicescd apps/order-servicebun run type-check
# Go servicescd apps/marketdata-servicego vet ./...Testing
Section titled “Testing”# Run tests for a servicecd apps/marketdata-servicemake test
# Run all tests# (varies by service)Hot Reload
Section titled “Hot Reload”Go Services
Section titled “Go Services”Use air for hot reload:
cd apps/marketdata-servicemake dev # Uses air for hot reloadTypeScript Services
Section titled “TypeScript Services”Use Bun’s built-in watch mode:
cd apps/order-servicebun run dev # Watches for changesPython Services
Section titled “Python Services”Use uvicorn’s reload flag:
cd apps/auth-serviceuv run uvicorn app.main:app --reloadDebugging
Section titled “Debugging”Go Services
Section titled “Go Services”# Use Delve debuggerdlv debug ./cmd/marketdata/main.goTypeScript Services
Section titled “TypeScript Services”# Use Node.js debuggernode --inspect-brk index.tsPython Services
Section titled “Python Services”# Use Python debuggerpython -m pdb -m uvicorn app.main:appCommon Issues
Section titled “Common Issues”Port Conflicts
Section titled “Port Conflicts”If ports are already in use:
# Find process using portlsof -i :8080
# Kill process or change port in .envDatabase Connection Issues
Section titled “Database Connection Issues”# Check if database is runningdocker ps | grep postgres
# Check connectionpsql $POSTGRES_URLKafka Connection Issues
Section titled “Kafka Connection Issues”# Check if Kafka is runningdocker ps | grep kafka
# Check Kafka logsdocker logs tradex-kafka-1-dev