# tradingview/lightweight-charts architecture

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

- Interactive diagram: https://gitdiagram.com/tradingview/lightweight-charts
- Repository: https://github.com/tradingview/lightweight-charts

## Overview

#### Purpose and distribution
This is the TypeScript implementation of TradingView Lightweight Charts: a browser-side HTML5 canvas library for interactive financial charts. It ships npm ES modules and standalone IIFE bundles exposing `window.LightweightCharts`; Rollup is the main library bundler. Public entry points are `src/index.ts` (module exports) and `src/standalone.ts` (global build), with build definition in `rollup.config.js`.

#### Public API boundary
Consumers create charts and manipulate typed chart, series, pane, price-scale, and time-scale APIs. API façade classes isolate public contracts from internal mutable model and GUI state.
- `src/api/create-chart.ts`
- `src/api/chart-api.ts`
- `src/api/series-api.ts`

Specialized creation paths support options charts and yield-curve charts:
- `src/api/create-options-chart.ts`
- `src/api/create-yield-curve-chart.ts`
- `src/api/yield-chart-api.ts`

#### Data ingestion and chart model
Series `setData`/updates flow through the data layer, which validates and converts user time/value/OHLC input into internal plot rows and ordered data structures. `ChartModel` owns panes, series, scales, crosshair state, invalidation, and redraw coordination. The time-based horizontal-scale behavior establishes time points/ticks; a separate yield-curve behavior supports non-time horizontal domains.
- `src/model/data-layer.ts`
- `src/model/data-consumer.ts`
- `src/model/chart-model.ts`
- `src/model/horz-scale-behavior-time/horz-scale-behavior-time.ts`
- `src/model/yield-curve-horz-scale-behavior/yield-curve-horz-scale-behavior.ts`

#### Scales, panes, and interaction
The model maps logical data to time and price coordinates, computes visible ranges/autoscaling, and partitions series among panes and price scales. Pointer/touch events are captured by GUI widgets, translated to model operations (scroll, zoom, crosshair, hit testing), then surfaced through API subscriptions.
- `src/model/time-scale.ts`
- `src/model/price-scale.ts`
- `src/model/pane.ts`
- `src/model/crosshair.ts`
- `src/gui/mouse-event-handler.ts`

#### View-to-canvas rendering pipeline
Model entities expose pane/axis views; views generate rendering data using current scale coordinates. Pane, price-axis, and time-axis widgets own DOM/canvas layout and invoke dedicated Canvas renderers for grid, series, crosshair, labels, and overlays. Invalidations from model/data/interaction drive redraws rather than a server-rendered UI cycle.
- `src/gui/chart-widget.ts`
- `src/gui/pane-widget.ts`
- `src/views/pane/ipane-view.ts`
- `src/renderers/ipane-renderer.ts`
- `src/renderers/candlesticks-renderer.ts`

#### Series and extensibility
Built-in line, area, baseline, bar, candlestick, histogram, and custom-series implementations share the model/renderer pipeline. Plugin adapters and primitive wrappers form the extension boundary: third parties can attach series or pane primitives, contribute views/renderers, autoscale information, axis labels, and hit tests without changing core model internals.
- `src/model/series/series-def.ts`
- `src/model/series/custom-series.ts`
- `src/model/series-primitive-wrapper.ts`
- `src/plugins/series-primitive-adapter.ts`
- `src/plugins/primitive-wrapper.ts`

#### Workspace packages and ecosystem
pnpm workspace packages publish reusable plugins, a plugin toolkit, and a scaffolding CLI. `lwc-toolkit` centralizes plugin base classes, custom-series rendering/stacking, canvas and dimension utilities. `create-lwc-plugin` generates plugin projects from series/pane templates. Official packages are independent extensions with their own compile scripts and browser examples.
- `pnpm-workspace.yaml`
- `packages/lwc-toolkit/src/plugin-base.ts`
- `packages/create-lwc-plugin/src/index.ts`
- `packages/lwc-plugin-accessibility/src/accessibility.ts`

#### Documentation, demos, and delivery infrastructure
The `website` is a Docusaurus documentation site, including a generated plugin catalogue and embedded examples. Standalone plugin and indicator demo sites use Vite. CI is split between CircleCI and GitHub Actions; automation builds, validates metadata/compatibility, packages plugins, deploys, and checks bundle size. Browser-level visual, interaction, coverage, and memory-leak runners use Puppeteer-oriented test infrastructure.
- `website/docusaurus.config.js`
- `scripts/plugins/catalogue.mjs`
- `.circleci/config.yml`
- `.github/workflows/plugins.yml`
- `tests/e2e/runner.ts`

