# crypt0inf0/openalgo-chart architecture

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

- Interactive diagram: https://gitdiagram.com/crypt0inf0/openalgo-chart
- Repository: https://github.com/crypt0inf0/openalgo-chart

## Overview

1. **Overall shape**
   - This is a **single-page React + TypeScript charting/trading application** built with **Vite** and centered on **lightweight-charts**.
   - The app is intended to run **locally**; the README warns that some API/CORS/websocket-dependent features are only reliable on `localhost`.

2. **Application shell**
   - `src/main.tsx` boots the app, `src/App.tsx` assembles the top-level layout, and `src/components/Layout` plus `src/components/Topbar`, `BottomBar`, `MobileNav`, and `Toolbar` provide the global UI frame.
   - The main screen is a **multi-chart workspace** with 1–4 chart panels, plus side panels and modals for watchlists, trading, settings, and drawing/indicator controls.

3. **State and cross-cutting contexts**
   - Global UI and user-facing state is distributed through React contexts in `src/context` such as `UIContext`, `ToolContext`, `ThemeContext`, `WatchlistContext`, `OrderContext`, and `UserContext`.
   - Workspace-level persistence and app state are also handled through stores in `src/store`, especially `workspaceStore` and `marketDataStore`.
   - This split suggests a boundary between **ephemeral interaction state** (contexts/hooks) and **shared persisted application state** (stores/services/local storage).

4. **Chart subsystem**
   - `src/components/Chart` is the core rendering subsystem: it owns the chart canvas, grid layout, overlays, context menus, price scale controls, OHLC header, and indicator legend.
   - Chart behavior is factored into hooks such as `useChartData`, `useChartInteraction`, `useChartReplay`, and `usePaneMenu`.
   - The chart layer consumes data and configuration from services/hooks, then renders series, overlays, indicators, and interaction affordances.

5. **Chart extensibility and custom primitives**
   - `src/plugins` contains the major extension layer for chart overlays and custom rendered primitives.
   - Included plugins cover **line tools**, **volume profile**, **TPO profile**, **OI profile**, **power trades**, **bar stats**, **delta profile**, **footprint chart**, **visual trading**, and **risk calculator** overlays.
   - This is a clear architectural boundary: chart visualization is extended via plugin modules rather than being hardcoded into the base chart component.

6. **Indicators and analytics**
   - Reusable indicator logic lives primarily in `src/utils/indicators` and is paired with chart integration helpers in `src/components/Chart/utils`.
   - The app supports common indicators like SMA, EMA, RSI, MACD, Bollinger Bands, ATR, Stochastic, VWAP, Supertrend, plus custom strategies such as TPO and several pattern/strategy indicators.
   - Indicator configuration is surfaced through `src/components/IndicatorSettings`, which acts as the user-facing control plane for these calculations.

7. **Drawing and interaction tools**
   - The drawing/annotation system is split between `src/plugins/line-tools` and UI controls in `src/components/Toolbar`, `src/hooks/useToolHandlers`, `useDrawingProperties`, and related interaction hooks.
   - This includes trend lines, rays, horizontal/vertical lines, Fibonacci tools, shapes, text, measurement, and custom line-tool templates.
   - The architecture implies a two-part flow: toolbar selection updates tool state, then the chart plugin layer renders and manages interactive primitives.

8. **Trading and account panel**
   - Trading-related UI is grouped under `src/components/TradingPanel` and `src/components/AccountPanel`, with dialogs for order entry, modifications, exits, and cancellations.
   - Data and behavior are centralized in services such as `src/services/trading/*`, `orderService`, `account.service`, and `useOrderHandlers` / `useOrderFormState`.
   - This subsystem bridges UI state, backend trading APIs, and table-style account views for positions, holdings, orders, trades, and closed positions.

9. **Market data, symbols, watchlists, and search**
   - `src/components/Watchlist`, `SymbolSearch`, and `Topbar` coordinate symbol selection and market navigation.
   - Supporting services include `marketService`, `instrumentService`, `chartDataService`, `tickDataService`, `tickStore`, `timeService`, `marketCapService`, and `stockLists`.
   - The data flow is typically: symbol selection → service fetch/stream → store/cache → chart/watchlist/trading panels update.

10. **Options and strategy workflow**
   - Options-specific functionality is concentrated in `OptionChainModal`, `QuickOptionPicker`, `OptionChain` hooks, `optionChain`/`optionsApiService`, and utility transformers in `src/utils/optionChainTransformers`.
   - The README highlights per-chart strategy configuration, strategy templates, Greeks display, OI bars, and multi-leg strategy building.
   - This subsystem feeds both chart overlays and OHLC/header display, so option strategy state is a first-class part of the workspace model rather than a separate tool.

