COPYTRADER PLATFORM

Go Backend · Next.js 14 · Apache Kafka · Multi-Broker Copy Trading

87
Tasks
7
Brokers
20+
Accounts
<3s
SLA
24
Weeks

01 · Project Summary

CopyTrader is a low-latency, multi-broker copy trading platform that mirrors trades from a master/leader account to up to 20+ follower accounts in parallel, with an end-to-end execution SLA of under 3 seconds. It supports 7 major futures brokers and provides a real-time dashboard for monitoring all accounts simultaneously.

Core Problem Being Solved

Traders running multiple prop firm or personal accounts need every follower account to execute the same trade as the leader account — fast, reliably, and at scale. Traditional manual duplication is impossible at the speed required. This platform automates the entire flow from signal detection to execution confirmation across all accounts.

Key Design Decisions

02 · System Architecture

Layer-by-Layer Data Flow

LayerComponent
1Next.js 14 Frontend (SSR + client components, WebSocket)
2Go WS Gateway (:8081) + Go REST API (:8080)
3Apache Kafka Cluster (KRaft, 6 topics)
4Go Microservices (Signal Ingestion, Fan-Out, Executor, Position Tracker)
57 Broker Adapters (persistent auth, circuit breakers)
6PostgreSQL+TimescaleDB, Redis, Prometheus+Grafana

Kafka Topics

TopicPartitionsKeyPurpose
trade.signals3symbolMaster order events
trade.executions10account_idFill confirmations
positions.updates10account_idPosition & P&L
account.status20account_idBroker health
order.errors5account_idExecution failures
system.heartbeat1-Service health

Execution Latency Budget (per trade)

Signal detection<50ms
Normalization + Kafka publish<25ms
Fan-out router + goroutine dispatch<10ms
Broker API execution (P95)<800ms
Result collection + Kafka publish<50ms
Total end-to-end (typical)<1 second
Total end-to-end (worst case SLA)<3 seconds

03 · Technology Stack

Frontend

  • Next.js 14 (App Router) TypeScript strict
  • Tailwind CSS shadcn/ui
  • Zustand AG Grid Community
  • TradingView Lightweight Charts
  • NextAuth.js TanStack Query
  • React Hook Form + Zod

Backend (Go)

  • Go 1.22+ Fiber v2
  • Gorilla WebSocket segmentio/kafka-go
  • Viper Zap logger
  • golang-migrate sync.WaitGroup
  • context.WithTimeout

Infrastructure

  • Kafka (KRaft) Redis
  • PostgreSQL + TimescaleDB
  • Prometheus + Grafana
  • Redpanda Console Docker Compose
  • Kubernetes GitHub Actions
  • Equinix NY4 / AWS us-east-1

04 · Broker Adapter Summary (7 Brokers)

BrokerProtocolConnectionKey Notes
TradovateREST + WebSocketPersistent WSSOAuth2 token, fill subscription via WS
RithmicR|API+ (proprietary)TCP binary (C SDK)Most complex — CGO wrapper
DxFeeddxLinkWebSocketOrder chain event subscription
NinjaTraderATITCP socketSuperDOM AT Interface, text commands
ProjectXREST + WebSocketHTTP + WSSStraightforward HTTP API, WS for fills
QuantowerFIX 4.2/4.4FIX sessionStandard FIX, session management
Sierra ChartSCID / DLLDLL/Extension APITrading extension interface

Every adapter implements BrokerAdapter Go interface: Connect(), PlaceOrder(), Subscribe(), Disconnect()

05 · Go Project Structure

/copytrader
├── cmd/
│   ├── ingestion/          # Signal ingestion service
│   ├── router/              # Fan-out order router
│   ├── executor/            # Broker executor worker pool
│   ├── gateway/             # WebSocket gateway (browser-facing)
│   └── tracker/             # Position & P&L tracker
├── internal/
│   ├── kafka/               # Producer/Consumer wrappers
│   ├── brokers/
│   │   ├── tradovate/
│   │   ├── rithmic/
│   │   ├── ninjatrader/
│   │   ├── projectx/
│   │   ├── dxfeed/
│   │   ├── quantower/
│   │   └── sierrachart/
│   ├── models/              # TradeSignal, Execution, Position
│   ├── router/               # Fan-out logic
│   ├── scaling/              # Scaling rules engine
│   └── circuit/              # Circuit breaker
├── pkg/
│   └── ws/                   # WebSocket hub
└── docker-compose.yml
        

06 · Next.js Frontend Structure

/copytrader-frontend
├── app/
│   ├── layout.tsx
│   ├── (auth)/login/page.tsx
│   ├── dashboard/page.tsx            # SERVER Component
│   ├── trading/page.tsx               # CLIENT Component
│   │   └── components/
│   │       ├── AccountGrid.tsx
│   │       ├── OrderLog.tsx
│   │       ├── PositionPanel.tsx
│   │       └── TradingChart.tsx
│   ├── accounts/page.tsx
│   ├── reports/page.tsx
│   └── api/
│       ├── accounts/route.ts
│       ├── orders/route.ts
│       └── auth/[...nextauth]/
├── hooks/
│   ├── useWebSocket.ts
│   ├── useTradeStream.ts
│   └── usePositions.ts
├── store/
│   ├── tradeStore.ts          # Zustand
│   ├── positionStore.ts
│   └── accountStore.ts
├── lib/
│   ├── ws.ts                   # WebSocket singleton
│   ├── api.ts
│   └── types.ts
└── middleware.ts
        

Critical Next.js Rules

  • WebSocket ALWAYS connects directly from browser to Go WS Gateway — never through Next.js
  • Server Components: dashboard, reports — no WebSocket
  • Client Components: trading, AG Grid, Zustand — all real-time UI
  • Next.js API routes are BFF only — proxy to Go REST API

07 · 6-Phase Implementation Plan · 87 Tasks

P1 · Infrastructure Setup · Weeks 1–2
1.1 Go monorepo init (cmd/, internal/, pkg/)
1.2 Next.js 14 scaffold (TS, Tailwind, shadcn/ui)
1.3 Docker Compose (Kafka KRaft, Redis, PostgreSQL+TimescaleDB)
1.4 Kafka topics creation script (6 topics)
1.5 PostgreSQL schema migrations
1.6 TimescaleDB hypertable setup
1.7 Prometheus + Grafana setup
1.8 Redpanda Console (Kafka UI)
1.9 Environment config (Viper, .env.local)
P2 · Broker Adapter Layer · Weeks 3–6
2.1 BrokerAdapter Go interface
2.2 Internal model structs (TradeSignal, Execution, Position)
2.3 Background token refresh goroutine pattern
2.4 Tradovate WebSocket adapter
2.5 Rithmic R|API+ adapter (CGO)
2.6 DxFeed dxLink adapter
2.7 NinjaTrader ATI adapter
2.8 ProjectX REST + WS adapter
2.9 Quantower FIX 4.2/4.4 adapter
2.10 Sierra Chart DLL adapter
2.11 Unit tests per adapter
P3 · Core Engine · Weeks 7–10
3.1 Signal ingestion service
3.2 Event normalization pipeline
3.3 Kafka producer setup (trade.signals)
3.4 Fan-out router Kafka consumer
3.5 Follower account loader (Redis hot config)
3.6 Scaling rules engine (fixed/proportional/percent)
3.7 Parallel goroutine fan-out (sync.WaitGroup)
3.8 2.5s context timeout enforcement
3.9 Circuit breaker per broker
3.10 Execution result aggregation
3.11 Position tracker service
3.12 Risk pre-trade checks
P4 · REST API & WebSocket Gateway · Weeks 11–14
4.1 Fiber REST API setup (middleware, CORS)
4.2 GET/POST/PUT/DELETE /accounts
4.3 PUT /accounts/:id/scaling
4.4 GET /orders with filters
4.5 GET /dashboard/:userId (SSR summary)
4.6 GET /health (broker status)
4.7 JWT auth middleware (Redis session store)
4.8 WebSocket hub (thread-safe registry)
4.9 Kafka → WebSocket bridge
4.10 Account-scoped routing
4.11 Prometheus metrics middleware
4.12 Ping/pong heartbeat (WS)
P5 · Next.js Frontend · Weeks 15–20
5.1 NextAuth.js JWT setup
5.2 middleware.ts route protection
5.3 App shell layout (sidebar, navbar, dark theme)
5.4 WebSocket singleton (lib/ws.ts, auto-reconnect)
5.5 Zustand tradeStore
5.6 Zustand positionStore
5.7 Zustand accountStore
5.8 useTradeStream hook
5.9 AccountGrid (AG Grid) live P&L
5.10 OrderLog component
5.11 PositionPanel component
5.12 TradingView chart integration
5.13 Dashboard page (Server Component)
5.14 Account management CRUD UI
5.15 Scaling rules configurator
5.16 Reports page with CSV export
5.17 TypeScript types (lib/types.ts)
5.18 BFF API routes (Next.js)
P6 · Production Hardening & Deployment · Weeks 21–24
6.1 Zap structured logger (JSON, trace IDs)
6.2 Prometheus metrics per service
6.3 Grafana dashboards (latency, Kafka lag)
6.4 Alerting rules (PagerDuty/Slack)
6.5 AES-256 credential encryption
6.6 Integration tests — full signal flow
6.7 Load test: 20 accounts, 100 signals/min
6.8 Circuit breaker chaos test
6.9 Equinix NY4 / AWS provisioning
6.10 Kubernetes manifests (Deployments, HPA)
6.11 GitHub Actions CI/CD pipeline
6.12 Next.js production deployment (Vercel/self-hosted)

08 · Session Continuation Guide

What to Tell Claude in a New Session

CONTEXT FOR NEW SESSION: I am building a multi-broker copy trading platform with the following stack: - Backend: Go (Fiber framework, segmentio/kafka-go, Gorilla WS, Zap logger) - Frontend: Next.js 14 with TypeScript, shadcn/ui, Zustand, AG Grid, TradingView Charts, NextAuth.js - Message Bus: Apache Kafka (KRaft mode) with 6 topics - Database: PostgreSQL + TimescaleDB, Redis - Brokers: Tradovate, Rithmic, DxFeed, NinjaTrader, ProjectX, Quantower, Sierra Chart - Target: <3s execution across 20+ follower accounts in parallel **- I am currently on Phase [X], Task [Y]. Please help me with [specific task].**

Phase Completion Checklist

P1 Infrastructure
▢ Not Started
P2 Broker Adapters
▢ Not Started
P3 Core Engine
▢ Not Started
P4 API & Gateway
▢ Not Started
P5 Frontend
▢ Not Started
P6 Production
▢ Not Started

Critical Rules to Always Keep in Mind