# google-research/football architecture

> Architecture diagram of the GitHub repository google-research/football, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/google-research/football
- Repository: https://github.com/google-research/football

## Overview

##### Main Components
- Python RL Environment (gfootball package):
– Contains modules for environment setup, configuration, and game scenarios (see gfootball/env, gfootball/scenarios, gfootball/examples).
– Hosts integrations for different types of players (keyboard, external agents, etc.) and the CLI entry point (play_game.py).
– Provides API documentation and training scripts to interact with RL frameworks.

- Game Engine (C++ Implementation):
– Found under third_party/gfootball_engine.
– Implements the fast simulation of game logic, physics, and rendering support.
– Built using CMake and integrated through build scripts in gfootball (e.g., build_game_engine.sh / .bat).

- Evaluation Server:
– Located in gfootball/eval_server.
– Implements communication via protocol buffers (proto files) to support evaluation routines and remote client interactions.

- CI/CD & Deployment:
– Dockerfile and Docker related scripts (Dockerfile, run_docker_test.sh, .github/workflows) support containerized builds and tests.
– GitHub Actions workflows manage builds for macOS and wheel publishing.

##### Relationships and Interactions
- The Python environment acts as a wrapper around the C++ game engine:
– When a user invokes the game (via gfootball.play_game), the Python layer initializes the environment, loads the appropriate scenario, and then communicates with the compiled game engine (built from the third_party/gfootball_engine code).
– The engine provides state updates and simulation steps back into the environment that delivers observations to agents and converts their actions into game events.

- The Evaluation Server operates as an auxiliary component:
– It exposes an API via gRPC (as shown by the proto definitions) to allow remote evaluation or testing with external client agents.

- The training scripts and examples (in gfootball/examples) serve as a bridge:
– They integrate with popular RL frameworks (TensorFlow 1.15, OpenAI Baselines) and use the Python environment to receive observations and provide actions in training loops.

- CI/CD components (Docker & GitHub workflows) support cross-platform builds and ensure that tests run (including building the C++ engine) are passed before publishing packages or deploying demos.

##### Important Architectural Patterns & Design Principles
- Separation of Concerns:
– The game engine (C++) focuses solely on speed and simulation fidelity, while the Python layer provides the interface for training agents and handling high-level API calls.

- Modular Design:
– The environment’s design is split into submodules (env, players, scenarios, examples) that can be developed, extended, or replaced individually.

- Integration via Wrappers:
– Python wrappers encapsulate the compiled C++ code, enabling seamless use in RL pipelines.

- Standardized Communication:
– Use of protocol buffers (in eval_server) and clear API boundaries (documentation in gfootball/doc) promote maintainability and extensibility.

##### Relevant Technologies, Frameworks, or Libraries
- For the Python Layer:
– Python3, TensorFlow 1.15, OpenAI Baselines, Gym-like interfaces.

- For the Game Engine (C++):
– CMake build system, SDL2 for rendering/input support, and various custom libraries/modules organized within third_party/gfootball_engine.

- For Deployment & CI:
– Docker for containerized builds, GitHub Actions for automated CI/CD.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Entities
    M["RL Frameworks (TensorFlow,Baselines)"]:::external

    %% Python RL Environment Subgraph
    subgraph "Python RL Environment"
        D["CLI (play_game.py)"]:::python
        A["Environment Module (env)"]:::python
        B["Scenarios Module (scenarios)"]:::python
        C["Examples Module (examples)"]:::python
    end

    %% Game Engine (C++) Subgraph
    subgraph "Game Engine (C++)"
        E["Game Engine Source (third_party/gfootball_engine)"]:::cpp
        F["Build Script (.sh)"]:::cpp
        G["Build Script (.bat)"]:::cpp
    end

    %% Evaluation Server Subgraph
    subgraph "Evaluation Server"
        H["Evaluation Service (eval_server)"]:::eval
        I["Proto Definitions (proto)"]:::eval
    end

    %% CI/CD & Deployment Subgraph
    subgraph "CI/CD & Deployment"
        J["Dockerfile"]:::ci
        K["Docker Test Script (run_docker_test.sh)"]:::ci
        L["GitHub Workflows (.github/workflows)"]:::ci
    end

    %% Connections
    M -->|"training_loop"| D

    D -->|"sim_commands"| E
    D -->|"eval_updates"| H

    I -->|"defines"| H

    L -->|"build_test"| D
    L -->|"build_test"| E

    %% Styles
    classDef python fill:#cce5ff,stroke:#003366,stroke-width:2px;
    classDef cpp fill:#e2ffcc,stroke:#336600,stroke-width:2px;
    classDef eval fill:#ffe6cc,stroke:#cc6600,stroke-width:2px;
    classDef ci fill:#ffcccc,stroke:#990000,stroke-width:2px;
    classDef external fill:#ffffcc,stroke:#999900,stroke-width:2px;

    %% Click Events
    click D "https://github.com/google-research/football/blob/master/gfootball/play_game.py"
    click A "https://github.com/google-research/football/tree/master/gfootball/env"
    click B "https://github.com/google-research/football/tree/master/gfootball/scenarios"
    click C "https://github.com/google-research/football/tree/master/gfootball/examples"
    click E "https://github.com/google-research/football/tree/master/third_party/gfootball_engine"
    click F "https://github.com/google-research/football/blob/master/gfootball/build_game_engine.sh"
    click G "https://github.com/google-research/football/blob/master/gfootball/build_game_engine.bat"
    click H "https://github.com/google-research/football/tree/master/gfootball/eval_server"
    click I "https://github.com/google-research/football/tree/master/gfootball/eval_server/proto"
    click J "https://github.com/google-research/football/tree/master/Dockerfile"
    click K "https://github.com/google-research/football/blob/master/run_docker_test.sh"
    click L "https://github.com/google-research/football/tree/master/.github/workflows"
```
