# zorab0310/titanrt architecture

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

- Interactive diagram: https://gitdiagram.com/zorab0310/titanrt
- Repository: https://github.com/zorab0310/titanrt

## Overview

TitanRt is a typed reactive runtime: an application supplies a model, while a control thread drives its lifecycle and the model owns optional worker streams. The main path is control inputs → runtime/controller → model; stream workers exchange typed actions and events with the model and can publish state and health. Separate capabilities include NATS bridging, HTTP/gRPC/WebSocket connectors, bounded channel transports, and core-affinity utilities. Edges reflect README statements or the supplied source index; several connector implementations were not sampled, so their detailed call paths are not inferred.

Main entry points: [`src/runtime.rs`](https://github.com/zorab0310/titanrt/blob/main/src/runtime.rs) (Runtime engine), [`src/control/controller.rs`](https://github.com/zorab0310/titanrt/blob/main/src/control/controller.rs) (Lifecycle controller), [`src/model.rs`](https://github.com/zorab0310/titanrt/blob/main/src/model.rs) (User model), [`src/connector/spawner.rs`](https://github.com/zorab0310/titanrt/blob/main/src/connector/spawner.rs) (Stream spawner)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime lifecycle"]
  node_control_inputs["Control inputs<br/>[inputs.rs]"]
  node_runtime_engine["Runtime engine<br/>[runtime.rs]"]
  node_controller["Lifecycle controller<br/>[controller.rs]"]
  node_model["User model<br/>[model.rs]"]
  node_runtime_config["Runtime config<br/>[config.rs]"]
  node_control_policy["Control policy<br/>[policy.rs]"]
end

subgraph group_connectors["Streams and connectors"]
  node_connector_api["Connector API<br/>[base.rs]"]
  node_stream_spawner["Stream spawner<br/>[spawner.rs]"]
  node_stream_handle["Stream handle<br/>[stream.rs]"]
  node_connector_hook["Event hook<br/>[hook.rs]"]
  node_http_connector["HTTP streams"]
  node_grpc_connector["gRPC streams"]
  node_websocket_connector["WebSocket streams<br/>[runner.rs]"]
  node_shared_stream_features["Shared stream features"]
end

subgraph group_transport["I/O and bridge"]
  node_transport_traits["Channel traits<br/>[base.rs]"]
  node_ringbuffer["Ring buffer<br/>[ringbuffer.rs]"]
  node_mpmc["MPMC channel<br/>[mpmc.rs]"]
  node_nats_bridge["NATS bridge<br/>[nats.rs]"]
end

subgraph group_support["State and scheduling"]
  node_state_health["State and health<br/>[state.rs]"]
  node_cancel_token["Cancellation<br/>[cancel_token.rs]"]
  node_core_pinning["Core selection<br/>[core_pinner.rs]"]
end

node_application(("Application"))
node_nats_service(("NATS service"))

node_application -->|"configures and starts"| node_runtime_engine
node_application -->|"sends commands"| node_control_inputs
node_runtime_engine -->|"reads settings"| node_runtime_config
node_runtime_engine -->|"drives control"| node_controller
node_runtime_engine -->|"initializes and executes"| node_model
node_controller -->|"handles"| node_control_inputs
node_controller -->|"dispatches through"| node_control_policy
node_controller -->|"controls lifecycle"| node_model
node_runtime_engine -->|"creates control channel"| node_ringbuffer
node_controller -->|"receives inputs"| node_ringbuffer
node_transport_traits -->|"implemented by"| node_ringbuffer
node_transport_traits -->|"implemented by"| node_mpmc
node_model -->|"owns connectors"| node_connector_api
node_connector_api -->|"spawns workers"| node_stream_spawner
node_stream_spawner -->|"creates handles"| node_stream_handle
node_model -->|"drains events and sends actions"| node_stream_handle
node_websocket_connector -->|"selects emitted events"| node_connector_hook
node_websocket_connector -->|"uses actions and events"| node_shared_stream_features
node_grpc_connector -->|"uses shared rate limits and events"| node_shared_stream_features
node_stream_spawner -->|"provides stream state and health"| node_state_health
node_model -->|"receives cancellation token"| node_cancel_token
node_runtime_engine -->|"optionally pins thread"| node_core_pinning
node_stream_spawner -->|"selects worker cores"| node_core_pinning
node_nats_service -->|"publishes commands and outputs"| node_nats_bridge
node_nats_bridge -->|"runs runtime"| node_runtime_engine
node_nats_bridge -->|"forwards decoded inputs"| node_control_inputs
node_nats_bridge -->|"receives outputs"| node_mpmc

click node_control_inputs "https://github.com/zorab0310/titanrt/blob/main/src/control/inputs.rs"
click node_runtime_engine "https://github.com/zorab0310/titanrt/blob/main/src/runtime.rs"
click node_controller "https://github.com/zorab0310/titanrt/blob/main/src/control/controller.rs"
click node_model "https://github.com/zorab0310/titanrt/blob/main/src/model.rs"
click node_runtime_config "https://github.com/zorab0310/titanrt/blob/main/src/config.rs"
click node_control_policy "https://github.com/zorab0310/titanrt/blob/main/src/control/policy.rs"
click node_connector_api "https://github.com/zorab0310/titanrt/blob/main/src/connector/base.rs"
click node_stream_spawner "https://github.com/zorab0310/titanrt/blob/main/src/connector/spawner.rs"
click node_stream_handle "https://github.com/zorab0310/titanrt/blob/main/src/connector/stream.rs"
click node_connector_hook "https://github.com/zorab0310/titanrt/blob/main/src/connector/hook.rs"
click node_http_connector "https://github.com/zorab0310/titanrt/tree/main/src/connector/features/reqwest/stream"
click node_grpc_connector "https://github.com/zorab0310/titanrt/tree/main/src/connector/features/tonic"
click node_websocket_connector "https://github.com/zorab0310/titanrt/blob/main/src/connector/features/websocket/runner.rs"
click node_shared_stream_features "https://github.com/zorab0310/titanrt/tree/main/src/connector/features/shared"
click node_transport_traits "https://github.com/zorab0310/titanrt/blob/main/src/io/base.rs"
click node_ringbuffer "https://github.com/zorab0310/titanrt/blob/main/src/io/ringbuffer.rs"
click node_mpmc "https://github.com/zorab0310/titanrt/blob/main/src/io/mpmc.rs"
click node_nats_bridge "https://github.com/zorab0310/titanrt/blob/main/src/bridges/nats.rs"
click node_state_health "https://github.com/zorab0310/titanrt/blob/main/src/utils/state.rs"
click node_cancel_token "https://github.com/zorab0310/titanrt/blob/main/src/utils/cancel_token.rs"
click node_core_pinning "https://github.com/zorab0310/titanrt/blob/main/src/utils/core_pinner.rs"

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_control_inputs,node_runtime_engine,node_controller,node_model,node_runtime_config,node_control_policy toneBlue
class node_connector_api,node_stream_spawner,node_stream_handle,node_connector_hook,node_http_connector,node_grpc_connector,node_websocket_connector,node_shared_stream_features toneAmber
class node_transport_traits,node_ringbuffer,node_mpmc,node_nats_bridge toneMint
class node_state_health,node_cancel_token,node_core_pinning toneRose
class node_application,node_nats_service toneIndigo
```

## Components

### Runtime lifecycle

- [Control inputs](https://github.com/zorab0310/titanrt/blob/main/src/control/inputs.rs): `src/control/inputs.rs`
- [Runtime engine](https://github.com/zorab0310/titanrt/blob/main/src/runtime.rs): `src/runtime.rs`
- [Lifecycle controller](https://github.com/zorab0310/titanrt/blob/main/src/control/controller.rs): `src/control/controller.rs`
- [User model](https://github.com/zorab0310/titanrt/blob/main/src/model.rs): `src/model.rs`
- [Runtime config](https://github.com/zorab0310/titanrt/blob/main/src/config.rs): `src/config.rs`
- [Control policy](https://github.com/zorab0310/titanrt/blob/main/src/control/policy.rs): `src/control/policy.rs`

### Streams and connectors

- [Connector API](https://github.com/zorab0310/titanrt/blob/main/src/connector/base.rs): `src/connector/base.rs`
- [Stream spawner](https://github.com/zorab0310/titanrt/blob/main/src/connector/spawner.rs): `src/connector/spawner.rs`
- [Stream handle](https://github.com/zorab0310/titanrt/blob/main/src/connector/stream.rs): `src/connector/stream.rs`
- [Event hook](https://github.com/zorab0310/titanrt/blob/main/src/connector/hook.rs): `src/connector/hook.rs`
- [HTTP streams](https://github.com/zorab0310/titanrt/tree/main/src/connector/features/reqwest/stream): `src/connector/features/reqwest/stream`
- [gRPC streams](https://github.com/zorab0310/titanrt/tree/main/src/connector/features/tonic): `src/connector/features/tonic`
- [WebSocket streams](https://github.com/zorab0310/titanrt/blob/main/src/connector/features/websocket/runner.rs): `src/connector/features/websocket/runner.rs`
- [Shared stream features](https://github.com/zorab0310/titanrt/tree/main/src/connector/features/shared): `src/connector/features/shared`

### I/O and bridge

- [Channel traits](https://github.com/zorab0310/titanrt/blob/main/src/io/base.rs): `src/io/base.rs`
- [Ring buffer](https://github.com/zorab0310/titanrt/blob/main/src/io/ringbuffer.rs): `src/io/ringbuffer.rs`
- [MPMC channel](https://github.com/zorab0310/titanrt/blob/main/src/io/mpmc.rs): `src/io/mpmc.rs`
- [NATS bridge](https://github.com/zorab0310/titanrt/blob/main/src/bridges/nats.rs): `src/bridges/nats.rs`

### State and scheduling

- [State and health](https://github.com/zorab0310/titanrt/blob/main/src/utils/state.rs): `src/utils/state.rs`
- [Cancellation](https://github.com/zorab0310/titanrt/blob/main/src/utils/cancel_token.rs): `src/utils/cancel_token.rs`
- [Core selection](https://github.com/zorab0310/titanrt/blob/main/src/utils/core_pinner.rs): `src/utils/core_pinner.rs`

### Other components

- **Application**
- **NATS service**

## Connections

- Application → Runtime engine: configures and starts
- Application → Control inputs: sends commands
- Runtime engine → Runtime config: reads settings (evidence: `src/runtime.rs`)
- Runtime engine → Lifecycle controller: drives control (evidence: `src/runtime.rs`)
- Runtime engine → User model: initializes and executes (evidence: `src/runtime.rs`)
- Lifecycle controller → Control inputs: handles (evidence: `src/control/controller.rs`)
- Lifecycle controller → Control policy: dispatches through (evidence: `src/control/controller.rs`)
- Lifecycle controller → User model: controls lifecycle (evidence: `src/control/controller.rs`)
- Runtime engine → Ring buffer: creates control channel (evidence: `src/runtime.rs`)
- Lifecycle controller → Ring buffer: receives inputs (evidence: `src/control/controller.rs`)
- Channel traits → Ring buffer: implemented by (evidence: `src/io/ringbuffer.rs`)
- Channel traits → MPMC channel: implemented by (evidence: `src/io/mpmc.rs`)
- User model → Connector API: owns connectors
- Connector API → Stream spawner: spawns workers
- Stream spawner → Stream handle: creates handles (evidence: `src/connector/spawner.rs`)
- User model → Stream handle: drains events and sends actions
- WebSocket streams → Event hook: selects emitted events (evidence: `src/connector/features/websocket/runner.rs`)
- WebSocket streams → Shared stream features: uses actions and events (evidence: `src/connector/features/websocket/runner.rs`)
- gRPC streams → Shared stream features: uses shared rate limits and events (evidence: `src/connector/features/tonic/streaming/handle_client.rs`)
- Stream spawner → State and health: provides stream state and health
- User model → Cancellation: receives cancellation token (evidence: `src/model.rs`)
- Runtime engine → Core selection: optionally pins thread (evidence: `src/runtime.rs`)
- Stream spawner → Core selection: selects worker cores
- NATS service → NATS bridge: publishes commands and outputs (evidence: `src/bridges/nats.rs`)
- NATS bridge → Runtime engine: runs runtime (evidence: `src/bridges/nats.rs`)
- NATS bridge → Control inputs: forwards decoded inputs (evidence: `src/bridges/nats.rs`)
- NATS bridge → MPMC channel: receives outputs (evidence: `src/bridges/nats.rs`)