11. **Risk calculator and specialized overlays**
   - The risk calculator exists in two layers: UI in `src/components/RiskCalculatorPanel` and chart rendering in `src/plugins/risk-calculator` plus `src/utils/indicators/riskCalculator*`.
   - E2E tests and docs show it is an important feature with drag interactions, templates, and validation.
   - Like options, this is integrated into the chart workspace as an overlay/panel rather than a standalone utility.

12. **Infrastructure, persistence, and integrations**
   - External access is abstracted through `src/services/api`, `openalgo`, `webhookService`, `preferencesService`, `storageService`, and `connectionStatus`.
   - Local persistence is used for preferences, shortcuts, layouts, watchlists, and other workspace settings via storage helpers and hooks like `useLocalStorage`.
   - There is no indication of a large server-side component in this repo; the app is primarily a **frontend client** that talks to trading/market APIs and possibly local or proxied endpoints.

13. **Testing and quality boundaries**
   - Unit/integration tests live in `tests` and `src/__tests__`, with domain coverage for indicators, stores, and cleanup behaviors.
   - End-to-end coverage is in `e2e`, especially around the risk calculator and chart interactions, using Playwright.
   - Mock service handlers in `tests/mocks` indicate API boundaries are tested through simulated network responses rather than tightly coupling UI tests to live services.

14. **Deployment and environment**
   - The repo includes `Dockerfile`, `nginx.conf`, and GitHub Actions workflows for CI/release, suggesting containerized production builds and static hosting of the frontend.
   - Because the app is local-first and chart-heavy, the deployed artifact is likely a static client bundle served by Nginx, with runtime dependencies on external market/trading endpoints.

