# venkateswarann/duck-brain architecture

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

- Interactive diagram: https://gitdiagram.com/venkateswarann/duck-brain
- Repository: https://github.com/venkateswarann/duck-brain

## Overview

This repository combines an offline conversational robot companion with DCS, the web-based robot control system beneath it. The principal interaction runs from speech or text through the brain’s model and safety checks to MCP actions on the robot, with speech and expressions as outputs. Separate capabilities include vision and face tracking, memory and trace, the phone-playable bluffing game, and DCS monitoring/setup. Edges follow README statements or shown imports/calls; unsampled implementation details are omitted rather than inferred.

Main entry points: [`brain/duck_brain/main.py`](https://github.com/venkateswarann/duck-brain/blob/main/brain/duck_brain/main.py) (Brain orchestration), [`backend/app/main.py`](https://github.com/venkateswarann/duck-brain/blob/main/backend/app/main.py) (FastAPI services), [`brain/duck_brain/game/server.py`](https://github.com/venkateswarann/duck-brain/blob/main/brain/duck_brain/game/server.py) (Game server), [`brain/duck_brain/robot.py`](https://github.com/venkateswarann/duck-brain/blob/main/brain/duck_brain/robot.py) (Robot MCP client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_brain["Companion brain"]
  node_brain_main["Brain orchestration<br/>[main.py]"]
  node_hearing["Speech recognition<br/>[hearing.py]"]
  node_gemma["Gemma client<br/>[llm.py]"]
  node_safety["Action safety<br/>[safety.py]"]
  node_robot_client["Robot MCP client<br/>[robot.py]"]
  node_memory[("Conversation memory<br/>[memory.py]")]
  node_tracking["Face tracking<br/>[tracking.py]"]
  node_trace["Decision trace<br/>[trace.py]"]
end

subgraph group_control["Robot control"]
  node_backend["FastAPI services<br/>[main.py]"]
  node_runtime["Node runtime<br/>[base_node.py]"]
  node_registry["Node lifecycle<br/>[registry.py]"]
  node_head_control["Clamped head control<br/>[head_control.py]"]
  node_script_nodes["Script runner<br/>[script_node.py]"]
  node_video["Camera streaming<br/>[video.py]"]
  node_framehub["Video frame hub<br/>[frame_hub.py]"]
end

subgraph group_ui["DCS interface"]
  node_frontend["DCS web pages<br/>[App.tsx]"]
end

subgraph group_device["Head device"]
  node_eyes_server["Eyes service<br/>[eyes_server.py]"]
  node_eye_engine["Eye animation<br/>[eye_engine.py]"]
  node_eye_render["Eye rendering<br/>[eye_renderer.py]"]
  node_body_io["Head hardware I/O<br/>[body_io.py]"]
end

subgraph group_game["Phone game"]
  node_game_server["Game server<br/>[server.py]"]
  node_game_rules["Liar's Duck rules<br/>[liars.py]"]
end

node_person(("Duck user"))
node_browser(("Browser operator"))
node_ollama["Local Ollama"]
node_phones(("Player phones"))

node_person -->|"speaks or types"| node_brain_main
node_brain_main -->|"starts listening"| node_hearing
node_brain_main -->|"requests actions"| node_gemma
node_gemma -->|"generates locally"| node_ollama
node_brain_main -->|"checks actions"| node_safety
node_brain_main -->|"dispatches MCP tools"| node_robot_client
node_brain_main -->|"uses memory"| node_memory
node_brain_main -->|"runs tracking"| node_tracking
node_brain_main -->|"emits decisions"| node_trace
node_robot_client -->|"calls robot API"| node_backend
node_backend -->|"registers nodes"| node_runtime
node_backend -->|"starts enabled nodes"| node_registry
node_backend -->|"registers head node"| node_head_control
node_backend -->|"registers script nodes"| node_script_nodes
node_backend -->|"serves camera stream"| node_video
node_video -->|"reads frames"| node_framehub
node_browser -->|"operates pages"| node_frontend
node_frontend -->|"REST and WebSocket"| node_backend
node_phones -->|"plays turns"| node_game_server
node_game_server -->|"uses game rules"| node_game_rules
node_game_server -->|"updates duck"| node_robot_client
node_eyes_server -.->|"runs animation"| node_eye_engine
node_eye_engine -->|"renders frames"| node_eye_render
node_eye_render -.->|"drives displays"| node_body_io
node_backend -->|"proxies eye controls"| node_eyes_server
node_head_control -->|"controls head hardware"| node_body_io

click node_brain_main "https://github.com/venkateswarann/duck-brain/blob/main/brain/duck_brain/main.py"
click node_hearing "https://github.com/venkateswarann/duck-brain/blob/main/brain/duck_brain/hearing.py"
click node_gemma "https://github.com/venkateswarann/duck-brain/blob/main/brain/duck_brain/llm.py"
click node_safety "https://github.com/venkateswarann/duck-brain/blob/main/brain/duck_brain/safety.py"
click node_robot_client "https://github.com/venkateswarann/duck-brain/blob/main/brain/duck_brain/robot.py"
click node_memory "https://github.com/venkateswarann/duck-brain/blob/main/brain/duck_brain/memory.py"
click node_tracking "https://github.com/venkateswarann/duck-brain/blob/main/brain/duck_brain/tracking.py"
click node_trace "https://github.com/venkateswarann/duck-brain/blob/main/brain/duck_brain/trace.py"
click node_game_server "https://github.com/venkateswarann/duck-brain/blob/main/brain/duck_brain/game/server.py"
click node_game_rules "https://github.com/venkateswarann/duck-brain/blob/main/brain/duck_brain/game/liars.py"
click node_frontend "https://github.com/venkateswarann/duck-brain/blob/main/frontend/src/App.tsx"
click node_backend "https://github.com/venkateswarann/duck-brain/blob/main/backend/app/main.py"
click node_runtime "https://github.com/venkateswarann/duck-brain/blob/main/backend/app/runtime/base_node.py"
click node_registry "https://github.com/venkateswarann/duck-brain/blob/main/backend/app/runtime/registry.py"
click node_head_control "https://github.com/venkateswarann/duck-brain/blob/main/backend/app/nodes/head_control.py"
click node_script_nodes "https://github.com/venkateswarann/duck-brain/blob/main/backend/app/nodes/script_node.py"
click node_video "https://github.com/venkateswarann/duck-brain/blob/main/backend/app/routes/video.py"
click node_framehub "https://github.com/venkateswarann/duck-brain/blob/main/backend/app/services/frame_hub.py"
click node_eyes_server "https://github.com/venkateswarann/duck-brain/blob/main/devices/head_zero/eyes_server.py"
click node_eye_engine "https://github.com/venkateswarann/duck-brain/blob/main/devices/head_zero/eye_engine.py"
click node_eye_render "https://github.com/venkateswarann/duck-brain/blob/main/devices/head_zero/eye_renderer.py"
click node_body_io "https://github.com/venkateswarann/duck-brain/blob/main/devices/head_zero/body_io.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_brain_main,node_hearing,node_gemma,node_safety,node_robot_client,node_memory,node_tracking,node_trace,node_person,node_browser toneBlue
class node_backend,node_runtime,node_registry,node_head_control,node_script_nodes,node_video,node_framehub toneAmber
class node_frontend toneMint
class node_eyes_server,node_eye_engine,node_eye_render,node_body_io toneRose
class node_game_server,node_game_rules,node_ollama,node_phones toneIndigo
```

## Components

### Companion brain

- [Brain orchestration](https://github.com/venkateswarann/duck-brain/blob/main/brain/duck_brain/main.py): `brain/duck_brain/main.py`
- [Speech recognition](https://github.com/venkateswarann/duck-brain/blob/main/brain/duck_brain/hearing.py): `brain/duck_brain/hearing.py`
- [Gemma client](https://github.com/venkateswarann/duck-brain/blob/main/brain/duck_brain/llm.py): `brain/duck_brain/llm.py`
- [Action safety](https://github.com/venkateswarann/duck-brain/blob/main/brain/duck_brain/safety.py): `brain/duck_brain/safety.py`
- [Robot MCP client](https://github.com/venkateswarann/duck-brain/blob/main/brain/duck_brain/robot.py): `brain/duck_brain/robot.py`
- [Conversation memory](https://github.com/venkateswarann/duck-brain/blob/main/brain/duck_brain/memory.py): `brain/duck_brain/memory.py`
- [Face tracking](https://github.com/venkateswarann/duck-brain/blob/main/brain/duck_brain/tracking.py): `brain/duck_brain/tracking.py`
- [Decision trace](https://github.com/venkateswarann/duck-brain/blob/main/brain/duck_brain/trace.py): `brain/duck_brain/trace.py`

### Robot control

- [FastAPI services](https://github.com/venkateswarann/duck-brain/blob/main/backend/app/main.py): `backend/app/main.py`
- [Node runtime](https://github.com/venkateswarann/duck-brain/blob/main/backend/app/runtime/base_node.py): `backend/app/runtime/base_node.py`
- [Node lifecycle](https://github.com/venkateswarann/duck-brain/blob/main/backend/app/runtime/registry.py): `backend/app/runtime/registry.py`
- [Clamped head control](https://github.com/venkateswarann/duck-brain/blob/main/backend/app/nodes/head_control.py): `backend/app/nodes/head_control.py`
- [Script runner](https://github.com/venkateswarann/duck-brain/blob/main/backend/app/nodes/script_node.py): `backend/app/nodes/script_node.py`
- [Camera streaming](https://github.com/venkateswarann/duck-brain/blob/main/backend/app/routes/video.py): `backend/app/routes/video.py`
- [Video frame hub](https://github.com/venkateswarann/duck-brain/blob/main/backend/app/services/frame_hub.py): `backend/app/services/frame_hub.py`

### DCS interface

- [DCS web pages](https://github.com/venkateswarann/duck-brain/blob/main/frontend/src/App.tsx): `frontend/src/App.tsx`

### Head device

- [Eyes service](https://github.com/venkateswarann/duck-brain/blob/main/devices/head_zero/eyes_server.py): `devices/head_zero/eyes_server.py`
- [Eye animation](https://github.com/venkateswarann/duck-brain/blob/main/devices/head_zero/eye_engine.py): `devices/head_zero/eye_engine.py`
- [Eye rendering](https://github.com/venkateswarann/duck-brain/blob/main/devices/head_zero/eye_renderer.py): `devices/head_zero/eye_renderer.py`
- [Head hardware I/O](https://github.com/venkateswarann/duck-brain/blob/main/devices/head_zero/body_io.py): `devices/head_zero/body_io.py`

### Phone game

- [Game server](https://github.com/venkateswarann/duck-brain/blob/main/brain/duck_brain/game/server.py): `brain/duck_brain/game/server.py`
- [Liar's Duck rules](https://github.com/venkateswarann/duck-brain/blob/main/brain/duck_brain/game/liars.py): `brain/duck_brain/game/liars.py`

### Other components

- **Duck user**
- **Browser operator**
- **Local Ollama**
- **Player phones**

## Connections

- Duck user → Brain orchestration: speaks or types
- Brain orchestration → Speech recognition: starts listening (evidence: `brain/duck_brain/main.py`)
- Brain orchestration → Gemma client: requests actions (evidence: `brain/duck_brain/main.py`)
- Gemma client → Local Ollama: generates locally (evidence: `brain/duck_brain/llm.py`)
- Brain orchestration → Action safety: checks actions (evidence: `brain/duck_brain/main.py`)
- Brain orchestration → Robot MCP client: dispatches MCP tools (evidence: `brain/duck_brain/main.py`)
- Brain orchestration → Conversation memory: uses memory (evidence: `brain/duck_brain/main.py`)
- Brain orchestration → Face tracking: runs tracking (evidence: `brain/duck_brain/main.py`)
- Brain orchestration → Decision trace: emits decisions (evidence: `brain/duck_brain/main.py`)
- Robot MCP client → FastAPI services: calls robot API
- FastAPI services → Node runtime: registers nodes (evidence: `backend/app/main.py`)
- FastAPI services → Node lifecycle: starts enabled nodes (evidence: `backend/app/main.py`)
- FastAPI services → Clamped head control: registers head node (evidence: `backend/app/main.py`)
- FastAPI services → Script runner: registers script nodes (evidence: `backend/app/main.py`)
- FastAPI services → Camera streaming: serves camera stream (evidence: `backend/app/main.py`)
- Camera streaming → Video frame hub: reads frames (evidence: `backend/app/routes/video.py`)
- Browser operator → DCS web pages: operates pages
- DCS web pages → FastAPI services: REST and WebSocket
- Player phones → Game server: plays turns
- Game server → Liar's Duck rules: uses game rules (evidence: `brain/duck_brain/game/server.py`)
- Game server → Robot MCP client: updates duck (evidence: `brain/duck_brain/game/server.py`)
- Eyes service → Eye animation: runs animation
- Eye animation → Eye rendering: renders frames (evidence: `devices/head_zero/eye_engine.py`)
- Eye rendering → Head hardware I/O: drives displays
- FastAPI services → Eyes service: proxies eye controls
- Clamped head control → Head hardware I/O: controls head hardware
