# ikrambagban/exness-cfd architecture

> Architecture diagram of the GitHub repository ikrambagban/exness-cfd, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ikrambagban/exness-cfd
- Repository: https://github.com/ikrambagban/exness-cfd

## Overview

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: [`apps/backend`](https://github.com/ikrambagban/exness-cfd/tree/main/apps/backend) (Backend), [`apps/engine`](https://github.com/ikrambagban/exness-cfd/tree/main/apps/engine) (Engine), [`.github/workflows`](https://github.com/ikrambagban/exness-cfd/blob/main/.github/workflows) (Deploy Workflows), [`apps/price-poller`](https://github.com/ikrambagban/exness-cfd/tree/main/apps/price-poller) (Price Poller)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_apps["Apps"]
  node_apps_frontend["Frontend<br/>vite-react-ui"]
  node_apps_backend["Backend<br/>http-auth-api"]
  node_apps_engine["Engine<br/>domain-service"]
  node_apps_price_poller["Price Poller<br/>ingestion-worker"]
  node_apps_ws["WebSocket<br/>realtime-gateway"]
end

subgraph group_packages["Shared packages"]
  node_packages_common["Common<br/>shared-contracts"]
  node_packages_services["Services<br/>infra-kit"]
  node_packages_db[("Database<br/>prisma-timescale")]
end

subgraph group_ops["Ops"]
  node_ops_docker["Dockerfiles<br/>service-images"]
  node_ops_github_actions["Deploy Workflows<br/>ci-cd<br/>[workflows]"]
end

node_apps_frontend -->|"API/auth"| node_apps_backend
node_apps_frontend -->|"live updates"| node_apps_ws
node_apps_backend -->|"commands"| node_apps_engine
node_apps_engine -->|"persist"| node_packages_db
node_apps_backend -->|"persist"| node_packages_db
node_apps_price_poller -->|"ticks"| node_packages_db
node_apps_price_poller -->|"publish"| node_packages_services
node_apps_backend -->|"redis"| node_packages_services
node_apps_engine -->|"pub/sub"| node_packages_services
node_apps_ws -->|"subscribe"| node_packages_services
node_apps_backend -->|"schemas"| node_packages_common
node_apps_engine -->|"types"| node_packages_common
node_apps_price_poller -->|"types"| node_packages_common
node_apps_ws -->|"contracts"| node_packages_common
node_apps_frontend -->|"contracts"| node_packages_common
node_ops_docker -.->|"build"| node_apps_backend
node_ops_docker -.->|"build"| node_apps_engine
node_ops_docker -.->|"build"| node_apps_price_poller
node_ops_docker -.->|"build"| node_apps_ws
node_ops_github_actions -.->|"deploy"| node_apps_backend
node_ops_github_actions -.->|"deploy"| node_apps_engine
node_ops_github_actions -.->|"deploy"| node_apps_frontend
node_ops_github_actions -.->|"deploy"| node_apps_price_poller
node_ops_github_actions -.->|"deploy"| node_apps_ws

click node_apps_frontend "https://github.com/ikrambagban/exness-cfd/tree/main/apps/frontend"
click node_apps_backend "https://github.com/ikrambagban/exness-cfd/tree/main/apps/backend"
click node_apps_engine "https://github.com/ikrambagban/exness-cfd/tree/main/apps/engine"
click node_apps_price_poller "https://github.com/ikrambagban/exness-cfd/tree/main/apps/price-poller"
click node_apps_ws "https://github.com/ikrambagban/exness-cfd/tree/main/apps/ws"
click node_packages_common "https://github.com/ikrambagban/exness-cfd/tree/main/packages/common"
click node_packages_services "https://github.com/ikrambagban/exness-cfd/tree/main/packages/services"
click node_packages_db "https://github.com/ikrambagban/exness-cfd/tree/main/packages/db"
click node_ops_docker "https://github.com/ikrambagban/exness-cfd/tree/main/docker"
click node_ops_github_actions "https://github.com/ikrambagban/exness-cfd/blob/main/.github/workflows"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_apps_frontend,node_apps_backend,node_apps_engine,node_apps_price_poller,node_apps_ws toneBlue
class node_packages_common,node_packages_services,node_packages_db toneAmber
class node_ops_docker,node_ops_github_actions toneMint
```

## Components

### Apps

Independently deployed runtimes for UI, API, execution, ingestion, and realtime fan-out.

- [Frontend](https://github.com/ikrambagban/exness-cfd/tree/main/apps/frontend): vite-react-ui · Browser trading UI with charting, instruments, orders, and trading panel. · `apps/frontend`
- [Backend](https://github.com/ikrambagban/exness-cfd/tree/main/apps/backend): http-auth-api · HTTP-facing API and auth service with routes and Redis event consumption. · `apps/backend`
- [Engine](https://github.com/ikrambagban/exness-cfd/tree/main/apps/engine): domain-service · Core business logic service for user state, actions, and execution orchestration. · `apps/engine`
- [Price Poller](https://github.com/ikrambagban/exness-cfd/tree/main/apps/price-poller): ingestion-worker · Market-data polling worker that fetches prices and republishes them into the event system. · `apps/price-poller`
- [WebSocket](https://github.com/ikrambagban/exness-cfd/tree/main/apps/ws): realtime-gateway · 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.

- [Common](https://github.com/ikrambagban/exness-cfd/tree/main/packages/common): shared-contracts · Shared types and Zod schemas used across services. · `packages/common`
- [Services](https://github.com/ikrambagban/exness-cfd/tree/main/packages/services): infra-kit · Reusable Redis, pub/sub, and queue helpers shared by runtime services. · `packages/services`
- [Database](https://github.com/ikrambagban/exness-cfd/tree/main/packages/db): prisma-timescale · Persistence boundary with Prisma schema, migrations, and Timescale support for ticks and snapshots. · `packages/db`

### Ops

Build and deployment assets for service-level releases.

- [Dockerfiles](https://github.com/ikrambagban/exness-cfd/tree/main/docker): service-images · Per-service container builds for backend, engine, price poller, and ws. · `docker`
- [Deploy Workflows](https://github.com/ikrambagban/exness-cfd/blob/main/.github/workflows): ci-cd · Independent GitHub Actions deployment workflows for each runtime service. · `.github/workflows`

## Connections

- 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.
