# agl/pond architecture

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

- Interactive diagram: https://gitdiagram.com/agl/pond
- Repository: https://github.com/agl/pond

## Overview

1. **What this repo is**
   Pond is a secure messaging system split into a desktop client, a message server, and a set of crypto/transport libraries. The codebase is organized so the application logic stays separate from the cryptographic primitives and wire protocols.

2. **Client is the main application boundary**
   The `client/` tree contains both the GUI and CLI entry points, plus the shared client runtime. It includes OS-specific startup files for Linux, macOS, and FreeBSD, so the same core client is packaged differently per platform. The client owns user interaction, message composition, synchronization, and local state management.

3. **Local state is a first-class subsystem**
   Client state is persisted as structured files, with dedicated code under `client/disk/`, `client/disk.go`, and `client/testdata/`. The presence of `editstate/` and `decrypt/` shows that state files and encrypted artifacts are important operational boundaries, not just internal implementation details. `client/tpm/` and `client/disk/tpm_linux.go` indicate optional hardware-backed protection on Linux.

4. **Message security is centered on ratcheting**
   `client/ratchet/` is the core message-security state machine. It is the part of the system that evolves keys over time so that each message can be protected with fresh material rather than a long-lived static key. In architecture diagrams, this sits between the UI/state layer and the transport layer.

5. **Anonymous authorization uses group signatures**
   `bbssig/` implements the BBS group signature scheme, and `bn256cgo/` is the pairing-crypto backend used to speed it up. This is one of Pond’s defining boundaries: the server can reject unauthorized traffic without learning which specific contact sent it. That makes `bbssig` a security subsystem, not just a library.

6. **Panda handles shared-key exchange**
   The `panda/` package implements the shared-key exchange mechanism used by the client. It has its own protobufs and crypto implementation (`rijndael/`), plus an App Engine deployment under `panda/appengine-server/`. This looks like a separate rendezvous/meeting-point service used to establish shared secrets before normal messaging begins.

7. **Transport is separate from the application protocol**
   `transport/` implements the low-level client-to-server transport protocol. Higher-level message formats live in `protos/` and `server/protos/`, while `client/disk/client.proto` defines on-disk client state. That separation means the repo distinguishes wire transport, application messages, and local persistence as different layers.

8. **Server is a distinct relay/validation service**
   `server/` contains the standalone Pond server, with its own `main.go`, server logic, and protobuf definitions. The server’s role is not to decrypt user traffic; it validates protocol-level constraints, uses the group-signature path for access control, and acts as the rendezvous/relay endpoint for clients. There is also an `appengine-server` variant, showing an alternate deployment target.

9. **Platform abstraction lives inside the client**
   Files like `client/system/sys_*.go`, `client/gtk.go`, `client/gui.go`, `client/nogtk.go`, and `client/gui-nogui.go` show a layered client architecture: a platform/system adapter, UI implementations, and fallback builds for environments without GTK or a GUI. This makes the client portable without pushing platform details into crypto or protocol code.

10. **Tooling and docs are supporting, not runtime, components**
   `doc/`, `papers/`, and `slides/` document the system and its threat model rather than participating in execution. `editstate/`, `decrypt/`, and `pathrewrite/` are operational utilities for debugging or manipulating data artifacts. These are useful to show as maintenance tools off to the side of the main client/server path.

11. **End-to-end data flow**
   A typical flow is: user action in the client UI/CLI → client state and ratchet logic update local session/message state → crypto layers (`panda`, `bbssig`, `bn256cgo`) prepare keys and authorization material → `transport` sends the request to `server/` → the server relays or stores data for the intended recipient. The client later pulls or receives the corresponding response and applies it back through the ratchet/state layer.

12. **Main architectural boundaries to draw**
   The cleanest diagram boundary is: **UI/OS-specific client shell**, **secure client core**, **crypto primitives**, **transport/protocol definitions**, and **server relay**. The notable security boundary is that the server should be treated as untrusted for content and identities, but trusted to enforce protocol rules and mailbox-style delivery.

