# nyannyn/drinkmorewater architecture

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

- Interactive diagram: https://gitdiagram.com/nyannyn/drinkmorewater
- Repository: https://github.com/nyannyn/drinkmorewater

## Overview

1. **Project shape**
   - This is an **Electron desktop app** for Windows/Linux, not a web app.
   - The app is split into a **Node-based main process** plus two renderer windows: a **floating cup overlay** and a **settings/statistics window**.
   - The repository is small and intentionally layered around those boundaries: `electron/` for app control, `renderer/` for UI, `build/` for icons and packaging assets.

2. **Main process is the control plane**
   - `electron/main.js` is the central orchestrator.
   - It owns the **system tray**, app lifecycle, reminder scheduling, system notifications, idle/power handling, and IPC routing.
   - This is where the app decides when to show/hide the cup overlay, when to fire reminders, and when to pause/resume based on lock/sleep/idle events.

3. **Two renderer windows with distinct roles**
   - `renderer/cup.html` + `renderer/cup.js` implement the **transparent, always-on-top floating cup** that appears only on reminder events.
   - `renderer/settings.html` + `renderer/settings.js` implement the **configuration and statistics UI**.
   - These windows do not directly manage app-wide state; they render state and emit user actions back to the main process.

4. **Preload scripts define the trust boundary**
   - `electron/preload-cup.js` and `electron/preload-settings.js` expose a limited API into each renderer via `contextBridge`.
   - This keeps the renderers isolated from raw Node/Electron access and makes the IPC boundary explicit.
   - Architecturally, the preload scripts are the “adapter” layer between UI code and the privileged main process.

5. **Persistent state lives outside the UI**
   - `electron/store.js` is the local data layer.
   - The README indicates it replaces `chrome.storage.local` from the app’s Chrome-extension origin and persists to `userData/data.json`.
   - This store likely holds reminder settings, daily/weekly drinking totals, enabled/disabled state, and other user preferences.

6. **Primary data flow: reminder cycle**
   - Main process schedules a timer based on the selected interval.
   - When the timer fires, it triggers both:
     - the **cup overlay** in the renderer, and
     - a **native system notification**.
   - The cup window then handles the interaction loop: user holds 3 seconds or presses Space/Enter to record water intake, after which the main process/store are updated.

7. **User interaction flow**
   - The tray icon is the app’s persistent entry point.
   - Left-click opens settings/statistics; right-click exposes actions like open settings, test reminder, enable/disable reminders, and quit.
   - The cup overlay supports drag/move behavior and focus-based keyboard shortcuts, so the renderer is responsible for visual interaction while the main process remains authoritative for state changes.

8. **Idle/power behavior is part of the core logic**
   - The app pauses reminders when the system is locked or sleeping and resumes afterward.
   - This is handled in the main process using Electron’s OS-level power/idle signals, which is important because reminder timing is tied to desktop state, not just elapsed wall-clock time.

9. **Build and packaging**
   - `package.json` drives Electron startup and Electron Builder packaging for Windows and Linux.
   - `build/make-icons.js` and `build/icons/` support app/tray icon generation, especially the multi-size Linux icon set.
   - `.github/workflows/release.yml` indicates automated release packaging from GitHub Actions.

10. **Architecture summary for diagramming**
   - Think of the app as:
     - **Main process** = scheduler, tray, notifications, persistence, OS integration
     - **Cup renderer** = transient reminder UI and drink action capture
     - **Settings renderer** = configuration and analytics display
     - **Store** = local JSON persistence
     - **Preloads** = safe IPC facade between privileged and unprivileged layers
   - The main process is the hub; the renderers are clients; the store is the durable backend.

