# polymarket/real-time-data-client architecture

> Architecture diagram of the GitHub repository polymarket/real-time-data-client, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/polymarket/real-time-data-client
- Repository: https://github.com/polymarket/real-time-data-client

## Overview

This small TypeScript library wraps a WebSocket service: applications create and connect a client, subscribe or unsubscribe over that connection, and receive parsed messages and connection callbacks. The client also manages pinging and automatic reconnection. The README documents topic-based streams and authentication options; the sampled implementation shows the client and message types, but not service-side behavior.

Main entry points: [`src/client.ts`](https://github.com/polymarket/real-time-data-client/blob/main/src/client.ts) (WebSocket Client), [`src/index.ts`](https://github.com/polymarket/real-time-data-client/blob/main/src/index.ts) (Public API), [`src/model.ts`](https://github.com/polymarket/real-time-data-client/blob/main/src/model.ts) (Message Types)

## Diagram (Mermaid)

```mermaid
flowchart TD

node_application(("Application"))
node_public_api["Public API<br/>[index.ts]"]
node_client["WebSocket Client<br/>[client.ts]"]
node_models["Message Types<br/>[model.ts]"]
node_service["Data Service"]

node_application -->|"imports"| node_public_api
node_public_api -->|"exports"| node_client
node_public_api -->|"exports"| node_models
node_client -->|"uses types"| node_models
node_application -->|"connects"| node_client
node_client -->|"opens connection"| node_service
node_application -->|"subscribes"| node_client
node_client -->|"sends requests"| node_service
node_service -->|"streams messages"| node_client
node_client -->|"calls callbacks"| node_application

click node_public_api "https://github.com/polymarket/real-time-data-client/blob/main/src/index.ts"
click node_client "https://github.com/polymarket/real-time-data-client/blob/main/src/client.ts"
click node_models "https://github.com/polymarket/real-time-data-client/blob/main/src/model.ts"

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_application,node_service toneIndigo
class node_public_api toneMint
class node_client toneBlue
class node_models toneTeal
```

## Components

### Other components

- **Application**
- [Public API](https://github.com/polymarket/real-time-data-client/blob/main/src/index.ts): `src/index.ts`
- [WebSocket Client](https://github.com/polymarket/real-time-data-client/blob/main/src/client.ts): `src/client.ts`
- [Message Types](https://github.com/polymarket/real-time-data-client/blob/main/src/model.ts): `src/model.ts`
- **Data Service**

## Connections

- Application → Public API: imports (evidence: `src/index.ts`)
- Public API → WebSocket Client: exports (evidence: `src/index.ts`)
- Public API → Message Types: exports (evidence: `src/index.ts`)
- WebSocket Client → Message Types: uses types (evidence: `src/client.ts`)
- Application → WebSocket Client: connects (evidence: `README.md`)
- WebSocket Client → Data Service: opens connection (evidence: `src/client.ts`)
- Application → WebSocket Client: subscribes (evidence: `README.md`)
- WebSocket Client → Data Service: sends requests (evidence: `src/client.ts`)
- Data Service → WebSocket Client: streams messages (evidence: `README.md`)
- WebSocket Client → Application: calls callbacks (evidence: `src/client.ts`)
