How kronex-stock-exchange/kronex-engine works
Kronex Engine consumes exchange requests from RabbitMQ, applies them to an in-memory ledger and price-time-priority order books, and records results for independent database projection and event publication. The graph also shows the documented admin/transfer paths, snapshot persistence, and recovery. Some subsystem links come from the README because their implementation was not excerpted; unsampled internal call details are not inferred.
Main entry points: engine.go Main Engine · handle.go Request Routing · order.go Order Matching · rabbitmq.go Queue Adapter
Components 21
Request Processing
- Queue Adapter
internal/messaging/rabbitmq.go - Main Engine
internal/core/engine.go - Request Routing
internal/core/handle.go - Order Validation
internal/core/order_validation.go - Order Matching
internal/core/order.go - Admin Requests
internal/core/handle_admin.go - Transfers
internal/core/transfer.go - Request Dedup
internal/core/dedup.go
Ledger State
- Memory Ledger
internal/ledger/ledger.go - Order Books
internal/ledger/orderbook.go - Account State
internal/ledger/account.go - Stock Balances
internal/ledger/stockbalance.go
Durability
- Write-Ahead Logs
internal/wal/wal.go - Snapshot Store
internal/storage/snapshot.go
Result Delivery
- DB Projector
internal/publisher/db_projector.go - Event Publisher
internal/publisher/event_publisher.go - Publisher Coordinator
internal/publisher/handler.go - Event Store
internal/storage/event.go
Other components
- API Server
- RabbitMQ
- MySQL
Connections 25
- API Server → RabbitMQ: enqueues requests
- RabbitMQ → Queue Adapter: delivers requests
internal/messaging/rabbitmq.go - Queue Adapter → Main Engine: supplies deliveries
- Main Engine → Request Routing: routes requests
internal/core/handle.go - Main Engine → Request Dedup: deduplicates requests
- Request Routing → Order Validation: validates orders
- Request Routing → Order Matching: handles orders
- Request Routing → Admin Requests: handles admin
- Request Routing → Transfers: handles transfers
- Main Engine → Write-Ahead Logs: records input and output
- Main Engine → Memory Ledger: restores and replays state
- Order Matching → Order Books: matches against
internal/core/order.go - Order Matching → Account State: updates balances
internal/core/order.go - Order Matching → Stock Balances: updates holdings
internal/core/order.go - Main Engine → Snapshot Store: saves and loads snapshots
- Snapshot Store → MySQL: persists snapshots
- Write-Ahead Logs → DB Projector: provides output records
- Write-Ahead Logs → Event Publisher: provides output records
- Main Engine → Publisher Coordinator: starts publisher
- Publisher Coordinator → DB Projector: runs independently
internal/publisher/handler.go - Publisher Coordinator → Event Publisher: runs independently
internal/publisher/handler.go - DB Projector → Event Store: applies events
internal/publisher/db_projector.go - Event Store → MySQL: updates query tables
internal/storage/event.go - Event Publisher → Queue Adapter: publishes event batches
internal/publisher/event_publisher.go - Queue Adapter → RabbitMQ: publishes events
internal/messaging/rabbitmq.go