# octree/stockee architecture

> Architecture diagram of the GitHub repository octree/stockee, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/octree/stockee
- Repository: https://github.com/octree/stockee

## Overview

##### Main Components
a. Library Core (Sources/Stockee):
- Core Functionality: Includes files in the “Core” directory with modules such as ChartRenderer, Configuration, QuoteProcessing, and other utilities that manage the rendering engine and data processing.
- Chart Renders: Divided into several subdirectories:
- Main Chart Renders (e.g., CandlestickChart, EMAChart, MAChart, SARChart, TimeShareChart, BOLLChart in the Main subdirectory).
- Sub Chart Renders (e.g., KDJChart, MACDChart, RSIChart, VolumeChart).
- Layers and Auxiliary Indicators: You see files in “ChartRenders/Auxiliary” and “ChartRenders/Layers” handling visual components such as grid indicators, price annotations, indicators’ views, etc.
- Indicator Algorithms: Contains implementations for various technical analysis algorithms (BollingerBands, ExponentialMovingAverage, MACDAlgorithm, etc.) found in the “IndicatorAlgorithm” directory. This component typically processes data inputs to compute values required by the renderers.
- Utilities and Extensions: Found in “Utils” and other helper modules, offering capabilities like binding, mathematical extensions, and patching.

b. View Layer:
- Chart Presentation and UI Composition: Located in “View” directory, which includes components for building the composite chart view (e.g., ChartView, ChartGroup, views for captions, interactions like tap or zoom, and selection indicators).
- Interaction Handlers: These files (in the “View/Interaction” subdirectory) capture user gestures such as long press, tap, or zoom actions that influence the chart’s presentation.

c. Demo / Example Usage:
- The “Demo/Playground” directory contains a sample Xcode project that demonstrates how to use Stockee’s components. This acts as an illustrative example of how the library is integrated into a SwiftUI-like workflow where developers set a chart descriptor using declarative syntax.

d. Testing:
- The “Tests” directory contains unit tests for various components (such as rendering, core processing, indicator algorithms, and utility functions) ensuring the reliability of the library.

##### Relationships and Interactions
- The Chart Renderer and Core Processing components (e.g., QuoteProcessing, Configuration, RendererContext) form the backbone that processes incoming data and prepares it for visualization.
- The Chart Renders are layered on top of the core to render different parts of the chart, organized into Main and Sub renders depending on their role (primary chart vs. supplementary indicators).
- Utility and algorithm components feed computed values into the renderers.
- The view components coordinate the final display by composing various chart groups, integrating both the visual layers and interaction handlers.
- The demo application shows how declarative syntax builds the chart by combining these components, and it often interacts with additional modules like WebSocket (for dynamic updates) – although that Websocket folder is only present in the demo’s playground for experimental purposes, its concept can be shown as an optional external data feed.

##### Architectural Patterns and Design Principles
- Modular Architecture: Each module (Core, Renderers, Algorithms, Views) is separated by responsibility, which encourages reusability and ease of testing.
- Declarative Syntax: The sample in the README hints at a SwiftUI-like approach where various components (like ChartGroup, GridIndicator, YAxisAnnotation, etc.) are declared to build the overall chart.
- Layered Architecture: The architecture is naturally divided into lower-level data processing and rendering layers, with higher-level interaction and view composition layers.
- Extensibility: The separation into auxiliary, main, and sub-components, along with support for extensions (as seen in the “Extensions” subdirectory), underlines an emphasis on customizable behavior.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Core Layer
    subgraph "Core Layer"
        nCore["Core Engine"]:::core
        nIndicator["Indicator Algorithms"]:::algorithm
        nUtils["Utilities & Extensions"]:::utility
    end

    %% Rendering Layer
    subgraph "Rendering Layer"
        nMain["Main Chart Renders"]:::render
        nSub["Sub Chart Renders"]:::render
        nAuxiliary["Auxiliary & Layers"]:::render
    end

    %% View Layer
    subgraph "View Layer"
        nView["View Composition"]:::view
        nInteraction["Interaction Handlers"]:::interaction
    end

    %% External and Integration
    nExternal["External Data Source (WebSocket)"]:::external
    nDemo["Demo Application"]:::demo
    nTesting["Testing"]:::testing

    %% Relationships
    nExternal -->|"data_flow"| nCore
    nCore -->|"data_flow"| nMain
    nCore -->|"data_flow"| nSub
    nCore -->|"data_flow"| nAuxiliary

    nIndicator -->|"computed_values"| nMain
    nIndicator -->|"computed_values"| nAuxiliary

    nUtils -->|"support"| nCore
    nUtils -->|"support"| nIndicator

    nMain -->|"render_output"| nView
    nSub -->|"render_output"| nView
    nAuxiliary -->|"render_output"| nView

    nInteraction -->|"user_input"| nView

    nDemo -->|"integration_usage"| nView

    nTesting -->|"tests"| nCore
    nTesting -->|"tests"| nMain
    nTesting -->|"tests"| nIndicator
    nTesting -->|"tests"| nView

    %% Click Events
    click nCore "https://github.com/octree/stockee/tree/main/Sources/Stockee/Core"
    click nMain "https://github.com/octree/stockee/tree/main/Sources/Stockee/ChartRenders/Main"
    click nSub "https://github.com/octree/stockee/tree/main/Sources/Stockee/ChartRenders/Sub"
    click nAuxiliary "https://github.com/octree/stockee/tree/main/Sources/Stockee/ChartRenders/Auxiliary"
    click nAuxiliary "https://github.com/octree/stockee/tree/main/Sources/Stockee/ChartRenders/Layers"
    click nIndicator "https://github.com/octree/stockee/tree/main/Sources/Stockee/IndicatorAlgorithm"
    click nUtils "https://github.com/octree/stockee/tree/main/Sources/Stockee/Utils"
    click nUtils "https://github.com/octree/stockee/tree/main/Sources/Stockee/IndicatorAlgorithm/Extensions"
    click nView "https://github.com/octree/stockee/tree/main/Sources/Stockee/View"
    click nInteraction "https://github.com/octree/stockee/tree/main/Sources/Stockee/View/Interaction"
    click nDemo "https://github.com/octree/stockee/tree/main/Demo/Playground"
    click nTesting "https://github.com/octree/stockee/tree/main/Tests"

    %% Styles
    classDef core fill:#f9e79f,stroke:#b9770e,stroke-width:2px;
    classDef algorithm fill:#aed6f1,stroke:#2874a6,stroke-width:2px;
    classDef utility fill:#fcf3cf,stroke:#b7950b,stroke-width:2px;
    classDef render fill:#d5f5e3,stroke:#229954,stroke-width:2px;
    classDef view fill:#f5cba7,stroke:#ba4a00,stroke-width:2px;
    classDef interaction fill:#d6eaf8,stroke:#2e86c1,stroke-width:2px;
    classDef external fill:#e8daef,stroke:#884ea0,stroke-width:2px;
    classDef demo fill:#fadbd8,stroke:#cd6155,stroke-width:2px;
    classDef testing fill:#f9e79f,stroke:#b9770e,stroke-width:2px;
```
