Expert guidance for building terminal UIs with Go, Bubbletea, Lipgloss, and Wire. Enforces Go conventions, widget patterns, lifecycle management, structured logging, and comprehensive testing practices.
Expert guidance for building terminal-based dashboard applications using Go, Bubbletea (terminal UI framework), Lipgloss (styling), and Wire (dependency injection).
Follow these Go coding standards:
1. **Formatting**: Use `gofmt` for automatic formatting
2. **Linting**: Apply `golangci-lint` for code quality checks
3. **Constants**: Replace magic numbers with named constants
4. **Documentation**: Document all exported symbols (functions, types, variables)
5. **Line Length**: Keep lines under 100 characters
- Check for zero time values
- Validate time pointers before use
- Use time comparison helpers
Use Bubbletea's built-in lifecycle system:
- Logger: Flush buffers on exit
- UI/Terminal: Let Bubbletea handle restoration
- Components: Use Init/Update methods for setup/teardown
- Widgets: Implement cleanup in Blur method
Use Wire for dependency management:
1. Define providers in `providers.go`
2. Define interfaces in `interfaces.go`
3. Generate code in `wire_gen.go`
4. Prefer constructor injection over field injection
5. Use interfaces for all external dependencies
Implement structured logging with uber-go/zap:
- `testutil.NewTestLogger` for test logger creation
- `testutil.ReadLogFile` to verify log output
- `testutil.VerifyLogContent` to validate log entries
**Important**: Do not use `fmt` package for output in dashboard code (except in tests, main.go, and logger package itself). Use the logger package instead.
Build components using Bubbletea's architecture:
Implement widgets with these features:
Every widget should handle:
1. **Dimension Management**: SetSize, GetDimensions
2. **Focus State Management**: Focus, Blur, IsFocused
3. **Style Selection**: Apply appropriate styles based on state
4. **Default Command Handling**: Process standard keyboard events
Define clear interfaces:
Use composition over inheritance for code reuse.
Follow SOLID principles:
Target these metrics:
1. **Unit Tests**: Widget behavior, state transitions, message handling, style application
2. **Integration Tests**: Widget interactions, focus management, layout behavior, event propagation
3. **Benchmark Tests**: View rendering, update performance, memory allocations, style operations
Use provided test helpers:
```go
// Create test logger
logger := testutil.NewTestLogger()
// Create UI test harness
uiTest := testutil.NewUITest()
// Verify log output
logs := testutil.ReadLogFile(logPath)
testutil.VerifyLogContent(logs, expectedContent)
```
**Important**: Use `testutil.NewTestLogger` instead of local `setupTestLogger` functions.
```
/cmd - Entry points
/internal - Private application code
/pkg - Public libraries
/docs - Documentation
/test - Test utilities
/scripts - Build and deployment scripts
/configs - Configuration files
```
```
components/widget.go - Widget interface definitions
widgets/{type}/widget.go - Widget implementations
styles/{widget}.go - Widget styles
widgets/{type}/widget_test.go - Widget tests
```
- Interface requirements
- Size management behavior
- Focus handling patterns
- Update message patterns
```go
// Widget interface compliance
type MyWidget struct {
base.Widget
// widget fields
}
// Implement required methods
func (w *MyWidget) Init() tea.Cmd { /* ... */ }
func (w *MyWidget) Update(msg tea.Msg) (tea.Model, tea.Cmd) { /* ... */ }
func (w *MyWidget) View() string { /* ... */ }
// Implement Focusable
func (w *MyWidget) Focus() { /* ... */ }
func (w *MyWidget) Blur() { /* cleanup */ }
func (w *MyWidget) IsFocused() bool { /* ... */ }
// Implement Sizable
func (w *MyWidget) SetSize(width, height int) { /* validate and store */ }
func (w *MyWidget) GetDimensions() (int, int) { /* return dimensions */ }
```
Leave a review
No reviews yet. Be the first to review this skill!
# Download SKILL.md from killerskills.ai/api/skills/go-dashboard-development-with-bubbletea/raw