# charmbracelet/gum architecture

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

- Interactive diagram: https://gitdiagram.com/charmbracelet/gum
- Repository: https://github.com/charmbracelet/gum

## Overview

#### Purpose and Runtime
Gum is a Go CLI for adding interactive, styled terminal UX to shell scripts. It exposes composable subcommands that read arguments/stdin, render terminal UIs or formatted output, write results to stdout, and signal outcomes through exit codes. Primary runtime boundary is the user’s terminal/stdin/stdout rather than a web or server process.

Paths: `main.go`, `gum.go`, `go.mod`

#### Process Entry and Command Routing
`main.go` starts the executable; the root command infrastructure in `gum.go` dispatches to independently implemented subcommands. Each command conventionally separates Cobra-style command wiring, option/env binding, and core execution into `command.go`, `options.go`, and implementation files. Completion is a sibling command surface for shell integration.

Paths: `main.go`, `gum.go`, `completion/command.go`

#### Interactive Selection and Input Stage
Interactive commands wrap Charm’s terminal UI ecosystem (Bubbles/Lip Gloss) to collect user choices or text. `choose` selects supplied or piped candidates; `filter` fuzzy-filters stdin; `input` and `write` collect short and multiline text; `confirm` maps a decision to shell-compatible status; `file` navigates filesystem choices. Their output is intended for command substitution and pipelines.

Paths: `choose/choose.go`, `filter/filter.go`, `input/input.go`

#### Terminal Display and Layout Stage
Non-prompt rendering commands transform text into terminal presentation: `style` applies colors, borders, alignment, padding, and margins; `join` composes rendered blocks; `table` parses/render-selects tabular input; `pager` provides navigable document viewing. These commands preserve CLI composition by consuming stdin or arguments and emitting rendered text/selections.

Paths: `style/lipgloss.go`, `table/table.go`, `pager/pager.go`

#### Content Formatting and Logging
`format` converts text through markdown, code, template, or emoji-oriented formatting modes. `log` emits leveled and optionally structured terminal logs. These are non-interactive output stages that can be embedded in scripts, unlike the TUI-driven selectors.

Paths: `format/command.go`, `format/formats.go`, `log/command.go`

#### Command Execution Supervision
`spin` launches an external command while rendering spinner progress, using pseudo-terminal support where needed; it terminates its UI based on child-process completion and can expose child output. This is the main boundary where Gum orchestrates another OS process rather than merely transforming terminal input.

Paths: `spin/spin.go`, `spin/pty.go`, `spin/spinners.go`

#### Shared CLI/Terminal Boundaries
Internal packages centralize cross-command behavior: stdin detection/reading, TTY capability handling, timeout contexts, exit behavior, and option decoding such as alignment. This layer isolates environment-sensitive behavior and makes command implementations consistent across interactive and piped use.

Paths: `internal/stdin/stdin.go`, `internal/tty/tty.go`, `internal/timeout/context.go`

#### Distribution and Automation
The project is built as a Go binary and ships through Docker, Nix, and GoReleaser-managed multi-platform releases. GitHub Actions handles build, lint, nightly, and release workflows. External operational dependencies are terminal capabilities, shell completion targets, and Charm’s Go UI libraries; no persistent service or database is indicated.

Paths: `Dockerfile`, `.goreleaser.yml`, `.github/workflows/goreleaser.yml`

