# orhun/ratty architecture

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

- Interactive diagram: https://gitdiagram.com/orhun/ratty
- Repository: https://github.com/orhun/ratty

## Overview

Ratty is a GPU-rendered terminal emulator that runs terminal applications while adding 2D/3D presentation, a custom cursor, inline 3D objects, and Kitty image support. The principal workflow is terminal input and PTY output feeding a terminal screen, which is rendered and presented through GPU-backed terminal surfaces; camera and input controls change the view. Ratty also exposes a local control bridge and an RGP widget for client applications. Some links reflect README capabilities because unsampled implementation details are not available here.

Main entry points: [`src/runtime.rs`](https://github.com/orhun/ratty/blob/main/src/runtime.rs) (PTY runtime), [`src/inline.rs`](https://github.com/orhun/ratty/blob/main/src/inline.rs) (Inline object state), [`src/control.rs`](https://github.com/orhun/ratty/blob/main/src/control.rs) (Control bridge), [`src/keyboard.rs`](https://github.com/orhun/ratty/blob/main/src/keyboard.rs) (Keyboard handling)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_terminal["Terminal Runtime"]
  node_pty["PTY runtime<br/>[runtime.rs]"]
  node_screen["Terminal screen state<br/>[screen.rs]"]
  node_terminal_surface["Terminal surface<br/>[terminal.rs]"]
  node_rendering["GPU text renderer<br/>[rendering.rs]"]
  node_config["Configuration<br/>[config.rs]"]
end

subgraph group_input["Input and Control"]
  node_keyboard["Keyboard handling<br/>[keyboard.rs]"]
  node_mouse["Mouse and selection<br/>[mouse.rs]"]
  node_controls["Control bridge<br/>[control.rs]"]
  node_mcp["MCP server<br/>[ratty-mcp.rs]"]
end

subgraph group_graphics["Graphics and Objects"]
  node_camera["Camera modes<br/>[camera.rs]"]
  node_scene["Scene presentation<br/>[mod.rs]"]
  node_systems["Runtime systems<br/>[systems.rs]"]
  node_models["3D model loading<br/>[model.rs]"]
  node_inline["Inline object state<br/>[inline.rs]"]
  node_kitty["Kitty graphics<br/>[kitty.rs]"]
end

subgraph group_clients["Protocol Clients"]
  node_rgp["RGP protocol<br/>[rgp.rs]"]
  node_widget["Ratatui RGP widget<br/>[lib.rs]"]
end

node_user(("Terminal user"))
node_app(("Terminal application"))

node_user -->|"types input"| node_keyboard
node_user -->|"uses controls"| node_mouse
node_keyboard -->|"writes input"| node_pty
node_mouse -->|"writes input"| node_pty
node_app -->|"exchanges terminal data"| node_pty
node_pty -.->|"updates screen"| node_screen
node_screen -.->|"supplies terminal state"| node_terminal_surface
node_terminal_surface -->|"renders text"| node_rendering
node_config -.->|"configures bindings"| node_keyboard
node_user -->|"changes view"| node_camera
node_camera -.->|"selects presentation"| node_scene
node_scene -->|"presents graphics"| node_rendering
node_inline -->|"loads objects"| node_models
node_inline -->|"consumes protocol"| node_rgp
node_inline -->|"handles graphics"| node_kitty
node_systems -->|"synchronizes objects"| node_inline
node_systems -->|"updates presentation"| node_scene
node_mcp -->|"uses bridge"| node_controls
node_controls -->|"writes agent input"| node_pty
node_controls -->|"updates camera"| node_camera
node_widget -.->|"emits protocol"| node_rgp

click node_pty "https://github.com/orhun/ratty/blob/main/src/runtime.rs"
click node_screen "https://github.com/orhun/ratty/blob/main/src/screen.rs"
click node_terminal_surface "https://github.com/orhun/ratty/blob/main/src/terminal.rs"
click node_rendering "https://github.com/orhun/ratty/blob/main/src/rendering.rs"
click node_config "https://github.com/orhun/ratty/blob/main/src/config.rs"
click node_keyboard "https://github.com/orhun/ratty/blob/main/src/keyboard.rs"
click node_mouse "https://github.com/orhun/ratty/blob/main/src/mouse.rs"
click node_controls "https://github.com/orhun/ratty/blob/main/src/control.rs"
click node_mcp "https://github.com/orhun/ratty/blob/main/src/bin/ratty-mcp.rs"
click node_camera "https://github.com/orhun/ratty/blob/main/src/camera.rs"
click node_scene "https://github.com/orhun/ratty/blob/main/src/scene/mod.rs"
click node_systems "https://github.com/orhun/ratty/blob/main/src/systems.rs"
click node_models "https://github.com/orhun/ratty/blob/main/src/model.rs"
click node_inline "https://github.com/orhun/ratty/blob/main/src/inline.rs"
click node_kitty "https://github.com/orhun/ratty/blob/main/src/kitty.rs"
click node_rgp "https://github.com/orhun/ratty/blob/main/src/rgp.rs"
click node_widget "https://github.com/orhun/ratty/blob/main/widget/src/lib.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_pty,node_screen,node_terminal_surface,node_rendering,node_config,node_user toneBlue
class node_keyboard,node_mouse,node_controls,node_mcp toneAmber
class node_camera,node_scene,node_systems,node_models,node_inline,node_kitty toneMint
class node_rgp,node_widget toneRose
class node_app toneIndigo
```

## Components

### Terminal Runtime

- [PTY runtime](https://github.com/orhun/ratty/blob/main/src/runtime.rs): `src/runtime.rs`
- [Terminal screen state](https://github.com/orhun/ratty/blob/main/src/screen.rs): `src/screen.rs`
- [Terminal surface](https://github.com/orhun/ratty/blob/main/src/terminal.rs): `src/terminal.rs`
- [GPU text renderer](https://github.com/orhun/ratty/blob/main/src/rendering.rs): `src/rendering.rs`
- [Configuration](https://github.com/orhun/ratty/blob/main/src/config.rs): `src/config.rs`

### Input and Control

- [Keyboard handling](https://github.com/orhun/ratty/blob/main/src/keyboard.rs): `src/keyboard.rs`
- [Mouse and selection](https://github.com/orhun/ratty/blob/main/src/mouse.rs): `src/mouse.rs`
- [Control bridge](https://github.com/orhun/ratty/blob/main/src/control.rs): `src/control.rs`
- [MCP server](https://github.com/orhun/ratty/blob/main/src/bin/ratty-mcp.rs): `src/bin/ratty-mcp.rs`

### Graphics and Objects

- [Camera modes](https://github.com/orhun/ratty/blob/main/src/camera.rs): `src/camera.rs`
- [Scene presentation](https://github.com/orhun/ratty/blob/main/src/scene/mod.rs): `src/scene/mod.rs`
- [Runtime systems](https://github.com/orhun/ratty/blob/main/src/systems.rs): `src/systems.rs`
- [3D model loading](https://github.com/orhun/ratty/blob/main/src/model.rs): `src/model.rs`
- [Inline object state](https://github.com/orhun/ratty/blob/main/src/inline.rs): `src/inline.rs`
- [Kitty graphics](https://github.com/orhun/ratty/blob/main/src/kitty.rs): `src/kitty.rs`

### Protocol Clients

- [RGP protocol](https://github.com/orhun/ratty/blob/main/src/rgp.rs): `src/rgp.rs`
- [Ratatui RGP widget](https://github.com/orhun/ratty/blob/main/widget/src/lib.rs): `widget/src/lib.rs`

### Other components

- **Terminal user**
- **Terminal application**

## Connections

- Terminal user → Keyboard handling: types input (evidence: `README.md`)
- Terminal user → Mouse and selection: uses controls (evidence: `README.md`)
- Keyboard handling → PTY runtime: writes input (evidence: `src/keyboard.rs`)
- Mouse and selection → PTY runtime: writes input (evidence: `src/mouse.rs`)
- Terminal application → PTY runtime: exchanges terminal data (evidence: `README.md`)
- PTY runtime → Terminal screen state: updates screen (evidence: `src/runtime.rs`)
- Terminal screen state → Terminal surface: supplies terminal state (evidence: `src/terminal.rs`)
- Terminal surface → GPU text renderer: renders text (evidence: `README.md`)
- Configuration → Keyboard handling: configures bindings (evidence: `src/keyboard.rs`)
- Terminal user → Camera modes: changes view (evidence: `README.md`)
- Camera modes → Scene presentation: selects presentation (evidence: `src/camera.rs`)
- Scene presentation → GPU text renderer: presents graphics (evidence: `README.md`)
- Inline object state → 3D model loading: loads objects (evidence: `src/inline.rs`)
- Inline object state → RGP protocol: consumes protocol (evidence: `src/inline.rs`)
- Inline object state → Kitty graphics: handles graphics (evidence: `src/inline.rs`)
- Runtime systems → Inline object state: synchronizes objects (evidence: `src/systems.rs`)
- Runtime systems → Scene presentation: updates presentation (evidence: `src/systems.rs`)
- MCP server → Control bridge: uses bridge (evidence: `src/control.rs`)
- Control bridge → PTY runtime: writes agent input (evidence: `src/control.rs`)
- Control bridge → Camera modes: updates camera (evidence: `src/control.rs`)
- Ratatui RGP widget → RGP protocol: emits protocol (evidence: `README.md`)
