# Architecture

Source: https://libtmux.org/en/swift/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/swift/latest/concepts/server-session-window-pane/).

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

## Calling operations

Swift's [`Session`](<https://libtmux.org/en/swift/latest/reference/session/>), [`Window`](<https://libtmux.org/en/swift/latest/reference/window/>), and [`Pane`](<https://libtmux.org/en/swift/latest/reference/pane/>) are [`Sendable`](<https://developer.apple.com/documentation/swift/sendable>) value types holding IDs
and state fields. [Format-token fields](https://libtmux.org/en/swift/latest/topics/format-tokens/) lists their fields.
Perform operations through [`Server`](<https://libtmux.org/en/swift/latest/reference/server/>), passing the target value:

```swift
try await server.sendKeys(["echo hi", "Enter"], to: pane)
try await server.kill(pane)
```

Keep the [`Server`](<https://libtmux.org/en/swift/latest/reference/server/>) that produced the snapshot. Pass its captured values back to
that server for operations.

<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.

Snapshots capture a fixed set of non-optional fields, including indices,
dimensions, active state, command, path, and edge flags.
[Format-token fields](https://libtmux.org/en/swift/latest/topics/format-tokens/) covers other tokens.

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

## Source layout

[`Sources/LibTmux/Server.swift`](<https://github.com/libtmux/libtmux-swift/blob/6b51d1408b55b8583825c6595405d08e728674bf/Sources/LibTmux/Server.swift>) defines [`Server`](<https://libtmux.org/en/swift/latest/reference/server/>). [`Sources/LibTmux/Session.swift`](<https://github.com/libtmux/libtmux-swift/blob/6b51d1408b55b8583825c6595405d08e728674bf/Sources/LibTmux/Session.swift>),
[`Sources/LibTmux/Window.swift`](<https://github.com/libtmux/libtmux-swift/blob/6b51d1408b55b8583825c6595405d08e728674bf/Sources/LibTmux/Window.swift>), and [`Sources/LibTmux/Pane.swift`](<https://github.com/libtmux/libtmux-swift/blob/6b51d1408b55b8583825c6595405d08e728674bf/Sources/LibTmux/Pane.swift>) define the
snapshot value types. [`Sources/LibTmux/Snapshot.swift`](<https://github.com/libtmux/libtmux-swift/blob/6b51d1408b55b8583825c6595405d08e728674bf/Sources/LibTmux/Snapshot.swift>) implements the
[relationship queries](https://libtmux.org/en/swift/latest/topics/traversal/).

Extensions on [`Server`](<https://libtmux.org/en/swift/latest/reference/server/>) group related operations:
[`Sources/LibTmux/Options.swift`](<https://github.com/libtmux/libtmux-swift/blob/6b51d1408b55b8583825c6595405d08e728674bf/Sources/LibTmux/Options.swift>) implements options and hooks,
[`Sources/LibTmux/PaneInteraction.swift`](<https://github.com/libtmux/libtmux-swift/blob/6b51d1408b55b8583825c6595405d08e728674bf/Sources/LibTmux/PaneInteraction.swift>) handles input and capture, and
[`Sources/LibTmux/Mutations.swift`](<https://github.com/libtmux/libtmux-swift/blob/6b51d1408b55b8583825c6595405d08e728674bf/Sources/LibTmux/Mutations.swift>) handles changes such as killing a pane.
