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+