How crypt0inf0/openalgo-chart works
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: Chart Chart core · App.tsx App · services Services · store Stores
Components 26
App shell
Bootstrapping, global layout, and shared UI chrome.
- main · Bootstraps the React app.
src/main.tsx - App · Assembles the top-level workspace and routing of UI panels.
src/App.tsx - Layout chrome · 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 · Main chart canvas, grid, menus, headers, indicators, and chart panels.
src/components/Chart - Chart hooks · Chart data, interaction, replay, and pane menu behavior.
src/components/Chart/hooks - Chart utils · Chart configuration, factories, metadata, cleanup, and series helpers.
src/components/Chart/utils - Toolbars · Tool selection and drawing-property controls for chart annotations.
src/components/Toolbar - Line tools · Interactive drawing primitives and tool manager for chart annotations.
src/plugins/line-tools - Chart plugins · Custom primitives and overlays such as volume, TPO, OI, footprint, delta, power trades, and visual trading.
src/plugins - Indicators · Reusable indicator calculations and chart-facing indicator integration.
src/utils/indicators - Indicator settings · UI for configuring indicator and strategy parameters.
src/components/IndicatorSettings
Market & trading
Symbol, watchlist, trading, options, and account workflows.
- Watchlist · Symbol list, selection, drag/drop, and keyboard navigation.
src/components/Watchlist - Symbol search · Search and symbol discovery for market navigation.
src/components/SymbolSearch - Trading panel · Order entry and account/trade management interface.
src/components/TradingPanel - Account panel · Positions, holdings, orders, trades, and closed positions tables.
src/components/AccountPanel - Options workflow · Option chain, quick picker, Greeks, and strategy building.
src/components/OptionChainModal - Risk calculator · Risk calculator panel and chart overlay rendering.
src/components/RiskCalculatorPanel
State & services
Contexts, stores, persistence, and external service boundaries.
- Contexts · React contexts for UI, tools, theme, watchlist, order, and user state.
src/context - Stores · Shared application stores for workspace and market data.
src/store - Services · API client, market data, trading, storage, options, and webhook integrations.
src/services - App hooks · Cross-cutting hooks for symbols, tools, orders, layout, persistence, and UI behavior.
src/hooks - Domain types · Shared domain, API, UI, and utility types.
src/types
Quality & delivery
Tests, docs, and deployment/runtime packaging.
- Tests · Unit, integration, and end-to-end test suites with mocks and fixtures.
tests - E2E · Playwright coverage focused on chart and risk-calculator interactions.
e2e - Docs · Architecture, implementation, testing, and feature documentation.
docs - Build & deploy · Vite build, Docker/Nginx packaging, and CI workflows.
Dockerfile
Connections 34
- 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.