# aronpc/ai-traffic-lights architecture

> Architecture diagram of the GitHub repository aronpc/ai-traffic-lights, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/aronpc/ai-traffic-lights
- Repository: https://github.com/aronpc/ai-traffic-lights

## Overview

AI Traffic Lights is an Electron desktop overlay for monitoring terminal-based AI-agent sessions. Agent hooks and adapters publish session state; the main process collects and merges it, then supplies the renderer with per-session and aggregate status. The graph also preserves documented capabilities for focus, alerts, usage, preferences, launching, updates, and opt-in multi-machine sync. Several implementation files were not excerpted, so those branches use README evidence; unverified internal calls are omitted.

Main entry points: [`main.js`](https://github.com/aronpc/ai-traffic-lights/blob/main/main.js) (Electron main), [`src/renderer.js`](https://github.com/aronpc/ai-traffic-lights/blob/main/src/renderer.js) (Traffic-light overlay), [`src/collect.js`](https://github.com/aronpc/ai-traffic-lights/blob/main/src/collect.js) (Session collector), [`src/settings-renderer.js`](https://github.com/aronpc/ai-traffic-lights/blob/main/src/settings-renderer.js) (Preferences UI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_capture["Session capture"]
  node_adapters["Agent adapters"]
  node_state_writer["State writer<br/>[state-writer.js]"]
  node_state_files[("Session state files")]
end

subgraph group_runtime["Monitoring runtime"]
  node_collector["Session collector<br/>[collect.js]"]
  node_session_merge["Session merge<br/>[sessions.js]"]
  node_identity["Session identity<br/>[identity.js]"]
  node_main_process["Electron main<br/>[main.js]"]
end

subgraph group_experience["Overlay experience"]
  node_overlay["Traffic-light overlay<br/>[renderer.js]"]
  node_terminal_focus["Terminal focus<br/>[focus.js]"]
  node_transcripts["Transcript lookup<br/>[transcript.js]"]
  node_usage["Usage meters<br/>[usage.js]"]
  node_alerts["State and alerts<br/>[state-machine.js]"]
end

subgraph group_controls["Controls and settings"]
  node_preferences["Preferences UI"]
  node_settings["Settings logic<br/>[settings.js]"]
  node_quick_launcher["Quick launcher<br/>[launcher.js]"]
  node_hook_setup["Hook installer<br/>[hook-installer.js]"]
  node_update_check["Update check<br/>[update.js]"]
end

subgraph group_sync["Peer sync"]
  node_sync_transport["Peer transport<br/>[net.js]"]
  node_headless_agent["Headless sync agent<br/>[agent.js]"]
end

node_agent_sessions(("Agent sessions"))

node_agent_sessions -->|"emit events"| node_adapters
node_adapters -->|"write state"| node_state_writer
node_state_writer -->|"persist state"| node_state_files
node_state_files -->|"read state"| node_collector
node_collector -->|"merge sessions"| node_session_merge
node_session_merge -->|"key sessions"| node_identity
node_main_process -->|"collect sessions"| node_collector
node_main_process -->|"send session state"| node_overlay
node_overlay -->|"request focus"| node_terminal_focus
node_main_process -->|"fetch transcripts"| node_transcripts
node_main_process -->|"collect usage"| node_usage
node_main_process -.->|"derive status"| node_alerts
node_overlay -->|"open preferences"| node_preferences
node_preferences -->|"edit settings"| node_settings
node_overlay -->|"launch agent"| node_quick_launcher
node_preferences -->|"manage hooks"| node_hook_setup
node_main_process -->|"check updates"| node_update_check
node_main_process -->|"serve and poll peers"| node_sync_transport
node_headless_agent -->|"collect local sessions"| node_collector
node_headless_agent -->|"start peer server"| node_sync_transport

click node_adapters "https://github.com/aronpc/ai-traffic-lights/tree/main/adapters"
click node_state_writer "https://github.com/aronpc/ai-traffic-lights/blob/main/src/state-writer.js"
click node_collector "https://github.com/aronpc/ai-traffic-lights/blob/main/src/collect.js"
click node_session_merge "https://github.com/aronpc/ai-traffic-lights/blob/main/src/sessions.js"
click node_identity "https://github.com/aronpc/ai-traffic-lights/blob/main/src/identity.js"
click node_main_process "https://github.com/aronpc/ai-traffic-lights/blob/main/main.js"
click node_overlay "https://github.com/aronpc/ai-traffic-lights/blob/main/src/renderer.js"
click node_terminal_focus "https://github.com/aronpc/ai-traffic-lights/blob/main/src/ipc/focus.js"
click node_transcripts "https://github.com/aronpc/ai-traffic-lights/blob/main/src/transcript.js"
click node_usage "https://github.com/aronpc/ai-traffic-lights/blob/main/src/usage.js"
click node_alerts "https://github.com/aronpc/ai-traffic-lights/blob/main/src/state-machine.js"
click node_preferences "https://github.com/aronpc/ai-traffic-lights/blob/main/src/settings-renderer.js"
click node_settings "https://github.com/aronpc/ai-traffic-lights/blob/main/src/settings.js"
click node_quick_launcher "https://github.com/aronpc/ai-traffic-lights/blob/main/src/launcher.js"
click node_hook_setup "https://github.com/aronpc/ai-traffic-lights/blob/main/src/hook-installer.js"
click node_update_check "https://github.com/aronpc/ai-traffic-lights/blob/main/src/ipc/update.js"
click node_sync_transport "https://github.com/aronpc/ai-traffic-lights/blob/main/src/net.js"
click node_headless_agent "https://github.com/aronpc/ai-traffic-lights/blob/main/agent.js"

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_adapters,node_state_writer,node_state_files toneBlue
class node_collector,node_session_merge,node_identity,node_main_process toneAmber
class node_overlay,node_terminal_focus,node_transcripts,node_usage,node_alerts toneMint
class node_preferences,node_settings,node_quick_launcher,node_hook_setup,node_update_check toneRose
class node_sync_transport,node_headless_agent,node_agent_sessions toneIndigo
```

## Components

### Session capture

- [Agent adapters](https://github.com/aronpc/ai-traffic-lights/tree/main/adapters): `adapters`
- [State writer](https://github.com/aronpc/ai-traffic-lights/blob/main/src/state-writer.js): `src/state-writer.js`
- **Session state files**

### Monitoring runtime

- [Session collector](https://github.com/aronpc/ai-traffic-lights/blob/main/src/collect.js): `src/collect.js`
- [Session merge](https://github.com/aronpc/ai-traffic-lights/blob/main/src/sessions.js): `src/sessions.js`
- [Session identity](https://github.com/aronpc/ai-traffic-lights/blob/main/src/identity.js): `src/identity.js`
- [Electron main](https://github.com/aronpc/ai-traffic-lights/blob/main/main.js): `main.js`

### Overlay experience

- [Traffic-light overlay](https://github.com/aronpc/ai-traffic-lights/blob/main/src/renderer.js): `src/renderer.js`
- [Terminal focus](https://github.com/aronpc/ai-traffic-lights/blob/main/src/ipc/focus.js): `src/ipc/focus.js`
- [Transcript lookup](https://github.com/aronpc/ai-traffic-lights/blob/main/src/transcript.js): `src/transcript.js`
- [Usage meters](https://github.com/aronpc/ai-traffic-lights/blob/main/src/usage.js): `src/usage.js`
- [State and alerts](https://github.com/aronpc/ai-traffic-lights/blob/main/src/state-machine.js): `src/state-machine.js`

### Controls and settings

- [Preferences UI](https://github.com/aronpc/ai-traffic-lights/blob/main/src/settings-renderer.js): `src/settings-renderer.js`
- [Settings logic](https://github.com/aronpc/ai-traffic-lights/blob/main/src/settings.js): `src/settings.js`
- [Quick launcher](https://github.com/aronpc/ai-traffic-lights/blob/main/src/launcher.js): `src/launcher.js`
- [Hook installer](https://github.com/aronpc/ai-traffic-lights/blob/main/src/hook-installer.js): `src/hook-installer.js`
- [Update check](https://github.com/aronpc/ai-traffic-lights/blob/main/src/ipc/update.js): `src/ipc/update.js`

### Peer sync

- [Peer transport](https://github.com/aronpc/ai-traffic-lights/blob/main/src/net.js): `src/net.js`
- [Headless sync agent](https://github.com/aronpc/ai-traffic-lights/blob/main/agent.js): `agent.js`

### Other components

- **Agent sessions**

## Connections

- Agent sessions → Agent adapters: emit events (evidence: `README.md`)
- Agent adapters → State writer: write state (evidence: `adapters/kiro/ai-traffic-lights.js`)
- State writer → Session state files: persist state
- Session state files → Session collector: read state (evidence: `README.md`)
- Session collector → Session merge: merge sessions (evidence: `src/collect.js`)
- Session merge → Session identity: key sessions (evidence: `src/sessions.js`)
- Electron main → Session collector: collect sessions (evidence: `main.js`)
- Electron main → Traffic-light overlay: send session state (evidence: `README.md`)
- Traffic-light overlay → Terminal focus: request focus (evidence: `README.md`)
- Electron main → Transcript lookup: fetch transcripts (evidence: `main.js`)
- Electron main → Usage meters: collect usage (evidence: `main.js`)
- Electron main → State and alerts: derive status
- Traffic-light overlay → Preferences UI: open preferences (evidence: `README.md`)
- Preferences UI → Settings logic: edit settings (evidence: `src/settings.js`)
- Traffic-light overlay → Quick launcher: launch agent (evidence: `README.md`)
- Preferences UI → Hook installer: manage hooks (evidence: `README.md`)
- Electron main → Update check: check updates (evidence: `main.js`)
- Electron main → Peer transport: serve and poll peers (evidence: `main.js`)
- Headless sync agent → Session collector: collect local sessions (evidence: `agent.js`)
- Headless sync agent → Peer transport: start peer server (evidence: `agent.js`)
