How riyadhossainczar/rinaco-elevate works
1. What this repo is
- Rinaco Elevate is a local, terminal-based recovery tracker written in Go.
- It is a Bubble Tea TUI app: keyboard-driven, stateful, and rendered entirely in the terminal.
- There is no server, database, or network dependency in the architecture; all persistence is local.
2. Top-level architecture
- The code is split into a few clear layers:
- Startup / wiring: main.go, tea_setup.go
- App state and domain models: models.go
- Event handling and state transitions: update.go
- Rendering: views.go, styles.go
- Persistence: storage.go
- Validation and utility helpers: validation.go, helpers.go
- Static reference content: plan_data.go
- This makes the app follow the standard Bubble Tea pattern: initialize model → process messages/keys → update state → render view.
3. Entry point and app bootstrap
- main.go is the executable entry.
- tea_setup.go likely constructs the initial Bubble Tea program/model, loads stored data, and configures any startup behavior such as the countdown timer or terminal sizing.
- From an architecture perspective, this is the boundary where the CLI runtime is connected to the app’s internal state machine.
4. State model and core domain
- models.go holds the app’s core data structures: user profile, recovery start time, relapse events, session history, trigger notes, statistics, and possibly the current screen/view.
- The model is the single source of truth for what the user sees and what is persisted.
- Features in the README like “real-time countdown,” “history,” “plan,” and “triggers” suggest the model combines both current recovery state and historical records.
5. Event-driven update loop
- update.go is the behavior engine.
- It handles key presses like s, r, h, p, t, j, e, and q, and likely also time-based messages for the live countdown.
- This is where user actions mutate the model:
- set start time
- mark relapse
- switch screens
- edit profile
- quit
- In diagram terms, this is the central control flow between input and state.
6. View and presentation layer
- views.go contains the screen rendering logic for the different UI modes: main dashboard, history, plan guide, statistics, triggers, and profile editing.
- styles.go defines terminal styling and visual consistency, probably via Lip Gloss.
- The architecture here is a clean separation: views read state only; they do not own persistence or business logic.
7. Persistence boundary
- storage.go is the local data access layer.
- The README says progress is saved to rinaco-elevate_data.json, so the app uses a JSON file in the working directory as its only storage mechanism.
- The likely flow is:
- load saved state on startup
- update in memory during interaction
- write back to JSON after meaningful changes
- This file is the main persistence boundary and the only durable data store.
8. Validation and safe input handling
- validation.go enforces correctness for user-provided values such as dates, times, and editable profile fields.
- This is important because recovery tracking depends on time accuracy, and invalid timestamps would break the countdown and statistics.
- Validation sits between the UI and the model/persistence layers, preventing bad state from being saved.
9. Shared utilities and derived calculations
- helpers.go likely contains reusable logic for formatting durations, computing elapsed time, converting timestamps, and other presentation-friendly calculations.
- Since the app centers on countdowns and session duration, helper functions probably support both the update loop and the view layer.
- These are “pure logic” utilities, not a separate subsystem.
10. Static recovery-plan content
- plan_data.go appears to provide built-in guidance text for the “standard recovery plan guide” screen.
- This is a content subsystem rather than user data: it is bundled into the binary and shown on demand.
- It sits apart from persisted state, which helps keep reference material stable and versioned with the app.
11. Data flow through the app
- Typical lifecycle:
- app starts
- saved JSON is loaded
- Bubble Tea model is initialized
- keyboard/time messages arrive
- update.go mutates state
- derived values are calculated
- views.go renders the current screen
- changes are persisted back to JSON
- The architecture is therefore event-driven, stateful, and local-first.
12. Operational characteristics
- The repo targets cross-platform terminal execution: Windows, Linux, and Android Termux.
- That portability comes from the Go runtime plus terminal UI libraries rather than any platform-specific subsystem.
- There are no external services, background workers, or APIs; the app’s runtime boundary is simply the terminal and local filesystem.
13. What to draw in an architecture diagram
- Show a central Bubble Tea app loop.
- Feed it with:
- keyboard input
- time/tick messages
- startup data loaded from JSON
- Connect it to:
- state/model
- view rendering
- validation/helpers
- JSON storage
- static plan content
- The main data boundary is the local data file, and the main control boundary is the event-driven update loop.
Main entry points: update.go update.go · views.go views.go · models.go models.go · tea_setup.go tea_setup.go
Components 16
Runtime
Executable entrypoint and Bubble Tea wiring.
- main.go · Program entry that starts the TUI application.
main.go - tea_setup.go · Constructs the Bubble Tea program and initial app state.
tea_setup.go - Keyboard input · User key presses that drive navigation and editing.
- Tick messages · Time-based messages used for countdown and refresh.
Core state
Domain model and event-driven update logic.
- models.go · Core state and domain structures for the recovery tracker.
models.go - update.go · Handles key messages, ticks, and state transitions.
update.go - helpers.go · Shared calculations and formatting helpers used across the app.
helpers.go - Recovery state · Current elapsed time, relapse data, and screen state.
- History stats · Session history, triggers, and statistics derived from events.
Presentation
Terminal screens and styling.
Data
Local persistence, validation, and bundled reference content.
- storage.go · Loads and saves local progress data in JSON.
storage.go - validation.go · Validates dates, times, and editable profile fields.
validation.go - plan_data.go · Bundled recovery-plan guidance shown in the app.
plan_data.go - Data file · rinaco-elevate_data.json in the working directory.
Connections 20
- main.go → tea_setup.go: start app · Main hands off execution to Bubble Tea setup.
- tea_setup.go → storage.go: load/save · Startup wiring connects the app to local persistence.
- tea_setup.go → models.go: init model · Creates the initial model from stored or default state.
- tea_setup.go → update.go: wire loop · Bootstraps the event-driven update cycle.
- Keyboard input → update.go: input · Key presses are translated into application actions.
- Tick messages → update.go: time · Timer updates refresh countdown-related state.
- update.go → models.go: mutate · Update logic changes the core application model.
- update.go → validation.go: validate · User edits are checked before being accepted.
- update.go → helpers.go: derive · Uses shared calculations for durations and formatting.
- update.go → storage.go: persist · Meaningful state changes are written to local JSON.
- storage.go → Data file: read/write · Persistence layer serializes app data to disk.
- models.go → Recovery state: holds · Model contains the live recovery state.
- models.go → History stats: contains · Model tracks historical records and summary data.
- Recovery state → views.go: render · Current state is read by the view layer.
- History stats → views.go: render · History and statistics are displayed in screens.
- plan_data.go → views.go: content · Bundled recovery guidance is shown in the plan screen.
- styles.go → views.go: style · Styling definitions shape the terminal presentation.
- views.go → Terminal UI: draw · Views produce the terminal interface output.
- helpers.go → views.go: format · Formatting helpers support screen rendering.
- validation.go → models.go: guard · Validation protects the model from invalid user input.