Main entry points: [`client/client.go`](https://github.com/agl/pond/blob/master/client/client.go) (Client app), [`client/disk.go`](https://github.com/agl/pond/blob/master/client/disk.go) (Local state), [`server/server.go`](https://github.com/agl/pond/blob/master/server/server.go) (Server core), [`panda/panda.go`](https://github.com/agl/pond/blob/master/panda/panda.go) (Panda)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Client"]
  node_client_main["Client app<br/>desktop client<br/>[client.go]"]
  node_client_ui["UI shell<br/>gui/cli layer<br/>[gui.go]"]
  node_client_platform["Platform glue<br/>OS adapters"]
  node_client_state[("Local state<br/>persistence<br/>[disk.go]")]
  node_client_ratchet{{"Ratchet<br/>session state machine<br/>[ratchet.go]"}}
  node_client_tpm["TPM<br/>hardware security<br/>[tpm.go]"]
end

subgraph group_crypto["Crypto"]
  node_panda{{"Panda<br/>shared-key exchange<br/>[panda.go]"}}
  node_panda_proto["Panda proto<br/>exchange schema<br/>[core.proto]"]
  node_rijndael["Rijndael<br/>symmetric crypto<br/>[rijndael.go]"]
  node_bbssig{{"BBS signatures<br/>group signature<br/>[bbssig.go]"}}
  node_bn256cgo["bn256 backend<br/>pairing crypto<br/>[bn256.go]"]
end

subgraph group_protocol["Protocol"]
  node_protos["Pond proto<br/>app messages<br/>[pond.proto]"]
  node_transport["Transport<br/>wire protocol<br/>[transport.go]"]
end

subgraph group_server["Server"]
  node_server_main["Server app<br/>relay service<br/>[main.go]"]
  node_server_core{{"Server core<br/>relay/validation<br/>[server.go]"}}
  node_server_proto["Server proto<br/>server schema<br/>[server.proto]"]
end

subgraph group_tools["Tools"]
  node_editstate["Edit state<br/>maintenance tool<br/>[editstate.go]"]
  node_decrypt["Decrypt tool<br/>maintenance tool<br/>[decrypt.go]"]
  node_pathrewrite["Path rewrite<br/>maintenance tool<br/>[pathrewrite.go]"]
end

node_client_ui -->|"drives"| node_client_main
node_client_platform -->|"boots"| node_client_ui
node_client_main -->|"persists"| node_client_state
node_client_main -->|"updates"| node_client_ratchet
node_client_state -->|"loads"| node_client_ratchet
node_client_main -.->|"optionally uses"| node_client_tpm
node_client_main -->|"establishes"| node_panda
node_panda -->|"defines"| node_panda_proto
node_panda -->|"encrypts"| node_rijndael
node_client_main -->|"authenticates"| node_bbssig
node_bbssig -->|"accelerates"| node_bn256cgo
node_client_main -->|"formats"| node_protos
node_client_main -->|"sends"| node_transport
node_transport -->|"connects"| node_server_main
node_server_main -->|"runs"| node_server_core
node_server_core -->|"parses"| node_server_proto
node_server_core -->|"verifies"| node_bbssig
node_server_core -->|"handles"| node_protos
node_editstate -->|"edits"| node_client_state
node_decrypt -->|"inspects"| node_client_state
node_pathrewrite -->|"rewrites"| node_client_state

click node_client_main "https://github.com/agl/pond/blob/master/client/client.go"
click node_client_ui "https://github.com/agl/pond/blob/master/client/gui.go"
click node_client_platform "https://github.com/agl/pond/tree/master/client/system"
click node_client_state "https://github.com/agl/pond/blob/master/client/disk.go"
click node_client_ratchet "https://github.com/agl/pond/blob/master/client/ratchet/ratchet.go"
click node_client_tpm "https://github.com/agl/pond/blob/master/client/tpm/tpm.go"
click node_panda "https://github.com/agl/pond/blob/master/panda/panda.go"
click node_panda_proto "https://github.com/agl/pond/blob/master/panda/proto/core.proto"
click node_rijndael "https://github.com/agl/pond/blob/master/panda/rijndael/rijndael.go"
click node_bbssig "https://github.com/agl/pond/blob/master/bbssig/bbssig.go"
click node_bn256cgo "https://github.com/agl/pond/blob/master/bn256cgo/bn256.go"
click node_protos "https://github.com/agl/pond/blob/master/protos/pond.proto"
click node_transport "https://github.com/agl/pond/blob/master/transport/transport.go"
click node_server_main "https://github.com/agl/pond/blob/master/server/main.go"
click node_server_core "https://github.com/agl/pond/blob/master/server/server.go"
click node_server_proto "https://github.com/agl/pond/blob/master/server/protos/server.proto"
click node_editstate "https://github.com/agl/pond/blob/master/editstate/editstate.go"
click node_decrypt "https://github.com/agl/pond/blob/master/decrypt/decrypt.go"
click node_pathrewrite "https://github.com/agl/pond/blob/master/pathrewrite/pathrewrite.go"

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_client_main,node_client_ui,node_client_platform,node_client_state,node_client_ratchet,node_client_tpm toneBlue
class node_panda,node_panda_proto,node_rijndael,node_bbssig,node_bn256cgo toneAmber
class node_protos,node_transport toneMint
class node_server_main,node_server_core,node_server_proto toneRose
class node_editstate,node_decrypt,node_pathrewrite toneIndigo
```

## Components

### Client

Desktop app shell, shared runtime, local state, and OS-specific startup.

- [Client app](https://github.com/agl/pond/blob/master/client/client.go): desktop client · Main user-facing application entry and runtime orchestration. · `client/client.go`
- [UI shell](https://github.com/agl/pond/blob/master/client/gui.go): gui/cli layer · GUI and CLI presentation layers plus build-time UI fallbacks. · `client/gui.go`
- [Platform glue](https://github.com/agl/pond/tree/master/client/system): OS adapters · OS-specific startup and system integration for Linux, macOS, and FreeBSD. · `client/system`
- [Local state](https://github.com/agl/pond/blob/master/client/disk.go): persistence · On-disk client state, disk formats, and encrypted artifacts. · `client/disk.go`
- [Ratchet](https://github.com/agl/pond/blob/master/client/ratchet/ratchet.go): session state machine · Message-security state evolution and per-message key progression. · `client/ratchet/ratchet.go`
- [TPM](https://github.com/agl/pond/blob/master/client/tpm/tpm.go): hardware security · Optional hardware-backed protection for client secrets on supported platforms. · `client/tpm/tpm.go`

### Crypto

Cryptographic primitives and key-evolution logic.

- [Panda](https://github.com/agl/pond/blob/master/panda/panda.go): shared-key exchange · Rendezvous and shared-secret exchange subsystem used before normal messaging. · `panda/panda.go`
- [Panda proto](https://github.com/agl/pond/blob/master/panda/proto/core.proto): exchange schema · Panda protocol definitions and generated messages. · `panda/proto/core.proto`
- [Rijndael](https://github.com/agl/pond/blob/master/panda/rijndael/rijndael.go): symmetric crypto · Panda's cipher implementation and crypto backend. · `panda/rijndael/rijndael.go`
- [BBS signatures](https://github.com/agl/pond/blob/master/bbssig/bbssig.go): group signature · Anonymous authorization and membership-based signing for server access control. · `bbssig/bbssig.go`
- [bn256 backend](https://github.com/agl/pond/blob/master/bn256cgo/bn256.go): pairing crypto · Acceleration backend for the BBS signature scheme. · `bn256cgo/bn256.go`

### Protocol

Wire formats and transport boundaries between client and server.

- [Pond proto](https://github.com/agl/pond/blob/master/protos/pond.proto): app messages · Core application message and state schemas shared by client and server. · `protos/pond.proto`
- [Transport](https://github.com/agl/pond/blob/master/transport/transport.go): wire protocol · Low-level client-to-server transport and framing. · `transport/transport.go`

### Server

Standalone relay and validation service.

- [Server app](https://github.com/agl/pond/blob/master/server/main.go): relay service · Standalone server entry point and deployment-specific startup. · `server/main.go`
- [Server core](https://github.com/agl/pond/blob/master/server/server.go): relay/validation · Protocol validation, mailbox-style relay behavior, and server-side coordination. · `server/server.go`
- [Server proto](https://github.com/agl/pond/blob/master/server/protos/server.proto): server schema · Server-specific request and response message definitions. · `server/protos/server.proto`

### Tools

Operational utilities and supporting documentation.

- [Edit state](https://github.com/agl/pond/blob/master/editstate/editstate.go): maintenance tool · Utility for inspecting and rewriting client state artifacts. · `editstate/editstate.go`
- [Decrypt tool](https://github.com/agl/pond/blob/master/decrypt/decrypt.go): maintenance tool · Utility for decrypting or examining protected artifacts. · `decrypt/decrypt.go`
- [Path rewrite](https://github.com/agl/pond/blob/master/pathrewrite/pathrewrite.go): maintenance tool · Utility for rewriting paths in repository-maintained artifacts. · `pathrewrite/pathrewrite.go`

## Connections

- UI shell → Client app: drives · User interaction enters the main client runtime.
- Platform glue → UI shell: boots · OS-specific startup selects UI/runtime behavior.
- Client app → Local state: persists · Client runtime reads and writes local structured state.
- Client app → Ratchet: updates · Messaging actions advance ratchet state and message keys.
- Local state → Ratchet: loads · Stored session material feeds the ratchet state machine.
- Client app → TPM: optionally uses · Hardware-backed protection may guard local secrets.
- Client app → Panda: establishes · Client uses Panda to negotiate shared secrets.
- Panda → Panda proto: defines · Panda exchanges use dedicated protobuf schemas.
- Panda → Rijndael: encrypts · Shared-key exchange relies on symmetric crypto primitives.
- Client app → BBS signatures: authenticates · Client prepares anonymous authorization material for server access.
- BBS signatures → bn256 backend: accelerates · Signature operations use the pairing backend.
- Client app → Pond proto: formats · Application-level messages are encoded with shared protobufs.
- Client app → Transport: sends · Client hands signed and encoded messages to transport.
- Transport → Server app: connects · Transport carries client traffic to the server endpoint.
- Server app → Server core: runs · Server entry point initializes relay and validation logic.
- Server core → Server proto: parses · Server logic consumes server-specific wire messages.
- Server core → BBS signatures: verifies · Server checks anonymous authorization using group signatures.
- Server core → Pond proto: handles · Server processes the same core application message schema.
- Edit state → Local state: edits · Tool operates on client persistence artifacts.
- Decrypt tool → Local state: inspects · Tool works with encrypted client artifacts.
- Path rewrite → Local state: rewrites · Utility adjusts stored paths in state-related artifacts.
