# hjiaxjason/pulse architecture

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

- Interactive diagram: https://gitdiagram.com/hjiaxjason/pulse
- Repository: https://github.com/hjiaxjason/pulse

## Overview

#### Purpose and Entry Point
Pulse is a Rust CLI for recording work activity and periodic “nudge” completions (such as water or stretching), then summarizing them for today or the current week. The executable starts in `src/main.rs`, parses commands through `src/cli.rs`, and routes them via `src/commands/mod.rs`.

#### Command Boundary
User-facing operations are organized as command handlers:
- Manual activity logging: `src/commands/log.rs`
- Daily and weekly reporting: `src/commands/today.rs`, `src/commands/week.rs`
- Nudge configuration inspection: `src/commands/config.rs`
- Installation-related behavior: `src/commands/install.rs`

CLI parsing is separated from command implementation, keeping argument interpretation in `src/cli.rs` and domain actions in the command modules.

#### Configuration Model
Nudge definitions are loaded from the user’s Pulse configuration, documented as `~/.config/pulse/config.toml`. `src/config.rs` owns configuration representation and loading; `src/commands/config.rs` exposes it to the CLI. Configured nudge names and intervals drive the recurring activity behavior rather than being hard-coded.

#### Persistent State and Logging
Pulse distinguishes durable application state from log operations:
- `src/state.rs` manages persisted state needed to determine nudge timing/completion.
- `src/log.rs` defines recording and retrieval of manual entries and completed nudges.
- `src/commands/log.rs` converts explicit user input into log records.

The reporting commands consume the combined log history: manual entries plus nudge completions.

#### Scheduling and Tick Flow
`src/tick.rs` represents the recurring evaluation cycle: it checks configured intervals against persisted state and determines when nudges should be handled or recorded. This is the core boundary between static configuration (`src/config.rs`), prior activity (`src/state.rs`), and runtime prompting/notification behavior.

#### Background Runtime / macOS Integration
Daemon support is isolated under `src/daemon/mod.rs`; `src/daemon/macos.rs` provides the macOS-specific implementation. This platform boundary allows the CLI and core scheduling/logging logic to remain separate from operating-system background execution mechanisms.

#### Primary Control Flow
1. `src/main.rs` starts Pulse and invokes CLI dispatch.
2. `src/cli.rs` selects a handler in `src/commands/`.
3. Logging commands write activity through `src/log.rs`; configuration and state are read as required.
4. Daemon/tick execution uses `src/tick.rs` with `src/config.rs` and `src/state.rs` to evaluate recurring nudges.
5. `today` and `week` commands query log data and present period-specific summaries.

