# amisha-ranjan34/local-llm-instrumentation-tracing-and-replay-platform architecture

> Architecture diagram of the GitHub repository amisha-ranjan34/local-llm-instrumentation-tracing-and-replay-platform, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/amisha-ranjan34/local-llm-instrumentation-tracing-and-replay-platform
- Repository: https://github.com/amisha-ranjan34/local-llm-instrumentation-tracing-and-replay-platform

## Overview

LLM Scope instruments transformer execution in a separate process, transports layer and attention packets through shared memory, and presents live diagnostics in a keyboard-driven terminal UI. The main workflow runs from model forward hooks through packet capture and transport to TUI ingestion and five diagnostic panels; demo and trace loading are alternate inputs. The graph preserves documented capabilities, but several implementation links rely on README statements because the relevant source excerpts are incomplete.

Main entry points: [`src/tui/tui_state.hpp`](https://github.com/amisha-ranjan34/local-llm-instrumentation-tracing-and-replay-platform/blob/main/src/tui/tui_state.hpp) (Viewer State), [`src/tui/tui_engine.cpp`](https://github.com/amisha-ranjan34/local-llm-instrumentation-tracing-and-replay-platform/blob/main/src/tui/tui_engine.cpp) (TUI Engine), [`src/tui/main_tui.cpp`](https://github.com/amisha-ranjan34/local-llm-instrumentation-tracing-and-replay-platform/blob/main/src/tui/main_tui.cpp) (Viewer Entry), [`src/instrumentation/main_instrument.cpp`](https://github.com/amisha-ranjan34/local-llm-instrumentation-tracing-and-replay-platform/blob/main/src/instrumentation/main_instrument.cpp) (Capture Entry)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_capture["Instrumentation"]
  node_instrument_main["Capture Entry"]
  node_hook_registry["Hook Registry<br/>[hook_registry.cpp]"]
  node_topology_parser["Topology Parser"]
  node_anomaly_detector["Anomaly Detector"]
end

subgraph group_transport["Packet Transport"]
  node_packet_schema["Packet Schemas<br/>[packets.hpp]"]
  node_ring_buffer["SPSC Ring Buffers<br/>[ring_buffer.hpp]"]
  node_shared_memory[("Shared Memory<br/>[shared_memory.hpp]")]
  node_topology_data["Model Topology<br/>[topology.hpp]"]
end

subgraph group_viewer["TUI Viewer"]
  node_tui_main["Viewer Entry<br/>[main_tui.cpp]"]
  node_tui_state["Viewer State<br/>[tui_state.hpp]"]
  node_tui_engine["TUI Engine<br/>[tui_engine.cpp]"]
end

subgraph group_diagnostics["TUI Diagnostics"]
  node_topology_panel["Topology Panel<br/>[panel_topology.cpp]"]
  node_stream_panel["Packet Stream<br/>[panel_stream.cpp]"]
  node_attention_panel["Attention Heatmap"]
  node_metrics_panel["Layer Metrics<br/>[panel_metrics.cpp]"]
  node_anomaly_panel["Anomaly Ledger<br/>[panel_anomaly.cpp]"]
end

node_model(("Transformer Model"))
node_trace_file["Trace File"]

node_model -->|"runs hooks"| node_hook_registry
node_instrument_main -->|"starts capture"| node_hook_registry
node_hook_registry -->|"checks packets"| node_anomaly_detector
node_hook_registry -->|"emits packets"| node_packet_schema
node_hook_registry -->|"writes packets"| node_ring_buffer
node_instrument_main -->|"creates segments"| node_shared_memory
node_instrument_main -->|"places buffers"| node_ring_buffer
node_topology_parser -->|"builds tree"| node_topology_data
node_instrument_main -->|"publishes topology"| node_topology_data
node_tui_main -->|"attaches to"| node_shared_memory
node_tui_main -->|"reads packets"| node_ring_buffer
node_tui_main -->|"loads topology"| node_topology_data
node_ring_buffer -->|"drains packets"| node_tui_state
node_tui_main -->|"sets up"| node_tui_state
node_tui_main -->|"runs viewer"| node_tui_engine
node_tui_engine -->|"creates panel"| node_topology_panel
node_tui_engine -->|"creates panel"| node_stream_panel
node_tui_engine -->|"creates panel"| node_attention_panel
node_tui_engine -->|"creates panel"| node_metrics_panel
node_tui_engine -->|"creates panel"| node_anomaly_panel
node_tui_state -->|"supplies state"| node_topology_panel
node_tui_state -->|"supplies state"| node_stream_panel
node_tui_state -->|"supplies state"| node_attention_panel
node_tui_state -->|"supplies state"| node_metrics_panel
node_tui_state -->|"supplies state"| node_anomaly_panel
node_instrument_main -.->|"writes trace"| node_trace_file
node_trace_file -->|"loads replay"| node_tui_main

click node_instrument_main "https://github.com/amisha-ranjan34/local-llm-instrumentation-tracing-and-replay-platform/blob/main/src/instrumentation/main_instrument.cpp"
click node_hook_registry "https://github.com/amisha-ranjan34/local-llm-instrumentation-tracing-and-replay-platform/blob/main/src/instrumentation/hook_registry.cpp"
click node_topology_parser "https://github.com/amisha-ranjan34/local-llm-instrumentation-tracing-and-replay-platform/blob/main/src/instrumentation/topology_parser.cpp"
click node_anomaly_detector "https://github.com/amisha-ranjan34/local-llm-instrumentation-tracing-and-replay-platform/blob/main/include/llm_scope/anomaly_detector.hpp"
click node_packet_schema "https://github.com/amisha-ranjan34/local-llm-instrumentation-tracing-and-replay-platform/blob/main/include/llm_scope/packets.hpp"
click node_ring_buffer "https://github.com/amisha-ranjan34/local-llm-instrumentation-tracing-and-replay-platform/blob/main/include/llm_scope/ring_buffer.hpp"
click node_shared_memory "https://github.com/amisha-ranjan34/local-llm-instrumentation-tracing-and-replay-platform/blob/main/include/llm_scope/shared_memory.hpp"
click node_topology_data "https://github.com/amisha-ranjan34/local-llm-instrumentation-tracing-and-replay-platform/blob/main/include/llm_scope/topology.hpp"
click node_tui_main "https://github.com/amisha-ranjan34/local-llm-instrumentation-tracing-and-replay-platform/blob/main/src/tui/main_tui.cpp"
click node_tui_state "https://github.com/amisha-ranjan34/local-llm-instrumentation-tracing-and-replay-platform/blob/main/src/tui/tui_state.hpp"
click node_tui_engine "https://github.com/amisha-ranjan34/local-llm-instrumentation-tracing-and-replay-platform/blob/main/src/tui/tui_engine.cpp"
click node_topology_panel "https://github.com/amisha-ranjan34/local-llm-instrumentation-tracing-and-replay-platform/blob/main/src/tui/panels/panel_topology.cpp"
click node_stream_panel "https://github.com/amisha-ranjan34/local-llm-instrumentation-tracing-and-replay-platform/blob/main/src/tui/panels/panel_stream.cpp"
click node_attention_panel "https://github.com/amisha-ranjan34/local-llm-instrumentation-tracing-and-replay-platform/blob/main/src/tui/panels/panel_attention.cpp"
click node_metrics_panel "https://github.com/amisha-ranjan34/local-llm-instrumentation-tracing-and-replay-platform/blob/main/src/tui/panels/panel_metrics.cpp"
click node_anomaly_panel "https://github.com/amisha-ranjan34/local-llm-instrumentation-tracing-and-replay-platform/blob/main/src/tui/panels/panel_anomaly.cpp"

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_instrument_main,node_hook_registry,node_topology_parser,node_anomaly_detector toneBlue
class node_packet_schema,node_ring_buffer,node_shared_memory,node_topology_data toneAmber
class node_tui_main,node_tui_state,node_tui_engine toneMint
class node_topology_panel,node_stream_panel,node_attention_panel,node_metrics_panel,node_anomaly_panel toneRose
class node_model,node_trace_file toneIndigo
```

## Components

### Instrumentation

- [Capture Entry](https://github.com/amisha-ranjan34/local-llm-instrumentation-tracing-and-replay-platform/blob/main/src/instrumentation/main_instrument.cpp): `src/instrumentation/main_instrument.cpp`
- [Hook Registry](https://github.com/amisha-ranjan34/local-llm-instrumentation-tracing-and-replay-platform/blob/main/src/instrumentation/hook_registry.cpp): `src/instrumentation/hook_registry.cpp`
- [Topology Parser](https://github.com/amisha-ranjan34/local-llm-instrumentation-tracing-and-replay-platform/blob/main/src/instrumentation/topology_parser.cpp): `src/instrumentation/topology_parser.cpp`
- [Anomaly Detector](https://github.com/amisha-ranjan34/local-llm-instrumentation-tracing-and-replay-platform/blob/main/include/llm_scope/anomaly_detector.hpp): `include/llm_scope/anomaly_detector.hpp`

### Packet Transport

- [Packet Schemas](https://github.com/amisha-ranjan34/local-llm-instrumentation-tracing-and-replay-platform/blob/main/include/llm_scope/packets.hpp): `include/llm_scope/packets.hpp`
- [SPSC Ring Buffers](https://github.com/amisha-ranjan34/local-llm-instrumentation-tracing-and-replay-platform/blob/main/include/llm_scope/ring_buffer.hpp): `include/llm_scope/ring_buffer.hpp`
- [Shared Memory](https://github.com/amisha-ranjan34/local-llm-instrumentation-tracing-and-replay-platform/blob/main/include/llm_scope/shared_memory.hpp): `include/llm_scope/shared_memory.hpp`
- [Model Topology](https://github.com/amisha-ranjan34/local-llm-instrumentation-tracing-and-replay-platform/blob/main/include/llm_scope/topology.hpp): `include/llm_scope/topology.hpp`

### TUI Viewer

- [Viewer Entry](https://github.com/amisha-ranjan34/local-llm-instrumentation-tracing-and-replay-platform/blob/main/src/tui/main_tui.cpp): `src/tui/main_tui.cpp`
- [Viewer State](https://github.com/amisha-ranjan34/local-llm-instrumentation-tracing-and-replay-platform/blob/main/src/tui/tui_state.hpp): `src/tui/tui_state.hpp`
- [TUI Engine](https://github.com/amisha-ranjan34/local-llm-instrumentation-tracing-and-replay-platform/blob/main/src/tui/tui_engine.cpp): `src/tui/tui_engine.cpp`

### TUI Diagnostics

- [Topology Panel](https://github.com/amisha-ranjan34/local-llm-instrumentation-tracing-and-replay-platform/blob/main/src/tui/panels/panel_topology.cpp): `src/tui/panels/panel_topology.cpp`
- [Packet Stream](https://github.com/amisha-ranjan34/local-llm-instrumentation-tracing-and-replay-platform/blob/main/src/tui/panels/panel_stream.cpp): `src/tui/panels/panel_stream.cpp`
- [Attention Heatmap](https://github.com/amisha-ranjan34/local-llm-instrumentation-tracing-and-replay-platform/blob/main/src/tui/panels/panel_attention.cpp): `src/tui/panels/panel_attention.cpp`
- [Layer Metrics](https://github.com/amisha-ranjan34/local-llm-instrumentation-tracing-and-replay-platform/blob/main/src/tui/panels/panel_metrics.cpp): `src/tui/panels/panel_metrics.cpp`
- [Anomaly Ledger](https://github.com/amisha-ranjan34/local-llm-instrumentation-tracing-and-replay-platform/blob/main/src/tui/panels/panel_anomaly.cpp): `src/tui/panels/panel_anomaly.cpp`

### Other components

- **Transformer Model**
- **Trace File**

## Connections

- Transformer Model → Hook Registry: runs hooks (evidence: `README.md`)
- Capture Entry → Hook Registry: starts capture (evidence: `src/instrumentation/main_instrument.cpp`)
- Hook Registry → Anomaly Detector: checks packets
- Hook Registry → Packet Schemas: emits packets
- Hook Registry → SPSC Ring Buffers: writes packets
- Capture Entry → Shared Memory: creates segments (evidence: `src/instrumentation/main_instrument.cpp`)
- Capture Entry → SPSC Ring Buffers: places buffers (evidence: `src/instrumentation/main_instrument.cpp`)
- Topology Parser → Model Topology: builds tree (evidence: `include/llm_scope/topology.hpp`)
- Capture Entry → Model Topology: publishes topology (evidence: `README.md`)
- Viewer Entry → Shared Memory: attaches to (evidence: `src/tui/main_tui.cpp`)
- Viewer Entry → SPSC Ring Buffers: reads packets (evidence: `src/tui/main_tui.cpp`)
- Viewer Entry → Model Topology: loads topology (evidence: `src/tui/main_tui.cpp`)
- SPSC Ring Buffers → Viewer State: drains packets (evidence: `src/tui/tui_state.hpp`)
- Viewer Entry → Viewer State: sets up (evidence: `src/tui/main_tui.cpp`)
- Viewer Entry → TUI Engine: runs viewer (evidence: `src/tui/main_tui.cpp`)
- TUI Engine → Topology Panel: creates panel (evidence: `src/tui/tui_engine.cpp`)
- TUI Engine → Packet Stream: creates panel (evidence: `src/tui/tui_engine.cpp`)
- TUI Engine → Attention Heatmap: creates panel (evidence: `src/tui/tui_engine.cpp`)
- TUI Engine → Layer Metrics: creates panel (evidence: `src/tui/tui_engine.cpp`)
- TUI Engine → Anomaly Ledger: creates panel (evidence: `src/tui/tui_engine.cpp`)
- Viewer State → Topology Panel: supplies state
- Viewer State → Packet Stream: supplies state
- Viewer State → Attention Heatmap: supplies state
- Viewer State → Layer Metrics: supplies state
- Viewer State → Anomaly Ledger: supplies state
- Capture Entry → Trace File: writes trace (evidence: `README.md`)
- Trace File → Viewer Entry: loads replay (evidence: `src/tui/main_tui.cpp`)