Main entry points: [`electron/main.js`](https://github.com/nyannyn/drinkmorewater/blob/main/electron/main.js) (Main process), [`renderer/cup.html`](https://github.com/nyannyn/drinkmorewater/blob/main/renderer/cup.html) (Cup overlay), [`renderer/settings.html`](https://github.com/nyannyn/drinkmorewater/blob/main/renderer/settings.html) (Settings window), [`electron/preload-cup.js`](https://github.com/nyannyn/drinkmorewater/blob/main/electron/preload-cup.js) (Cup preload)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_electron["Main process"]
  node_node_main["Main process<br/>electron orchestrator<br/>[main.js]"]
  node_node_store[("Store<br/>json persistence<br/>[store.js]")]
  node_node_preload_cup["Cup preload<br/>ipc bridge<br/>[preload-cup.js]"]
  node_node_preload_settings["Settings preload<br/>ipc bridge"]
end

subgraph group_group_renderer["Renderers"]
  node_node_cup_ui["Cup overlay<br/>reminder window<br/>[cup.html]"]
  node_node_cup_logic["Cup logic<br/>interaction UI<br/>[cup.js]"]
  node_node_settings_ui["Settings window<br/>config window<br/>[settings.html]"]
  node_node_settings_logic["Settings logic<br/>dashboard UI<br/>[settings.js]"]
end

subgraph group_group_build["Build assets"]
  node_node_icons[("Icons<br/>packaging assets")]
  node_node_make_icons["Icon builder<br/>asset script<br/>[make-icons.js]"]
end

node_node_package["Package config<br/>build manifest<br/>[package.json]"]
node_node_release["Release workflow<br/>ci pipeline<br/>[release.yml]"]

node_node_main -->|"reads/writes"| node_node_store
node_node_main -->|"loads"| node_node_preload_cup
node_node_main -->|"loads"| node_node_preload_settings
node_node_preload_cup -->|"exposes API"| node_node_cup_ui
node_node_preload_settings -->|"exposes API"| node_node_settings_ui
node_node_cup_ui -->|"runs"| node_node_cup_logic
node_node_settings_ui -->|"runs"| node_node_settings_logic
node_node_main -->|"shows on reminder"| node_node_cup_ui
node_node_main -->|"opens"| node_node_settings_ui
node_node_main -.->|"schedules"| node_node_main
node_node_main -->|"updates intake"| node_node_store
node_node_main -->|"uses"| node_node_icons
node_node_make_icons -->|"generates"| node_node_icons
node_node_package -->|"starts"| node_node_main
node_node_release -->|"packages"| node_node_package

click node_node_main "https://github.com/nyannyn/drinkmorewater/blob/main/electron/main.js"
click node_node_store "https://github.com/nyannyn/drinkmorewater/blob/main/electron/store.js"
click node_node_preload_cup "https://github.com/nyannyn/drinkmorewater/blob/main/electron/preload-cup.js"
click node_node_preload_settings "https://github.com/nyannyn/drinkmorewater/blob/main/electron/preload-settings.js"
click node_node_cup_ui "https://github.com/nyannyn/drinkmorewater/blob/main/renderer/cup.html"
click node_node_cup_logic "https://github.com/nyannyn/drinkmorewater/blob/main/renderer/cup.js"
click node_node_settings_ui "https://github.com/nyannyn/drinkmorewater/blob/main/renderer/settings.html"
click node_node_settings_logic "https://github.com/nyannyn/drinkmorewater/blob/main/renderer/settings.js"
click node_node_icons "https://github.com/nyannyn/drinkmorewater/tree/main/build/icons"
click node_node_make_icons "https://github.com/nyannyn/drinkmorewater/blob/main/build/make-icons.js"
click node_node_package "https://github.com/nyannyn/drinkmorewater/blob/main/package.json"
click node_node_release "https://github.com/nyannyn/drinkmorewater/blob/main/.github/workflows/release.yml"

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_node_main,node_node_store,node_node_preload_cup,node_node_preload_settings toneBlue
class node_node_cup_ui,node_node_cup_logic,node_node_settings_ui,node_node_settings_logic toneAmber
class node_node_icons,node_node_make_icons toneMint
class node_node_package,node_node_release toneNeutral
```

## Components

### Main process

Privileged Electron control plane and persistence layer.

- [Main process](https://github.com/nyannyn/drinkmorewater/blob/main/electron/main.js): electron orchestrator · Owns tray, lifecycle, reminders, notifications, idle/power handling, and IPC routing. · `electron/main.js`
- [Store](https://github.com/nyannyn/drinkmorewater/blob/main/electron/store.js): json persistence · Local data store for settings, totals, and reminder state. · `electron/store.js`
- [Cup preload](https://github.com/nyannyn/drinkmorewater/blob/main/electron/preload-cup.js): ipc bridge · Exposes a limited API to the cup renderer via contextBridge. · `electron/preload-cup.js`
- [Settings preload](https://github.com/nyannyn/drinkmorewater/blob/main/electron/preload-settings.js): ipc bridge · Exposes a limited API to the settings renderer via contextBridge. · `electron/preload-settings.js`

### Renderers

Unprivileged UI windows for reminders and settings.

- [Cup overlay](https://github.com/nyannyn/drinkmorewater/blob/main/renderer/cup.html): reminder window · Transparent always-on-top floating cup shown for reminder events. · `renderer/cup.html`
- [Cup logic](https://github.com/nyannyn/drinkmorewater/blob/main/renderer/cup.js): interaction UI · Handles hold-to-drink, keyboard shortcuts, and overlay behavior. · `renderer/cup.js`
- [Settings window](https://github.com/nyannyn/drinkmorewater/blob/main/renderer/settings.html): config window · Configuration and statistics interface for the app. · `renderer/settings.html`
- [Settings logic](https://github.com/nyannyn/drinkmorewater/blob/main/renderer/settings.js): dashboard UI · Renders preferences and drinking statistics, emitting actions back to main. · `renderer/settings.js`

### Build assets

Packaging, icon generation, and release assets.

- [Icons](https://github.com/nyannyn/drinkmorewater/tree/main/build/icons): packaging assets · App and tray icon set used across platforms. · `build/icons`
- [Icon builder](https://github.com/nyannyn/drinkmorewater/blob/main/build/make-icons.js): asset script · Generates icon assets, especially the Linux multi-size set. · `build/make-icons.js`

### Other components

- [Package config](https://github.com/nyannyn/drinkmorewater/blob/main/package.json): build manifest · Electron startup and Electron Builder packaging configuration. · `package.json`
- [Release workflow](https://github.com/nyannyn/drinkmorewater/blob/main/.github/workflows/release.yml): ci pipeline · Automated packaging and release flow in GitHub Actions. · `.github/workflows/release.yml`

## Connections

- Main process → Store: reads/writes · Persists reminder settings, totals, and app state.
- Main process → Cup preload: loads · Attaches the cup renderer preload to the overlay window.
- Main process → Settings preload: loads · Attaches the settings renderer preload to the settings window.
- Cup preload → Cup overlay: exposes API · Provides the cup window with a safe IPC surface.
- Settings preload → Settings window: exposes API · Provides the settings window with a safe IPC surface.
- Cup overlay → Cup logic: runs · HTML shell hosts the cup interaction code.
- Settings window → Settings logic: runs · HTML shell hosts the settings and statistics code.
- Main process → Cup overlay: shows on reminder · Opens the floating cup when the reminder timer fires.
- Main process → Settings window: opens · Shows the settings/statistics window from tray or app actions.
- Main process → Main process: schedules · Runs reminder timers and reacts to power/idle state changes.
- Main process → Store: updates intake · Records completed drinking actions and app counters.
- Main process → Icons: uses · Consumes app and tray icons at runtime and packaging time.
- Icon builder → Icons: generates · Build script produces the icon asset set.
- Package config → Main process: starts · Defines Electron entrypoint and packaging targets.
- Release workflow → Package config: packages · CI workflow builds distributable releases from the package configuration.
