BubbleTea Code Review
Hard gates (sequence)
Advance only when each pass condition is objectively true (reduces false positives on tea.Cmd and unsubstantiated blocking claims):
| Gate |
Pass condition |
| G1 — Anti–false-positive |
You skimmed NOT Issues below or read references/elm-architecture.md before recording a finding about tea.Cmd returns, value receivers on Update, or nested child Update. |
| G2 — Evidence for blocking / suspicious I/O |
Each Critical/Major finding names file path + line (or a short quoted snippet) showing the blocking call, huh.Form.Run in the wrong place, or other asserted anti-pattern—not a hypothetical. |
| G3 — Verification |
Before publishing review output, you applied the review-verification-protocol to each proposed finding. |
Quick Reference
| Issue Type |
Reference |
| Elm architecture, tea.Cmd as data |
references/elm-architecture.md |
| Model state, message handling |
references/model-update.md |
| View rendering, Lipgloss styling |
references/view-styling.md |
| Component composition, Huh forms |
references/composition.md |
| Bubbles components (list, table, etc.) |
references/bubbles-components.md |
CRITICAL: Avoid False Positives
Read elm-architecture.md first! The most common review mistake is flagging correct patterns as bugs.
NOT Issues (Do NOT Flag These)
| Pattern |
Why It's Correct |
return m, m.loadData() |
tea.Cmd is returned immediately; runtime executes async |
Value receiver on Update() |
Standard BubbleTea pattern; model returned by value |
Nested m.child, cmd = m.child.Update(msg) |
Normal component composition |
Helper functions returning tea.Cmd |
Creates command descriptor, no I/O in Update |
tea.Batch(cmd1, cmd2) |
Commands execute concurrently by runtime |
ACTUAL Issues (DO Flag These)
| Pattern |
Why It's Wrong |
os.ReadFile() in Update |
Blocks UI thread |
http.Get() in Update |
Network I/O blocks |
time.Sleep() in Update |
Freezes UI |
<-channel in Update (blocking) |
May block indefinitely |
huh.Form.Run() in Update |
Blocking call |
Review Checklist
Architecture
Model & Update
View & Styling
Components
Critical Patterns
Model Must Be Immutable
// BAD - mutates model
func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.items = append(m.items, newItem) // mutation!
return m, nil
}
// GOOD - returns new model
func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
newItems := make([]Item, len(m.items)+1)
copy(newItems, m.items)
newItems[len(m.items)] = newItem
m.items = newItems
return m, nil
}
Commands for Async/IO
// BAD - blocking in Update
func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
data, _ := os.ReadFile("config.json") // blocks UI!
m.config = parse(data)
return m, nil
}
// GOOD - use commands
func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, loadConfigCmd()
}
func loadConfigCmd() tea.Cmd {
return func() tea.Msg {
data, err := os.ReadFile("config.json")
if err != nil {
return errMsg{err}
}
return configLoadedMsg{parse(data)}
}
}
Styles Defined Once
// BAD - creates new style each render
func (m Model) View() string {
style := lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Color("205"))
return style.Render("Hello")
}
// GOOD - define styles at package level or in model
var titleStyle = lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Color("205"))
func (m Model) View() string {
return titleStyle.Render("Hello")
}
When to Load References
- First time reviewing BubbleTea → elm-architecture.md (prevents false positives)
- Reviewing Update function logic → model-update.md
- Reviewing View function, styling → view-styling.md
- Reviewing component hierarchy → composition.md
- Using Bubbles components → bubbles-components.md
Review Questions
- Is Update() free of blocking I/O? (NOT: "is the cmd helper blocking?")
- Is the model immutable in Update?
- Are Lipgloss styles defined once, not in View?
- Is WindowSizeMsg handled for resizing?
- Are key bindings documented with help.KeyMap?
- Are Bubbles components sized correctly?
1---2name: bubbletea-code-review3description: Reviews BubbleTea TUI code for proper Elm architecture, model/update/view patterns, and Lipgloss styling. Use when reviewing terminal UI code using charmbracelet/bubbletea.4---5
6# BubbleTea Code Review
7
8## Hard gates (sequence)
9
10Advance only when each **pass condition** is objectively true (reduces false positives on `tea.Cmd` and unsubstantiated blocking claims):
11
12| Gate | Pass condition |
13|------|----------------|
14| **G1 — Anti–false-positive** | You skimmed **NOT Issues** below **or** read [references/elm-architecture.md](references/elm-architecture.md) **before** recording a finding about `tea.Cmd` returns, value receivers on `Update`, or nested child `Update`. |
15| **G2 — Evidence for blocking / suspicious I/O** | Each Critical/Major finding names **file path + line** (or a short quoted snippet) showing the blocking call, `huh.Form.Run` in the wrong place, or other asserted anti-pattern—not a hypothetical. |
16| **G3 — Verification** | Before publishing review output, you applied the **[review-verification-protocol](../review-verification-protocol/SKILL.md)** to each proposed finding. |
17
18## Quick Reference
19
20| Issue Type | Reference |
21|------------|-----------|
22| Elm architecture, tea.Cmd as data | [references/elm-architecture.md](references/elm-architecture.md) |
23| Model state, message handling | [references/model-update.md](references/model-update.md) |
24| View rendering, Lipgloss styling | [references/view-styling.md](references/view-styling.md) |
25| Component composition, Huh forms | [references/composition.md](references/composition.md) |
26| Bubbles components (list, table, etc.) | [references/bubbles-components.md](references/bubbles-components.md) |
27
28## CRITICAL: Avoid False Positives
29
30**Read [elm-architecture.md](references/elm-architecture.md) first!** The most common review mistake is flagging correct patterns as bugs.
31
32### NOT Issues (Do NOT Flag These)
33
34| Pattern | Why It's Correct |
35|---------|------------------|
36| `return m, m.loadData()` | `tea.Cmd` is returned immediately; runtime executes async |
37| Value receiver on `Update()` | Standard BubbleTea pattern; model returned by value |
38| Nested `m.child, cmd = m.child.Update(msg)` | Normal component composition |
39| Helper functions returning `tea.Cmd` | Creates command descriptor, no I/O in Update |
40| `tea.Batch(cmd1, cmd2)` | Commands execute concurrently by runtime |
41
42### ACTUAL Issues (DO Flag These)
43
44| Pattern | Why It's Wrong |
45|---------|----------------|
46| `os.ReadFile()` in Update | Blocks UI thread |
47| `http.Get()` in Update | Network I/O blocks |
48| `time.Sleep()` in Update | Freezes UI |
49| `<-channel` in Update (blocking) | May block indefinitely |
50| `huh.Form.Run()` in Update | Blocking call |
51
52## Review Checklist
53
54### Architecture
55- [ ] **No blocking I/O in Update()** (file, network, sleep)
56- [ ] Helper functions returning `tea.Cmd` are NOT flagged as blocking
57- [ ] Commands used for all async operations
58
59### Model & Update
60- [ ] Model is immutable (Update returns new model, not mutates)
61- [ ] Init returns proper initial command (or nil)
62- [ ] Update handles all expected message types
63- [ ] WindowSizeMsg handled for responsive layout
64- [ ] tea.Batch used for multiple commands
65- [ ] tea.Quit used correctly for exit
66
67### View & Styling
68- [ ] View is a pure function (no side effects)
69- [ ] Lipgloss styles defined once, not in View
70- [ ] Key bindings use key.Matches with help.KeyMap
71
72### Components
73- [ ] Sub-component updates propagated correctly
74- [ ] Bubbles components initialized with dimensions
75- [ ] Huh forms embedded via Update loop (not Run())
76
77## Critical Patterns
78
79### Model Must Be Immutable
80
81```go
82// BAD - mutates model
83func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
84 m.items = append(m.items, newItem) // mutation!
85 return m, nil
86}
87
88// GOOD - returns new model
89func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
90 newItems := make([]Item, len(m.items)+1)
91 copy(newItems, m.items)
92 newItems[len(m.items)] = newItem
93 m.items = newItems
94 return m, nil
95}
96```
97
98### Commands for Async/IO
99
100```go
101// BAD - blocking in Update
102func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
103 data, _ := os.ReadFile("config.json") // blocks UI!
104 m.config = parse(data)
105 return m, nil
106}
107
108// GOOD - use commands
109func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
110 return m, loadConfigCmd()
111}
112
113func loadConfigCmd() tea.Cmd {
114 return func() tea.Msg {
115 data, err := os.ReadFile("config.json")
116 if err != nil {
117 return errMsg{err}
118 }
119 return configLoadedMsg{parse(data)}
120 }
121}
122```
123
124### Styles Defined Once
125
126```go
127// BAD - creates new style each render
128func (m Model) View() string {
129 style := lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Color("205"))
130 return style.Render("Hello")
131}
132
133// GOOD - define styles at package level or in model
134var titleStyle = lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Color("205"))
135
136func (m Model) View() string {
137 return titleStyle.Render("Hello")
138}
139```
140
141## When to Load References
142
143- **First time reviewing BubbleTea** → [elm-architecture.md](references/elm-architecture.md) (prevents false positives)
144- Reviewing Update function logic → [model-update.md](references/model-update.md)
145- Reviewing View function, styling → [view-styling.md](references/view-styling.md)
146- Reviewing component hierarchy → [composition.md](references/composition.md)
147- Using Bubbles components → [bubbles-components.md](references/bubbles-components.md)
148
149## Review Questions
150
1511. Is Update() free of blocking I/O? (NOT: "is the cmd helper blocking?")
1522. Is the model immutable in Update?
1533. Are Lipgloss styles defined once, not in View?
1544. Is WindowSizeMsg handled for resizing?
1555. Are key bindings documented with help.KeyMap?
1566. Are Bubbles components sized correctly?