ui

package
v0.1.35 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 9, 2026 License: Apache-2.0 Imports: 32 Imported by: 0

README

Resource Management System

This directory contains a comprehensive resource management system for the Kafui application, built using the Bubbletea TUI framework.

Overview

The resource management system provides a modular, extensible interface for managing Kafka resources including topics, consumer groups, schemas, and custom resource types.

Components

Core Files
  • resource_management.go - Main resource management model with tree view, details panel, and operations
  • resource_tree.go - Hierarchical tree component for displaying resources
  • resource_operations.go - Forms and handlers for resource CRUD operations
  • resource_integration.go - Integration helpers and utilities
  • resource_example.go - Usage examples and extension patterns
  • resource_management_test.go - Comprehensive test suite

Features

1. Resource Types
  • Topics - Kafka topic management
  • Consumer Groups - Consumer group monitoring and management
  • Schemas - Schema registry integration (placeholder)
  • Custom Resources - Extensible custom resource types
2. Resource Operations
  • Create - Create new resources with validation
  • Delete - Delete existing resources with confirmation
  • Update - Modify resource configurations
  • View - Display detailed resource information
  • Batch Operations - Perform operations on multiple resources
3. User Interface
  • Resource Tree View - Hierarchical display of resources by type
  • Details Panel - Detailed information about selected resources
  • Action Menus - Context-sensitive operation menus
  • Status Indicators - Visual status feedback
  • Search Functionality - Filter resources by name or description
4. Integration Features
  • Data Source Connections - Pluggable data source interface
  • Error Handling - Comprehensive error reporting and recovery
  • Progress Feedback - Real-time operation progress
  • State Persistence - Save and restore UI state

Usage

Basic Integration
// Create a resource management page
dataSource := kafds.NewKafkaDataSourceKaf()
resourcePage := NewResourceManagementPage(dataSource)

// Initialize and run
cmd := resourcePage.Init()
// Handle in your main update loop
Extending the Main UI
// Extend the main model to include resource management
type ExtendedModel struct {
    Model // Embed existing model
    resourcePage *ResourceManagementPage
}

// Add resource management as a new page
const resourceManagementPage page = 3

// Handle in Update method
case resourceManagementPage:
    if em.resourcePage != nil {
        model, cmd := em.resourcePage.Update(msg)
        // Handle updates...
    }
Custom Resource Types
// Define custom resource type
const MyCustomResource ResourceType = 100

// Implement loading function
func LoadMyCustomResources(dataSource api.KafkaDataSource) []ResourceItem {
    // Load your custom resources
    return resources
}

// Extend the resource management model
func (m *ResourceManagementModel) loadCustomResources() tea.Msg {
    resources := LoadMyCustomResources(m.dataSource)
    return resourceLoadedMsg{
        resourceType: MyCustomResource,
        resources:    resources,
    }
}

Key Bindings

Navigation
  • ↑/↓ or j/k - Navigate resource list
  • →/l - Expand tree node
  • ←/h - Collapse tree node
  • enter - View resource details
  • esc - Go back/cancel
Operations
  • c - Create new resource
  • d - Delete selected resource
  • u - Update selected resource
  • r - Refresh resources
  • b - Batch operations
  • m - Show action menu
Search and Filtering
  • / - Enter search mode
  • esc - Exit search mode
  • enter - Apply search filter
General
  • ctrl+c - Quit application
  • tab/shift+tab - Navigate form fields (in operation forms)
  • ctrl+s - Submit form (in operation forms)

Architecture

Model-View-Update Pattern

The system follows the Bubbletea MVU (Model-View-Update) pattern:

  1. Model - Contains application state
  2. View - Renders the current state
  3. Update - Handles messages and updates state
Component Hierarchy
ResourceManagementModel
├── ResourceTreeModel (tree view)
├── Table (details panel)
├── TextInput (search)
├── Spinner (loading indicator)
└── ResourceOperationModel (operation forms)
Message Flow
User Input → Key Messages → Update Functions → State Changes → View Updates

Styling

The system uses Lipgloss for styling with consistent color schemes:

  • Primary: Color 205 (pink/magenta)
  • Success: Color 46 (green)
  • Error: Color 196 (red)
  • Warning: Color 226 (yellow)
  • Secondary: Color 240 (gray)