Main entry points: [`gum.go`](https://github.com/charmbracelet/gum/blob/main/gum.go) (Root command router), [`spin/spin.go`](https://github.com/charmbracelet/gum/blob/main/spin/spin.go) (Process supervisor), [`main.go`](https://github.com/charmbracelet/gum/blob/main/main.go) (Executable entry), [`internal/stdin/stdin.go`](https://github.com/charmbracelet/gum/blob/main/internal/stdin/stdin.go) (Shared terminal I/O)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cli["CLI Runtime"]
  node_main["Executable entry<br/>Go main<br/>[main.go]"]
  node_root{{"Root command router<br/>Cobra command root<br/>[gum.go]"}}
  node_completion["Shell completion<br/>command surface<br/>[command.go]"]
end

subgraph group_interactive["Interactive Commands"]
  node_selectors["Selection &amp; text input<br/>interactive commands<br/>[choose.go]"]
  node_filter["Fuzzy filter<br/>interactive command<br/>[filter.go]"]
  node_input["Text input<br/>interactive command<br/>[input.go]"]
end

subgraph group_rendering["Rendering Commands"]
  node_style["Style &amp; layout<br/>render command<br/>[lipgloss.go]"]
  node_table["Table renderer<br/>render command<br/>[table.go]"]
  node_pager["Document pager<br/>render command<br/>[pager.go]"]
  node_format["Content formatter<br/>output command<br/>[formats.go]"]
  node_log["Terminal logger<br/>output command<br/>[command.go]"]
end

subgraph group_platform["Platform &amp; Delivery"]
  node_spin{{"Process supervisor<br/>interactive command<br/>[spin.go]"}}
  node_pty["Pseudo-terminal support<br/>process I/O<br/>[pty.go]"]
  node_terminal_io["Shared terminal I/O<br/>internal package<br/>[stdin.go]"]
  node_build["Go build module<br/>build definition<br/>[go.mod]"]
  node_release["Release pipeline<br/>distribution automation<br/>[.goreleaser.yml]"]
  node_docker["Container image<br/>distribution target"]
end

node_terminal(("User terminal / shell<br/>runtime boundary"))

node_terminal -->|"invokes"| node_main
node_main -->|"starts"| node_root
node_root -->|"dispatches"| node_completion
node_root -->|"dispatches"| node_selectors
node_root -->|"dispatches"| node_filter
node_root -->|"dispatches"| node_input
node_root -->|"dispatches"| node_style
node_root -->|"dispatches"| node_table
node_root -->|"dispatches"| node_pager
node_root -->|"dispatches"| node_format
node_root -->|"dispatches"| node_log
node_root -->|"dispatches"| node_spin
node_selectors -->|"uses"| node_terminal_io
node_filter -->|"reads stdin via"| node_terminal_io
node_input -->|"uses TTY via"| node_terminal_io
node_style -->|"writes rendered stdout"| node_terminal
node_format -->|"writes formatted stdout"| node_terminal
node_log -->|"writes logs"| node_terminal
node_spin -->|"uses"| node_pty
node_spin -->|"supervises child output"| node_terminal
node_build -->|"builds"| node_main
node_release -->|"packages"| node_build
node_release -->|"publishes"| node_docker

click node_main "https://github.com/charmbracelet/gum/blob/main/main.go"
click node_root "https://github.com/charmbracelet/gum/blob/main/gum.go"
click node_completion "https://github.com/charmbracelet/gum/blob/main/completion/command.go"
click node_selectors "https://github.com/charmbracelet/gum/blob/main/choose/choose.go"
click node_filter "https://github.com/charmbracelet/gum/blob/main/filter/filter.go"
click node_input "https://github.com/charmbracelet/gum/blob/main/input/input.go"
click node_style "https://github.com/charmbracelet/gum/blob/main/style/lipgloss.go"
click node_table "https://github.com/charmbracelet/gum/blob/main/table/table.go"
click node_pager "https://github.com/charmbracelet/gum/blob/main/pager/pager.go"
click node_format "https://github.com/charmbracelet/gum/blob/main/format/formats.go"
click node_log "https://github.com/charmbracelet/gum/blob/main/log/command.go"
click node_spin "https://github.com/charmbracelet/gum/blob/main/spin/spin.go"
click node_pty "https://github.com/charmbracelet/gum/blob/main/spin/pty.go"
click node_terminal_io "https://github.com/charmbracelet/gum/blob/main/internal/stdin/stdin.go"
click node_build "https://github.com/charmbracelet/gum/blob/main/go.mod"
click node_release "https://github.com/charmbracelet/gum/blob/main/.goreleaser.yml"
click node_docker "https://github.com/charmbracelet/gum/blob/main/Dockerfile"

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_main,node_root,node_completion toneBlue
class node_selectors,node_filter,node_input toneAmber
class node_style,node_table,node_pager,node_format,node_log toneMint
class node_spin,node_pty,node_terminal_io,node_build,node_release,node_docker toneRose
class node_terminal toneNeutral
```

## Components

### CLI Runtime

Go executable and command routing.

- [Executable entry](https://github.com/charmbracelet/gum/blob/main/main.go): Go main · `main.go`
- [Root command router](https://github.com/charmbracelet/gum/blob/main/gum.go): Cobra command root · Registers and dispatches Gum subcommands. · `gum.go`
- [Shell completion](https://github.com/charmbracelet/gum/blob/main/completion/command.go): command surface · `completion/command.go`

### Interactive Commands

Terminal UI commands for shell pipelines.

- [Selection & text input](https://github.com/charmbracelet/gum/blob/main/choose/choose.go): interactive commands · Choose, filter, input, and write collect values for command substitution. · `choose/choose.go`
- [Fuzzy filter](https://github.com/charmbracelet/gum/blob/main/filter/filter.go): interactive command · Filters candidates read from stdin. · `filter/filter.go`
- [Text input](https://github.com/charmbracelet/gum/blob/main/input/input.go): interactive command · Collects short text input. · `input/input.go`

### Rendering Commands

Text presentation and non-interactive output.

- [Style & layout](https://github.com/charmbracelet/gum/blob/main/style/lipgloss.go): render command · Applies Lip Gloss styling and block layout. · `style/lipgloss.go`
- [Table renderer](https://github.com/charmbracelet/gum/blob/main/table/table.go): render command · Parses and renders selectable tabular input. · `table/table.go`
- [Document pager](https://github.com/charmbracelet/gum/blob/main/pager/pager.go): render command · Provides navigable terminal document viewing. · `pager/pager.go`
- [Content formatter](https://github.com/charmbracelet/gum/blob/main/format/formats.go): output command · Formats markdown, code, templates, and emoji text. · `format/formats.go`
- [Terminal logger](https://github.com/charmbracelet/gum/blob/main/log/command.go): output command · Emits leveled or structured logs. · `log/command.go`

### Platform & Delivery

Terminal boundaries, process supervision, and release automation.

- [Process supervisor](https://github.com/charmbracelet/gum/blob/main/spin/spin.go): interactive command · Runs a child command while displaying spinner progress. · `spin/spin.go`
- [Pseudo-terminal support](https://github.com/charmbracelet/gum/blob/main/spin/pty.go): process I/O · Connects supervised child processes to terminal I/O when needed. · `spin/pty.go`
- [Shared terminal I/O](https://github.com/charmbracelet/gum/blob/main/internal/stdin/stdin.go): internal package · Normalizes stdin reading, TTY handling, timeouts, and exit behavior. · `internal/stdin/stdin.go`
- [Go build module](https://github.com/charmbracelet/gum/blob/main/go.mod): build definition · `go.mod`
- [Release pipeline](https://github.com/charmbracelet/gum/blob/main/.goreleaser.yml): distribution automation · Builds multi-platform releases through GoReleaser and GitHub Actions. · `.goreleaser.yml`
- [Container image](https://github.com/charmbracelet/gum/blob/main/Dockerfile): distribution target · `Dockerfile`

### Other components

- **User terminal / shell**: runtime boundary · Supplies arguments, stdin, TTY capabilities, and receives stdout and exit codes.

## Connections

- User terminal / shell → Executable entry: invokes
- Executable entry → Root command router: starts
- Root command router → Shell completion: dispatches
- Root command router → Selection & text input: dispatches
- Root command router → Fuzzy filter: dispatches
- Root command router → Text input: dispatches
- Root command router → Style & layout: dispatches
- Root command router → Table renderer: dispatches
- Root command router → Document pager: dispatches
- Root command router → Content formatter: dispatches
- Root command router → Terminal logger: dispatches
- Root command router → Process supervisor: dispatches
- Selection & text input → Shared terminal I/O: uses
- Fuzzy filter → Shared terminal I/O: reads stdin via
- Text input → Shared terminal I/O: uses TTY via
- Style & layout → User terminal / shell: writes rendered stdout
- Content formatter → User terminal / shell: writes formatted stdout
- Terminal logger → User terminal / shell: writes logs
- Process supervisor → Pseudo-terminal support: uses
- Process supervisor → User terminal / shell: supervises child output
- Go build module → Executable entry: builds
- Release pipeline → Go build module: packages
- Release pipeline → Container image: publishes
