Building the Matchstick Trading Engine with Polylith Architecture

Most trading engines are monolithic and tightly coupled to their interface. That makes them hard to test and impossible to reuse across CLI, TUI, and web clients. I wanted a clean separation between business logic and interfaces without giving up performance.

The Problem

Trading engines often suffer from:

  • Monolithic structure that mixes UI and core logic
  • Low testability due to hard dependencies
  • Slow iteration when interfaces change
  • Performance compromises under load

The Solution

Matchstick CLI/Engine is a Rust trading engine built with Polylith architecture. The core business logic is extracted into reusable components, while interfaces are thin bases that compose those components.

Polylith Components

  • core-types - Market structures and position tracking
  • indicators - 50+ technical indicators
  • orders - Order lifecycle management and execution tracking
  • risk - Position sizing and portfolio metrics
  • strategy - Strategy state and backtesting hooks

Bases

  • CLI - Command-line interface using Clap
  • Planned - TUI and Web-RPC interfaces

Technical Highlights

  • 309 passing tests with concurrency and edge-case coverage
  • Sub-millisecond operations for core execution paths
  • Concurrency-safe order processing validated with parallel tests
  • Polylith dependency graph keeps components isolated and reusable

Impact

  • Reusable business logic across CLI, TUI, and Web-RPC
  • Faster testing by isolating components
  • More reliable execution with aggressive test coverage

What Makes It Different

The engine is designed as a set of reusable components rather than a single executable. That keeps the core logic stable while interfaces evolve independently.

Tech Stack

  • Rust 1.70+
  • Polylith architecture
  • Clap for CLI
  • Comprehensive Rust test suite

Current Status

v0.0.2 Released:

  • Polylith foundation with 5 components
  • CLI base implemented
  • 4 critical bugs fixed pre-release

Planned:

  • TUI dashboard
  • Web-RPC interface
  • Live trading integrations

What I Learned

Polylith architecture scales well for complex domains when you prioritize clean interfaces. Testing early and aggressively is the fastest way to catch the bugs that matter.

Links


Small components make complex systems easier to test and reuse.