Testing

Run the test suite:

go test ./pkg/ui/...

The test suite includes:

  • Unit tests for all components
  • Integration tests
  • Benchmark tests for performance
  • Mock data source testing

Extension Points

Adding New Resource Types
  1. Define new ResourceType constant
  2. Implement loading function
  3. Add to resource management model
  4. Implement operations (optional)
Custom Operations
  1. Define new ResourceOperation constant
  2. Implement operation handler
  3. Add to operation model
  4. Update UI as needed
Custom Data Sources
  1. Implement api.KafkaDataSource interface
  2. Add resource-specific methods
  3. Handle in loading functions

Performance Considerations

  • Tree updates are optimized for large resource sets
  • Lazy loading of resource details
  • Efficient filtering and searching
  • Minimal re-renders through proper state management

Future Enhancements

  • Real-time resource monitoring
  • Advanced filtering and sorting
  • Export/import functionality
  • Resource templates
  • Audit logging
  • Multi-cluster support
  • Plugin system for custom resources

Dependencies

  • github.com/charmbracelet/bubbletea - TUI framework
  • github.com/charmbracelet/bubbles - UI components
  • github.com/charmbracelet/lipgloss - Styling
  • github.com/Benny93/kafui/pkg/api - Data source interface

Contributing

When contributing to the resource management system:

  1. Follow the existing MVU patterns
  2. Add comprehensive tests
  3. Update documentation
  4. Ensure consistent styling
  5. Consider performance implications
  6. Maintain backward compatibility

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init(opts InitOptions)

Init boots kafui with the given options.

func OpenUI

func OpenUI(dataSource api.KafkaDataSource, appCfg appconfig.Config, gate *authz.Gate, identity, initialTopic, initialResource, metricsListen string)

Types

type InitOptions

type InitOptions struct {
	ConfigFile     string
	Mock           bool
	Brokers        []string
	SchemaRegistry string
	Cluster        string
	Verbose        bool
	// ReadOnly is the global --read-only flag: when true every cluster is
	// treated read-only and all altering operations are denied (AA-4).
	ReadOnly bool
	// Topic deep-links directly to a topic page on startup (UI-9).
	Topic string
	// Resource pre-switches the main page to a resource type on startup (UI-9).
	Resource string
	// MetricsListen is the optional --metrics-listen address (e.g. ":9090"). When
	// non-empty, kafui serves the current metrics snapshot in Prometheus
	// exposition format for the lifetime of the program (MM-16). Default off.
	MetricsListen string
}

InitOptions carries CLI-level configuration into the app.

type Model

type Model struct {
	Router *router.Router // Exported for testing

	HelpSystem   *core.HelpSystem // Help system
	FocusManager *core.FocusManager
	// contains filtered or unexported fields
}

Model represents the main application state

func NewUIModel

func NewUIModel(dataSource api.KafkaDataSource) *Model

NewUIModel creates a new UI model using router-based navigation

func NewUIModelWithCommon

func NewUIModelWithCommon(common *core.Common) *Model

NewUIModelWithCommon creates a new UI model with a pre-configured Common context

func NewUIModelWithRouter

func NewUIModelWithRouter(dataSource api.KafkaDataSource) *Model

NewUIModelWithRouter creates a new UI model using router-based navigation

func (*Model) GetCommon

func (m *Model) GetCommon() *core.Common

GetCommon returns the shared context

func (*Model) GetFocusState

func (m *Model) GetFocusState() core.FocusState

GetFocusState returns the current focus state

func (*Model) GetState

func (m *Model) GetState() core.UIState

GetState returns the current UI state

func (*Model) Init

func (m *Model) Init() tea.Cmd

func (*Model) Update

func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd)

func (*Model) View

func (m *Model) View() string

Directories

