# amcheste/pokemon-red-ai architecture

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

- Interactive diagram: https://gitdiagram.com/amcheste/pokemon-red-ai
- Repository: https://github.com/amcheste/pokemon-red-ai

## Overview

Pokémon Red RL Toolkit provides an emulator-backed Gymnasium environment and a RecurrentPPO experiment workflow. A user launches training with a ROM and save state; the trainer builds a model and environment, which turns emulator state into observations and rewards for the agent. Evaluation and statistical comparison support the resulting runs, while callbacks, alerts, and monitoring provide operational feedback. README-documented features include pixel, symbolic, and hybrid observations, multiple reward strategies, and live monitoring. Some subsystem links rely on README documentation because their implementation was not excerpted.

Main entry points: [`pokemon_red_ai/environment/gym_env.py`](https://github.com/amcheste/pokemon-red-ai/blob/develop/pokemon_red_ai/environment/gym_env.py) (Gym environment), [`pokemon_red_ai/training/trainer.py`](https://github.com/amcheste/pokemon-red-ai/blob/develop/pokemon_red_ai/training/trainer.py) (Trainer), [`pokemon_red_ai/game/agent.py`](https://github.com/amcheste/pokemon-red-ai/blob/develop/pokemon_red_ai/game/agent.py) (Emulated agent), [`scripts/train.py`](https://github.com/amcheste/pokemon-red-ai/blob/develop/scripts/train.py) (Training entry)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experiment["Experiment workflow"]
  node_train_entry["Training entry<br/>[train.py]"]
  node_trainer["Trainer<br/>[trainer.py]"]
  node_models["RL models<br/>[models.py]"]
  node_evaluation["Evaluation<br/>[eval.py]"]
end

subgraph group_environment["Game environment"]
  node_env["Gym environment<br/>[gym_env.py]"]
  node_observations["Observation treatments<br/>[observations.py]"]
  node_rewards["Reward strategies<br/>[rewards.py]"]
end

subgraph group_game["Game interface"]
  node_agent["Emulated agent<br/>[agent.py]"]
  node_controls["Game controls<br/>[controls.py]"]
  node_memory["Game memory<br/>[memory.py]"]
  node_flags["Event flags<br/>[event_flags.py]"]
end

subgraph group_operations["Monitoring and analysis"]
  node_callbacks["Training callbacks<br/>[callbacks.py]"]
  node_alerts["Configurable alerts<br/>[alerts.py]"]
  node_monitor["Live dashboard<br/>[monitor.py]"]
  node_comparison["Run comparison<br/>[comparison.py]"]
  node_analysis["Statistical analysis<br/>[analyze.py]"]
  node_compare_ui["Comparison dashboard<br/>[compare.py]"]
end

node_user(("Experimenter"))
node_pyboy["PyBoy emulator"]

node_user -->|"starts training"| node_train_entry
node_train_entry -->|"configures training"| node_trainer
node_trainer -->|"creates model"| node_models
node_trainer -->|"creates environment"| node_env
node_env -->|"steps game"| node_agent
node_agent -->|"drives emulator"| node_pyboy
node_agent -->|"uses controls"| node_controls
node_agent -->|"reads state"| node_memory
node_env -->|"builds observations"| node_observations
node_env -->|"calculates rewards"| node_rewards
node_observations -->|"reads event flags"| node_flags
node_rewards -->|"uses flag events"| node_flags
node_flags -->|"reads memory"| node_memory
node_trainer -->|"registers callbacks"| node_callbacks
node_train_entry -->|"configures alerts"| node_alerts
node_callbacks -.->|"feeds monitoring"| node_monitor
node_user -->|"evaluates runs"| node_evaluation
node_evaluation -->|"uses environment"| node_env
node_user -->|"analyzes results"| node_analysis
node_analysis -->|"uses comparisons"| node_comparison
node_user -->|"compares runs"| node_compare_ui
node_compare_ui -->|"uses comparison logic"| node_comparison

click node_train_entry "https://github.com/amcheste/pokemon-red-ai/blob/develop/scripts/train.py"
click node_trainer "https://github.com/amcheste/pokemon-red-ai/blob/develop/pokemon_red_ai/training/trainer.py"
click node_models "https://github.com/amcheste/pokemon-red-ai/blob/develop/pokemon_red_ai/training/models.py"
click node_evaluation "https://github.com/amcheste/pokemon-red-ai/blob/develop/scripts/eval.py"
click node_env "https://github.com/amcheste/pokemon-red-ai/blob/develop/pokemon_red_ai/environment/gym_env.py"
click node_observations "https://github.com/amcheste/pokemon-red-ai/blob/develop/pokemon_red_ai/environment/observations.py"
click node_rewards "https://github.com/amcheste/pokemon-red-ai/blob/develop/pokemon_red_ai/environment/rewards.py"
click node_agent "https://github.com/amcheste/pokemon-red-ai/blob/develop/pokemon_red_ai/game/agent.py"
click node_controls "https://github.com/amcheste/pokemon-red-ai/blob/develop/pokemon_red_ai/game/controls.py"
click node_memory "https://github.com/amcheste/pokemon-red-ai/blob/develop/pokemon_red_ai/game/memory.py"
click node_flags "https://github.com/amcheste/pokemon-red-ai/blob/develop/pokemon_red_ai/game/event_flags.py"
click node_callbacks "https://github.com/amcheste/pokemon-red-ai/blob/develop/pokemon_red_ai/training/callbacks.py"
click node_alerts "https://github.com/amcheste/pokemon-red-ai/blob/develop/pokemon_red_ai/training/alerts.py"
click node_monitor "https://github.com/amcheste/pokemon-red-ai/blob/develop/scripts/monitor.py"
click node_comparison "https://github.com/amcheste/pokemon-red-ai/blob/develop/pokemon_red_ai/analysis/comparison.py"
click node_analysis "https://github.com/amcheste/pokemon-red-ai/blob/develop/scripts/analyze.py"
click node_compare_ui "https://github.com/amcheste/pokemon-red-ai/blob/develop/scripts/compare.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_train_entry,node_trainer,node_models,node_evaluation toneBlue
class node_env,node_observations,node_rewards toneAmber
class node_agent,node_controls,node_memory,node_flags toneMint
class node_callbacks,node_alerts,node_monitor,node_comparison,node_analysis,node_compare_ui toneRose
class node_user,node_pyboy toneIndigo
```

## Components

### Experiment workflow

- [Training entry](https://github.com/amcheste/pokemon-red-ai/blob/develop/scripts/train.py): `scripts/train.py`
- [Trainer](https://github.com/amcheste/pokemon-red-ai/blob/develop/pokemon_red_ai/training/trainer.py): `pokemon_red_ai/training/trainer.py`
- [RL models](https://github.com/amcheste/pokemon-red-ai/blob/develop/pokemon_red_ai/training/models.py): `pokemon_red_ai/training/models.py`
- [Evaluation](https://github.com/amcheste/pokemon-red-ai/blob/develop/scripts/eval.py): `scripts/eval.py`

### Game environment

- [Gym environment](https://github.com/amcheste/pokemon-red-ai/blob/develop/pokemon_red_ai/environment/gym_env.py): `pokemon_red_ai/environment/gym_env.py`
- [Observation treatments](https://github.com/amcheste/pokemon-red-ai/blob/develop/pokemon_red_ai/environment/observations.py): `pokemon_red_ai/environment/observations.py`
- [Reward strategies](https://github.com/amcheste/pokemon-red-ai/blob/develop/pokemon_red_ai/environment/rewards.py): `pokemon_red_ai/environment/rewards.py`

### Game interface

- [Emulated agent](https://github.com/amcheste/pokemon-red-ai/blob/develop/pokemon_red_ai/game/agent.py): `pokemon_red_ai/game/agent.py`
- [Game controls](https://github.com/amcheste/pokemon-red-ai/blob/develop/pokemon_red_ai/game/controls.py): `pokemon_red_ai/game/controls.py`
- [Game memory](https://github.com/amcheste/pokemon-red-ai/blob/develop/pokemon_red_ai/game/memory.py): `pokemon_red_ai/game/memory.py`
- [Event flags](https://github.com/amcheste/pokemon-red-ai/blob/develop/pokemon_red_ai/game/event_flags.py): `pokemon_red_ai/game/event_flags.py`

### Monitoring and analysis

- [Training callbacks](https://github.com/amcheste/pokemon-red-ai/blob/develop/pokemon_red_ai/training/callbacks.py): `pokemon_red_ai/training/callbacks.py`
- [Configurable alerts](https://github.com/amcheste/pokemon-red-ai/blob/develop/pokemon_red_ai/training/alerts.py): `pokemon_red_ai/training/alerts.py`
- [Live dashboard](https://github.com/amcheste/pokemon-red-ai/blob/develop/scripts/monitor.py): `scripts/monitor.py`
- [Run comparison](https://github.com/amcheste/pokemon-red-ai/blob/develop/pokemon_red_ai/analysis/comparison.py): `pokemon_red_ai/analysis/comparison.py`
- [Statistical analysis](https://github.com/amcheste/pokemon-red-ai/blob/develop/scripts/analyze.py): `scripts/analyze.py`
- [Comparison dashboard](https://github.com/amcheste/pokemon-red-ai/blob/develop/scripts/compare.py): `scripts/compare.py`

### Other components

- **Experimenter**
- **PyBoy emulator**

## Connections

- Experimenter → Training entry: starts training (evidence: `README.md`)
- Training entry → Trainer: configures training (evidence: `scripts/train.py`)
- Trainer → RL models: creates model (evidence: `pokemon_red_ai/training/trainer.py`)
- Trainer → Gym environment: creates environment (evidence: `pokemon_red_ai/training/trainer.py`)
- Gym environment → Emulated agent: steps game (evidence: `pokemon_red_ai/environment/gym_env.py`)
- Emulated agent → PyBoy emulator: drives emulator (evidence: `pokemon_red_ai/game/agent.py`)
- Emulated agent → Game controls: uses controls (evidence: `pokemon_red_ai/game/agent.py`)
- Emulated agent → Game memory: reads state (evidence: `pokemon_red_ai/game/agent.py`)
- Gym environment → Observation treatments: builds observations (evidence: `pokemon_red_ai/environment/gym_env.py`)
- Gym environment → Reward strategies: calculates rewards (evidence: `pokemon_red_ai/environment/gym_env.py`)
- Observation treatments → Event flags: reads event flags (evidence: `pokemon_red_ai/environment/observations.py`)
- Reward strategies → Event flags: uses flag events (evidence: `pokemon_red_ai/environment/rewards.py`)
- Event flags → Game memory: reads memory (evidence: `pokemon_red_ai/game/event_flags.py`)
- Trainer → Training callbacks: registers callbacks (evidence: `pokemon_red_ai/training/trainer.py`)
- Training entry → Configurable alerts: configures alerts (evidence: `scripts/train.py`)
- Training callbacks → Live dashboard: feeds monitoring
- Experimenter → Evaluation: evaluates runs (evidence: `README.md`)
- Evaluation → Gym environment: uses environment (evidence: `scripts/eval.py`)
- Experimenter → Statistical analysis: analyzes results (evidence: `README.md`)
- Statistical analysis → Run comparison: uses comparisons (evidence: `scripts/analyze.py`)
- Experimenter → Comparison dashboard: compares runs (evidence: `README.md`)
- Comparison dashboard → Run comparison: uses comparison logic (evidence: `scripts/compare.py`)
