# Architecture

Source: https://libtmux.org/en/ts/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/ts/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.

```typescript
await pane.sendKeys("echo hi");
await pane.kill();
```

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

[`packages/libtmux/src/_generated/format_fields.ts`](<https://github.com/libtmux/libtmux-ts/blob/f8ca14551254f81800faedc8bee9151565044ef1/packages/libtmux/src/_generated/format_fields.ts>) records each token's scope
and first tmux version. [`packages/libtmux/src/_generated/field_aliases.ts`](<https://github.com/libtmux/libtmux-ts/blob/f8ca14551254f81800faedc8bee9151565044ef1/packages/libtmux/src/_generated/field_aliases.ts>)
provides camelCase aliases for fields on [`Pane`](<https://libtmux.org/en/ts/latest/reference/pane-pane/>), [`Session`](<https://libtmux.org/en/ts/latest/reference/session-session/>), and [`Window`](<https://libtmux.org/en/ts/latest/reference/window-window/>).

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

## Source layout

The public classes live in [`packages/libtmux/src/server.ts`](<https://github.com/libtmux/libtmux-ts/blob/f8ca14551254f81800faedc8bee9151565044ef1/packages/libtmux/src/server.ts>),
[`packages/libtmux/src/session.ts`](<https://github.com/libtmux/libtmux-ts/blob/f8ca14551254f81800faedc8bee9151565044ef1/packages/libtmux/src/session.ts>), [`packages/libtmux/src/window.ts`](<https://github.com/libtmux/libtmux-ts/blob/f8ca14551254f81800faedc8bee9151565044ef1/packages/libtmux/src/window.ts>),
[`packages/libtmux/src/pane.ts`](<https://github.com/libtmux/libtmux-ts/blob/f8ca14551254f81800faedc8bee9151565044ef1/packages/libtmux/src/pane.ts>), and [`packages/libtmux/src/client.ts`](<https://github.com/libtmux/libtmux-ts/blob/f8ca14551254f81800faedc8bee9151565044ef1/packages/libtmux/src/client.ts>).

Their operations are split by concern under
[`packages/libtmux/src/_internal/operations/`](<https://github.com/libtmux/libtmux-ts/tree/f8ca14551254f81800faedc8bee9151565044ef1/packages/libtmux/src/_internal/operations>), including
[`packages/libtmux/src/_internal/operations/pane_io.ts`](<https://github.com/libtmux/libtmux-ts/blob/f8ca14551254f81800faedc8bee9151565044ef1/packages/libtmux/src/_internal/operations/pane_io.ts>),
[`packages/libtmux/src/_internal/operations/hooks.ts`](<https://github.com/libtmux/libtmux-ts/blob/f8ca14551254f81800faedc8bee9151565044ef1/packages/libtmux/src/_internal/operations/hooks.ts>),
[`packages/libtmux/src/_internal/operations/options.ts`](<https://github.com/libtmux/libtmux-ts/blob/f8ca14551254f81800faedc8bee9151565044ef1/packages/libtmux/src/_internal/operations/options.ts>), and
[`packages/libtmux/src/_internal/operations/topology.ts`](<https://github.com/libtmux/libtmux-ts/blob/f8ca14551254f81800faedc8bee9151565044ef1/packages/libtmux/src/_internal/operations/topology.ts>).
[`packages/libtmux/src/_generated/`](<https://github.com/libtmux/libtmux-ts/tree/f8ca14551254f81800faedc8bee9151565044ef1/packages/libtmux/src/_generated>) contains the generated field catalogs.
Workspaces and the MCP server have separate packages in the same repository.
