# 1-ken/cpp-fx architecture

> Architecture diagram of the GitHub repository 1-ken/cpp-fx, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/1-ken/cpp-fx
- Repository: https://github.com/1-ken/cpp-fx

## Overview

cTrader Plus is a C++ market-observation API: clients request snapshots, historical bars, account features, alerts, or live WebSocket updates; the server obtains broker data, shapes market responses, evaluates alerts, and persists user and alert state. The graph preserves the documented HTTP, streaming, history, authentication, administration, and notification capabilities. Sampled source confirms startup wiring, cTrader frame conversion, WebSocket enrichment, and alert persistence; links for unsampled controller and market internals follow documented responsibilities only where indicated.

Main entry points: [`src/alerts/AlertManager.cc`](https://github.com/1-ken/cpp-fx/blob/main/src/alerts/AlertManager.cc) (Alert manager), [`src/controllers/Routes.cc`](https://github.com/1-ken/cpp-fx/blob/main/src/controllers/Routes.cc) (HTTP routes), [`src/ctrader/CTraderClient.cc`](https://github.com/1-ken/cpp-fx/blob/main/src/ctrader/CTraderClient.cc) (cTrader client), [`src/market/MarketHub.cc`](https://github.com/1-ken/cpp-fx/blob/main/src/market/MarketHub.cc) (Market hub)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["API and access"]
  node_server["Server startup<br/>[main.cc]"]
  node_routes["HTTP routes<br/>[Routes.cc]"]
  node_authroutes["Auth routes<br/>[AuthRoutes.cc]"]
  node_admin["Admin routes<br/>[AdminRoutes.cc]"]
  node_ws["Observe WebSocket"]
  node_dashboard["Dashboard response<br/>[Dashboard.cc]"]
  node_auth["Authentication<br/>[Auth.cc]"]
end

subgraph group_market["Market data"]
  node_ctrader["cTrader client<br/>[CTraderClient.cc]"]
  node_symbols["Symbol registry<br/>[SymbolRegistry.cc]"]
  node_planner["Subscription planner"]
  node_hub["Market hub<br/>[MarketHub.cc]"]
  node_history["Historical bars<br/>[CTraderClient.cc]"]
  node_structure["Market structure<br/>[StructureEngine.cc]"]
end

subgraph group_alerts["Alerts and notifications"]
  node_alerts["Alert manager<br/>[AlertManager.cc]"]
  node_candlemonitor["Candle monitor"]
  node_queue["Notification queue"]
  node_notifier["Notifier<br/>[Notifier.cc]"]
end

subgraph group_state["Persistence and services"]
  node_postgres[("PostgreSQL<br/>[PostgresService.cc]")]
  node_redis[("Redis<br/>[RedisService.cc]")]
end

node_client(("API clients"))
node_externalbroker(("cTrader Open API"))
node_delivery(("Notification providers"))

node_client -->|"HTTP requests"| node_routes
node_client -->|"opens stream"| node_ws
node_server -->|"registers routes"| node_routes
node_server -->|"starts client"| node_ctrader
node_server -->|"starts hub"| node_hub
node_server -->|"configures manager"| node_alerts
node_server -->|"starts queue"| node_queue
node_routes -->|"checks identity"| node_auth
node_authroutes -->|"reads and writes users"| node_postgres
node_admin -->|"queries admin data"| node_postgres
node_ws -->|"reads live data"| node_hub
node_ws -->|"reads alert state"| node_alerts
node_ws -->|"streams updates"| node_client
node_routes -->|"serves snapshots"| node_hub
node_routes -->|"requests OHLC"| node_history
node_routes -->|"manages alerts"| node_alerts
node_routes -->|"serves dashboard"| node_dashboard
node_ctrader -->|"TLS Protobuf"| node_externalbroker
node_externalbroker -->|"market events"| node_ctrader
node_ctrader -->|"loads symbols"| node_symbols
node_planner -->|"selects instruments"| node_symbols
node_planner -->|"subscribes symbols"| node_ctrader
node_ctrader -->|"spot updates"| node_hub
node_history -->|"requests trend bars"| node_externalbroker
node_hub -->|"provides market updates"| node_alerts
node_candlemonitor -->|"checks candle triggers"| node_alerts
node_alerts -->|"analyzes candles"| node_structure
node_alerts -->|"persists alerts"| node_postgres
node_alerts -->|"queues alert events"| node_redis
node_queue -->|"reads retry queue"| node_redis
node_queue -->|"dispatches notifications"| node_notifier
node_notifier -.->|"sends alerts"| node_delivery
node_hub -.->|"archives snapshots"| node_postgres

click node_server "https://github.com/1-ken/cpp-fx/blob/main/src/main.cc"
click node_routes "https://github.com/1-ken/cpp-fx/blob/main/src/controllers/Routes.cc"
click node_authroutes "https://github.com/1-ken/cpp-fx/blob/main/src/controllers/AuthRoutes.cc"
click node_admin "https://github.com/1-ken/cpp-fx/blob/main/src/controllers/AdminRoutes.cc"
click node_ws "https://github.com/1-ken/cpp-fx/blob/main/src/controllers/WsObserveController.cc"
click node_dashboard "https://github.com/1-ken/cpp-fx/blob/main/src/controllers/Dashboard.cc"
click node_auth "https://github.com/1-ken/cpp-fx/blob/main/src/core/Auth.cc"
click node_ctrader "https://github.com/1-ken/cpp-fx/blob/main/src/ctrader/CTraderClient.cc"
click node_symbols "https://github.com/1-ken/cpp-fx/blob/main/src/ctrader/SymbolRegistry.cc"
click node_planner "https://github.com/1-ken/cpp-fx/blob/main/src/market/SymbolSubscriptionPlanner.cc"
click node_hub "https://github.com/1-ken/cpp-fx/blob/main/src/market/MarketHub.cc"
click node_history "https://github.com/1-ken/cpp-fx/blob/main/src/ctrader/CTraderClient.cc"
click node_structure "https://github.com/1-ken/cpp-fx/blob/main/src/market/StructureEngine.cc"
click node_alerts "https://github.com/1-ken/cpp-fx/blob/main/src/alerts/AlertManager.cc"
click node_candlemonitor "https://github.com/1-ken/cpp-fx/blob/main/src/alerts/CandleAlertMonitor.cc"
click node_queue "https://github.com/1-ken/cpp-fx/blob/main/src/services/NotificationQueue.cc"
click node_notifier "https://github.com/1-ken/cpp-fx/blob/main/src/services/Notifier.cc"
click node_postgres "https://github.com/1-ken/cpp-fx/blob/main/src/services/PostgresService.cc"
click node_redis "https://github.com/1-ken/cpp-fx/blob/main/src/services/RedisService.cc"

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_server,node_routes,node_authroutes,node_admin,node_ws,node_dashboard,node_auth,node_client toneBlue
class node_ctrader,node_symbols,node_planner,node_hub,node_history,node_structure toneAmber
class node_alerts,node_candlemonitor,node_queue,node_notifier,node_externalbroker toneMint
class node_postgres,node_redis toneRose
class node_delivery toneIndigo
```

## Components

### API and access

- [Server startup](https://github.com/1-ken/cpp-fx/blob/main/src/main.cc): `src/main.cc`
- [HTTP routes](https://github.com/1-ken/cpp-fx/blob/main/src/controllers/Routes.cc): `src/controllers/Routes.cc`
- [Auth routes](https://github.com/1-ken/cpp-fx/blob/main/src/controllers/AuthRoutes.cc): `src/controllers/AuthRoutes.cc`
- [Admin routes](https://github.com/1-ken/cpp-fx/blob/main/src/controllers/AdminRoutes.cc): `src/controllers/AdminRoutes.cc`
- [Observe WebSocket](https://github.com/1-ken/cpp-fx/blob/main/src/controllers/WsObserveController.cc): `src/controllers/WsObserveController.cc`
- [Dashboard response](https://github.com/1-ken/cpp-fx/blob/main/src/controllers/Dashboard.cc): `src/controllers/Dashboard.cc`
- [Authentication](https://github.com/1-ken/cpp-fx/blob/main/src/core/Auth.cc): `src/core/Auth.cc`

### Market data

- [cTrader client](https://github.com/1-ken/cpp-fx/blob/main/src/ctrader/CTraderClient.cc): `src/ctrader/CTraderClient.cc`
- [Symbol registry](https://github.com/1-ken/cpp-fx/blob/main/src/ctrader/SymbolRegistry.cc): `src/ctrader/SymbolRegistry.cc`
- [Subscription planner](https://github.com/1-ken/cpp-fx/blob/main/src/market/SymbolSubscriptionPlanner.cc): `src/market/SymbolSubscriptionPlanner.cc`
- [Market hub](https://github.com/1-ken/cpp-fx/blob/main/src/market/MarketHub.cc): `src/market/MarketHub.cc`
- [Historical bars](https://github.com/1-ken/cpp-fx/blob/main/src/ctrader/CTraderClient.cc): `src/ctrader/CTraderClient.cc`
- [Market structure](https://github.com/1-ken/cpp-fx/blob/main/src/market/StructureEngine.cc): `src/market/StructureEngine.cc`

### Alerts and notifications

- [Alert manager](https://github.com/1-ken/cpp-fx/blob/main/src/alerts/AlertManager.cc): `src/alerts/AlertManager.cc`
- [Candle monitor](https://github.com/1-ken/cpp-fx/blob/main/src/alerts/CandleAlertMonitor.cc): `src/alerts/CandleAlertMonitor.cc`
- [Notification queue](https://github.com/1-ken/cpp-fx/blob/main/src/services/NotificationQueue.cc): `src/services/NotificationQueue.cc`
- [Notifier](https://github.com/1-ken/cpp-fx/blob/main/src/services/Notifier.cc): `src/services/Notifier.cc`

### Persistence and services

- [PostgreSQL](https://github.com/1-ken/cpp-fx/blob/main/src/services/PostgresService.cc): `src/services/PostgresService.cc`
- [Redis](https://github.com/1-ken/cpp-fx/blob/main/src/services/RedisService.cc): `src/services/RedisService.cc`

### Other components

- **API clients**
- **cTrader Open API**
- **Notification providers**

## Connections

- API clients → HTTP routes: HTTP requests
- API clients → Observe WebSocket: opens stream
- Server startup → HTTP routes: registers routes
- Server startup → cTrader client: starts client
- Server startup → Market hub: starts hub
- Server startup → Alert manager: configures manager
- Server startup → Notification queue: starts queue
- HTTP routes → Authentication: checks identity
- Auth routes → PostgreSQL: reads and writes users
- Admin routes → PostgreSQL: queries admin data
- Observe WebSocket → Market hub: reads live data
- Observe WebSocket → Alert manager: reads alert state
- Observe WebSocket → API clients: streams updates
- HTTP routes → Market hub: serves snapshots
- HTTP routes → Historical bars: requests OHLC
- HTTP routes → Alert manager: manages alerts
- HTTP routes → Dashboard response: serves dashboard
- cTrader client → cTrader Open API: TLS Protobuf
- cTrader Open API → cTrader client: market events
- cTrader client → Symbol registry: loads symbols
- Subscription planner → Symbol registry: selects instruments
- Subscription planner → cTrader client: subscribes symbols
- cTrader client → Market hub: spot updates
- Historical bars → cTrader Open API: requests trend bars
- Market hub → Alert manager: provides market updates
- Candle monitor → Alert manager: checks candle triggers
- Alert manager → Market structure: analyzes candles
- Alert manager → PostgreSQL: persists alerts
- Alert manager → Redis: queues alert events
- Notification queue → Redis: reads retry queue
- Notification queue → Notifier: dispatches notifications
- Notifier → Notification providers: sends alerts
- Market hub → PostgreSQL: archives snapshots
