# kanav14/ai-workload architecture

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

- Interactive diagram: https://gitdiagram.com/kanav14/ai-workload
- Repository: https://github.com/kanav14/ai-workload

## Overview

ai-workload is a two-Mac LLM inference router that chooses a host based on swap pressure, exposes generation and status endpoints, and provides a dashboard. Its principal request flow measures swap, selects a Mac, and forwards a chat-completion request to that Mac’s llama.cpp server. Separately, a coordinator starts and monitors both servers, while an experiment runner benchmarks routing and records system conditions. The API and coordinator implement separate routing decisions. The empty system_monitor.py and unsampled data files are not expanded; source evidence limits other inferred connections.

Main entry points: [`api.py`](https://github.com/kanav14/ai-workload/blob/main/api.py) (Generation and status API), [`experiment.py`](https://github.com/kanav14/ai-workload/blob/main/experiment.py) (Benchmark runner), [`coordinator.py`](https://github.com/kanav14/ai-workload/blob/main/coordinator.py) (Server lifecycle and monitor), [`rebalancer.py`](https://github.com/kanav14/ai-workload/blob/main/rebalancer.py) (Swap rebalancer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_serving["Serving and dashboard"]
  node_api["Generation and status API<br/>[api.py]"]
  node_dashboard["Live dashboard<br/>[api.py]"]
  node_local_swap["Local swap probe<br/>[api.py]"]
  node_remote_swap["Remote swap probe<br/>[api.py]"]
end

subgraph group_coordination["Node coordination"]
  node_coordinator["Server lifecycle and monitor<br/>[coordinator.py]"]
  node_rebalancer["Swap rebalancer<br/>[rebalancer.py]"]
end

subgraph group_evaluation["Benchmarking"]
  node_experiment["Benchmark runner<br/>[experiment.py]"]
end

subgraph group_state["Runtime records"]
  node_routing_log[("Routing log<br/>[routing_log.csv]")]
  node_experiment_log[("Experiment results")]
  node_system_log[("System measurements<br/>[system_log.csv]")]
end

node_client(("Generation client"))
node_local_os["Mac 1 macOS"]
node_remote_mac["Mac 2 over SSH"]
node_llama_servers["llama.cpp servers"]

node_client -->|"submits prompt"| node_api
node_api -->|"measures swap"| node_local_swap
node_api -->|"measures swap"| node_remote_swap
node_local_swap -->|"runs sysctl"| node_local_os
node_remote_swap -->|"runs SSH probe"| node_remote_mac
node_api -->|"routes completion"| node_llama_servers
node_llama_servers -->|"returns completion"| node_api
node_dashboard -->|"fetches status"| node_api
node_api -->|"reads event count"| node_routing_log
node_coordinator -->|"probes swap"| node_local_os
node_coordinator -->|"probes and starts server"| node_remote_mac
node_coordinator -->|"starts servers"| node_llama_servers
node_coordinator -->|"checks and chooses node"| node_rebalancer
node_rebalancer -->|"writes decision"| node_routing_log
node_experiment -->|"measures swap and temperature"| node_local_os
node_experiment -->|"probes swap over SSH"| node_remote_mac
node_experiment -->|"sends benchmark request"| node_llama_servers
node_experiment -->|"appends run results"| node_experiment_log
node_experiment -->|"appends measurements"| node_system_log

click node_api "https://github.com/kanav14/ai-workload/blob/main/api.py"
click node_dashboard "https://github.com/kanav14/ai-workload/blob/main/api.py"
click node_local_swap "https://github.com/kanav14/ai-workload/blob/main/api.py"
click node_remote_swap "https://github.com/kanav14/ai-workload/blob/main/api.py"
click node_coordinator "https://github.com/kanav14/ai-workload/blob/main/coordinator.py"
click node_rebalancer "https://github.com/kanav14/ai-workload/blob/main/rebalancer.py"
click node_experiment "https://github.com/kanav14/ai-workload/blob/main/experiment.py"
click node_routing_log "https://github.com/kanav14/ai-workload/blob/main/data/routing_log.csv"
click node_experiment_log "https://github.com/kanav14/ai-workload/blob/main/data/experiment_results.csv"
click node_system_log "https://github.com/kanav14/ai-workload/blob/main/data/system_log.csv"

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_api,node_dashboard,node_local_swap,node_remote_swap,node_client toneBlue
class node_coordinator,node_rebalancer toneAmber
class node_experiment,node_llama_servers toneMint
class node_routing_log,node_experiment_log,node_system_log toneRose
class node_local_os,node_remote_mac toneIndigo
```

## Components

### Serving and dashboard

- [Generation and status API](https://github.com/kanav14/ai-workload/blob/main/api.py): `api.py`
- [Live dashboard](https://github.com/kanav14/ai-workload/blob/main/api.py): `api.py`
- [Local swap probe](https://github.com/kanav14/ai-workload/blob/main/api.py): `api.py`
- [Remote swap probe](https://github.com/kanav14/ai-workload/blob/main/api.py): `api.py`

### Node coordination

- [Server lifecycle and monitor](https://github.com/kanav14/ai-workload/blob/main/coordinator.py): `coordinator.py`
- [Swap rebalancer](https://github.com/kanav14/ai-workload/blob/main/rebalancer.py): `rebalancer.py`

### Benchmarking

- [Benchmark runner](https://github.com/kanav14/ai-workload/blob/main/experiment.py): `experiment.py`

### Runtime records

- [Routing log](https://github.com/kanav14/ai-workload/blob/main/data/routing_log.csv): `data/routing_log.csv`
- [Experiment results](https://github.com/kanav14/ai-workload/blob/main/data/experiment_results.csv): `data/experiment_results.csv`
- [System measurements](https://github.com/kanav14/ai-workload/blob/main/data/system_log.csv): `data/system_log.csv`

### Other components

- **Generation client**
- **Mac 1 macOS**
- **Mac 2 over SSH**
- **llama.cpp servers**

## Connections

- Generation client → Generation and status API: submits prompt (evidence: `api.py`)
- Generation and status API → Local swap probe: measures swap (evidence: `api.py`)
- Generation and status API → Remote swap probe: measures swap (evidence: `api.py`)
- Local swap probe → Mac 1 macOS: runs sysctl (evidence: `api.py`)
- Remote swap probe → Mac 2 over SSH: runs SSH probe (evidence: `api.py`)
- Generation and status API → llama.cpp servers: routes completion (evidence: `api.py`)
- llama.cpp servers → Generation and status API: returns completion (evidence: `api.py`)
- Live dashboard → Generation and status API: fetches status (evidence: `api.py`)
- Generation and status API → Routing log: reads event count (evidence: `api.py`)
- Server lifecycle and monitor → Mac 1 macOS: probes swap (evidence: `coordinator.py`)
- Server lifecycle and monitor → Mac 2 over SSH: probes and starts server (evidence: `coordinator.py`)
- Server lifecycle and monitor → llama.cpp servers: starts servers (evidence: `coordinator.py`)
- Server lifecycle and monitor → Swap rebalancer: checks and chooses node (evidence: `coordinator.py`)
- Swap rebalancer → Routing log: writes decision (evidence: `rebalancer.py`)
- Benchmark runner → Mac 1 macOS: measures swap and temperature (evidence: `experiment.py`)
- Benchmark runner → Mac 2 over SSH: probes swap over SSH (evidence: `experiment.py`)
- Benchmark runner → llama.cpp servers: sends benchmark request (evidence: `experiment.py`)
- Benchmark runner → Experiment results: appends run results (evidence: `experiment.py`)
- Benchmark runner → System measurements: appends measurements (evidence: `experiment.py`)