Path Synopsis
datatable
Package datatable provides a reusable table component wrapping github.com/charmbracelet/bubbles/table.
Package datatable provides a reusable table component wrapping github.com/charmbracelet/bubbles/table.
form
Package form provides a reusable, typed form model for create/edit flows.
Package form provides a reusable, typed form model for create/edit flows.
menu
Package menu provides the filterable overlay list behind the two discovery surfaces the controls spec requires: the command palette (`:`) and the contextual actions menu (`a` / right-click).
Package menu provides the filterable overlay list behind the two discovery surfaces the controls spec requires: the command palette (`:`) and the contextual actions menu (`a` / right-click).
tabstrip
Package tabstrip renders a tab bar whose tabs are click and hover targets.
Package tabstrip renders a tab bar whose tabs are click and hover targets.
Package core provides core types and interfaces for the Kafui UI framework.
Package core provides core types and interfaces for the Kafui UI framework.
Package debug provides debugging utilities for Kafui.
Package debug provides debugging utilities for Kafui.
Package dialog provides the root-owned modal confirmation overlay used for destructive-action confirmation across all pages.
Package dialog provides the root-owned modal confirmation overlay used for destructive-action confirmation across all pages.
Package keys is the single binding registry required by the controls specification (kafui-specification/controls).
Package keys is the single binding registry required by the controls specification (kafui-specification/controls).
Package layout provides centralized layout management for the Kafui UI.
Package layout provides centralized layout management for the Kafui UI.
Package notify provides the shell-owned notification (status line) system: severity-styled, auto-expiring, deduplicated transient messages rendered in the footer area.
Package notify provides the shell-owned notification (status line) system: severity-styled, auto-expiring, deduplicated transient messages rendered in the footer area.
pages
appconfig_view
Package appconfig_view contains the read-only "Application Config" page.
Package appconfig_view contains the read-only "Application Config" page.
broker
Package broker implements the broker detail page (dynamic page ID "broker:<id>").
Package broker implements the broker detail page (dynamic page ID "broker:<id>").
cluster_form
Package cluster_form implements the cluster setup-wizard page (AC-12/AC-13): add, edit or delete a cluster in the kafui-owned config, validate connectivity without saving, and apply changes with an in-place datasource reload.
Package cluster_form implements the cluster setup-wizard page (AC-12/AC-13): add, edit or delete a cluster in the kafui-owned config, validate connectivity without saving, and apply changes with an in-place datasource reload.
clusters
Package clusters implements the cluster overview dashboard page (page ID "clusters").
Package clusters implements the cluster overview dashboard page (page ID "clusters").
connector
Package connector implements the connector detail page (dynamic page ID "connector:<connect>:<name>").
Package connector implements the connector detail page (dynamic page ID "connector:<connect>:<name>").
consumer_group
Package consumergroup implements the consumer-group detail page (dynamic page ID "consumer_group:<groupID>").
Package consumergroup implements the consumer-group detail page (dynamic page ID "consumer_group:<groupID>").
errorpage
Package errorpage provides a full-content error view used as the router's fallback for unknown/uncreatable routes (UI-10).
Package errorpage provides a full-content error view used as the router's fallback for unknown/uncreatable routes (UI-10).
ksql
Package ksql implements the ksqlDB UI: an overview page (page ID "ksql") listing the cluster's streams and tables in two tabs, and a query editor page (page ID "ksql_query") for executing statements and streaming SELECT results.
Package ksql implements the ksqlDB UI: an overview page (page ID "ksql") listing the cluster's streams and tables in two tabs, and a query editor page (page ID "ksql_query") for executing statements and streaming SELECT results.
main
Package mainpage contains the main page components for the Kafui application.
Package mainpage contains the main page components for the Kafui application.
message_detail
Package messagedetail contains the message detail page components for the Kafui application.
Package messagedetail contains the message detail page components for the Kafui application.
metrics
Package metrics implements the metrics & monitoring page (page ID "metrics").
Package metrics implements the metrics & monitoring page (page ID "metrics").
resource_detail
Package resource_detail contains the resource detail page components for the Kafui application.
Package resource_detail contains the resource detail page components for the Kafui application.
topic
Package topic contains the topic page components for the Kafui application.
Package topic contains the topic page components for the Kafui application.
aclcsv
Package aclcsv provides pure CSV serialization/parsing of ACL bindings and a declarative sync (diff + apply) between a desired binding set and the cluster.
Package aclcsv provides pure CSV serialization/parsing of ACL bindings and a declarative sync (diff + apply) between a desired binding set and the cluster.
template
ui

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL