# mach4-braai/hum architecture

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

- Interactive diagram: https://gitdiagram.com/mach4-braai/hum
- Repository: https://github.com/mach4-braai/hum

## Overview

#### Purpose and executables
Hum is a local-first ambient-audio system for work-session lifecycle events. `hum` is the user/client CLI; `humd` is the long-running daemon that owns session state and audio output. Clients are tool-agnostic and communicate with the daemon through a local Unix-socket JSON protocol.
- `cmd/hum/main.go`
- `cmd/humd/main.go`
- `cmd/humd/daemon.go`

#### CLI client and process control
The `hum` command parses lifecycle, status, audio-control, theme, setup, diagnostics, and version commands; it connects to the daemon, sends protocol requests, and renders human or JSON output. It also includes daemon-management behavior such as starting/stopping and supervisor integration rather than embedding audio in the CLI.
- `cmd/hum/client.go`
- `cmd/hum/start.go`
- `cmd/hum/supervisor.go`

#### Daemon orchestration and ownership
`humd` wires configuration, socket transport, session registry, harmony allocation, theme loading, renderer/audio lifecycle, logging, and shutdown. This is the authoritative process for mutable session and output state; clients issue requests rather than directly manipulating audio.
- `cmd/humd/daemon.go`
- `cmd/humd/logging.go`
- `cmd/humd/main.go`

#### Local transport and wire boundary
The transport layer hosts the daemon endpoint and handles platform-specific socket behavior; the protocol package defines framing, requests, payloads, responses, and codec validation. This boundary permits any integration that can write line-delimited JSON, while keeping the daemon local. POSIX runtime directories/sockets are permission-restricted; Windows support is best-effort with differing socket security and signal behavior.
- `internal/transport/transport.go`
- `internal/transport/unix.go`
- `internal/protocol/protocol.go`
- `internal/protocol/codec.go`

#### Session lifecycle and harmony decisions
A registry manages live sessions and their lifecycle transitions: start creates sustained voices; completion/failure trigger distinct musical phrases before removal; cancellation stops without cadence; updates carry progress/metadata. The harmony engine allocates pitches from configured key/scale so simultaneous active sessions form chords.
- `internal/session/registry.go`
- `internal/session/session.go`
- `internal/harmony/engine.go`
- `internal/harmony/allocator.go`

#### Rendering and audio pipeline
Daemon events become renderer operations, with a renderer abstraction allowing implementations such as no-op output. The audio implementation synthesizes oscillators and phrases, mixes concurrent voices, and applies format/output behavior. Themes define the soundscape parameters used by this chain and can be swapped at runtime.
- `internal/renderer/renderer.go`
- `internal/audio/renderer.go`
- `internal/audio/mixer.go`
- `internal/theme/theme.go`

#### Configuration, deployment, and platform runtime
Configuration is loaded/resolved from configured locations and persisted for initialization/theme selection. Runtime paths centralize home, logs, runtime directory, and socket placement. Primary supported audio environments are macOS (AudioToolbox via pure Go) and Linux (ALSA, requiring headers/C toolchain); user-level service deployment is supplied for systemd and Homebrew packages provide macOS service operation.
- `internal/config/load.go`
- `internal/config/resolve.go`
- `internal/paths/paths.go`
- `contrib/systemd/humd.service`

Main entry points: [`cmd/humd/daemon.go`](https://github.com/mach4-braai/hum/blob/master/cmd/humd/daemon.go) (Daemon orchestrator), [`internal/session/registry.go`](https://github.com/mach4-braai/hum/blob/master/internal/session/registry.go) (Session registry), [`internal/transport/transport.go`](https://github.com/mach4-braai/hum/blob/master/internal/transport/transport.go) (Local socket endpoint), [`cmd/hum/client.go`](https://github.com/mach4-braai/hum/blob/master/cmd/hum/client.go) (CLI protocol client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Client control"]
  node_hum["hum CLI<br/>Go executable<br/>[main.go]"]
  node_client["CLI protocol client<br/>client control<br/>[client.go]"]
  node_process_control["Daemon process control<br/>supervision<br/>[supervisor.go]"]
end

subgraph group_daemon["Daemon core"]
  node_humd["humd daemon<br/>Go executable<br/>[main.go]"]
  node_daemon_orchestrator["Daemon orchestrator<br/>composition root<br/>[daemon.go]"]
  node_transport{{"Local socket endpoint<br/>Unix-socket transport<br/>[transport.go]"}}
  node_protocol["JSON wire protocol<br/>protocol codec<br/>[protocol.go]"]
  node_registry["Session registry<br/>lifecycle state<br/>[registry.go]"]
  node_harmony["Harmony allocator<br/>pitch allocation<br/>[allocator.go]"]
end

subgraph group_audio["Audio pipeline"]
  node_renderer["Renderer abstraction<br/>render interface<br/>[renderer.go]"]
  node_audio_renderer["Audio renderer<br/>synthesis engine<br/>[renderer.go]"]
  node_mixer["Concurrent voice mixer<br/>audio mix<br/>[mixer.go]"]
  node_themes["Themes<br/>soundscape settings<br/>[theme.go]"]
end

subgraph group_runtime["Runtime &amp; deployment"]
  node_config["Configuration<br/>load and resolve<br/>[load.go]"]
  node_paths["Runtime paths<br/>platform paths<br/>[paths.go]"]
  node_systemd["systemd user service<br/>deployment unit<br/>[humd.service]"]
end

node_hum -->|"invokes"| node_client
node_hum -->|"manages daemon"| node_process_control
node_client -->|"encodes requests"| node_protocol
node_client -->|"connects locally"| node_transport
node_process_control -->|"starts/stops"| node_humd
node_humd -->|"runs"| node_daemon_orchestrator
node_daemon_orchestrator -->|"hosts"| node_transport
node_transport -->|"decodes/encodes"| node_protocol
node_protocol -->|"lifecycle requests"| node_registry
node_daemon_orchestrator -->|"owns"| node_registry
node_registry -->|"allocates active pitches"| node_harmony
node_registry -->|"emits lifecycle events"| node_renderer
node_daemon_orchestrator -->|"loads and swaps"| node_themes
node_themes -->|"sound parameters"| node_renderer
node_renderer -->|"audio implementation"| node_audio_renderer
node_audio_renderer -->|"produces voices"| node_mixer
node_daemon_orchestrator -->|"loads settings"| node_config
node_config -->|"resolves locations"| node_paths
node_paths -->|"socket location"| node_transport
node_systemd -->|"runs as user service"| node_humd

click node_hum "https://github.com/mach4-braai/hum/blob/master/cmd/hum/main.go"
click node_client "https://github.com/mach4-braai/hum/blob/master/cmd/hum/client.go"
click node_process_control "https://github.com/mach4-braai/hum/blob/master/cmd/hum/supervisor.go"
click node_humd "https://github.com/mach4-braai/hum/blob/master/cmd/humd/main.go"
click node_daemon_orchestrator "https://github.com/mach4-braai/hum/blob/master/cmd/humd/daemon.go"
click node_transport "https://github.com/mach4-braai/hum/blob/master/internal/transport/transport.go"
click node_protocol "https://github.com/mach4-braai/hum/blob/master/internal/protocol/protocol.go"
click node_registry "https://github.com/mach4-braai/hum/blob/master/internal/session/registry.go"
click node_harmony "https://github.com/mach4-braai/hum/blob/master/internal/harmony/allocator.go"
click node_renderer "https://github.com/mach4-braai/hum/blob/master/internal/renderer/renderer.go"
click node_audio_renderer "https://github.com/mach4-braai/hum/blob/master/internal/audio/renderer.go"
click node_mixer "https://github.com/mach4-braai/hum/blob/master/internal/audio/mixer.go"
click node_themes "https://github.com/mach4-braai/hum/blob/master/internal/theme/theme.go"
click node_config "https://github.com/mach4-braai/hum/blob/master/internal/config/load.go"
click node_paths "https://github.com/mach4-braai/hum/blob/master/internal/paths/paths.go"
click node_systemd "https://github.com/mach4-braai/hum/blob/master/contrib/systemd/humd.service"

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_hum,node_client,node_process_control toneBlue
class node_humd,node_daemon_orchestrator,node_transport,node_protocol,node_registry,node_harmony toneAmber
class node_renderer,node_audio_renderer,node_mixer,node_themes toneMint
class node_config,node_paths,node_systemd toneRose
```

## Components

### Client control

- [hum CLI](https://github.com/mach4-braai/hum/blob/master/cmd/hum/main.go): Go executable · Tool-agnostic client for lifecycle and control commands. · `cmd/hum/main.go`
- [CLI protocol client](https://github.com/mach4-braai/hum/blob/master/cmd/hum/client.go): client control · Sends daemon requests and renders human or JSON responses. · `cmd/hum/client.go`
- [Daemon process control](https://github.com/mach4-braai/hum/blob/master/cmd/hum/supervisor.go): supervision · Starts, stops, and integrates humd with supervisors. · `cmd/hum/supervisor.go`

### Daemon core

- [humd daemon](https://github.com/mach4-braai/hum/blob/master/cmd/humd/main.go): Go executable · Authoritative owner of mutable sessions and audio output. · `cmd/humd/main.go`
- [Daemon orchestrator](https://github.com/mach4-braai/hum/blob/master/cmd/humd/daemon.go): composition root · Wires transport, state, themes, rendering, and shutdown. · `cmd/humd/daemon.go`
- [Local socket endpoint](https://github.com/mach4-braai/hum/blob/master/internal/transport/transport.go): Unix-socket transport · Hosts the local daemon endpoint with platform-specific behavior. · `internal/transport/transport.go`
- [JSON wire protocol](https://github.com/mach4-braai/hum/blob/master/internal/protocol/protocol.go): protocol codec · Defines line-delimited JSON requests, responses, framing, and validation. · `internal/protocol/protocol.go`
- [Session registry](https://github.com/mach4-braai/hum/blob/master/internal/session/registry.go): lifecycle state · Tracks live sessions and completion, failure, cancellation, and update transitions. · `internal/session/registry.go`
- [Harmony allocator](https://github.com/mach4-braai/hum/blob/master/internal/harmony/allocator.go): pitch allocation · Selects key/scale pitches so active sessions form chords. · `internal/harmony/allocator.go`

### Audio pipeline

- [Renderer abstraction](https://github.com/mach4-braai/hum/blob/master/internal/renderer/renderer.go): render interface · Converts daemon events into output operations and permits no-op output. · `internal/renderer/renderer.go`
- [Audio renderer](https://github.com/mach4-braai/hum/blob/master/internal/audio/renderer.go): synthesis engine · Synthesizes sustained voices and lifecycle phrases. · `internal/audio/renderer.go`
- [Concurrent voice mixer](https://github.com/mach4-braai/hum/blob/master/internal/audio/mixer.go): audio mix · Mixes simultaneous oscillator voices for output. · `internal/audio/mixer.go`
- [Themes](https://github.com/mach4-braai/hum/blob/master/internal/theme/theme.go): soundscape settings · Defines runtime-swappable soundscape parameters. · `internal/theme/theme.go`

### Runtime & deployment

- [Configuration](https://github.com/mach4-braai/hum/blob/master/internal/config/load.go): load and resolve · Loads persisted initialization and theme-selection settings. · `internal/config/load.go`
- [Runtime paths](https://github.com/mach4-braai/hum/blob/master/internal/paths/paths.go): platform paths · Centralizes home, logs, runtime directory, and socket locations. · `internal/paths/paths.go`
- [systemd user service](https://github.com/mach4-braai/hum/blob/master/contrib/systemd/humd.service): deployment unit · Supplies Linux user-level humd deployment. · `contrib/systemd/humd.service`

## Connections

- hum CLI → CLI protocol client: invokes
- hum CLI → Daemon process control: manages daemon
- CLI protocol client → JSON wire protocol: encodes requests
- CLI protocol client → Local socket endpoint: connects locally
- Daemon process control → humd daemon: starts/stops
- humd daemon → Daemon orchestrator: runs
- Daemon orchestrator → Local socket endpoint: hosts
- Local socket endpoint → JSON wire protocol: decodes/encodes
- JSON wire protocol → Session registry: lifecycle requests
- Daemon orchestrator → Session registry: owns
- Session registry → Harmony allocator: allocates active pitches
- Session registry → Renderer abstraction: emits lifecycle events
- Daemon orchestrator → Themes: loads and swaps
- Themes → Renderer abstraction: sound parameters
- Renderer abstraction → Audio renderer: audio implementation
- Audio renderer → Concurrent voice mixer: produces voices
- Daemon orchestrator → Configuration: loads settings
- Configuration → Runtime paths: resolves locations
- Runtime paths → Local socket endpoint: socket location
- systemd user service → humd daemon: runs as user service
