How ypatel2022/ttt works
Project Type and Purpose
• CLI/TUI application written in Go
• Provides typing tests in 200+ natural and programming languages
• Uses Bubble Tea for UI, Lipgloss for styling, Viper for config
File Structure
• ttt/
– main.go: application entrypoint
– app.go, model.go, ui.go: Bubble Tea model-view components
– config_picker.go, settings.go: settings menu and config management
– calculations.go: WPM & accuracy logic
– test.go: test orchestration
• config.yaml: persistent settings store
• languages/*.json: static word-list data sets
• assets/: images for README demos
• go.mod/go.sum: dependencies including Bubble Tea, Lipgloss, Viper
README Insights
• Describes three logical segments: configuration, UI, test logic
• Highlights use of external libs (Bubble Tea, Lipgloss, Viper)
• Language files sourced externally but used locally
Main Components and Their Relationships
a. User Interface Layer
– Bubble Tea framework (third-party)
– ui.go: defines View functions, keybindings, menu screens
– Lipgloss styling library
b. Application Core
– Model (model.go): holds current state (menu selection, test state)
– Controller logic (app.go): orchestrates transitions & commands
– Calculations (calculations.go): computes WPM/accuracy
– Test orchestration (test.go): picks words, tracks progress
c. Configuration
– settings.go & config_picker.go: read/write config.yaml via Viper
– config.yaml: YAML file persisted on disk
d. Data Store
– languages/*.json: JSON files loaded at runtime for word sets
– file-I/O module (part of core)
e. Entry Point
– main.go: initializes Viper, loads config, boots Bubble Tea program
Interactions and Data Flows
• On startup:
→ main.go loads config.yaml (Viper)
→ loads language JSON into memory
→ initializes Bubble Tea Program with model, view, update
• User navigates menus:
→ ui.go dispatches keystrokes → update() in model → view() renders UI
• Starting a test:
→ test.go selects words, updates model
→ calculations.go tracks keystrokes → computes metrics
→ UI layer displays live WPM/accuracy
• Settings change:
→ config_picker.go writes back to config.yaml (Viper)
Architectural Patterns and Principles
• MVC-style layering:
– Model: model.go
– View/Controller: ui.go & app.go
• Single-process, event-driven architecture provided by Bubble Tea
• Separation of concerns: UI, config, data, business logic separated into packages/files
• Static resources (languages) decoupled from code