# Architecture

Source: https://libtmux.org/en/rs/latest/topics/architecture/

> Locate operations, distinguish snapshots from live commands, and find their implementation.

A server handle selects a tmux server. Object IDs select sessions, windows, and
panes within it. For the object hierarchy and stable IDs, start with [Server,
session, window, pane](https://libtmux.org/en/rs/latest/concepts/server-session-window-pane/).

<a id="where-behavior-lives-on-the-object-or-through-the-server"></a>

## Calling operations

Session, window, and pane handles carry their ID and server context. Call an
operation on the object you want to change. The examples below send input and
kill that pane.

```rust
pane.send_line("echo hi").await?;
pane.kill().await?; // consumes the handle: see Context managers
```

<a id="a-generated-data-table-under-a-hand-written-surface"></a>

## Reading tmux fields

Object IDs become tmux targets (`-t`). Format variables (`#{...}`) provide
the state returned by tmux.

[`crates/libtmux/src/formats.rs`](<https://github.com/libtmux/libtmux-rs/blob/84de9258a07d10bdd5f6da01b016a9ae06fe1210/crates/libtmux/src/formats.rs>) defines the format catalog. Each entry records
the tmux name, required context, first supported release, decoder, and handling
of empty values. [`crates/libtmux/src/snapshot.rs`](<https://github.com/libtmux/libtmux-rs/blob/84de9258a07d10bdd5f6da01b016a9ae06fe1210/crates/libtmux/src/snapshot.rs>) uses that catalog to decode
captured fields.

Handle accessors such as [`Pane.current_command`](<https://libtmux.org/en/rs/latest/reference/pane-pane-current_command/>) return `Option<T>` when a
value can be absent. Typed field queries return [`Availability`](<https://libtmux.org/en/rs/latest/reference/snapshot-availability/>), which also
distinguishes an unsupported field from an absent value. See
[Format-token fields](https://libtmux.org/en/rs/latest/topics/format-tokens/) for field availability.

<a id="module-layout-by-port"></a>

## Source layout

[`Server`](<https://libtmux.org/en/rs/latest/reference/server-server/>), [`Session`](<https://libtmux.org/en/rs/latest/reference/session-session/>), [`Window`](<https://libtmux.org/en/rs/latest/reference/window-window/>), and [`Pane`](<https://libtmux.org/en/rs/latest/reference/pane-pane/>) are defined in
[`crates/libtmux/src/server.rs`](<https://github.com/libtmux/libtmux-rs/blob/84de9258a07d10bdd5f6da01b016a9ae06fe1210/crates/libtmux/src/server.rs>), [`crates/libtmux/src/session.rs`](<https://github.com/libtmux/libtmux-rs/blob/84de9258a07d10bdd5f6da01b016a9ae06fe1210/crates/libtmux/src/session.rs>),
[`crates/libtmux/src/window.rs`](<https://github.com/libtmux/libtmux-rs/blob/84de9258a07d10bdd5f6da01b016a9ae06fe1210/crates/libtmux/src/window.rs>), and [`crates/libtmux/src/pane.rs`](<https://github.com/libtmux/libtmux-rs/blob/84de9258a07d10bdd5f6da01b016a9ae06fe1210/crates/libtmux/src/pane.rs>).
Their additional operations live in [`crates/libtmux/src/server/`](<https://github.com/libtmux/libtmux-rs/tree/84de9258a07d10bdd5f6da01b016a9ae06fe1210/crates/libtmux/src/server>),
[`crates/libtmux/src/session/`](<https://github.com/libtmux/libtmux-rs/tree/84de9258a07d10bdd5f6da01b016a9ae06fe1210/crates/libtmux/src/session>), [`crates/libtmux/src/window/`](<https://github.com/libtmux/libtmux-rs/tree/84de9258a07d10bdd5f6da01b016a9ae06fe1210/crates/libtmux/src/window>), and
[`crates/libtmux/src/pane/`](<https://github.com/libtmux/libtmux-rs/tree/84de9258a07d10bdd5f6da01b016a9ae06fe1210/crates/libtmux/src/pane>).

The [options and hooks](https://libtmux.org/en/rs/latest/topics/options-and-hooks/) methods are grouped in
[`crates/libtmux/src/server/settings.rs`](<https://github.com/libtmux/libtmux-rs/blob/84de9258a07d10bdd5f6da01b016a9ae06fe1210/crates/libtmux/src/server/settings.rs>),
[`crates/libtmux/src/session/settings.rs`](<https://github.com/libtmux/libtmux-rs/blob/84de9258a07d10bdd5f6da01b016a9ae06fe1210/crates/libtmux/src/session/settings.rs>),
[`crates/libtmux/src/window/settings.rs`](<https://github.com/libtmux/libtmux-rs/blob/84de9258a07d10bdd5f6da01b016a9ae06fe1210/crates/libtmux/src/window/settings.rs>), and
[`crates/libtmux/src/pane/settings.rs`](<https://github.com/libtmux/libtmux-rs/blob/84de9258a07d10bdd5f6da01b016a9ae06fe1210/crates/libtmux/src/pane/settings.rs>).
[`crates/libtmux/src/hooks.rs`](<https://github.com/libtmux/libtmux-rs/blob/84de9258a07d10bdd5f6da01b016a9ae06fe1210/crates/libtmux/src/hooks.rs>) defines [`IndexedHooks`](<https://libtmux.org/en/rs/latest/reference/hooks-indexedhooks/>) and [`SparseValues`](<https://libtmux.org/en/rs/latest/reference/hooks-sparsevalues/>);
[`crates/libtmux/src/options.rs`](<https://github.com/libtmux/libtmux-rs/blob/84de9258a07d10bdd5f6da01b016a9ae06fe1210/crates/libtmux/src/options.rs>) defines option schemas and values.
Workspaces and the MCP server are separate crates under
[`crates/tmux-workspace/`](<https://github.com/libtmux/libtmux-rs/tree/84de9258a07d10bdd5f6da01b016a9ae06fe1210/crates/tmux-workspace>) and [`crates/tmux-mcp/`](<https://github.com/libtmux/libtmux-rs/tree/84de9258a07d10bdd5f6da01b016a9ae06fe1210/crates/tmux-mcp>).
