TRADENOVA

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

Common Architecture
7 diagrams · system map · pipelines · DB schema
ProjectX Architecture
10 diagrams · SignalR · poll fallback · circuit breaker
87
Tasks
7
Brokers
20+
Accounts
<3s
SLA
24
Weeks

01 · Project Summary

TradeNova 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. TradeNova 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, 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.heartbeat1Service 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 CSSshadcn/ui
  • ZustandAG Grid Community
  • TradingView Lightweight Charts
  • NextAuth.jsTanStack Query
  • React Hook Form + Zod

Backend (Go)

  • Go 1.22+Fiber v2
  • Gorilla WebSocketsegmentio/kafka-go
  • ViperZap logger
  • golang-migratesync.WaitGroup
  • context.WithTimeoutgobreaker

Infrastructure

  • Kafka (KRaft)Redis
  • PostgreSQL
  • Prometheus + Grafana
  • Redpanda ConsoleDocker Compose
  • KubernetesGitHub 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
ProjectX REST + SignalR HTTP + WSS SignalR fills · HTTP poll fallback · pgcrypto account sync
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

/tradenova-backend
├── cmd/
│   ├── ingestion/          # Signal ingestion service  :9100
│   ├── router/              # Fan-out order router      :9101
│   ├── executor/            # Broker executor worker pool
│   ├── gateway/             # REST :8080 · WebSocket :8081
│   └── tracker/             # Position & P&L tracker   :9103
├── internal/
│   ├── kafka/               # Producer/Consumer wrappers
│   ├── brokers/
│   │   ├── tradovate/
│   │   ├── rithmic/
│   │   ├── ninjatrader/
│   │   ├── projectx/        # SignalR + HTTP poll fallback
│   │   ├── dxfeed/
│   │   ├── quantower/
│   │   └── sierrachart/
│   ├── api/
│   │   ├── handlers/        # auth, accounts, orders, dashboard
│   │   └── middleware/      # JWTProtected (jwt/v5, NOT jwtware)
│   ├── models/              # TradeSignal, Execution, Position
│   ├── router/               # Fan-out logic (fanout.go)
│   ├── scaling/              # Scaling rules engine
│   └── circuit/              # gobreaker per broker
├── pkg/
│   └── ws/                   # WebSocket hub (thread-safe)
└── docker-compose.yml

06 · Next.js Frontend Structure

/tradenova-frontend
├── app/
│   ├── layout.tsx
│   ├── (auth)/login/page.tsx        # NextAuth credentials signIn
│   ├── (auth)/signup/page.tsx       # POST /api/auth/signup
│   ├── accounts/page.tsx            # flat list · crown icons
│   ├── dashboard/page.tsx           # SERVER Component
│   └── api/
│       ├── auth/[...nextauth]/route.ts   # calls Go /auth/login
│       ├── auth/signup/route.ts          # proxies to Go /auth/register
│       ├── accounts/route.ts             # Bearer token → Go /accounts
│       ├── orders/route.ts
│       └── projectx/auth/route.ts        # server-side PX account sync
├── components/
│   └── accounts/AddConnectionModal.tsx   # ProjectX sync flow
├── hooks/
│   ├── useTradeStream.ts            # routes WS messages to stores
│   └── usePositions.ts
├── store/
│   ├── tradeStore.ts                # Zustand · 500 exec ring buffer
│   ├── positionStore.ts             # Zustand · position map
│   └── accountStore.ts
├── lib/
│   ├── ws.ts                        # WS singleton · exp backoff reconnect
│   ├── types.ts                     # Account, Execution, Position, WSMessage
│   └── go-auth.ts                   # goAuthHeader() reads goToken from session
└── 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 ✓ COMPLETE
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)
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 ✓ COMPLETE
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 + SignalR 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 ✓ COMPLETE
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 ✓ COMPLETE
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 (jwt/v5, 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 ◑ IN PROGRESS
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 (500 exec ring buffer)
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 ProjectX account sync (AddConnectionModal)
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 ▢ NOT STARTED
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)

Phase Completion Status

P1 Infrastructure
✓ Complete
P2 Broker Adapters
✓ Complete
P3 Core Engine
✓ Complete
P4 API & Gateway
✓ Complete
P5 Frontend
◑ In Progress
P6 Production
▢ Not Started

Critical Rules to Always Keep in Mind