# uzairakbar/deepracer architecture

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

- Interactive diagram: https://gitdiagram.com/uzairakbar/deepracer
- Repository: https://github.com/uzairakbar/deepracer

## Overview

#### Purpose and Entry Points
DeepRacer Gym is a Python 3.12+ Gymnasium integration for the AWS DeepRacer simulator. Creating `gym.make("deepracer-v0")` launches an isolated containerized simulator and presents reset/step/close through Gymnasium. Package registration and adapter entry points are in `client/deepracer/__init__.py` and `client/deepracer/gym_adapter.py`; environment behavior is implemented in `client/deepracer/envs/env.py`.

#### Gym Environment Boundary
The Gym adapter owns the user-facing lifecycle: construct environment, reset simulator episode, submit actions, receive observations/rewards/termination state, and close resources. `client/deepracer/envs/env.py` is the primary environment implementation, while `client/deepracer/envs/utils.py` translates or supports simulator-facing environment data. Default agent, environment, reward, and track inputs ship under `client/deepracer/defaults/`.

#### Service Lifecycle Manager
Each environment delegates simulator provisioning to a service layer rather than embedding container commands in Gym logic. `client/deepracer/service/manager.py` coordinates create/start/stop/remove behavior; `client/deepracer/service/spec.py` represents service configuration and materialized launch details; `client/deepracer/service/validate.py` guards service inputs and runtime prerequisites. This boundary enables per-environment simulator isolation.

#### Runtime Backend Abstraction
Docker, Podman, and Apptainer are interchangeable execution backends behind `client/deepracer/service/backends.py`. The backend layer constructs runtime-specific commands and manages the simulator container/process, while `client/deepracer/service/identity.py` allocates identifying or isolating values needed for concurrent services. Container runtime selection and launch details remain below the Gym API.

#### Simulator Transport and Control Flow
After provisioning, the Python client communicates with the simulator over ZeroMQ via `client/deepracer/zmq_client.py`. The typical control flow is: Gym `reset`/`step` → environment implementation → ZMQ request/response → running DeepRacer simulator → converted Gymnasium result. The transport separates Python training code from ROS/Gazebo-based simulator internals and container networking/process concerns.

#### Service Image and Upstream Integration
The simulator service is built from an upstream DeepRacer-for-Cloud workspace represented by `service/upstream`, with a maintained patch series in `service/patches/`. Patches address containerization, architecture support, local filesystem/S3 behavior, resource/port isolation, Gazebo rendering, and simulator lifecycle defects. `service/scripts/build.sh` builds the service image; CI publishes it through `.github/workflows/build-service-image.yml`.

#### Operational Interfaces and Infrastructure
The package depends on Gymnasium plus one local container runtime; supported runtimes include Docker, Podman, and Apptainer, with Apptainer serving rootless/HPC deployments. The simulator side materially involves ZeroMQ, ROS/Gazebo, and container images hosted through GitHub Container Registry. User cleanup is exposed in `client/deepracer/clean.py`, and broader lifecycle/documented configuration surfaces are centered on `client/deepracer/service/` and `docs/guide/managing.md`.

