# ianwes92/fly-brain-plays-pokemon architecture

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

- Interactive diagram: https://gitdiagram.com/ianwes92/fly-brain-plays-pokemon
- Repository: https://github.com/ianwes92/fly-brain-plays-pokemon

## Overview

Fly Brain Plays Pokémon is a Raspberry Pi–hosted FlyWire brain simulation that plays FireRed live, accepts Twitch control and training, and publishes live visualization and operational/science reporting. The main path runs from the game frame through sensory input and connectome simulation to motor output, while chat can steer or teach the fly. The OBS PC presents the Pi’s feeds and monitors the stream. Several subsystem links reflect README descriptions or SOURCE INDEX references; unsampled implementation details are not inferred.

Main entry points: [`pi/flybrain/playview.py`](https://github.com/ianwes92/fly-brain-plays-pokemon/blob/main/pi/flybrain/playview.py) (Play window), [`pi/flybrain/twitch.py`](https://github.com/ianwes92/fly-brain-plays-pokemon/blob/main/pi/flybrain/twitch.py) (Twitch control), [`pi/flybrain/engine.py`](https://github.com/ianwes92/fly-brain-plays-pokemon/blob/main/pi/flybrain/engine.py) (Neuron engine), [`pi/flybrain/relay.py`](https://github.com/ianwes92/fly-brain-plays-pokemon/blob/main/pi/flybrain/relay.py) (HTTP relay)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_brain["Brain simulation"]
  node_connectome[("FlyWire connectome<br/>[connectome.py]")]
  node_engine["Neuron engine<br/>[engine.py]"]
  node_effectors["Motor effectors<br/>[effectors.py]"]
  node_learning["Learning and reward<br/>[learning.py]"]
  node_mood["Mood state<br/>[mood.py]"]
  node_nose["Scent sensing<br/>[nose.py]"]
  node_brainviz["Live brain visualization<br/>[viz.py]"]
end

subgraph group_game["Game and interaction"]
  node_emulator["FireRed emulator<br/>[game.py]"]
  node_sensory["Sensory mapping<br/>[game.py]"]
  node_playview["Play window<br/>[playview.py]"]
end

subgraph group_live["Live services"]
  node_twitch["Twitch control<br/>[twitch.py]"]
  node_relay["HTTP relay<br/>[relay.py]"]
  node_panel["Pi live panel<br/>[panel.py]"]
  node_runclock["Run lifecycle<br/>[run_clock.py]"]
  node_discord["Discord updates<br/>[discord_poster.py]"]
  node_youtube["YouTube promotion<br/>[youtube_promo.py]"]
end

subgraph group_streaming["Streaming PC"]
  node_reports["Run reports<br/>[run_report.py]"]
  node_controlpanel["OBS control panel<br/>[flypanel.py]"]
  node_obsws["OBS connection<br/>[obsws.py]"]
end

subgraph group_science["Science"]
  node_experiments["Behavior experiments"]
  node_recompute["Independent recomputes"]
end

node_viewer(("Viewers"))
node_chat(("Twitch chat"))
node_twitchservice{{"Twitch service"}}
node_discordservice{{"Discord service"}}
node_youtubeservice{{"YouTube service"}}
node_obs{{"OBS"}}

node_emulator -->|"provides frames"| node_sensory
node_sensory -->|"feeds inputs"| node_engine
node_connectome -->|"wires neurons"| node_engine
node_engine -->|"drives neurons"| node_effectors
node_effectors -->|"presses buttons"| node_emulator
node_chat -->|"sends commands"| node_twitch
node_twitch -->|"steers game"| node_emulator
node_twitch -->|"teaches fly"| node_learning
node_playview -->|"renders game"| node_emulator
node_playview -->|"renders activity"| node_brainviz
node_engine -->|"supplies spikes"| node_brainviz
node_playview -->|"reads state"| node_mood
node_playview -->|"reads state"| node_nose
node_playview -->|"reads lessons"| node_learning
node_relay -->|"serves live feeds"| node_playview
node_relay -->|"serves panel"| node_panel
node_panel -->|"uses channel data"| node_twitch
node_runclock -->|"defines run window"| node_playview
node_discord -->|"posts updates"| node_discordservice
node_youtube -->|"promotes stream"| node_youtubeservice
node_experiments -->|"results checked by"| node_recompute
node_viewer -.->|"watches stream"| node_twitch
node_viewer -->|"steers and trains"| node_chat
node_controlpanel -->|"checks health"| node_relay
node_controlpanel -->|"controls OBS"| node_obsws
node_controlpanel -->|"uses run data"| node_reports
node_obs -->|"composes Pi feeds"| node_relay
node_obs -->|"shows brain layer"| node_brainviz
node_obsws -->|"sends websocket calls"| node_obs
node_twitch -.->|"uses API"| node_twitchservice

click node_emulator "https://github.com/ianwes92/fly-brain-plays-pokemon/blob/main/pi/flybrain/game.py"
click node_sensory "https://github.com/ianwes92/fly-brain-plays-pokemon/blob/main/pi/flybrain/game.py"
click node_connectome "https://github.com/ianwes92/fly-brain-plays-pokemon/blob/main/pi/flybrain/connectome.py"
click node_engine "https://github.com/ianwes92/fly-brain-plays-pokemon/blob/main/pi/flybrain/engine.py"
click node_effectors "https://github.com/ianwes92/fly-brain-plays-pokemon/blob/main/pi/flybrain/effectors.py"
click node_learning "https://github.com/ianwes92/fly-brain-plays-pokemon/blob/main/pi/flybrain/learning.py"
click node_mood "https://github.com/ianwes92/fly-brain-plays-pokemon/blob/main/pi/flybrain/mood.py"
click node_nose "https://github.com/ianwes92/fly-brain-plays-pokemon/blob/main/pi/flybrain/nose.py"
click node_playview "https://github.com/ianwes92/fly-brain-plays-pokemon/blob/main/pi/flybrain/playview.py"
click node_twitch "https://github.com/ianwes92/fly-brain-plays-pokemon/blob/main/pi/flybrain/twitch.py"
click node_relay "https://github.com/ianwes92/fly-brain-plays-pokemon/blob/main/pi/flybrain/relay.py"
click node_panel "https://github.com/ianwes92/fly-brain-plays-pokemon/blob/main/pi/flybrain/panel.py"
click node_runclock "https://github.com/ianwes92/fly-brain-plays-pokemon/blob/main/pi/play/run_clock.py"
click node_discord "https://github.com/ianwes92/fly-brain-plays-pokemon/blob/main/pi/play/discord_poster.py"
click node_youtube "https://github.com/ianwes92/fly-brain-plays-pokemon/blob/main/pi/play/youtube_promo.py"
click node_reports "https://github.com/ianwes92/fly-brain-plays-pokemon/blob/main/obs-pc/run_report.py"
click node_controlpanel "https://github.com/ianwes92/fly-brain-plays-pokemon/blob/main/obs-pc/flypanel.py"
click node_obsws "https://github.com/ianwes92/fly-brain-plays-pokemon/blob/main/obs-pc/obsws.py"
click node_brainviz "https://github.com/ianwes92/fly-brain-plays-pokemon/blob/main/pi/flybrain/viz.py"
click node_experiments "https://github.com/ianwes92/fly-brain-plays-pokemon/tree/main/pi/data/experiments"
click node_recompute "https://github.com/ianwes92/fly-brain-plays-pokemon/tree/main/science"

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_connectome,node_engine,node_effectors,node_learning,node_mood,node_nose,node_brainviz,node_viewer toneBlue
class node_emulator,node_sensory,node_playview toneAmber
class node_twitch,node_relay,node_panel,node_runclock,node_discord,node_youtube toneMint
class node_reports,node_controlpanel,node_obsws toneRose
class node_experiments,node_recompute,node_chat,node_twitchservice,node_discordservice,node_youtubeservice,node_obs toneIndigo
```

## Components

### Brain simulation

- [FlyWire connectome](https://github.com/ianwes92/fly-brain-plays-pokemon/blob/main/pi/flybrain/connectome.py): `pi/flybrain/connectome.py`
- [Neuron engine](https://github.com/ianwes92/fly-brain-plays-pokemon/blob/main/pi/flybrain/engine.py): `pi/flybrain/engine.py`
- [Motor effectors](https://github.com/ianwes92/fly-brain-plays-pokemon/blob/main/pi/flybrain/effectors.py): `pi/flybrain/effectors.py`
- [Learning and reward](https://github.com/ianwes92/fly-brain-plays-pokemon/blob/main/pi/flybrain/learning.py): `pi/flybrain/learning.py`
- [Mood state](https://github.com/ianwes92/fly-brain-plays-pokemon/blob/main/pi/flybrain/mood.py): `pi/flybrain/mood.py`
- [Scent sensing](https://github.com/ianwes92/fly-brain-plays-pokemon/blob/main/pi/flybrain/nose.py): `pi/flybrain/nose.py`
- [Live brain visualization](https://github.com/ianwes92/fly-brain-plays-pokemon/blob/main/pi/flybrain/viz.py): `pi/flybrain/viz.py`

### Game and interaction

- [FireRed emulator](https://github.com/ianwes92/fly-brain-plays-pokemon/blob/main/pi/flybrain/game.py): `pi/flybrain/game.py`
- [Sensory mapping](https://github.com/ianwes92/fly-brain-plays-pokemon/blob/main/pi/flybrain/game.py): `pi/flybrain/game.py`
- [Play window](https://github.com/ianwes92/fly-brain-plays-pokemon/blob/main/pi/flybrain/playview.py): `pi/flybrain/playview.py`

### Live services

- [Twitch control](https://github.com/ianwes92/fly-brain-plays-pokemon/blob/main/pi/flybrain/twitch.py): `pi/flybrain/twitch.py`
- [HTTP relay](https://github.com/ianwes92/fly-brain-plays-pokemon/blob/main/pi/flybrain/relay.py): `pi/flybrain/relay.py`
- [Pi live panel](https://github.com/ianwes92/fly-brain-plays-pokemon/blob/main/pi/flybrain/panel.py): `pi/flybrain/panel.py`
- [Run lifecycle](https://github.com/ianwes92/fly-brain-plays-pokemon/blob/main/pi/play/run_clock.py): `pi/play/run_clock.py`
- [Discord updates](https://github.com/ianwes92/fly-brain-plays-pokemon/blob/main/pi/play/discord_poster.py): `pi/play/discord_poster.py`
- [YouTube promotion](https://github.com/ianwes92/fly-brain-plays-pokemon/blob/main/pi/play/youtube_promo.py): `pi/play/youtube_promo.py`

### Streaming PC

- [Run reports](https://github.com/ianwes92/fly-brain-plays-pokemon/blob/main/obs-pc/run_report.py): `obs-pc/run_report.py`
- [OBS control panel](https://github.com/ianwes92/fly-brain-plays-pokemon/blob/main/obs-pc/flypanel.py): `obs-pc/flypanel.py`
- [OBS connection](https://github.com/ianwes92/fly-brain-plays-pokemon/blob/main/obs-pc/obsws.py): `obs-pc/obsws.py`

### Science

- [Behavior experiments](https://github.com/ianwes92/fly-brain-plays-pokemon/tree/main/pi/data/experiments): `pi/data/experiments`
- [Independent recomputes](https://github.com/ianwes92/fly-brain-plays-pokemon/tree/main/science): `science`

### Other components

- **Viewers**
- **Twitch chat**
- **Twitch service**
- **Discord service**
- **YouTube service**
- **OBS**

## Connections

- FireRed emulator → Sensory mapping: provides frames (evidence: `pi/flybrain/game.py`)
- Sensory mapping → Neuron engine: feeds inputs (evidence: `pi/flybrain/game.py`)
- FlyWire connectome → Neuron engine: wires neurons (evidence: `pi/flybrain/engine.py`)
- Neuron engine → Motor effectors: drives neurons
- Motor effectors → FireRed emulator: presses buttons
- Twitch chat → Twitch control: sends commands
- Twitch control → FireRed emulator: steers game (evidence: `pi/flybrain/game.py`)
- Twitch control → Learning and reward: teaches fly
- Play window → FireRed emulator: renders game (evidence: `pi/flybrain/playview.py`)
- Play window → Live brain visualization: renders activity (evidence: `pi/flybrain/playview.py`)
- Neuron engine → Live brain visualization: supplies spikes (evidence: `pi/flybrain/viz.py`)
- Play window → Mood state: reads state (evidence: `pi/flybrain/playview.py`)
- Play window → Scent sensing: reads state (evidence: `pi/flybrain/playview.py`)
- Play window → Learning and reward: reads lessons (evidence: `pi/flybrain/playview.py`)
- HTTP relay → Play window: serves live feeds
- HTTP relay → Pi live panel: serves panel (evidence: `pi/flybrain/relay.py`)
- Pi live panel → Twitch control: uses channel data (evidence: `pi/flybrain/panel.py`)
- Run lifecycle → Play window: defines run window (evidence: `pi/flybrain/playview.py`)
- Discord updates → Discord service: posts updates (evidence: `pi/play/discord_poster.py`)
- YouTube promotion → YouTube service: promotes stream (evidence: `pi/play/youtube_promo.py`)
- Behavior experiments → Independent recomputes: results checked by
- Viewers → Twitch control: watches stream
- Viewers → Twitch chat: steers and trains
- OBS control panel → HTTP relay: checks health (evidence: `obs-pc/flypanel.py`)
- OBS control panel → OBS connection: controls OBS (evidence: `obs-pc/flypanel.py`)
- OBS control panel → Run reports: uses run data (evidence: `obs-pc/run_report.py`)
- OBS → HTTP relay: composes Pi feeds
- OBS → Live brain visualization: shows brain layer
- OBS connection → OBS: sends websocket calls (evidence: `obs-pc/obsws.py`)
- Twitch control → Twitch service: uses API
