# applejag/kubectl-klock architecture

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

- Interactive diagram: https://gitdiagram.com/applejag/kubectl-klock
- Repository: https://github.com/applejag/kubectl-klock

## Overview

kubectl-klock is a terminal UI for streaming Kubernetes resource-watch results in a kubectl-get-like table. The workflow starts with a kubectl user invoking the Cobra command, which resolves options and hands resource arguments to the watch-and-print runtime; updates populate the interactive table. The README also documents filtering, pagination, deleted-row handling, color themes, and kubeconfig-triggered watch restarts. Relationships below use shown imports/calls or README statements; some runtime details are unsampled, so uncertain links are omitted.

Main entry points: [`pkg/klock/klock.go`](https://github.com/applejag/kubectl-klock/blob/main/pkg/klock/klock.go) (Watch runtime), [`pkg/table/table.go`](https://github.com/applejag/kubectl-klock/blob/main/pkg/table/table.go) (Terminal table UI), [`cmd/root.go`](https://github.com/applejag/kubectl-klock/blob/main/cmd/root.go) (CLI command), [`pkg/types/optionalduration.go`](https://github.com/applejag/kubectl-klock/blob/main/pkg/types/optionalduration.go) (Optional duration)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Command entry"]
  node_main["Program entry<br/>[main.go]"]
  node_command["CLI command<br/>[root.go]"]
  node_completion["Shell completion<br/>[completion.go]"]
end

subgraph group_watch["Watch and render"]
  node_klock["Watch runtime<br/>[klock.go]"]
  node_decoder["Watch decoding<br/>[decoder.go]"]
  node_printer["Resource printer<br/>[klock.go]"]
  node_format["Output formatting<br/>[parsing.go]"]
  node_color["Status coloring<br/>[color.go]"]
end

subgraph group_terminal["Interactive table"]
  node_table["Terminal table UI<br/>[table.go]"]
  node_keys["Key bindings<br/>[keys.go]"]
  node_rows["Row model<br/>[row.go]"]
end

subgraph group_shared["Shared behavior"]
  node_duration["Optional duration"]
  node_human_duration["Duration parsing<br/>[humanduration.go]"]
  node_string_util["String splitting<br/>[strings.go]"]
end

node_user(("kubectl user"))
node_resource{{"Kubernetes API"}}

node_user -->|"invokes"| node_main
node_main -->|"starts"| node_command
node_command -->|"executes"| node_klock
node_command -->|"registers"| node_completion
node_command -->|"configures"| node_duration
node_klock -->|"watches"| node_resource
node_klock -->|"updates"| node_table
node_klock -->|"configures"| node_printer
node_printer -->|"adds rows"| node_table
node_printer -->|"uses styles"| node_color
node_printer -->|"parses values"| node_format
node_table -->|"handles keys"| node_keys
node_table -->|"renders rows"| node_rows
node_klock -->|"parses durations"| node_human_duration
node_duration -->|"parses values"| node_human_duration
node_table -->|"uses option"| node_duration
node_format -->|"uses splitting"| node_string_util
node_klock -.->|"decodes events"| node_decoder

click node_main "https://github.com/applejag/kubectl-klock/blob/main/main.go"
click node_command "https://github.com/applejag/kubectl-klock/blob/main/cmd/root.go"
click node_completion "https://github.com/applejag/kubectl-klock/blob/main/cmd/completion.go"
click node_klock "https://github.com/applejag/kubectl-klock/blob/main/pkg/klock/klock.go"
click node_decoder "https://github.com/applejag/kubectl-klock/blob/main/pkg/klock/decoder.go"
click node_printer "https://github.com/applejag/kubectl-klock/blob/main/pkg/klock/klock.go"
click node_format "https://github.com/applejag/kubectl-klock/blob/main/pkg/klock/parsing.go"
click node_color "https://github.com/applejag/kubectl-klock/blob/main/pkg/klock/color.go"
click node_table "https://github.com/applejag/kubectl-klock/blob/main/pkg/table/table.go"
click node_keys "https://github.com/applejag/kubectl-klock/blob/main/pkg/table/keys.go"
click node_rows "https://github.com/applejag/kubectl-klock/blob/main/pkg/table/row.go"
click node_duration "https://github.com/applejag/kubectl-klock/blob/main/pkg/types/optionalduration.go"
click node_human_duration "https://github.com/applejag/kubectl-klock/blob/main/internal/util/humanduration.go"
click node_string_util "https://github.com/applejag/kubectl-klock/blob/main/internal/util/strings.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_main,node_command,node_completion,node_user toneBlue
class node_klock,node_decoder,node_printer,node_format,node_color toneAmber
class node_table,node_keys,node_rows,node_resource toneMint
class node_duration,node_human_duration,node_string_util toneRose
```

## Components

### Command entry

- [Program entry](https://github.com/applejag/kubectl-klock/blob/main/main.go): `main.go`
- [CLI command](https://github.com/applejag/kubectl-klock/blob/main/cmd/root.go): `cmd/root.go`
- [Shell completion](https://github.com/applejag/kubectl-klock/blob/main/cmd/completion.go): `cmd/completion.go`

### Watch and render

- [Watch runtime](https://github.com/applejag/kubectl-klock/blob/main/pkg/klock/klock.go): `pkg/klock/klock.go`
- [Watch decoding](https://github.com/applejag/kubectl-klock/blob/main/pkg/klock/decoder.go): `pkg/klock/decoder.go`
- [Resource printer](https://github.com/applejag/kubectl-klock/blob/main/pkg/klock/klock.go): `pkg/klock/klock.go`
- [Output formatting](https://github.com/applejag/kubectl-klock/blob/main/pkg/klock/parsing.go): `pkg/klock/parsing.go`
- [Status coloring](https://github.com/applejag/kubectl-klock/blob/main/pkg/klock/color.go): `pkg/klock/color.go`

### Interactive table

- [Terminal table UI](https://github.com/applejag/kubectl-klock/blob/main/pkg/table/table.go): `pkg/table/table.go`
- [Key bindings](https://github.com/applejag/kubectl-klock/blob/main/pkg/table/keys.go): `pkg/table/keys.go`
- [Row model](https://github.com/applejag/kubectl-klock/blob/main/pkg/table/row.go): `pkg/table/row.go`

### Shared behavior

- [Optional duration](https://github.com/applejag/kubectl-klock/blob/main/pkg/types/optionalduration.go): `pkg/types/optionalduration.go`
- [Duration parsing](https://github.com/applejag/kubectl-klock/blob/main/internal/util/humanduration.go): `internal/util/humanduration.go`
- [String splitting](https://github.com/applejag/kubectl-klock/blob/main/internal/util/strings.go): `internal/util/strings.go`

### Other components

- **kubectl user**
- **Kubernetes API**

## Connections

- kubectl user → Program entry: invokes (evidence: `README.md`)
- Program entry → CLI command: starts (evidence: `main.go`)
- CLI command → Watch runtime: executes (evidence: `cmd/root.go`)
- CLI command → Shell completion: registers (evidence: `cmd/root.go`)
- CLI command → Optional duration: configures (evidence: `cmd/root.go`)
- Watch runtime → Kubernetes API: watches (evidence: `README.md`)
- Watch runtime → Terminal table UI: updates (evidence: `pkg/klock/klock.go`)
- Watch runtime → Resource printer: configures (evidence: `pkg/klock/klock.go`)
- Resource printer → Terminal table UI: adds rows (evidence: `pkg/klock/klock.go`)
- Resource printer → Status coloring: uses styles (evidence: `pkg/klock/color.go`)
- Resource printer → Output formatting: parses values (evidence: `pkg/klock/klock.go`)
- Terminal table UI → Key bindings: handles keys (evidence: `pkg/table/table.go`)
- Terminal table UI → Row model: renders rows (evidence: `pkg/table/table.go`)
- Watch runtime → Duration parsing: parses durations (evidence: `pkg/klock/klock.go`)
- Optional duration → Duration parsing: parses values (evidence: `pkg/types/optionalduration.go`)
- Terminal table UI → Optional duration: uses option (evidence: `pkg/table/table.go`)
- Output formatting → String splitting: uses splitting (evidence: `pkg/klock/parsing.go`)
- Watch runtime → Watch decoding: decodes events