Main entry points: [`src/model/chart-model.ts`](https://github.com/tradingview/lightweight-charts/blob/master/src/model/chart-model.ts) (Chart model), [`src/gui/chart-widget.ts`](https://github.com/tradingview/lightweight-charts/blob/master/src/gui/chart-widget.ts) (Chart widget), [`src/api/chart-api.ts`](https://github.com/tradingview/lightweight-charts/blob/master/src/api/chart-api.ts) (Chart API façade), [`pnpm-workspace.yaml`](https://github.com/tradingview/lightweight-charts/blob/master/pnpm-workspace.yaml) (pnpm workspace)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_distribution["Distribution"]
  node_rollup{{"Rollup builds<br/>bundler config<br/>[rollup.config.js]"}}
  node_module_entry["ES module entry<br/>public entry<br/>[index.ts]"]
  node_standalone_entry["Standalone entry<br/>global entry<br/>[standalone.ts]"]
end

subgraph group_public_api["Public API"]
  node_create_chart["Chart creation<br/>API factory<br/>[create-chart.ts]"]
  node_chart_api["Chart API façade<br/>public API<br/>[chart-api.ts]"]
  node_series_api["Series API façade<br/>public API<br/>[series-api.ts]"]
  node_specialized_charts["Options &amp; yield APIs<br/>specialized factories"]
  node_yield_chart_api["Yield chart API<br/>public API<br/>[yield-chart-api.ts]"]
end

subgraph group_core["Chart Core"]
  node_data_layer["Data layer<br/>ingestion pipeline<br/>[data-layer.ts]"]
  node_chart_model["Chart model<br/>state coordinator<br/>[chart-model.ts]"]
  node_horizontal_scales["Horizontal-scale behaviors<br/>domain mapping"]
  node_scales_panes["Scales, panes &amp; crosshair<br/>model geometry<br/>[time-scale.ts]"]
  node_series_core["Series implementations<br/>series model<br/>[series-def.ts]"]
  node_extension_boundary["Primitive extension boundary<br/>plugin adapters"]
end

subgraph group_rendering["GUI &amp; Rendering"]
  node_chart_widget["Chart widget<br/>GUI root<br/>[chart-widget.ts]"]
  node_input_handler["Pointer/touch input<br/>event handling"]
  node_pane_views["Pane views<br/>render-data views<br/>[ipane-view.ts]"]
  node_canvas_renderers["Canvas renderers<br/>canvas rendering"]
end

subgraph group_ecosystem["Workspace &amp; Delivery"]
  node_workspace["pnpm workspace<br/>package workspace"]
  node_toolkit["Plugin toolkit<br/>extension toolkit<br/>[plugin-base.ts]"]
  node_plugin_scaffold["Plugin scaffolder<br/>CLI<br/>[index.ts]"]
  node_docs_delivery["Docs, catalogue &amp; CI<br/>delivery automation"]
end

node_rollup -->|"bundles"| node_module_entry
node_rollup -->|"bundles"| node_standalone_entry
node_module_entry -->|"exports"| node_create_chart
node_standalone_entry -->|"exposes globally"| node_create_chart
node_create_chart -->|"creates"| node_chart_api
node_chart_api -->|"manages"| node_series_api
node_specialized_charts -->|"creates"| node_yield_chart_api
node_chart_api -->|"controls"| node_chart_model
node_series_api -->|"setData / updates"| node_data_layer
node_data_layer -->|"updates series state"| node_chart_model
node_chart_model -->|"uses domain behavior"| node_horizontal_scales
node_chart_model -->|"coordinates"| node_scales_panes
node_chart_model -->|"owns"| node_series_core
node_extension_boundary -->|"attaches primitives"| node_series_core
node_chart_model -->|"invalidates"| node_chart_widget
node_input_handler -->|"scrolls, zooms, hit-tests"| node_chart_model
node_chart_widget -->|"captures events"| node_input_handler
node_chart_widget -->|"requests view data"| node_pane_views
node_pane_views -->|"supplies rendering data"| node_canvas_renderers
node_canvas_renderers -->|"draws canvases"| node_chart_widget
node_workspace -->|"contains"| node_toolkit
node_workspace -->|"contains"| node_plugin_scaffold
node_toolkit -.->|"supports plugin authors"| node_extension_boundary
node_plugin_scaffold -->|"generates projects using"| node_toolkit
node_docs_delivery -->|"builds and publishes"| node_workspace

click node_rollup "https://github.com/tradingview/lightweight-charts/blob/master/rollup.config.js"
click node_module_entry "https://github.com/tradingview/lightweight-charts/blob/master/src/index.ts"
click node_standalone_entry "https://github.com/tradingview/lightweight-charts/blob/master/src/standalone.ts"
click node_create_chart "https://github.com/tradingview/lightweight-charts/blob/master/src/api/create-chart.ts"
click node_chart_api "https://github.com/tradingview/lightweight-charts/blob/master/src/api/chart-api.ts"
click node_series_api "https://github.com/tradingview/lightweight-charts/blob/master/src/api/series-api.ts"
click node_specialized_charts "https://github.com/tradingview/lightweight-charts/blob/master/src/api/create-options-chart.ts"
click node_yield_chart_api "https://github.com/tradingview/lightweight-charts/blob/master/src/api/yield-chart-api.ts"
click node_data_layer "https://github.com/tradingview/lightweight-charts/blob/master/src/model/data-layer.ts"
click node_chart_model "https://github.com/tradingview/lightweight-charts/blob/master/src/model/chart-model.ts"
click node_horizontal_scales "https://github.com/tradingview/lightweight-charts/blob/master/src/model/horz-scale-behavior-time/horz-scale-behavior-time.ts"
click node_scales_panes "https://github.com/tradingview/lightweight-charts/blob/master/src/model/time-scale.ts"
click node_series_core "https://github.com/tradingview/lightweight-charts/blob/master/src/model/series/series-def.ts"
click node_extension_boundary "https://github.com/tradingview/lightweight-charts/blob/master/src/plugins/series-primitive-adapter.ts"
click node_chart_widget "https://github.com/tradingview/lightweight-charts/blob/master/src/gui/chart-widget.ts"
click node_input_handler "https://github.com/tradingview/lightweight-charts/blob/master/src/gui/mouse-event-handler.ts"
click node_pane_views "https://github.com/tradingview/lightweight-charts/blob/master/src/views/pane/ipane-view.ts"
click node_canvas_renderers "https://github.com/tradingview/lightweight-charts/blob/master/src/renderers/candlesticks-renderer.ts"
click node_workspace "https://github.com/tradingview/lightweight-charts/blob/master/pnpm-workspace.yaml"
click node_toolkit "https://github.com/tradingview/lightweight-charts/blob/master/packages/lwc-toolkit/src/plugin-base.ts"
click node_plugin_scaffold "https://github.com/tradingview/lightweight-charts/blob/master/packages/create-lwc-plugin/src/index.ts"
click node_docs_delivery "https://github.com/tradingview/lightweight-charts/blob/master/website/docusaurus.config.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_rollup,node_module_entry,node_standalone_entry toneBlue
class node_create_chart,node_chart_api,node_series_api,node_specialized_charts,node_yield_chart_api toneAmber
class node_data_layer,node_chart_model,node_horizontal_scales,node_scales_panes,node_series_core,node_extension_boundary toneMint
class node_chart_widget,node_input_handler,node_pane_views,node_canvas_renderers toneRose
class node_workspace,node_toolkit,node_plugin_scaffold,node_docs_delivery toneIndigo
```

## Components

### Distribution

- [Rollup builds](https://github.com/tradingview/lightweight-charts/blob/master/rollup.config.js): bundler config · `rollup.config.js`
- [ES module entry](https://github.com/tradingview/lightweight-charts/blob/master/src/index.ts): public entry · `src/index.ts`
- [Standalone entry](https://github.com/tradingview/lightweight-charts/blob/master/src/standalone.ts): global entry · Produces window.LightweightCharts. · `src/standalone.ts`

### Public API

- [Chart creation](https://github.com/tradingview/lightweight-charts/blob/master/src/api/create-chart.ts): API factory · `src/api/create-chart.ts`
- [Chart API façade](https://github.com/tradingview/lightweight-charts/blob/master/src/api/chart-api.ts): public API · Isolates public contracts from mutable chart state. · `src/api/chart-api.ts`
- [Series API façade](https://github.com/tradingview/lightweight-charts/blob/master/src/api/series-api.ts): public API · `src/api/series-api.ts`
- [Options & yield APIs](https://github.com/tradingview/lightweight-charts/blob/master/src/api/create-options-chart.ts): specialized factories · `src/api/create-options-chart.ts`
- [Yield chart API](https://github.com/tradingview/lightweight-charts/blob/master/src/api/yield-chart-api.ts): public API · `src/api/yield-chart-api.ts`

### Chart Core

- [Data layer](https://github.com/tradingview/lightweight-charts/blob/master/src/model/data-layer.ts): ingestion pipeline · Validates input and creates ordered internal plot rows. · `src/model/data-layer.ts`
- [Chart model](https://github.com/tradingview/lightweight-charts/blob/master/src/model/chart-model.ts): state coordinator · Owns panes, series, scales, crosshair, invalidation, and redraw coordination. · `src/model/chart-model.ts`
- [Horizontal-scale behaviors](https://github.com/tradingview/lightweight-charts/blob/master/src/model/horz-scale-behavior-time/horz-scale-behavior-time.ts): domain mapping · Supports time-based and yield-curve domains. · `src/model/horz-scale-behavior-time/horz-scale-behavior-time.ts`
- [Scales, panes & crosshair](https://github.com/tradingview/lightweight-charts/blob/master/src/model/time-scale.ts): model geometry · Maps data to coordinates and visible ranges. · `src/model/time-scale.ts`
- [Series implementations](https://github.com/tradingview/lightweight-charts/blob/master/src/model/series/series-def.ts): series model · Built-in and custom series share the model/rendering pipeline. · `src/model/series/series-def.ts`
- [Primitive extension boundary](https://github.com/tradingview/lightweight-charts/blob/master/src/plugins/series-primitive-adapter.ts): plugin adapters · Lets plugins contribute views, renderers, autoscale data, labels, and hit tests. · `src/plugins/series-primitive-adapter.ts`

### GUI & Rendering

- [Chart widget](https://github.com/tradingview/lightweight-charts/blob/master/src/gui/chart-widget.ts): GUI root · Owns chart DOM/canvas layout and redraw execution. · `src/gui/chart-widget.ts`
- [Pointer/touch input](https://github.com/tradingview/lightweight-charts/blob/master/src/gui/mouse-event-handler.ts): event handling · `src/gui/mouse-event-handler.ts`
- [Pane views](https://github.com/tradingview/lightweight-charts/blob/master/src/views/pane/ipane-view.ts): render-data views · Generate render data from current scale coordinates. · `src/views/pane/ipane-view.ts`
- [Canvas renderers](https://github.com/tradingview/lightweight-charts/blob/master/src/renderers/candlesticks-renderer.ts): canvas rendering · Draw grid, series, crosshair, labels, and overlays. · `src/renderers/candlesticks-renderer.ts`

### Workspace & Delivery

- [pnpm workspace](https://github.com/tradingview/lightweight-charts/blob/master/pnpm-workspace.yaml): package workspace · `pnpm-workspace.yaml`
- [Plugin toolkit](https://github.com/tradingview/lightweight-charts/blob/master/packages/lwc-toolkit/src/plugin-base.ts): extension toolkit · Provides plugin bases and custom-series rendering utilities. · `packages/lwc-toolkit/src/plugin-base.ts`
- [Plugin scaffolder](https://github.com/tradingview/lightweight-charts/blob/master/packages/create-lwc-plugin/src/index.ts): CLI · Generates series and pane plugin projects. · `packages/create-lwc-plugin/src/index.ts`
- [Docs, catalogue & CI](https://github.com/tradingview/lightweight-charts/blob/master/website/docusaurus.config.js): delivery automation · Publishes docs/plugins and validates compatibility and bundles. · `website/docusaurus.config.js`

## Connections

- Rollup builds → ES module entry: bundles
- Rollup builds → Standalone entry: bundles
- ES module entry → Chart creation: exports
- Standalone entry → Chart creation: exposes globally
- Chart creation → Chart API façade: creates
- Chart API façade → Series API façade: manages
- Options & yield APIs → Yield chart API: creates
- Chart API façade → Chart model: controls
- Series API façade → Data layer: setData / updates
- Data layer → Chart model: updates series state
- Chart model → Horizontal-scale behaviors: uses domain behavior
- Chart model → Scales, panes & crosshair: coordinates
- Chart model → Series implementations: owns
- Primitive extension boundary → Series implementations: attaches primitives
- Chart model → Chart widget: invalidates
- Pointer/touch input → Chart model: scrolls, zooms, hit-tests
- Chart widget → Pointer/touch input: captures events
- Chart widget → Pane views: requests view data
- Pane views → Canvas renderers: supplies rendering data
- Canvas renderers → Chart widget: draws canvases
- pnpm workspace → Plugin toolkit: contains
- pnpm workspace → Plugin scaffolder: contains
- Plugin toolkit → Primitive extension boundary: supports plugin authors
- Plugin scaffolder → Plugin toolkit: generates projects using
- Docs, catalogue & CI → pnpm workspace: builds and publishes
