High-performance order execution engine with multi-DEX routing and real-time WebSocket updates for Solana. Uses mock DEX implementation with realistic delays and price variations.
๐ Live API: https://order-execution-engine-production-fa00.up.railway.app | ๐ฎ Postman: Collection | ๐บ Demo: Youtube
| Category | Technologies |
|---|---|
| Backend | Node.js, TypeScript, Fastify |
| Database | PostgreSQL (Prisma ORM), Redis |
| Queue | BullMQ |
| WebSocket | @fastify/websocket |
| Validation | Zod |
| Testing | Integration & E2E tests |
| Dev Tooling | Docker Compose, ESLint, Winston Logger |
Clean Architecture + Repository Pattern
โโโโโโโโโโโโโโโโโโโ
โ HTTP/WS API โ โ Fastify routes
โโโโโโโโโโโโโโโโโโโค
โ Controllers โ โ Request handlers
โโโโโโโโโโโโโโโโโโโค
โ Services โ โ Business logic (DEX, Orders, Queue, WebSocket)
โโโโโโโโโโโโโโโโโโโค
โ Repositories โ โ Data access (Database, Redis)
โโโโโโโโโโโโโโโโโโโค
โ PostgreSQL/Redisโ โ Persistent storage
โโโโโโโโโโโโโโโโโโโ
Order Processing Flow:
API Request โ Validation โ Queue (BullMQ) โ Worker โ DEX Router โ Execution โ WebSocket Broadcast
Implementation: Mock DEX providers (Option B) - simulates Raydium/Meteora with realistic delays (2-3s) and price variations (~2-5%). Focus on architecture and flow rather than real devnet execution.
src/
โโโ server.ts # Main entry point
โโโ config/ # Environment config
โโโ controllers/ # Request handlers (health, orders)
โโโ routes/ # API route definitions
โโโ services/
โ โโโ dex/ # DEX providers (Raydium, Meteora) + routing
โ โโโ orders/ # Order management & lifecycle
โ โโโ queue/ # BullMQ queue + worker
โ โโโ websocket/ # WebSocket manager (subscriptions, broadcasts)
โโโ repositories/ # Database/Redis access layer
โโโ validators/ # Zod schemas
โโโ types/ # TypeScript types
โโโ utils/ # Logger, helpers
prisma/
โโโ schema.prisma # Database schema
โโโ migrations/ # SQL migrations
tests/
โโโ integration/ # Service-level tests (no server)
โโโ e2e/ # Full API tests (with server)
- Node.js โฅ18.0.0
- Docker & Docker Compose
- pnpm v10+ (install with
npm install -g pnpm)
1. Clone the repository
git clone <repository-url>
cd order-execution-engine2. Install dependencies
pnpm install3. Configure environment
cp .env.example .env
# Edit .env with your database credentials if needed4. Start services (PostgreSQL & Redis)
pnpm docker:up5. Run database migrations
pnpm db:migrate6. Start the server
pnpm dev
# Server runs at http://localhost:30007. Verify installation
curl http://localhost:3000/health
# Should return: {"status":"ok","timestamp":...}pnpm install # Install dependencies
pnpm docker:up # Start PostgreSQL & Redis
pnpm db:migrate # Run migrations
pnpm dev # Start server (http://localhost:3000)| Method | Endpoint | Description |
|---|---|---|
GET |
/health |
Basic health check |
GET |
/health/status |
Detailed system status |
GET |
/health/websocket |
WebSocket stats |
GET |
/health/queue |
Queue statistics |
| Method | Endpoint | Description |
|---|---|---|
POST |
/api/orders/execute |
Execute market order |
POST |
/api/orders/simulate |
Simulate order (dry-run) |
GET |
/api/orders/:orderId |
Get order status |
GET |
/api/orders/stats |
Order statistics |
| Protocol | Endpoint | Description |
|---|---|---|
WS |
/ws |
Real-time order updates (subscribe to orderId or * for all) |
Note: WebSocket uses standard GET-based upgrade handshake (RFC 6455). POST requests cannot be upgraded to WebSocket on the same connection. Use separate POST for order execution, then connect via WebSocket for updates.
curl -X POST http://localhost:3000/api/orders/execute \
-H "Content-Type: application/json" \
-d '{
"type": "MARKET",
"tokenIn": "SOL",
"tokenOut": "USDC",
"amountIn": 2.0,
"slippage": 0.01
}'const ws = new WebSocket('ws://localhost:3000/ws');
ws.onopen = () => {
ws.send(
JSON.stringify({
type: 'subscribe',
payload: { orderId: '*' },
})
);
};
ws.onmessage = (event) => {
const data = JSON.parse(event.data);
console.log('Order status:', data);
// Receive: PENDING โ ROUTING โ BUILDING โ SUBMITTED โ CONFIRMED
};PENDING โ ROUTING โ BUILDING โ SUBMITTED โ CONFIRMED โ
โ โ โ โ
Queue DEX Price Build Tx Send Tx
(200ms) โ
FAILED โ
(on error)
Orders can fail at any stage (routing, building, submission) and transition directly to FAILED status.
# Integration tests (no server needed)
pnpm test:all:integration# E2E tests (server must be running)
pnpm dev # Terminal 1
pnpm test:all:e2e # Terminal 2pnpm test:db # Database & Redispnpm test:dex # DEX routingpnpm test:queue # Queue processingpnpm test:orders # Order servicepnpm test:websocket # WebSocket real-timepnpm test:api # API endpointspnpm test:integration # Full integrationpnpm dev # Start with hot reloadpnpm build # Build for productionpnpm start # Run production buildpnpm db:migrate # Run migrationspnpm db:push # Push schema changespnpm db:studio # Open Prisma Studiopnpm docker:up # Start PostgreSQL & Redispnpm docker:down # Stop servicespnpm docker:logs # View logspnpm lint # Check issuespnpm lint:fix # Auto-fix issuespnpm format # Format code- โ Multi-DEX routing (Raydium, Meteora)
- โ Real-time WebSocket updates
- โ BullMQ queue with retries
- โ 10 concurrent order processing
- โ Health monitoring endpoints
- โ Zod validation
- โ PostgreSQL + Redis
- โ Docker Compose setup
- โ Integration & E2E tests
- Node.js โฅ18.0.0
- PostgreSQL 14+
- Redis 6+
- pnpm v10+