# smlfg/the-farmer-was-replaced architecture

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

- Interactive diagram: https://gitdiagram.com/smlfg/the-farmer-was-replaced
- Repository: https://github.com/smlfg/the-farmer-was-replaced

## Overview

This is a local spoken learning companion for The Farmer Was Replaced. Its main workflow is to detect the game session, observe saved code and (when available) the game window, combine that context with spoken questions or runtime errors, generate a teaching response, and speak it while maintaining learning progress. The core watcher and RPC orchestration in tutor.py is only partially excerpted, so undocumented internal call links are omitted; README-described capabilities are retained.

Main entry points: [`tutor.py`](https://github.com/smlfg/the-farmer-was-replaced/blob/main/tutor.py) (Session watcher), [`offline_tutor.py`](https://github.com/smlfg/the-farmer-was-replaced/blob/main/offline_tutor.py) (Offline tutor fallback), [`ptt.swift`](https://github.com/smlfg/the-farmer-was-replaced/blob/main/ptt.swift) (Push-to-talk listener), [`konzepte.py`](https://github.com/smlfg/the-farmer-was-replaced/blob/main/konzepte.py) (Concept map)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Tutor runtime"]
  node_watcher["Session watcher<br/>[tutor.py]"]
  node_game_state["Code and save reader<br/>[tutor.py]"]
  node_screen["Game screenshot capture<br/>[tutor.py]"]
  node_observation["Observation builder<br/>[tutor.py]"]
  node_response["Response and lesson parser<br/>[tutor.py]"]
  node_manual["Tutor commands<br/>[tutor.py]"]
end

subgraph group_learning["Learning support"]
  node_concepts["Concept map<br/>[konzepte.py]"]
  node_practice["Practice streak<br/>[konzepte.py]"]
  node_curriculum["Daily lesson plan<br/>[konzepte.py]"]
  node_notebook["Tutor notebook<br/>[tutor.py]"]
end

subgraph group_voice["Voice interaction"]
  node_speech["Speech playback<br/>[tutor.py]"]
  node_ptt["Push-to-talk listener<br/>[ptt.swift]"]
  node_transcribe["Local transcription<br/>[tutor.py]"]
end

subgraph group_providers["Tutor providers"]
  node_pi_rpc["Pi RPC tutor<br/>[tutor.py]"]
  node_offline["Offline tutor fallback<br/>[offline_tutor.py]"]
  node_hint["Rule-based hint<br/>[offline_tutor.py]"]
end

node_learner(("Learner"))
node_game["Game session"]
node_ollama["Loopback Ollama"]
node_cloud["MiniMax API"]
node_piper["Piper Thorsten"]

node_learner -->|"holds key"| node_ptt
node_ptt -->|"signals key"| node_transcribe
node_transcribe -->|"supplies question"| node_watcher
node_learner -->|"sends commands"| node_manual
node_game -->|"session detected"| node_watcher
node_watcher -->|"reads saved files"| node_game_state
node_watcher -->|"captures window"| node_screen
node_watcher -.->|"assembles context"| node_observation
node_game -->|"provides runtime errors"| node_observation
node_observation -->|"requests analysis"| node_pi_rpc
node_pi_rpc -->|"sends tutor request"| node_cloud
node_pi_rpc -->|"falls back"| node_offline
node_offline -->|"requests local model"| node_ollama
node_offline -->|"falls back"| node_hint
node_pi_rpc -.->|"returns tutor text"| node_response
node_response -.->|"queues lesson"| node_speech
node_speech -->|"speaks text"| node_piper
node_watcher -->|"updates progress"| node_concepts
node_watcher -.->|"records activity"| node_practice
node_watcher -.->|"loads lesson"| node_curriculum
node_watcher -->|"persists teaching context"| node_notebook
node_response -->|"updates notes"| node_notebook

click node_watcher "https://github.com/smlfg/the-farmer-was-replaced/blob/main/tutor.py"
click node_game_state "https://github.com/smlfg/the-farmer-was-replaced/blob/main/tutor.py"
click node_screen "https://github.com/smlfg/the-farmer-was-replaced/blob/main/tutor.py"
click node_observation "https://github.com/smlfg/the-farmer-was-replaced/blob/main/tutor.py"
click node_pi_rpc "https://github.com/smlfg/the-farmer-was-replaced/blob/main/tutor.py"
click node_response "https://github.com/smlfg/the-farmer-was-replaced/blob/main/tutor.py"
click node_speech "https://github.com/smlfg/the-farmer-was-replaced/blob/main/tutor.py"
click node_ptt "https://github.com/smlfg/the-farmer-was-replaced/blob/main/ptt.swift"
click node_transcribe "https://github.com/smlfg/the-farmer-was-replaced/blob/main/tutor.py"
click node_manual "https://github.com/smlfg/the-farmer-was-replaced/blob/main/tutor.py"
click node_offline "https://github.com/smlfg/the-farmer-was-replaced/blob/main/offline_tutor.py"
click node_hint "https://github.com/smlfg/the-farmer-was-replaced/blob/main/offline_tutor.py"
click node_concepts "https://github.com/smlfg/the-farmer-was-replaced/blob/main/konzepte.py"
click node_practice "https://github.com/smlfg/the-farmer-was-replaced/blob/main/konzepte.py"
click node_curriculum "https://github.com/smlfg/the-farmer-was-replaced/blob/main/konzepte.py"
click node_notebook "https://github.com/smlfg/the-farmer-was-replaced/blob/main/tutor.py"

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_watcher,node_game_state,node_screen,node_observation,node_response,node_manual toneBlue
class node_concepts,node_practice,node_curriculum,node_notebook toneAmber
class node_speech,node_ptt,node_transcribe,node_cloud toneMint
class node_pi_rpc,node_offline,node_hint toneRose
class node_learner,node_game,node_ollama,node_piper toneIndigo
```

## Components

### Tutor runtime

- [Session watcher](https://github.com/smlfg/the-farmer-was-replaced/blob/main/tutor.py): `tutor.py`
- [Code and save reader](https://github.com/smlfg/the-farmer-was-replaced/blob/main/tutor.py): `tutor.py`
- [Game screenshot capture](https://github.com/smlfg/the-farmer-was-replaced/blob/main/tutor.py): `tutor.py`
- [Observation builder](https://github.com/smlfg/the-farmer-was-replaced/blob/main/tutor.py): `tutor.py`
- [Response and lesson parser](https://github.com/smlfg/the-farmer-was-replaced/blob/main/tutor.py): `tutor.py`
- [Tutor commands](https://github.com/smlfg/the-farmer-was-replaced/blob/main/tutor.py): `tutor.py`

### Learning support

- [Concept map](https://github.com/smlfg/the-farmer-was-replaced/blob/main/konzepte.py): `konzepte.py`
- [Practice streak](https://github.com/smlfg/the-farmer-was-replaced/blob/main/konzepte.py): `konzepte.py`
- [Daily lesson plan](https://github.com/smlfg/the-farmer-was-replaced/blob/main/konzepte.py): `konzepte.py`
- [Tutor notebook](https://github.com/smlfg/the-farmer-was-replaced/blob/main/tutor.py): `tutor.py`

### Voice interaction

- [Speech playback](https://github.com/smlfg/the-farmer-was-replaced/blob/main/tutor.py): `tutor.py`
- [Push-to-talk listener](https://github.com/smlfg/the-farmer-was-replaced/blob/main/ptt.swift): `ptt.swift`
- [Local transcription](https://github.com/smlfg/the-farmer-was-replaced/blob/main/tutor.py): `tutor.py`

### Tutor providers

- [Pi RPC tutor](https://github.com/smlfg/the-farmer-was-replaced/blob/main/tutor.py): `tutor.py`
- [Offline tutor fallback](https://github.com/smlfg/the-farmer-was-replaced/blob/main/offline_tutor.py): `offline_tutor.py`
- [Rule-based hint](https://github.com/smlfg/the-farmer-was-replaced/blob/main/offline_tutor.py): `offline_tutor.py`

### Other components

- **Learner**
- **Game session**
- **Loopback Ollama**
- **MiniMax API**
- **Piper Thorsten**

## Connections

- Learner → Push-to-talk listener: holds key (evidence: `README.md`)
- Push-to-talk listener → Local transcription: signals key (evidence: `README.md`)
- Local transcription → Session watcher: supplies question (evidence: `README.md`)
- Learner → Tutor commands: sends commands (evidence: `README.md`)
- Game session → Session watcher: session detected (evidence: `README.md`)
- Session watcher → Code and save reader: reads saved files (evidence: `README.md`)
- Session watcher → Game screenshot capture: captures window (evidence: `README.md`)
- Session watcher → Observation builder: assembles context (evidence: `tutor.py`)
- Game session → Observation builder: provides runtime errors (evidence: `README.md`)
- Observation builder → Pi RPC tutor: requests analysis (evidence: `README.md`)
- Pi RPC tutor → MiniMax API: sends tutor request (evidence: `README.md`)
- Pi RPC tutor → Offline tutor fallback: falls back (evidence: `README.md`)
- Offline tutor fallback → Loopback Ollama: requests local model (evidence: `README.md`)
- Offline tutor fallback → Rule-based hint: falls back (evidence: `offline_tutor.py`)
- Pi RPC tutor → Response and lesson parser: returns tutor text (evidence: `tutor.py`)
- Response and lesson parser → Speech playback: queues lesson (evidence: `tutor.py`)
- Speech playback → Piper Thorsten: speaks text (evidence: `README.md`)
- Session watcher → Concept map: updates progress (evidence: `tutor.py`)
- Session watcher → Practice streak: records activity (evidence: `tutor.py`)
- Session watcher → Daily lesson plan: loads lesson (evidence: `tutor.py`)
- Session watcher → Tutor notebook: persists teaching context (evidence: `README.md`)
- Response and lesson parser → Tutor notebook: updates notes (evidence: `tutor.py`)
