# en/siren architecture

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

- Interactive diagram: https://gitdiagram.com/en/siren
- Repository: https://github.com/en/siren

## Overview

Siren is a cryptocurrency exchange organized as gRPC microservices, with an HTTP API for account and trading operations and a WebSocket service for live market updates. The principal workflow is an authenticated client request entering the gateway, which dispatches trading requests to the matching service or account and wallet requests to their respective services. Matching maintains order-book and balance state; the repository also includes SQL-backed transfer handling, Redis market-data storage, and Ethereum deposit processing. Several cross-service connections are not shown in the excerpts, so those links are omitted or marked unverified.

Main entry points: [`svc-gateway/handlers.go`](https://github.com/en/siren/blob/master/svc-gateway/handlers.go) (API handlers), [`svc-wallet/main.go`](https://github.com/en/siren/blob/master/svc-wallet/main.go) (Wallet service), [`svc-match/main.go`](https://github.com/en/siren/blob/master/svc-match/main.go) (Matching service), [`svc-gateway/main.go`](https://github.com/en/siren/blob/master/svc-gateway/main.go) (HTTP gateway)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Client API"]
  node_gateway["HTTP gateway<br/>[main.go]"]
  node_gateway_handlers["API handlers<br/>[handlers.go]"]
  node_ws["WebSocket service<br/>[main.go]"]
end

subgraph group_trading["Trading Engine"]
  node_match["Matching service<br/>[main.go]"]
  node_asset["Asset balances<br/>[asset.go]"]
  node_market["Order matching<br/>[market.go]"]
  node_history["Trade history<br/>[history.go]"]
  node_match_messages["Match messaging<br/>[message.go]"]
  node_skiplist["Order-book skiplist<br/>[skiplist.go]"]
end

subgraph group_data["Market Data"]
  node_memory["Market-data store<br/>[main.go]"]
end

subgraph group_accounts["Accounts and Wallets"]
  node_sql["SQL service<br/>[main.go]"]
  node_sql_messaging["Transfer consumer<br/>[messaging.go]"]
  node_wallet["Wallet service<br/>[main.go]"]
  node_ethereum["Ethereum wallet<br/>[main.go]"]
  node_eth_events["Deposit watcher<br/>[events.go]"]
  node_bitcoin["Bitcoin service<br/>[main.go]"]
end

subgraph group_messaging["Event Messaging"]
  node_kafka["Kafka"]
  node_topics["Message topics<br/>[topics.go]"]
  node_message_types["Transfer messages<br/>[types.go]"]
end

node_client(("Exchange client"))
node_auth0["Auth0 identity"]
node_redis[("Redis")]
node_postgres[("PostgreSQL")]
node_eth_chain["Ethereum node"]

node_client -->|"sends HTTP"| node_gateway
node_client -.->|"opens socket"| node_ws
node_gateway -.->|"routes requests"| node_gateway_handlers
node_gateway -->|"fetches signing keys"| node_auth0
node_ws -->|"fetches signing keys"| node_auth0
node_gateway_handlers -->|"calls trading RPCs"| node_match
node_gateway_handlers -->|"calls transfer RPC"| node_sql
node_gateway_handlers -->|"calls wallet RPCs"| node_wallet
node_ws -->|"dials gRPC"| node_match
node_match -->|"queries state"| node_postgres
node_market -->|"uses order book"| node_skiplist
node_match -->|"reads balances"| node_asset
node_market -->|"updates balances"| node_asset
node_sql -->|"queries transfers"| node_postgres
node_wallet -->|"records withdrawals"| node_postgres
node_wallet -->|"dispatches ETH"| node_ethereum
node_wallet -->|"dispatches BTC"| node_bitcoin
node_ethereum -->|"reads and writes addresses"| node_postgres
node_ethereum -->|"connects node"| node_eth_chain
node_eth_events -->|"publishes deposits"| node_kafka
node_sql_messaging -->|"consumes transfers"| node_kafka
node_sql_messaging -->|"inserts transfers"| node_postgres
node_memory -->|"reads and writes"| node_redis

click node_gateway "https://github.com/en/siren/blob/master/svc-gateway/main.go"
click node_gateway_handlers "https://github.com/en/siren/blob/master/svc-gateway/handlers.go"
click node_ws "https://github.com/en/siren/blob/master/svc-ws/main.go"
click node_match "https://github.com/en/siren/blob/master/svc-match/main.go"
click node_asset "https://github.com/en/siren/blob/master/svc-match/asset.go"
click node_market "https://github.com/en/siren/blob/master/svc-match/market.go"
click node_history "https://github.com/en/siren/blob/master/svc-match/history.go"
click node_match_messages "https://github.com/en/siren/blob/master/svc-match/message.go"
click node_skiplist "https://github.com/en/siren/blob/master/svc-match/fast-skiplist/skiplist.go"
click node_memory "https://github.com/en/siren/blob/master/svc-memorystore/main.go"
click node_sql "https://github.com/en/siren/blob/master/svc-sql/main.go"
click node_sql_messaging "https://github.com/en/siren/blob/master/svc-sql/messaging.go"
click node_wallet "https://github.com/en/siren/blob/master/svc-wallet/main.go"
click node_ethereum "https://github.com/en/siren/blob/master/svc-wallet/ethereum/main.go"
click node_eth_events "https://github.com/en/siren/blob/master/svc-wallet/ethereum/events.go"
click node_bitcoin "https://github.com/en/siren/blob/master/svc-wallet/bitcoin/main.go"
click node_topics "https://github.com/en/siren/blob/master/messaging/topics.go"
click node_message_types "https://github.com/en/siren/blob/master/messaging/types.go"

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_gateway,node_gateway_handlers,node_ws,node_client toneBlue
class node_match,node_asset,node_market,node_history,node_match_messages,node_skiplist,node_redis,node_postgres toneAmber
class node_memory toneMint
class node_sql,node_sql_messaging,node_wallet,node_ethereum,node_eth_events,node_bitcoin toneRose
class node_kafka,node_topics,node_message_types,node_auth0,node_eth_chain toneIndigo
```

## Components

### Client API

- [HTTP gateway](https://github.com/en/siren/blob/master/svc-gateway/main.go): `svc-gateway/main.go`
- [API handlers](https://github.com/en/siren/blob/master/svc-gateway/handlers.go): `svc-gateway/handlers.go`
- [WebSocket service](https://github.com/en/siren/blob/master/svc-ws/main.go): `svc-ws/main.go`

### Trading Engine

- [Matching service](https://github.com/en/siren/blob/master/svc-match/main.go): `svc-match/main.go`
- [Asset balances](https://github.com/en/siren/blob/master/svc-match/asset.go): `svc-match/asset.go`
- [Order matching](https://github.com/en/siren/blob/master/svc-match/market.go): `svc-match/market.go`
- [Trade history](https://github.com/en/siren/blob/master/svc-match/history.go): `svc-match/history.go`
- [Match messaging](https://github.com/en/siren/blob/master/svc-match/message.go): `svc-match/message.go`
- [Order-book skiplist](https://github.com/en/siren/blob/master/svc-match/fast-skiplist/skiplist.go): `svc-match/fast-skiplist/skiplist.go`

### Market Data

- [Market-data store](https://github.com/en/siren/blob/master/svc-memorystore/main.go): `svc-memorystore/main.go`

### Accounts and Wallets

- [SQL service](https://github.com/en/siren/blob/master/svc-sql/main.go): `svc-sql/main.go`
- [Transfer consumer](https://github.com/en/siren/blob/master/svc-sql/messaging.go): `svc-sql/messaging.go`
- [Wallet service](https://github.com/en/siren/blob/master/svc-wallet/main.go): `svc-wallet/main.go`
- [Ethereum wallet](https://github.com/en/siren/blob/master/svc-wallet/ethereum/main.go): `svc-wallet/ethereum/main.go`
- [Deposit watcher](https://github.com/en/siren/blob/master/svc-wallet/ethereum/events.go): `svc-wallet/ethereum/events.go`
- [Bitcoin service](https://github.com/en/siren/blob/master/svc-wallet/bitcoin/main.go): `svc-wallet/bitcoin/main.go`

### Event Messaging

- **Kafka**
- [Message topics](https://github.com/en/siren/blob/master/messaging/topics.go): `messaging/topics.go`
- [Transfer messages](https://github.com/en/siren/blob/master/messaging/types.go): `messaging/types.go`

### Other components

- **Exchange client**
- **Auth0 identity**
- **Redis**
- **PostgreSQL**
- **Ethereum node**

## Connections

- Exchange client → HTTP gateway: sends HTTP (evidence: `svc-gateway/main.go`)
- Exchange client → WebSocket service: opens socket
- HTTP gateway → API handlers: routes requests
- HTTP gateway → Auth0 identity: fetches signing keys (evidence: `svc-gateway/main.go`)
- WebSocket service → Auth0 identity: fetches signing keys (evidence: `svc-ws/main.go`)
- API handlers → Matching service: calls trading RPCs (evidence: `svc-gateway/handlers.go`)
- API handlers → SQL service: calls transfer RPC (evidence: `svc-gateway/handlers.go`)
- API handlers → Wallet service: calls wallet RPCs (evidence: `svc-gateway/handlers.go`)
- WebSocket service → Matching service: dials gRPC (evidence: `svc-ws/main.go`)
- Matching service → PostgreSQL: queries state (evidence: `svc-match/main.go`)
- Order matching → Order-book skiplist: uses order book (evidence: `svc-match/market.go`)
- Matching service → Asset balances: reads balances (evidence: `svc-match/main.go`)
- Order matching → Asset balances: updates balances (evidence: `svc-match/market.go`)
- SQL service → PostgreSQL: queries transfers (evidence: `svc-sql/main.go`)
- Wallet service → PostgreSQL: records withdrawals (evidence: `svc-wallet/main.go`)
- Wallet service → Ethereum wallet: dispatches ETH (evidence: `svc-wallet/main.go`)
- Wallet service → Bitcoin service: dispatches BTC (evidence: `svc-wallet/main.go`)
- Ethereum wallet → PostgreSQL: reads and writes addresses (evidence: `svc-wallet/ethereum/main.go`)
- Ethereum wallet → Ethereum node: connects node (evidence: `svc-wallet/ethereum/main.go`)
- Deposit watcher → Kafka: publishes deposits (evidence: `svc-wallet/ethereum/events.go`)
- Transfer consumer → Kafka: consumes transfers (evidence: `svc-sql/messaging.go`)
- Transfer consumer → PostgreSQL: inserts transfers (evidence: `svc-sql/messaging.go`)
- Market-data store → Redis: reads and writes (evidence: `svc-memorystore/main.go`)
