# quantpad/pine-runner architecture

> Architecture diagram of the GitHub repository quantpad/pine-runner, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/quantpad/pine-runner
- Repository: https://github.com/quantpad/pine-runner

## Overview

This is a process-isolated Pine Script runner: a parent application sends a JSON scan or run request, and the child returns a sentinel-encoded JSON response. Runs configure and execute the Pine engine against supplied OHLCV data, then return normalized chart visuals and a bounded strategy-state snapshot. The graph follows the sampled entry point and orchestrator; unsampled normalization details are represented by their documented subsystem, without inferring additional internal calls.

Main entry points: [`src/run.ts`](https://github.com/quantpad/pine-runner/blob/main/src/run.ts) (Run Orchestrator), [`src/main.ts`](https://github.com/quantpad/pine-runner/blob/main/src/main.ts) (Child Entry Point), [`src/provider.ts`](https://github.com/quantpad/pine-runner/blob/main/src/provider.ts) (Candle Provider), [`src/engine.ts`](https://github.com/quantpad/pine-runner/blob/main/src/engine.ts) (Engine Adapter)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_boundary["Process Boundary"]
  node_protocol["JSON Protocol<br/>[protocol.ts]"]
  node_entry["Child Entry Point<br/>[main.ts]"]
  node_codec["Special Number Codec<br/>[codec.ts]"]
  node_types["Runner Data Types<br/>[types.ts]"]
end

subgraph group_execution["Pine Execution"]
  node_runner["Run Orchestrator<br/>[run.ts]"]
  node_engine_adapter["Engine Adapter<br/>[engine.ts]"]
  node_pine_engine["PineTS Engine"]
  node_compat["Runtime Compatibility<br/>[runtime-compat.ts]"]
end

subgraph group_market["Market Data"]
  node_provider["Candle Provider<br/>[provider.ts]"]
  node_resample["OHLCV Resampling<br/>[resample.ts]"]
end

subgraph group_results["Settings and Results"]
  node_settings["Settings Resolver<br/>[settings.ts]"]
  node_normalize["Visual Normalizer<br/>[normalize.ts]"]
end

node_parent(("Parent Application"))

node_parent -->|"sends requests"| node_protocol
node_parent -->|"spawns child"| node_entry
node_entry -->|"handles request types"| node_protocol
node_entry -->|"dispatches scan/run"| node_runner
node_entry -->|"encodes response"| node_codec
node_entry -->|"writes JSON response"| node_parent
node_runner -->|"loads engine"| node_engine_adapter
node_engine_adapter -->|"loads package"| node_pine_engine
node_runner -->|"patches runtime"| node_compat
node_runner -->|"resolves overrides"| node_settings
node_settings -->|"creates indicator"| node_engine_adapter
node_runner -->|"creates data provider"| node_provider
node_provider -->|"converts candles"| node_normalize
node_provider -->|"aggregates bars"| node_resample
node_runner -->|"normalizes plots"| node_normalize
node_runner -->|"returns run result"| node_parent

click node_protocol "https://github.com/quantpad/pine-runner/blob/main/src/protocol.ts"
click node_entry "https://github.com/quantpad/pine-runner/blob/main/src/main.ts"
click node_codec "https://github.com/quantpad/pine-runner/blob/main/src/codec.ts"
click node_runner "https://github.com/quantpad/pine-runner/blob/main/src/run.ts"
click node_engine_adapter "https://github.com/quantpad/pine-runner/blob/main/src/engine.ts"
click node_compat "https://github.com/quantpad/pine-runner/blob/main/src/runtime-compat.ts"
click node_provider "https://github.com/quantpad/pine-runner/blob/main/src/provider.ts"
click node_resample "https://github.com/quantpad/pine-runner/blob/main/src/resample.ts"
click node_settings "https://github.com/quantpad/pine-runner/blob/main/src/settings.ts"
click node_normalize "https://github.com/quantpad/pine-runner/blob/main/src/normalize.ts"
click node_types "https://github.com/quantpad/pine-runner/blob/main/src/types.ts"

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_protocol,node_entry,node_codec,node_types toneBlue
class node_runner,node_engine_adapter,node_pine_engine,node_compat toneAmber
class node_provider,node_resample toneMint
class node_settings,node_normalize toneRose
class node_parent toneIndigo
```

## Components

### Process Boundary

- [JSON Protocol](https://github.com/quantpad/pine-runner/blob/main/src/protocol.ts): `src/protocol.ts`
- [Child Entry Point](https://github.com/quantpad/pine-runner/blob/main/src/main.ts): `src/main.ts`
- [Special Number Codec](https://github.com/quantpad/pine-runner/blob/main/src/codec.ts): `src/codec.ts`
- [Runner Data Types](https://github.com/quantpad/pine-runner/blob/main/src/types.ts): `src/types.ts`

### Pine Execution

- [Run Orchestrator](https://github.com/quantpad/pine-runner/blob/main/src/run.ts): `src/run.ts`
- [Engine Adapter](https://github.com/quantpad/pine-runner/blob/main/src/engine.ts): `src/engine.ts`
- **PineTS Engine**
- [Runtime Compatibility](https://github.com/quantpad/pine-runner/blob/main/src/runtime-compat.ts): `src/runtime-compat.ts`

### Market Data

- [Candle Provider](https://github.com/quantpad/pine-runner/blob/main/src/provider.ts): `src/provider.ts`
- [OHLCV Resampling](https://github.com/quantpad/pine-runner/blob/main/src/resample.ts): `src/resample.ts`

### Settings and Results

- [Settings Resolver](https://github.com/quantpad/pine-runner/blob/main/src/settings.ts): `src/settings.ts`
- [Visual Normalizer](https://github.com/quantpad/pine-runner/blob/main/src/normalize.ts): `src/normalize.ts`

### Other components

- **Parent Application**

## Connections

- Parent Application → JSON Protocol: sends requests (evidence: `README.md`)
- Parent Application → Child Entry Point: spawns child (evidence: `README.md`)
- Child Entry Point → JSON Protocol: handles request types (evidence: `src/main.ts`)
- Child Entry Point → Run Orchestrator: dispatches scan/run (evidence: `src/main.ts`)
- Child Entry Point → Special Number Codec: encodes response (evidence: `src/main.ts`)
- Child Entry Point → Parent Application: writes JSON response (evidence: `README.md`)
- Run Orchestrator → Engine Adapter: loads engine (evidence: `src/run.ts`)
- Engine Adapter → PineTS Engine: loads package (evidence: `src/engine.ts`)
- Run Orchestrator → Runtime Compatibility: patches runtime (evidence: `src/run.ts`)
- Run Orchestrator → Settings Resolver: resolves overrides (evidence: `src/run.ts`)
- Settings Resolver → Engine Adapter: creates indicator (evidence: `src/settings.ts`)
- Run Orchestrator → Candle Provider: creates data provider (evidence: `src/run.ts`)
- Candle Provider → Visual Normalizer: converts candles (evidence: `src/provider.ts`)
- Candle Provider → OHLCV Resampling: aggregates bars (evidence: `src/provider.ts`)
- Run Orchestrator → Visual Normalizer: normalizes plots (evidence: `src/run.ts`)
- Run Orchestrator → Parent Application: returns run result (evidence: `README.md`)