Main entry points: [`src/components/Chart`](https://github.com/crypt0inf0/openalgo-chart/tree/main/src/components/Chart) (Chart core), [`src/App.tsx`](https://github.com/crypt0inf0/openalgo-chart/blob/main/src/App.tsx) (App), [`src/services`](https://github.com/crypt0inf0/openalgo-chart/tree/main/src/services) (Services), [`src/store`](https://github.com/crypt0inf0/openalgo-chart/tree/main/src/store) (Stores)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_app_shell["App shell"]
  node_node_main(("main<br/>entry<br/>[main.tsx]"))
  node_node_app["App<br/>composition<br/>[App.tsx]"]
  node_node_layout["Layout chrome<br/>ui shell"]
end

subgraph group_group_chart["Chart workspace"]
  node_node_chart["Chart core<br/>rendering"]
  node_node_chart_hooks["Chart hooks<br/>interaction"]
  node_node_chart_utils["Chart utils<br/>chart support"]
  node_node_toolbar["Toolbars<br/>drawing UI"]
  node_node_line_tools["Line tools<br/>plugin system"]
  node_node_plugins["Chart plugins<br/>overlays"]
  node_node_indicators["Indicators<br/>analytics"]
  node_node_indicator_settings["Indicator settings<br/>controls"]
end

subgraph group_group_market["Market & trading"]
  node_node_watchlist["Watchlist<br/>symbol nav"]
  node_node_symbol_search["Symbol search"]
  node_node_trading["Trading panel<br/>trading UI"]
  node_node_account["Account panel<br/>account views"]
  node_node_options["Options workflow"]
  node_node_risk["Risk calculator<br/>overlay tool"]
end

subgraph group_group_state["State & services"]
  node_node_contexts["Contexts<br/>ui state"]
  node_node_stores[("Stores<br/>workspace state")]
  node_node_services["Services<br/>integrations"]
  node_node_hooks["App hooks<br/>orchestration"]
  node_node_types["Domain types<br/>models"]
end

subgraph group_group_quality["Quality & delivery"]
  node_node_tests["Tests<br/>verification"]
  node_node_e2e["E2E<br/>playwright"]
  node_node_docs["Docs<br/>documentation"]
  node_node_delivery["Build & deploy<br/>frontend delivery"]
end

node_node_main -->|"mounts"| node_node_app
node_node_app -->|"frames"| node_node_layout
node_node_app -->|"hosts"| node_node_chart
node_node_app -->|"shows"| node_node_watchlist
node_node_app -->|"includes"| node_node_trading
node_node_app -->|"opens"| node_node_options
node_node_app -->|"opens"| node_node_risk
node_node_chart -->|"uses"| node_node_chart_hooks
node_node_chart -->|"depends on"| node_node_chart_utils
node_node_chart -->|"renders"| node_node_indicators
node_node_chart -->|"extends with"| node_node_plugins
node_node_chart -->|"enables"| node_node_line_tools
node_node_toolbar -->|"updates"| node_node_contexts
node_node_line_tools -->|"driven by"| node_node_toolbar
node_node_indicator_settings -->|"configures"| node_node_indicators
node_node_watchlist -->|"pairs with"| node_node_symbol_search
node_node_watchlist -->|"fetches"| node_node_services
node_node_trading -->|"links to"| node_node_account
node_node_trading -->|"calls"| node_node_services
node_node_options -->|"fetches"| node_node_services
node_node_options -->|"influences"| node_node_chart
node_node_risk -->|"renders via"| node_node_plugins
node_node_contexts -->|"coordinates"| node_node_stores
node_node_stores -->|"persists via"| node_node_services
node_node_hooks -->|"consumes"| node_node_contexts
node_node_hooks -->|"syncs"| node_node_stores
node_node_services -->|"uses"| node_node_types
node_node_tests -->|"covers"| node_node_indicators
node_node_tests -->|"covers"| node_node_stores
node_node_e2e -->|"covers"| node_node_risk
node_node_e2e -->|"covers"| node_node_chart
node_node_docs -->|"describes"| node_node_chart
node_node_delivery -->|"packages"| node_node_app
node_node_delivery -->|"depends on"| node_node_services

click node_node_main "https://github.com/crypt0inf0/openalgo-chart/blob/main/src/main.tsx"
click node_node_app "https://github.com/crypt0inf0/openalgo-chart/blob/main/src/App.tsx"
click node_node_layout "https://github.com/crypt0inf0/openalgo-chart/tree/main/src/components/Layout"
click node_node_chart "https://github.com/crypt0inf0/openalgo-chart/tree/main/src/components/Chart"
click node_node_chart_hooks "https://github.com/crypt0inf0/openalgo-chart/tree/main/src/components/Chart/hooks"
click node_node_chart_utils "https://github.com/crypt0inf0/openalgo-chart/tree/main/src/components/Chart/utils"
click node_node_toolbar "https://github.com/crypt0inf0/openalgo-chart/tree/main/src/components/Toolbar"
click node_node_line_tools "https://github.com/crypt0inf0/openalgo-chart/tree/main/src/plugins/line-tools"
click node_node_plugins "https://github.com/crypt0inf0/openalgo-chart/tree/main/src/plugins"
click node_node_indicators "https://github.com/crypt0inf0/openalgo-chart/tree/main/src/utils/indicators"
click node_node_indicator_settings "https://github.com/crypt0inf0/openalgo-chart/tree/main/src/components/IndicatorSettings"
click node_node_watchlist "https://github.com/crypt0inf0/openalgo-chart/tree/main/src/components/Watchlist"
click node_node_symbol_search "https://github.com/crypt0inf0/openalgo-chart/tree/main/src/components/SymbolSearch"
click node_node_trading "https://github.com/crypt0inf0/openalgo-chart/tree/main/src/components/TradingPanel"
click node_node_account "https://github.com/crypt0inf0/openalgo-chart/tree/main/src/components/AccountPanel"
click node_node_options "https://github.com/crypt0inf0/openalgo-chart/tree/main/src/components/OptionChainModal"
click node_node_risk "https://github.com/crypt0inf0/openalgo-chart/tree/main/src/components/RiskCalculatorPanel"
click node_node_contexts "https://github.com/crypt0inf0/openalgo-chart/tree/main/src/context"
click node_node_stores "https://github.com/crypt0inf0/openalgo-chart/tree/main/src/store"
click node_node_services "https://github.com/crypt0inf0/openalgo-chart/tree/main/src/services"
click node_node_hooks "https://github.com/crypt0inf0/openalgo-chart/tree/main/src/hooks"
click node_node_types "https://github.com/crypt0inf0/openalgo-chart/tree/main/src/types"
click node_node_tests "https://github.com/crypt0inf0/openalgo-chart/tree/main/tests"
click node_node_e2e "https://github.com/crypt0inf0/openalgo-chart/tree/main/e2e"
click node_node_docs "https://github.com/crypt0inf0/openalgo-chart/tree/main/docs"
click node_node_delivery "https://github.com/crypt0inf0/openalgo-chart/tree/main/Dockerfile"

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_node_main,node_node_app,node_node_layout toneBlue
class node_node_chart,node_node_chart_hooks,node_node_chart_utils,node_node_toolbar,node_node_line_tools,node_node_plugins,node_node_indicators,node_node_indicator_settings toneAmber
class node_node_watchlist,node_node_symbol_search,node_node_trading,node_node_account,node_node_options,node_node_risk toneMint
class node_node_contexts,node_node_stores,node_node_services,node_node_hooks,node_node_types toneRose
class node_node_tests,node_node_e2e,node_node_docs,node_node_delivery toneIndigo
```

## Components

### App shell

Bootstrapping, global layout, and shared UI chrome.

- [main](https://github.com/crypt0inf0/openalgo-chart/blob/main/src/main.tsx): entry · Bootstraps the React app. · `src/main.tsx`
- [App](https://github.com/crypt0inf0/openalgo-chart/blob/main/src/App.tsx): composition · Assembles the top-level workspace and routing of UI panels. · `src/App.tsx`
- [Layout chrome](https://github.com/crypt0inf0/openalgo-chart/tree/main/src/components/Layout): ui shell · Global frame: layout, topbar, toolbar, bottom bar, and mobile nav. · `src/components/Layout`

### Chart workspace

Multi-chart rendering, interaction, overlays, and drawing tools.

- [Chart core](https://github.com/crypt0inf0/openalgo-chart/tree/main/src/components/Chart): rendering · Main chart canvas, grid, menus, headers, indicators, and chart panels. · `src/components/Chart`
- [Chart hooks](https://github.com/crypt0inf0/openalgo-chart/tree/main/src/components/Chart/hooks): interaction · Chart data, interaction, replay, and pane menu behavior. · `src/components/Chart/hooks`
- [Chart utils](https://github.com/crypt0inf0/openalgo-chart/tree/main/src/components/Chart/utils): chart support · Chart configuration, factories, metadata, cleanup, and series helpers. · `src/components/Chart/utils`
- [Toolbars](https://github.com/crypt0inf0/openalgo-chart/tree/main/src/components/Toolbar): drawing UI · Tool selection and drawing-property controls for chart annotations. · `src/components/Toolbar`
- [Line tools](https://github.com/crypt0inf0/openalgo-chart/tree/main/src/plugins/line-tools): plugin system · Interactive drawing primitives and tool manager for chart annotations. · `src/plugins/line-tools`
- [Chart plugins](https://github.com/crypt0inf0/openalgo-chart/tree/main/src/plugins): overlays · Custom primitives and overlays such as volume, TPO, OI, footprint, delta, power trades, and visual trading. · `src/plugins`
- [Indicators](https://github.com/crypt0inf0/openalgo-chart/tree/main/src/utils/indicators): analytics · Reusable indicator calculations and chart-facing indicator integration. · `src/utils/indicators`
- [Indicator settings](https://github.com/crypt0inf0/openalgo-chart/tree/main/src/components/IndicatorSettings): controls · UI for configuring indicator and strategy parameters. · `src/components/IndicatorSettings`

### Market & trading

Symbol, watchlist, trading, options, and account workflows.

- [Watchlist](https://github.com/crypt0inf0/openalgo-chart/tree/main/src/components/Watchlist): symbol nav · Symbol list, selection, drag/drop, and keyboard navigation. · `src/components/Watchlist`
- [Symbol search](https://github.com/crypt0inf0/openalgo-chart/tree/main/src/components/SymbolSearch): search · Search and symbol discovery for market navigation. · `src/components/SymbolSearch`
- [Trading panel](https://github.com/crypt0inf0/openalgo-chart/tree/main/src/components/TradingPanel): trading UI · Order entry and account/trade management interface. · `src/components/TradingPanel`
- [Account panel](https://github.com/crypt0inf0/openalgo-chart/tree/main/src/components/AccountPanel): account views · Positions, holdings, orders, trades, and closed positions tables. · `src/components/AccountPanel`
- [Options workflow](https://github.com/crypt0inf0/openalgo-chart/tree/main/src/components/OptionChainModal): options · Option chain, quick picker, Greeks, and strategy building. · `src/components/OptionChainModal`
- [Risk calculator](https://github.com/crypt0inf0/openalgo-chart/tree/main/src/components/RiskCalculatorPanel): overlay tool · Risk calculator panel and chart overlay rendering. · `src/components/RiskCalculatorPanel`

### State & services

Contexts, stores, persistence, and external service boundaries.

- [Contexts](https://github.com/crypt0inf0/openalgo-chart/tree/main/src/context): ui state · React contexts for UI, tools, theme, watchlist, order, and user state. · `src/context`
- [Stores](https://github.com/crypt0inf0/openalgo-chart/tree/main/src/store): workspace state · Shared application stores for workspace and market data. · `src/store`
- [Services](https://github.com/crypt0inf0/openalgo-chart/tree/main/src/services): integrations · API client, market data, trading, storage, options, and webhook integrations. · `src/services`
- [App hooks](https://github.com/crypt0inf0/openalgo-chart/tree/main/src/hooks): orchestration · Cross-cutting hooks for symbols, tools, orders, layout, persistence, and UI behavior. · `src/hooks`
- [Domain types](https://github.com/crypt0inf0/openalgo-chart/tree/main/src/types): models · Shared domain, API, UI, and utility types. · `src/types`

### Quality & delivery

Tests, docs, and deployment/runtime packaging.

- [Tests](https://github.com/crypt0inf0/openalgo-chart/tree/main/tests): verification · Unit, integration, and end-to-end test suites with mocks and fixtures. · `tests`
- [E2E](https://github.com/crypt0inf0/openalgo-chart/tree/main/e2e): playwright · Playwright coverage focused on chart and risk-calculator interactions. · `e2e`
- [Docs](https://github.com/crypt0inf0/openalgo-chart/tree/main/docs): documentation · Architecture, implementation, testing, and feature documentation. · `docs`
- [Build & deploy](https://github.com/crypt0inf0/openalgo-chart/tree/main/Dockerfile): frontend delivery · Vite build, Docker/Nginx packaging, and CI workflows. · `Dockerfile`

## Connections

- main → App: mounts · Application bootstrap renders the root app.
- App → Layout chrome: frames · App composes the global chrome and workspace shell.
- App → Chart core: hosts · Main workspace centers on chart panels.
- App → Watchlist: shows · Workspace includes symbol navigation and watchlists.
- App → Trading panel: includes · Trading controls are part of the main UI.
- App → Options workflow: opens · Option chain and strategy flows are surfaced from the app.
- App → Risk calculator: opens · Risk calculator is integrated into the workspace.
- Chart core → Chart hooks: uses · Chart UI is driven by chart-specific hooks.
- Chart core → Chart utils: depends on · Chart rendering relies on helper and factory utilities.
- Chart core → Indicators: renders · Indicators are calculated and displayed on charts.
- Chart core → Chart plugins: extends with · Overlays and custom primitives augment the chart.
- Chart core → Line tools: enables · Chart embeds interactive drawing primitives.
- Toolbars → Contexts: updates · Tool selections and drawing settings flow through context state.
- Line tools → Toolbars: driven by · Toolbar selects and configures line tools.
- Indicator settings → Indicators: configures · Indicator settings map to indicator calculations and options.
- Watchlist → Symbol search: pairs with · Watchlist and search jointly drive symbol selection.
- Watchlist → Services: fetches · Watchlist entries depend on market data and symbol services.
- Trading panel → Account panel: links to · Trading workflow connects to account and order views.
- Trading panel → Services: calls · Trading actions are backed by order and account services.
- Options workflow → Services: fetches · Option chain data and strategy data come from services.
- Options workflow → Chart core: influences · Options state affects chart overlays and headers.
- Risk calculator → Chart plugins: renders via · Risk calculator uses chart plugin rendering.
- Contexts → Stores: coordinates · Contexts and stores split ephemeral UI from shared workspace state.
- Stores → Services: persists via · Stores are populated and synchronized through services.
- App hooks → Contexts: consumes · Cross-cutting hooks read and update context state.
- App hooks → Stores: syncs · Hooks bridge UI interactions to persisted stores.
- Services → Domain types: uses · Services share API and domain type definitions.
- Tests → Indicators: covers · Unit and integration tests focus heavily on indicators.
- Tests → Stores: covers · Store behavior is validated in unit tests.
- E2E → Risk calculator: covers · E2E suite validates the risk calculator workflow.
- E2E → Chart core: covers · End-to-end tests exercise chart interactions.
- Docs → Chart core: describes · Documentation captures architecture and feature behavior.
- Build & deploy → App: packages · Build and deployment target the frontend app bundle.
- Build & deploy → Services: depends on · Runtime delivery assumes external API and local proxy endpoints.
