How ikrambagban/exness-cfd works
1. Repository shape
- This is a TypeScript monorepo managed with pnpm workspaces and Turborepo.
- It contains several separately deployable apps plus shared packages, so the architecture is closer to a distributed system than a single app.
2. Top-level runtime boundaries
- apps/frontend: browser UI.
- apps/backend: HTTP API/auth service.
- apps/engine: core domain/processing service.
- apps/price-poller: market-data ingestion service.
- apps/ws: realtime push gateway.
- These services are built and deployed independently, with dedicated Dockerfiles and GitHub Actions workflows per service.
3. Frontend subsystem
- The frontend is a Vite + React + TypeScript application.
- Its UI is centered around trading-oriented components such as Chart, Instruments, Orders, and TradingPanel.
- It uses a query/client layer (src/lib/queryClient.ts, src/utils/queries.ts, src/utils/apiClient.ts) to talk to the backend and likely a realtime channel for live updates.
4. Backend subsystem
- apps/backend is the main HTTP-facing service, with routes under src/routes.
- The presence of auth.route.ts and a resend.ts utility suggests it handles authentication and account-related flows, including email-based communication.
- redis-subscriber.ts indicates it also consumes Redis events, so it is not just a request/response API.
5. Engine subsystem
- apps/engine appears to be the domain execution / business logic layer.
- Its internal modules (action.ts, store.ts, user-manager.ts) imply it orchestrates user state, actions, and persisted business data.
- In the overall architecture, this service is likely where trading or account actions are validated and applied before results are stored or published outward.
6. Realtime and event propagation
- apps/ws is the dedicated WebSocket/realtime service.
- apps/price-poller and packages/services/src/pubsub.ts point to a pub/sub backbone, with Redis as the shared event transport.
- This suggests a flow where services publish events into Redis/pubsub, and the WS service subscribes and forwards them to connected clients.
7. Market-data ingestion
- apps/price-poller is a separate polling/ingestion worker.
- Its services/pubsub.ts and utils/services.ts imply it fetches external price data and republishes it into the shared event system.
- This keeps external market-data fetching isolated from the API and UI layers.
8. Shared infrastructure packages
- packages/services centralizes reusable infrastructure helpers such as Redis, pub/sub, and a queue manager.
- packages/db is the persistence boundary, using Prisma with migrations and a TimescaleDB-related SQL file, indicating time-series storage for ticks/prices.
- packages/common holds shared domain types and Zod schemas, which likely define contracts used across apps.
9. Data stores and persistence
- The database package contains migrations for users, ticks, and a snapshot table, showing persistent domain data plus time-series data.
- The architecture therefore has at least two important state layers:
- relational/domain state via Prisma-managed tables
- time-series price/tick storage optimized for historical data
10. Cross-service communication pattern
- The dominant integration style is event-driven:
- price data is ingested by the poller
- events are published through Redis/pubsub
- WS broadcasts live updates to clients
- backend/engine can also subscribe to those events for state changes
- HTTP is used for synchronous operations such as auth and UI-driven commands, while Redis/pubsub handles realtime fan-out and service coordination.
11. Deployment and ops
- Each runtime service has its own Dockerfile under docker/, and its own GitHub Actions deployment workflow.
- That separation reinforces service-level deployment autonomy and makes the diagram naturally split into independently scaled components.
12. What to draw in the architecture diagram
- Place the frontend on the edge.
- Connect it to the backend for API/auth calls.
- Connect it to the ws service for live updates.
- Show price-poller feeding Redis/pubsub.
- Show engine and backend/ws consuming shared events and using packages/db for persistence.
- Use packages/services and packages/common as shared internal foundations rather than runtime services.
Main entry points: backend Backend · engine Engine · workflows Deploy Workflows · price-poller Price Poller
Components 10
Apps
Independently deployed runtimes for UI, API, execution, ingestion, and realtime fan-out.
- Frontend · Browser trading UI with charting, instruments, orders, and trading panel.
apps/frontend - Backend · HTTP-facing API and auth service with routes and Redis event consumption.
apps/backend - Engine · Core business logic service for user state, actions, and execution orchestration.
apps/engine - Price Poller · Market-data polling worker that fetches prices and republishes them into the event system.
apps/price-poller - WebSocket · Realtime push service that subscribes to events and broadcasts updates to clients.
apps/ws
Shared packages
Cross-cutting libraries for data contracts, persistence, and infrastructure plumbing.
Ops
Build and deployment assets for service-level releases.
- Dockerfiles · Per-service container builds for backend, engine, price poller, and ws.
docker - Deploy Workflows · Independent GitHub Actions deployment workflows for each runtime service.
.github/workflows
Connections 24
- Frontend → Backend: API/auth · Frontend issues synchronous queries and commands to the backend.
- Frontend → WebSocket: live updates · Frontend receives realtime trading and market updates from WebSocket push.
- Backend → Engine: commands · Backend forwards validated application actions into the engine.
- Engine → Database: persist · Engine reads and writes domain state and business data.
- Backend → Database: persist · Backend stores account and auth-related state.
- Price Poller → Database: ticks · Polling worker can record or backfill market data in time-series storage.
- Price Poller → Services: publish · Price poller publishes fetched market data into shared pub/sub.
- Backend → Services: redis · Backend consumes shared Redis and pub/sub helpers for event-driven flows.
- Engine → Services: pub/sub · Engine coordinates state changes and event emission through shared infrastructure.
- WebSocket → Services: subscribe · Realtime gateway subscribes to shared events for fan-out.
- Backend → Common: schemas · Backend shares common types and validation contracts.
- Engine → Common: types · Engine uses shared domain contracts.
- Price Poller → Common: types · Polling worker relies on shared data contracts.
- WebSocket → Common: contracts · WebSocket layer uses shared message and payload shapes.
- Frontend → Common: contracts · Frontend consumes shared types for request and response shapes.
- Dockerfiles → Backend: build · Service image for backend deployment.
- Dockerfiles → Engine: build · Service image for engine deployment.
- Dockerfiles → Price Poller: build · Service image for price poller deployment.
- Dockerfiles → WebSocket: build · Service image for realtime gateway deployment.
- Deploy Workflows → Backend: deploy · Dedicated workflow deploys backend independently.
- Deploy Workflows → Engine: deploy · Dedicated workflow deploys engine independently.
- Deploy Workflows → Frontend: deploy · Dedicated workflow deploys frontend independently.
- Deploy Workflows → Price Poller: deploy · Dedicated workflow deploys price poller independently.
- Deploy Workflows → WebSocket: deploy · Dedicated workflow deploys WebSocket service independently.