Project Structure
VibeTrader is a TypeScript-based charting application built with React, organized into a clean, modular architecture:Core Architecture Layers
1. Time Series Layer
The foundation of VibeTrader is the time series system (lib/timeseris/), which provides:
- TSer: Time series interface for managing temporal data
- TVar: Variables that hold time-indexed values
- TFrame: Timeframe definitions (1m, 5m, 1h, 1D, etc.)
- TStamps: Timestamp management with calendar modes
2. Domain Layer
The domain layer (lib/domain/) contains business logic and data models:
- Kline: OHLCV candlestick data model
- PineData: Pine Script compatible data format
- DataFetcher: Market data retrieval
- TSerProvider: Data provider interface
- BinanaceData, YFinanceData: Exchange-specific adapters
3. Charting Layer
The charting layer (lib/charting/) handles visualization:
- View Components: ChartView hierarchy for rendering
- Plot Components: Specialized renderers (klines, lines, indicators)
- Pane Components: UI elements (axes, titles, spacing)
- Drawing Tools: Interactive chart annotations
- Controls: ChartXControl and ChartYControl for coordinate mapping
4. Collection Layer
Efficient data structures (lib/collection/):
- ValueList: High-performance array-like container
- Collection: Generic collection interface
- CIterator: Custom iterator implementation
Data Flow
Typical Flow
- Data Fetching:
DataFetcherretrieves market data from exchanges - Series Creation: Data is stored in
DefaultTSerwithTVar<Kline>variables - View Container:
KlineViewContainermanages the chart state and layout - Controls:
ChartXControlandChartYControlhandle coordinate transformations - Views: Multiple
ChartViewinstances render different aspects (price, volume, indicators) - Plots: Specialized plot components render the actual visual elements
Coordinate System
VibeTrader uses a sophisticated coordinate system:X-Axis (Time)
- Row: Integer index in display order
- Bar: Visual bar position (rightSideRow - i)
- Time: Milliseconds since epoch
- Index: Position in occurred data
ChartXControl manages conversions:
Y-Axis (Value)
TheChartYControl handles value-to-pixel mapping with:
- Value scaling: Linear, logarithmic (lg, ln)
- Normalization: Auto-scaling for different value ranges
- Zooming/Panning: Interactive chart manipulation
Component Lifecycle
Initialization
App.tsxsets up the router and theme providerHomePagerendersKlineViewContainer- Container creates
DefaultTSerwith specified timeframe - Data is fetched and populated into
TVar<Kline> ChartXControlis initialized with the base series- View components (
KlineView,VolumeView, etc.) are created
Rendering
ChartView.computeGeometry()calculates coordinate mappingsChartView.plot()generates JSX elements for visualization- Plot components render SVG paths, shapes, and text
- State updates trigger re-renders via React lifecycle
User Interaction
- Mouse events are captured by view components
- Controls update based on user actions (pan, zoom, cursor)
UpdateEventpropagates changes to all views- Views recompute geometry and re-render affected areas
State Management
VibeTrader uses React component state with a centralized update pattern:KlineViewContainer manages:
- Chart dimensions and layout
- Indicator overlays and stacked indicators
- Drawing tools and annotations
- Cursor positions and labels
- Screenshot functionality
Extension Points
Adding New Plot Types
- Create a new component in
lib/charting/plot/ - Implement the rendering logic using SVG primitives
- Register in
KlineView.plotOverlayCharts()orIndicatorView.plot()
Adding New Indicators
- Write Pine Script or TypeScript indicator logic
- Use
PineTSruntime to execute scripts - Output results as
PineData[]arrays - Render using existing plot components
Adding New Data Sources
- Create a new class extending the data fetcher pattern
- Implement
getMarketData()method - Convert to
Klineformat - Register in
DataFetcher.ts
Performance Considerations
Efficient Rendering
- SVG elements are generated only for visible bars
ChartXControl.nBarslimits the render window- Memoization prevents unnecessary re-renders
Data Management
ValueListuses typed arrays for efficiencyTStampsemploys binary search for time lookups- Capacity limits prevent unbounded memory growth
Update Batching
- Multiple changes are batched into single
UpdateEvent - Geometry calculations are cached when possible
- React’s reconciliation optimizes DOM updates
Technology Stack
- React 18: UI framework with hooks and concurrent features
- TypeScript: Type-safe development
- React Spectrum S2: Adobe’s design system for UI components
- Temporal API: Modern date/time handling (polyfilled)
- PineTS: Pine Script runtime for indicators
- html2canvas: Screenshot generation
- Vite: Build tool and dev server
Next Steps
- Explore the Component Hierarchy to understand the view layer
- Learn about the Time Series System for data management
- Check the API reference for detailed interface documentation