Main entry points: [`client/deepracer/service/manager.py`](https://github.com/uzairakbar/deepracer/blob/main/client/deepracer/service/manager.py) (Service manager), [`client/deepracer/envs/env.py`](https://github.com/uzairakbar/deepracer/blob/main/client/deepracer/envs/env.py) (DeepRacer environment), [`service/scripts/build.sh`](https://github.com/uzairakbar/deepracer/blob/main/service/scripts/build.sh) (Service image build), [`client/deepracer/service/backends.py`](https://github.com/uzairakbar/deepracer/blob/main/client/deepracer/service/backends.py) (Runtime backends)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Python client"]
  node_registration["Package registration<br/>entry point<br/>[__init__.py]"]
  node_adapter["Gym adapter<br/>[gym_adapter.py]"]
  node_environment["DeepRacer environment<br/>Gym environment<br/>[env.py]"]
  node_env_utils["Environment utilities<br/>data translation<br/>[utils.py]"]
  node_defaults["Default inputs<br/>agent/env/reward/track assets"]
  node_zmq["ZeroMQ client<br/>transport<br/>[zmq_client.py]"]
  node_cleanup["Cleanup command<br/>operational interface<br/>[clean.py]"]
end

subgraph group_service["Simulator service"]
  node_manager["Service manager<br/>lifecycle coordinator<br/>[manager.py]"]
  node_spec["Service spec<br/>launch model<br/>[spec.py]"]
  node_validation["Service validation<br/>prerequisite guard<br/>[validate.py]"]
  node_identity["Service identity<br/>isolation allocator<br/>[identity.py]"]
  node_backends{{"Runtime backends<br/>Docker/Podman/Apptainer abstraction<br/>[backends.py]"}}
end

subgraph group_image["Image build pipeline"]
  node_upstream["Upstream workspace<br/>DeepRacer-for-Cloud source"]
  node_patches["Patch series<br/>upstream modifications"]
  node_build["Service image build<br/>image build script<br/>[build.sh]"]
  node_ci["Image publishing CI<br/>GitHub Actions workflow"]
end

node_gym(("Gymnasium user code<br/>consumer"))
node_simulator["DeepRacer simulator<br/>ROS/Gazebo service"]
node_registry[("GHCR image registry<br/>container registry")]

node_gym -->|"gym.make"| node_registration
node_registration -->|"loads"| node_adapter
node_adapter -->|"constructs"| node_environment
node_environment -->|"uses"| node_defaults
node_environment -->|"translates data with"| node_env_utils
node_environment -->|"provisions simulator"| node_manager
node_environment -->|"reset / step"| node_zmq
node_zmq -->|"ZeroMQ request/response"| node_simulator
node_manager -->|"checks"| node_validation
node_manager -->|"materializes"| node_spec
node_manager -->|"allocates isolation"| node_identity
node_manager -->|"lifecycle commands"| node_backends
node_backends -->|"starts and manages"| node_simulator
node_cleanup -->|"removes services"| node_manager
node_upstream -->|"modified by"| node_patches
node_patches -->|"applied during build"| node_build
node_upstream -->|"build input"| node_build
node_build -->|"produces image"| node_registry
node_ci -->|"runs"| node_build
node_registry -->|"image source"| node_backends

click node_registration "https://github.com/uzairakbar/deepracer/blob/main/client/deepracer/__init__.py"
click node_adapter "https://github.com/uzairakbar/deepracer/blob/main/client/deepracer/gym_adapter.py"
click node_environment "https://github.com/uzairakbar/deepracer/blob/main/client/deepracer/envs/env.py"
click node_env_utils "https://github.com/uzairakbar/deepracer/blob/main/client/deepracer/envs/utils.py"
click node_zmq "https://github.com/uzairakbar/deepracer/blob/main/client/deepracer/zmq_client.py"
click node_cleanup "https://github.com/uzairakbar/deepracer/blob/main/client/deepracer/clean.py"
click node_manager "https://github.com/uzairakbar/deepracer/blob/main/client/deepracer/service/manager.py"
click node_spec "https://github.com/uzairakbar/deepracer/blob/main/client/deepracer/service/spec.py"
click node_validation "https://github.com/uzairakbar/deepracer/blob/main/client/deepracer/service/validate.py"
click node_identity "https://github.com/uzairakbar/deepracer/blob/main/client/deepracer/service/identity.py"
click node_backends "https://github.com/uzairakbar/deepracer/blob/main/client/deepracer/service/backends.py"
click node_upstream "https://github.com/uzairakbar/deepracer/tree/main/service/upstream"
click node_build "https://github.com/uzairakbar/deepracer/blob/main/service/scripts/build.sh"
click node_ci "https://github.com/uzairakbar/deepracer/blob/main/.github/workflows/build-service-image.yml"

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_registration,node_adapter,node_environment,node_env_utils,node_defaults,node_zmq,node_cleanup toneBlue
class node_manager,node_spec,node_validation,node_identity,node_backends toneAmber
class node_upstream,node_patches,node_build,node_ci toneMint
class node_gym,node_simulator,node_registry toneNeutral
```

## Components

### Python client

Gymnasium-facing package and lifecycle control.

- [Package registration](https://github.com/uzairakbar/deepracer/blob/main/client/deepracer/__init__.py): entry point · `client/deepracer/__init__.py`
- [Gym adapter](https://github.com/uzairakbar/deepracer/blob/main/client/deepracer/gym_adapter.py): adapter · Exposes construction and Gym lifecycle methods. · `client/deepracer/gym_adapter.py`
- [DeepRacer environment](https://github.com/uzairakbar/deepracer/blob/main/client/deepracer/envs/env.py): Gym environment · Coordinates episode state and converts simulator results. · `client/deepracer/envs/env.py`
- [Environment utilities](https://github.com/uzairakbar/deepracer/blob/main/client/deepracer/envs/utils.py): data translation · `client/deepracer/envs/utils.py`
- **Default inputs**: agent/env/reward/track assets
- [ZeroMQ client](https://github.com/uzairakbar/deepracer/blob/main/client/deepracer/zmq_client.py): transport · Sends simulator control requests and receives episode results. · `client/deepracer/zmq_client.py`
- [Cleanup command](https://github.com/uzairakbar/deepracer/blob/main/client/deepracer/clean.py): operational interface · `client/deepracer/clean.py`

### Simulator service

Provisioning and runtime abstraction.

- [Service manager](https://github.com/uzairakbar/deepracer/blob/main/client/deepracer/service/manager.py): lifecycle coordinator · Creates, starts, stops, and removes isolated simulators. · `client/deepracer/service/manager.py`
- [Service spec](https://github.com/uzairakbar/deepracer/blob/main/client/deepracer/service/spec.py): launch model · `client/deepracer/service/spec.py`
- [Service validation](https://github.com/uzairakbar/deepracer/blob/main/client/deepracer/service/validate.py): prerequisite guard · `client/deepracer/service/validate.py`
- [Service identity](https://github.com/uzairakbar/deepracer/blob/main/client/deepracer/service/identity.py): isolation allocator · Allocates values for concurrent services. · `client/deepracer/service/identity.py`
- [Runtime backends](https://github.com/uzairakbar/deepracer/blob/main/client/deepracer/service/backends.py): Docker/Podman/Apptainer abstraction · Builds runtime-specific commands and manages processes. · `client/deepracer/service/backends.py`

### Image build pipeline

Builds the patched simulator image.

- [Upstream workspace](https://github.com/uzairakbar/deepracer/tree/main/service/upstream): DeepRacer-for-Cloud source · `service/upstream`
- **Patch series**: upstream modifications · Adds container, isolation, rendering, and lifecycle support.
- [Service image build](https://github.com/uzairakbar/deepracer/blob/main/service/scripts/build.sh): image build script · `service/scripts/build.sh`
- [Image publishing CI](https://github.com/uzairakbar/deepracer/blob/main/.github/workflows/build-service-image.yml): GitHub Actions workflow · `.github/workflows/build-service-image.yml`

### Other components

- **Gymnasium user code**: consumer
- **DeepRacer simulator**: ROS/Gazebo service · Containerized simulator serving ZeroMQ control traffic.
- **GHCR image registry**: container registry

## Connections

- Gymnasium user code → Package registration: gym.make
- Package registration → Gym adapter: loads
- Gym adapter → DeepRacer environment: constructs
- DeepRacer environment → Default inputs: uses
- DeepRacer environment → Environment utilities: translates data with
- DeepRacer environment → Service manager: provisions simulator
- DeepRacer environment → ZeroMQ client: reset / step
- ZeroMQ client → DeepRacer simulator: ZeroMQ request/response
- Service manager → Service validation: checks
- Service manager → Service spec: materializes
- Service manager → Service identity: allocates isolation
- Service manager → Runtime backends: lifecycle commands
- Runtime backends → DeepRacer simulator: starts and manages
- Cleanup command → Service manager: removes services
- Upstream workspace → Patch series: modified by
- Patch series → Service image build: applied during build
- Upstream workspace → Service image build: build input
- Service image build → GHCR image registry: produces image
- Image publishing CI → Service image build: runs
- GHCR image registry → Runtime backends: image source