Main entry points: [`src/commands/mod.rs`](https://github.com/hjiaxjason/pulse/blob/main/src/commands/mod.rs) (Command handlers), [`src/tick.rs`](https://github.com/hjiaxjason/pulse/blob/main/src/tick.rs) (Nudge evaluation), [`src/log.rs`](https://github.com/hjiaxjason/pulse/blob/main/src/log.rs) (Activity log), [`src/config.rs`](https://github.com/hjiaxjason/pulse/blob/main/src/config.rs) (Configuration loader)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cli["CLI &amp; Commands"]
  node_main["Pulse executable<br/>Rust entry point<br/>[main.rs]"]
  node_cli_parser["CLI parser &amp; dispatch<br/>command routing<br/>[cli.rs]"]
  node_commands["Command handlers<br/>command module<br/>[mod.rs]"]
  node_log_command["Manual logging<br/>command handler<br/>[log.rs]"]
  node_today_command["Today report<br/>command handler<br/>[today.rs]"]
  node_week_command["Week report<br/>command handler<br/>[week.rs]"]
  node_config_command["Config inspection<br/>command handler<br/>[config.rs]"]
  node_install_command["Installation behavior<br/>command handler<br/>[install.rs]"]
end

subgraph group_core["Core Data"]
  node_config_file["User nudge config<br/>TOML configuration"]
  node_config["Configuration loader<br/>config model<br/>[config.rs]"]
  node_state[("Persisted nudge state<br/>state management<br/>[state.rs]")]
  node_activity_log[("Activity log<br/>log storage API<br/>[log.rs]")]
end

subgraph group_runtime["Recurring Runtime"]
  node_tick{{"Nudge evaluation<br/>recurring scheduler<br/>[tick.rs]"}}
  node_daemon["Background daemon<br/>runtime boundary<br/>[mod.rs]"]
  node_macos_daemon["macOS daemon<br/>platform implementation<br/>[macos.rs]"]
end

node_main -->|"invokes"| node_cli_parser
node_cli_parser -->|"routes to"| node_commands
node_commands -->|"includes"| node_log_command
node_commands -->|"includes"| node_today_command
node_commands -->|"includes"| node_week_command
node_commands -->|"includes"| node_config_command
node_commands -->|"includes"| node_install_command
node_log_command -->|"writes entries"| node_activity_log
node_today_command -->|"queries"| node_activity_log
node_week_command -->|"queries"| node_activity_log
node_config_command -->|"reads"| node_config
node_config_file -->|"loaded by"| node_config
node_daemon -->|"runs"| node_tick
node_macos_daemon -->|"implements"| node_daemon
node_tick -->|"uses intervals"| node_config
node_tick -->|"checks and updates"| node_state
node_tick -->|"records completions"| node_activity_log

click node_main "https://github.com/hjiaxjason/pulse/blob/main/src/main.rs"
click node_cli_parser "https://github.com/hjiaxjason/pulse/blob/main/src/cli.rs"
click node_commands "https://github.com/hjiaxjason/pulse/blob/main/src/commands/mod.rs"
click node_log_command "https://github.com/hjiaxjason/pulse/blob/main/src/commands/log.rs"
click node_today_command "https://github.com/hjiaxjason/pulse/blob/main/src/commands/today.rs"
click node_week_command "https://github.com/hjiaxjason/pulse/blob/main/src/commands/week.rs"
click node_config_command "https://github.com/hjiaxjason/pulse/blob/main/src/commands/config.rs"
click node_install_command "https://github.com/hjiaxjason/pulse/blob/main/src/commands/install.rs"
click node_config "https://github.com/hjiaxjason/pulse/blob/main/src/config.rs"
click node_state "https://github.com/hjiaxjason/pulse/blob/main/src/state.rs"
click node_activity_log "https://github.com/hjiaxjason/pulse/blob/main/src/log.rs"
click node_tick "https://github.com/hjiaxjason/pulse/blob/main/src/tick.rs"
click node_daemon "https://github.com/hjiaxjason/pulse/blob/main/src/daemon/mod.rs"
click node_macos_daemon "https://github.com/hjiaxjason/pulse/blob/main/src/daemon/macos.rs"

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,node_cli_parser,node_commands,node_log_command,node_today_command,node_week_command,node_config_command,node_install_command toneBlue
class node_config_file,node_config,node_state,node_activity_log toneAmber
class node_tick,node_daemon,node_macos_daemon toneMint
```

## Components

### CLI & Commands

- [Pulse executable](https://github.com/hjiaxjason/pulse/blob/main/src/main.rs): Rust entry point · `src/main.rs`
- [CLI parser & dispatch](https://github.com/hjiaxjason/pulse/blob/main/src/cli.rs): command routing · `src/cli.rs`
- [Command handlers](https://github.com/hjiaxjason/pulse/blob/main/src/commands/mod.rs): command module · `src/commands/mod.rs`
- [Manual logging](https://github.com/hjiaxjason/pulse/blob/main/src/commands/log.rs): command handler · `src/commands/log.rs`
- [Today report](https://github.com/hjiaxjason/pulse/blob/main/src/commands/today.rs): command handler · `src/commands/today.rs`
- [Week report](https://github.com/hjiaxjason/pulse/blob/main/src/commands/week.rs): command handler · `src/commands/week.rs`
- [Config inspection](https://github.com/hjiaxjason/pulse/blob/main/src/commands/config.rs): command handler · `src/commands/config.rs`
- [Installation behavior](https://github.com/hjiaxjason/pulse/blob/main/src/commands/install.rs): command handler · `src/commands/install.rs`

### Core Data

- **User nudge config**: TOML configuration · Defines nudge names and intervals.
- [Configuration loader](https://github.com/hjiaxjason/pulse/blob/main/src/config.rs): config model · `src/config.rs`
- [Persisted nudge state](https://github.com/hjiaxjason/pulse/blob/main/src/state.rs): state management · Tracks timing and completion state. · `src/state.rs`
- [Activity log](https://github.com/hjiaxjason/pulse/blob/main/src/log.rs): log storage API · Records and retrieves manual entries and nudge completions. · `src/log.rs`

### Recurring Runtime

- [Nudge evaluation](https://github.com/hjiaxjason/pulse/blob/main/src/tick.rs): recurring scheduler · `src/tick.rs`
- [Background daemon](https://github.com/hjiaxjason/pulse/blob/main/src/daemon/mod.rs): runtime boundary · `src/daemon/mod.rs`
- [macOS daemon](https://github.com/hjiaxjason/pulse/blob/main/src/daemon/macos.rs): platform implementation · `src/daemon/macos.rs`

## Connections

- Pulse executable → CLI parser & dispatch: invokes
- CLI parser & dispatch → Command handlers: routes to
- Command handlers → Manual logging: includes
- Command handlers → Today report: includes
- Command handlers → Week report: includes
- Command handlers → Config inspection: includes
- Command handlers → Installation behavior: includes
- Manual logging → Activity log: writes entries
- Today report → Activity log: queries
- Week report → Activity log: queries
- Config inspection → Configuration loader: reads
- User nudge config → Configuration loader: loaded by
- Background daemon → Nudge evaluation: runs
- macOS daemon → Background daemon: implements
- Nudge evaluation → Configuration loader: uses intervals
- Nudge evaluation → Persisted nudge state: checks and updates
- Nudge evaluation → Activity log: records completions
