Skip to content

Architecture ​

The exchange is one Laravel application surrounded by a few small services. Knowing which part does what makes installation, monitoring and troubleshooting much easier.

5 minutesOverviewSite owner / DevOpsVerified against the platform code

The big picture ​

Browsers & API clientsVisitors, traders, admins, merchants
HTTPS 443 · WSS 443
Nginxyourdomain.com · /chart.io · socket.yourdomain.com
PHP-FPM · proxy
Laravel web appPages, admin panel, REST API, order entry
Soketi:6001 · live updates
chart-udf:8081 · provider candles
shared database, Redis and code
Horizon workersorders · orderbook · market · events · webhooks · low
PM2 processesorder-processor · stop-trigger · market-watcher · liquidity runners · bots · futures · P2P · options
Schedulercron · deposits · rewards · watchers
read / write
PostgreSQL:5432 · users, balances, orders, settings
Redis:6379 · queues, cache, sessions
Rust engine:9000 · optional
blockchains & market data
Bridges:8000–8007 · ETH, BNB, Tron, Polygon, Solana, TON
External servicesBinance · MEXC · Bybit · Etherscan · node providers · KYC · payments

The parts ​

PartWhat it doesRuns as
Laravel web appEvery page, the admin panel at /exchange-control-panel, the REST API at /api/v1, sign-in, and placing ordersPHP-FPM behind Nginx
PostgreSQLThe source of truth: users, wallets and balances, orders, trades, deposits, withdrawals, and every admin settingSystem service
RedisQueues, cache (including live market statistics) and sessionsSystem service
HorizonBackground workers for queued jobs: order processing, live updates, emails, merchant webhooksPM2 horizon, started by pm:watcher
Order processorEvery 2 seconds, fills resting spot limit orders that the liquidity provider's moving prices now cross (new orders are matched the moment they're placed)PM2 order-processor, started by pm:watcher
Price trackerKeeps market prices and 24h statistics current and pushes them to browsersPM2 market-watcher, started by pm:watcher
Liquidity runnersTwo processes for all markets: one Binance connection mirrors the book and trades of every provider-backed market; the other simulates every custom-token marketPM2 liquidity-binance, liquidity-custom, started by pm:watcher
Stop triggerPlaces stop-limit and OCO stop orders, moves and fires trailing stops, and fires TP/SL orders when a trade or price move reaches the stop (woken at once, checks every 3 s anyway)PM2 stop-trigger, started by pm:watcher
Futures, P2P and options processorsLiquidations, futures limit and TP/SL orders, expired P2P orders, option settlementPM2, started by pm:watcher (plan 5)
SchedulerEverything on a timer: deposit detection, wallet balances, rewards, funding fees, mini-charts, the process watchersOne cron entry
SoketiPushes live updates to browsers over WebSocketsPM2 soket
chart-udfServes Binance candles for markets whose chart type is From liquidity providerPM2 chart
BridgesOne Node.js service per network: create addresses, sign and send transactionsPM2 bridge-<network>
Rust matching engineOptional in-memory matching for markets without a liquidity providerPM2 matching-engine

Details for each are in Services & infrastructure. Ports and process names are in Ports & processes.

What happens when someone places an order ​

  1. The order form sends the order to the platform's API. Orders from the website are allowed automatically for signed-in users. Orders from trading bots need an API key with the trade permission.
  2. One market at a time. The spot engine (app/Services/Spot) takes a database lock for the market and opens one database transaction. Everything below happens inside it: if anything fails, nothing is kept.
  3. Checks and balance hold. Price, amount, minimums and the order type's rules are checked. The amount the order needs is moved from the user's available balance to in orders with a guarded update (it can't go below zero), and the order is saved with what it holds. An OCO saves two orders sharing one hold.
  4. Matching. The order is matched straight away by price, then time, against the platform's book and the liquidity provider's mirrored levels as one book (stop-limit orders wait for their stop price instead). See Spot trading → How orders are matched.
  5. Trades are recorded. Each fill creates the two trade rows, moves funds between the wallets and takes the maker or taker fee by role.
  6. The rest. A limit order that isn't fully filled stays in the book (IOC / FOK / market orders don't). The order-processor fills resting orders later if the liquidity provider's price moves through them; orders:trigger-stops and every trade trigger waiting stop orders.
  7. Live updates. After the transaction is saved, order-book, trade, price and wallet events go onto the orderbook, market and events queues. Horizon sends them to Soketi, and every open trade page updates within moments.

Two front-end bundles, one theme system ​

The browser code is built twice from the same source:

  • the visitor bundle (public/frontend/) for everyone without the admin role, and
  • the admin bundle (public/alternative/), which adds the admin panel and is loaded for admins on every page.

Both use the same page templates: each template is looked up in resources/js/Themes/prime first, then resources/js/Themes/default. Visitors can pick light, dark or system theme; the colour palette is Gold (set with UI_PALETTE). See Building assets and Languages & themes.

Plans ​

APP_PLAN in .env sets which product package is active. With APP_PLAN=5 (the value in .env.example) the platform also runs the futures, P2P and options background processors and shows plan-5 admin features such as cold storage.

Optional modules ​

Some modules are switched on in .env:

ModuleSwitch
LendingLENDING_ENABLED=true
Merchant paymentsMERCHANT_ACQUIRING_ENABLED=true
Rust matching engineMATCHING_ENGINE_ENABLED=true
Card on-ramp (Buy crypto)UNLIMIT_ENABLED=true
Sumsub KYCSUMSUB_ENABLED=true
Fireblocks custodyFIREBLOCKS_ENABLED=true
Deposit bonusesDEPOSIT_BONUS_ENABLED=true

All of them are explained in Environment (.env).

Owner documentation for the CryptoTech exchange platform.