# barchart/marketdata-api-js architecture

> Architecture diagram of the GitHub repository barchart/marketdata-api-js, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/barchart/marketdata-api-js
- Repository: https://github.com/barchart/marketdata-api-js

## Overview

This SDK lets an application connect to Barchart quote servers over WebSocket, subscribe to symbols, and receive DDF market-data updates. Connection handles authentication, subscriptions, inbound parsing, dispatch, and snapshot requests; MarketState turns messages into accessible profile and quote state. Separate snapshot helpers retrieve quotes, profile extensions, and exchange metadata over HTTP. Environment strategies select browser or Node WebSocket/XML implementations. Utilities parse symbols and format market values. The README establishes the user workflow; some internal wiring is supported by the SOURCE INDEX, while unsampled implementation details are not inferred.

Main entry points: [`lib/connection/Connection.js`](https://github.com/barchart/marketdata-api-js/blob/master/lib/connection/Connection.js) (Connection), [`lib/environment/Environment.js`](https://github.com/barchart/marketdata-api-js/blob/master/lib/environment/Environment.js) (Environment strategy), [`lib/connection/ConnectionBase.js`](https://github.com/barchart/marketdata-api-js/blob/master/lib/connection/ConnectionBase.js) (Connection base), [`lib/connection/snapshots/quotes/retrieveSnapshots.js`](https://github.com/barchart/marketdata-api-js/blob/master/lib/connection/snapshots/quotes/retrieveSnapshots.js) (Quote snapshots)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_connection["Connection and transport"]
  node_connection["Connection<br/>[Connection.js]"]
  node_connection_base["Connection base<br/>[ConnectionBase.js]"]
  node_environment["Environment strategy<br/>[Environment.js]"]
  node_websocket_adapter["WebSocket adapter"]
  node_browser_environment["Browser environment"]
  node_node_environment["Node environment"]
  node_diagnostics["Diagnostics controller"]
  node_logger["Logging factory<br/>[LoggerFactory.js]"]
end

subgraph group_snapshots["Snapshots and metadata"]
  node_snapshot_quotes["Quote snapshots"]
  node_profile_extensions["Profile extensions"]
  node_exchange_metadata["Exchange metadata"]
end

subgraph group_state["Market state"]
  node_market_state[("Market state<br/>[MarketState.js]")]
  node_profile_quote["Profile and quote models<br/>[Quote.js]"]
end

subgraph group_utilities["Parsing and utilities"]
  node_ddf_parser["DDF message parser<br/>[message.js]"]
  node_symbol_parser["Symbol parser<br/>[SymbolParser.js]"]
  node_unit_codes["Price unit codes<br/>[UnitCode.js]"]
end

node_application(("SDK consumer"))
node_quote_server{{"Barchart quote servers"}}
node_http_services{{"Barchart HTTP services"}}

node_application -->|"connects and subscribes"| node_connection
node_connection -->|"extends"| node_connection_base
node_connection_base -->|"uses strategy"| node_environment
node_environment -->|"provides factory"| node_websocket_adapter
node_browser_environment -->|"specializes"| node_environment
node_node_environment -->|"specializes"| node_environment
node_connection -->|"streams via WebSocket"| node_quote_server
node_quote_server -->|"sends DDF stream"| node_connection
node_connection -->|"parses messages"| node_ddf_parser
node_connection_base -->|"creates state"| node_market_state
node_market_state -->|"manages models"| node_profile_quote
node_connection -->|"requests snapshots"| node_snapshot_quotes
node_connection -->|"retrieves extensions"| node_profile_extensions
node_connection -->|"retrieves exchanges"| node_exchange_metadata
node_snapshot_quotes -->|"requests HTTP data"| node_http_services
node_profile_extensions -->|"requests HTTP data"| node_http_services
node_exchange_metadata -->|"requests HTTP data"| node_http_services
node_profile_extensions -->|"classifies symbols"| node_symbol_parser
node_snapshot_quotes -->|"resolves symbols"| node_symbol_parser
node_connection -->|"implements diagnostics"| node_diagnostics
node_connection -->|"obtains logger"| node_logger
node_symbol_parser -.-> node_unit_codes

click node_connection "https://github.com/barchart/marketdata-api-js/blob/master/lib/connection/Connection.js"
click node_connection_base "https://github.com/barchart/marketdata-api-js/blob/master/lib/connection/ConnectionBase.js"
click node_environment "https://github.com/barchart/marketdata-api-js/blob/master/lib/environment/Environment.js"
click node_websocket_adapter "https://github.com/barchart/marketdata-api-js/blob/master/lib/connection/adapter/WebSocketAdapter.js"
click node_browser_environment "https://github.com/barchart/marketdata-api-js/blob/master/lib/environment/EnvironmentForBrowsers.js"
click node_node_environment "https://github.com/barchart/marketdata-api-js/blob/master/lib/environment/EnvironmentForNode.js"
click node_ddf_parser "https://github.com/barchart/marketdata-api-js/blob/master/lib/utilities/parse/ddf/message.js"
click node_market_state "https://github.com/barchart/marketdata-api-js/blob/master/lib/marketState/MarketState.js"
click node_profile_quote "https://github.com/barchart/marketdata-api-js/blob/master/lib/marketState/Quote.js"
click node_snapshot_quotes "https://github.com/barchart/marketdata-api-js/blob/master/lib/connection/snapshots/quotes/retrieveSnapshots.js"
click node_profile_extensions "https://github.com/barchart/marketdata-api-js/blob/master/lib/connection/snapshots/profiles/retrieveExtensions.js"
click node_exchange_metadata "https://github.com/barchart/marketdata-api-js/blob/master/lib/connection/snapshots/exchanges/retrieveExchanges.js"
click node_symbol_parser "https://github.com/barchart/marketdata-api-js/blob/master/lib/utilities/parsers/SymbolParser.js"
click node_unit_codes "https://github.com/barchart/marketdata-api-js/blob/master/lib/utilities/data/UnitCode.js"
click node_diagnostics "https://github.com/barchart/marketdata-api-js/blob/master/lib/connection/diagnostics/DiagnosticsControllerBase.js"
click node_logger "https://github.com/barchart/marketdata-api-js/blob/master/lib/logging/LoggerFactory.js"

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_connection,node_connection_base,node_environment,node_websocket_adapter,node_browser_environment,node_node_environment,node_diagnostics,node_logger toneBlue
class node_snapshot_quotes,node_profile_extensions,node_exchange_metadata toneAmber
class node_market_state,node_profile_quote,node_quote_server toneMint
class node_ddf_parser,node_symbol_parser,node_unit_codes toneRose
class node_application,node_http_services toneIndigo
```

## Components

### Connection and transport

- [Connection](https://github.com/barchart/marketdata-api-js/blob/master/lib/connection/Connection.js): `lib/connection/Connection.js`
- [Connection base](https://github.com/barchart/marketdata-api-js/blob/master/lib/connection/ConnectionBase.js): `lib/connection/ConnectionBase.js`
- [Environment strategy](https://github.com/barchart/marketdata-api-js/blob/master/lib/environment/Environment.js): `lib/environment/Environment.js`
- [WebSocket adapter](https://github.com/barchart/marketdata-api-js/blob/master/lib/connection/adapter/WebSocketAdapter.js): `lib/connection/adapter/WebSocketAdapter.js`
- [Browser environment](https://github.com/barchart/marketdata-api-js/blob/master/lib/environment/EnvironmentForBrowsers.js): `lib/environment/EnvironmentForBrowsers.js`
- [Node environment](https://github.com/barchart/marketdata-api-js/blob/master/lib/environment/EnvironmentForNode.js): `lib/environment/EnvironmentForNode.js`
- [Diagnostics controller](https://github.com/barchart/marketdata-api-js/blob/master/lib/connection/diagnostics/DiagnosticsControllerBase.js): `lib/connection/diagnostics/DiagnosticsControllerBase.js`
- [Logging factory](https://github.com/barchart/marketdata-api-js/blob/master/lib/logging/LoggerFactory.js): `lib/logging/LoggerFactory.js`

### Snapshots and metadata

- [Quote snapshots](https://github.com/barchart/marketdata-api-js/blob/master/lib/connection/snapshots/quotes/retrieveSnapshots.js): `lib/connection/snapshots/quotes/retrieveSnapshots.js`
- [Profile extensions](https://github.com/barchart/marketdata-api-js/blob/master/lib/connection/snapshots/profiles/retrieveExtensions.js): `lib/connection/snapshots/profiles/retrieveExtensions.js`
- [Exchange metadata](https://github.com/barchart/marketdata-api-js/blob/master/lib/connection/snapshots/exchanges/retrieveExchanges.js): `lib/connection/snapshots/exchanges/retrieveExchanges.js`

### Market state

- [Market state](https://github.com/barchart/marketdata-api-js/blob/master/lib/marketState/MarketState.js): `lib/marketState/MarketState.js`
- [Profile and quote models](https://github.com/barchart/marketdata-api-js/blob/master/lib/marketState/Quote.js): `lib/marketState/Quote.js`

### Parsing and utilities

- [DDF message parser](https://github.com/barchart/marketdata-api-js/blob/master/lib/utilities/parse/ddf/message.js): `lib/utilities/parse/ddf/message.js`
- [Symbol parser](https://github.com/barchart/marketdata-api-js/blob/master/lib/utilities/parsers/SymbolParser.js): `lib/utilities/parsers/SymbolParser.js`
- [Price unit codes](https://github.com/barchart/marketdata-api-js/blob/master/lib/utilities/data/UnitCode.js): `lib/utilities/data/UnitCode.js`

### Other components

- **SDK consumer**
- **Barchart quote servers**
- **Barchart HTTP services**

## Connections

- SDK consumer → Connection: connects and subscribes
- Connection → Connection base: extends (evidence: `lib/connection/Connection.js`)
- Connection base → Environment strategy: uses strategy (evidence: `lib/connection/ConnectionBase.js`)
- Environment strategy → WebSocket adapter: provides factory (evidence: `lib/environment/Environment.js`)
- Browser environment → Environment strategy: specializes (evidence: `lib/environment/EnvironmentForBrowsers.js`)
- Node environment → Environment strategy: specializes (evidence: `lib/environment/EnvironmentForNode.js`)
- Connection → Barchart quote servers: streams via WebSocket
- Barchart quote servers → Connection: sends DDF stream
- Connection → DDF message parser: parses messages (evidence: `lib/connection/Connection.js`)
- Connection base → Market state: creates state (evidence: `lib/connection/ConnectionBase.js`)
- Market state → Profile and quote models: manages models (evidence: `lib/marketState/MarketState.js`)
- Connection → Quote snapshots: requests snapshots (evidence: `lib/connection/Connection.js`)
- Connection → Profile extensions: retrieves extensions (evidence: `lib/connection/Connection.js`)
- Connection → Exchange metadata: retrieves exchanges (evidence: `lib/connection/Connection.js`)
- Quote snapshots → Barchart HTTP services: requests HTTP data (evidence: `lib/connection/snapshots/quotes/retrieveSnapshots.js`)
- Profile extensions → Barchart HTTP services: requests HTTP data (evidence: `lib/connection/snapshots/profiles/retrieveExtensions.js`)
- Exchange metadata → Barchart HTTP services: requests HTTP data (evidence: `lib/connection/snapshots/exchanges/retrieveExchanges.js`)
- Profile extensions → Symbol parser: classifies symbols (evidence: `lib/connection/snapshots/profiles/retrieveExtensions.js`)
- Quote snapshots → Symbol parser: resolves symbols (evidence: `lib/connection/snapshots/quotes/retrieveSnapshots.js`)
- Connection → Diagnostics controller: implements diagnostics (evidence: `lib/connection/Connection.js`)
- Connection → Logging factory: obtains logger (evidence: `lib/connection/Connection.js`)
- Symbol parser → Price unit codes
