# riyadhossainczar/rinaco-elevate architecture

> Architecture diagram of the GitHub repository riyadhossainczar/rinaco-elevate, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/riyadhossainczar/rinaco-elevate
- Repository: https://github.com/riyadhossainczar/rinaco-elevate

## Overview

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`](https://github.com/riyadhossainczar/rinaco-elevate/blob/main/update.go) (update.go), [`views.go`](https://github.com/riyadhossainczar/rinaco-elevate/blob/main/views.go) (views.go), [`models.go`](https://github.com/riyadhossainczar/rinaco-elevate/blob/main/models.go) (models.go), [`tea_setup.go`](https://github.com/riyadhossainczar/rinaco-elevate/blob/main/tea_setup.go) (tea_setup.go)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime"]
  node_main_go["main.go<br/>entrypoint<br/>[main.go]"]
  node_tea_setup_go["tea_setup.go<br/>bootstrap<br/>[tea_setup.go]"]
  node_keyboard_input(("Keyboard input<br/>terminal events"))
  node_tick_messages(("Tick messages<br/>timer events"))
end

subgraph group_core["Core state"]
  node_models_go["models.go<br/>app model<br/>[models.go]"]
  node_update_go["update.go<br/>event loop<br/>[update.go]"]
  node_helpers_go{{"helpers.go<br/>derived logic<br/>[helpers.go]"}}
  node_countdown_state(("Recovery state<br/>live state"))
  node_history_stats(("History stats<br/>derived state"))
end

subgraph group_presentation["Presentation"]
  node_views_go["views.go<br/>screens<br/>[views.go]"]
  node_styles_go["styles.go<br/>styling<br/>[styles.go]"]
  node_terminal_ui["Terminal UI<br/>Bubble Tea view"]
end

subgraph group_data["Data"]
  node_storage_go[("storage.go<br/>json store<br/>[storage.go]")]
  node_validation_go{{"validation.go<br/>input checks<br/>[validation.go]"}}
  node_plan_data_go["plan_data.go<br/>reference content<br/>[plan_data.go]"]
  node_local_json[("Data file<br/>local persistence")]
end

node_main_go -->|"start app"| node_tea_setup_go
node_tea_setup_go -->|"load/save"| node_storage_go
node_tea_setup_go -->|"init model"| node_models_go
node_tea_setup_go -->|"wire loop"| node_update_go
node_keyboard_input -->|"input"| node_update_go
node_tick_messages -->|"time"| node_update_go
node_update_go -->|"mutate"| node_models_go
node_update_go -->|"validate"| node_validation_go
node_update_go -->|"derive"| node_helpers_go
node_update_go -->|"persist"| node_storage_go
node_storage_go -->|"read/write"| node_local_json
node_models_go -->|"holds"| node_countdown_state
node_models_go -->|"contains"| node_history_stats
node_countdown_state -->|"render"| node_views_go
node_history_stats -->|"render"| node_views_go
node_plan_data_go -->|"content"| node_views_go
node_styles_go -->|"style"| node_views_go
node_views_go -->|"draw"| node_terminal_ui
node_helpers_go -->|"format"| node_views_go
node_validation_go -->|"guard"| node_models_go

click node_main_go "https://github.com/riyadhossainczar/rinaco-elevate/blob/main/main.go"
click node_tea_setup_go "https://github.com/riyadhossainczar/rinaco-elevate/blob/main/tea_setup.go"
click node_models_go "https://github.com/riyadhossainczar/rinaco-elevate/blob/main/models.go"
click node_update_go "https://github.com/riyadhossainczar/rinaco-elevate/blob/main/update.go"
click node_helpers_go "https://github.com/riyadhossainczar/rinaco-elevate/blob/main/helpers.go"
click node_views_go "https://github.com/riyadhossainczar/rinaco-elevate/blob/main/views.go"
click node_styles_go "https://github.com/riyadhossainczar/rinaco-elevate/blob/main/styles.go"
click node_storage_go "https://github.com/riyadhossainczar/rinaco-elevate/blob/main/storage.go"
click node_validation_go "https://github.com/riyadhossainczar/rinaco-elevate/blob/main/validation.go"
click node_plan_data_go "https://github.com/riyadhossainczar/rinaco-elevate/blob/main/plan_data.go"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main_go,node_tea_setup_go,node_keyboard_input,node_tick_messages toneBlue
class node_models_go,node_update_go,node_helpers_go,node_countdown_state,node_history_stats toneAmber
class node_views_go,node_styles_go,node_terminal_ui toneMint
class node_storage_go,node_validation_go,node_plan_data_go,node_local_json toneRose
```

## Components

### Runtime

Executable entrypoint and Bubble Tea wiring.

- [main.go](https://github.com/riyadhossainczar/rinaco-elevate/blob/main/main.go): entrypoint · Program entry that starts the TUI application. · `main.go`
- [tea_setup.go](https://github.com/riyadhossainczar/rinaco-elevate/blob/main/tea_setup.go): bootstrap · Constructs the Bubble Tea program and initial app state. · `tea_setup.go`
- **Keyboard input**: terminal events · User key presses that drive navigation and editing.
- **Tick messages**: timer events · Time-based messages used for countdown and refresh.

### Core state

Domain model and event-driven update logic.

- [models.go](https://github.com/riyadhossainczar/rinaco-elevate/blob/main/models.go): app model · Core state and domain structures for the recovery tracker. · `models.go`
- [update.go](https://github.com/riyadhossainczar/rinaco-elevate/blob/main/update.go): event loop · Handles key messages, ticks, and state transitions. · `update.go`
- [helpers.go](https://github.com/riyadhossainczar/rinaco-elevate/blob/main/helpers.go): derived logic · Shared calculations and formatting helpers used across the app. · `helpers.go`
- **Recovery state**: live state · Current elapsed time, relapse data, and screen state.
- **History stats**: derived state · Session history, triggers, and statistics derived from events.

### Presentation

Terminal screens and styling.

- [views.go](https://github.com/riyadhossainczar/rinaco-elevate/blob/main/views.go): screens · Renders the terminal screens and UI modes. · `views.go`
- [styles.go](https://github.com/riyadhossainczar/rinaco-elevate/blob/main/styles.go): styling · Terminal style definitions and visual constants. · `styles.go`
- **Terminal UI**: Bubble Tea view · Rendered terminal interface presented to the user.

### Data

Local persistence, validation, and bundled reference content.

- [storage.go](https://github.com/riyadhossainczar/rinaco-elevate/blob/main/storage.go): json store · Loads and saves local progress data in JSON. · `storage.go`
- [validation.go](https://github.com/riyadhossainczar/rinaco-elevate/blob/main/validation.go): input checks · Validates dates, times, and editable profile fields. · `validation.go`
- [plan_data.go](https://github.com/riyadhossainczar/rinaco-elevate/blob/main/plan_data.go): reference content · Bundled recovery-plan guidance shown in the app. · `plan_data.go`
- **Data file**: local persistence · rinaco-elevate_data.json in the working directory.

## Connections

- 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.
