1# UI Development Instructions
2
3## General Guidelines
4- Never use commands to send messages when you can directly mutate children or state.
5- Keep things simple; do not overcomplicate.
6- Create files if needed to separate logic; do not nest models.
7- Always do IO in commands
8- Never change the model state inside of a command use messages and than update the state in the main loop
9
10## Architecture
11
12### Main Model (`model/ui.go`)
13Keep most of the logic and state in the main model. This is where:
14- Message routing happens
15- Focus and UI state is managed
16- Layout calculations are performed
17- Dialogs are orchestrated
18
19### Components Should Be Dumb
20Components should not handle bubbletea messages directly. Instead:
21- Expose methods for state changes
22- Return `tea.Cmd` from methods when side effects are needed
23- Handle their own rendering via `Render(width int) string`
24
25### Chat Logic (`model/chat.go`)
26Most chat-related logic belongs here. Individual chat items in `chat/` should be simple renderers that cache their output and invalidate when data changes (see `cachedMessageItem` in `chat/messages.go`).
27
28## Key Patterns
29
30### Composition Over Inheritance
31Use struct embedding for shared behaviors. See `chat/messages.go` for examples of reusable embedded structs for highlighting, caching, and focus.
32
33### Interfaces
34- List item interfaces are in `list/item.go`
35- Chat message interfaces are in `chat/messages.go`
36- Dialog interface is in `dialog/dialog.go`
37
38### Styling
39- All styles are defined in `styles/styles.go`
40- Access styles via `*common.Common` passed to components
41- Use semantic color fields rather than hardcoded colors
42
43### Dialogs
44- Implement the dialog interface in `dialog/dialog.go`
45- Return message types from `Update()` to signal actions to the main model
46- Use the overlay system for managing dialog lifecycle
47
48## File Organization
49- `model/` - Main UI model and major components (chat, sidebar, etc.)
50- `chat/` - Chat message item types and renderers
51- `dialog/` - Dialog implementations
52- `list/` - Generic list component with lazy rendering
53- `common/` - Shared utilities and the Common struct
54- `styles/` - All style definitions
55- `anim/` - Animation system
56- `logo/` - Logo rendering
57
58## Common Gotchas
59- Always account for padding/borders in width calculations
60- Use `tea.Batch()` when returning multiple commands
61- Pass `*common.Common` to components that need styles or app access