# crazydw4rf/caffeinate architecture

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

- Interactive diagram: https://gitdiagram.com/crazydw4rf/caffeinate
- Repository: https://github.com/crazydw4rf/caffeinate

## Overview

caffeinate is a small Rust daemon that watches PipeWire node activity and holds a systemd-logind idle inhibitor while audio is running. The workflow is single-instance startup, audio-state detection, then acquiring or releasing the inhibitor. Runtime behavior is implemented in src/main.rs; no separate modules are present.

Main entry points: [`src/main.rs`](https://github.com/crazydw4rf/caffeinate/blob/main/src/main.rs) (Caffeinate runtime)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_monitoring["Audio monitoring"]
  node_caffeinate["Caffeinate runtime<br/>[main.rs]"]
  node_pipewire["PipeWire"]
  node_node_listener["Node state listener<br/>[main.rs]"]
end

subgraph group_inhibition["Idle inhibition"]
  node_state_channel["Audio state channel<br/>[main.rs]"]
  node_inhibit_worker["Inhibit worker<br/>[main.rs]"]
  node_inhibit_fd["Inhibitor file descriptor<br/>[main.rs]"]
end

subgraph group_system["System interfaces"]
  node_single_instance["Instance lock<br/>[main.rs]"]
  node_lock_file["Lock file"]
  node_logind["systemd-logind"]
end

node_user(("User"))
node_app(("Audio playback"))

node_user -->|"starts"| node_caffeinate
node_caffeinate -->|"checks instance"| node_single_instance
node_single_instance -->|"locks"| node_lock_file
node_app -->|"creates audio nodes"| node_pipewire
node_caffeinate -->|"connects and registers"| node_pipewire
node_pipewire -->|"reports node states"| node_node_listener
node_node_listener -->|"sends audio state"| node_state_channel
node_state_channel -->|"delivers state"| node_inhibit_worker
node_inhibit_worker -->|"requests idle inhibitor"| node_logind
node_logind -->|"returns descriptor"| node_inhibit_fd
node_inhibit_worker -->|"holds or releases"| node_inhibit_fd

click node_caffeinate "https://github.com/crazydw4rf/caffeinate/blob/main/src/main.rs"
click node_single_instance "https://github.com/crazydw4rf/caffeinate/blob/main/src/main.rs"
click node_node_listener "https://github.com/crazydw4rf/caffeinate/blob/main/src/main.rs"
click node_state_channel "https://github.com/crazydw4rf/caffeinate/blob/main/src/main.rs"
click node_inhibit_worker "https://github.com/crazydw4rf/caffeinate/blob/main/src/main.rs"
click node_inhibit_fd "https://github.com/crazydw4rf/caffeinate/blob/main/src/main.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_caffeinate,node_pipewire,node_node_listener,node_user toneBlue
class node_state_channel,node_inhibit_worker,node_inhibit_fd toneAmber
class node_single_instance,node_lock_file,node_logind toneMint
class node_app toneIndigo
```

## Components

### Audio monitoring

- [Caffeinate runtime](https://github.com/crazydw4rf/caffeinate/blob/main/src/main.rs): `src/main.rs`
- **PipeWire**
- [Node state listener](https://github.com/crazydw4rf/caffeinate/blob/main/src/main.rs): `src/main.rs`

### Idle inhibition

- [Audio state channel](https://github.com/crazydw4rf/caffeinate/blob/main/src/main.rs): `src/main.rs`
- [Inhibit worker](https://github.com/crazydw4rf/caffeinate/blob/main/src/main.rs): `src/main.rs`
- [Inhibitor file descriptor](https://github.com/crazydw4rf/caffeinate/blob/main/src/main.rs): `src/main.rs`

### System interfaces

- [Instance lock](https://github.com/crazydw4rf/caffeinate/blob/main/src/main.rs): `src/main.rs`
- **Lock file**
- **systemd-logind**

### Other components

- **User**
- **Audio playback**

## Connections

- User → Caffeinate runtime: starts
- Caffeinate runtime → Instance lock: checks instance
- Instance lock → Lock file: locks
- Audio playback → PipeWire: creates audio nodes
- Caffeinate runtime → PipeWire: connects and registers
- PipeWire → Node state listener: reports node states
- Node state listener → Audio state channel: sends audio state
- Audio state channel → Inhibit worker: delivers state
- Inhibit worker → systemd-logind: requests idle inhibitor
- systemd-logind → Inhibitor file descriptor: returns descriptor
- Inhibit worker → Inhibitor file descriptor: holds or releases
