# ros2/examples architecture

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

- Interactive diagram: https://gitdiagram.com/ros2/examples
- Repository: https://github.com/ros2/examples

## Overview

This repository is a collection of ROS 2 example packages, not a single application. The architectural unit is the package: each example lives in its own ROS package with its own manifest, build config, and entry points, and all of them communicate through the ROS 2 runtime and middleware rather than through internal library calls.

1. **Top-level split by language and purpose**
   - `rclcpp/` contains C++ examples.
   - `rclpy/` contains Python examples.
   - `launch_testing/` contains examples of ROS 2 launch-based system testing.
   - The repo is organized as a tutorial/reference suite for ROS 2 concepts, with no central service or shared runtime state beyond the ROS graph.

2. **Package boundary model**
   - Most subdirectories under `rclcpp/` and `rclpy/` are standalone packages with their own `package.xml`.
   - Python examples additionally have `setup.py`, `setup.cfg`, and `resource/` markers, showing they install as importable Python packages and executable console scripts.
   - C++ examples have `CMakeLists.txt`, indicating standard ROS 2/ament C++ builds.
   - This means each example can be built, installed, and run independently.

3. **Primary communication pattern: topics**
   - The `topics/minimal_publisher` and `topics/minimal_subscriber` packages in both languages are the core pub/sub examples.
   - Data flows from publishers into the ROS middleware and then out to subscribers via topic names and message types.
   - These packages demonstrate variants such as lambda callbacks, member functions, type adapters, QoS-related behavior, and composition-aware versus standalone nodes.
   - `rclpy/topics/pointcloud_publisher` is a more concrete topic example publishing a richer sensor-style message rather than a trivial string.

4. **Request/response boundary: services**
   - `services/minimal_service` and `services/minimal_client` in both languages show the synchronous and asynchronous service interaction model.
   - The server owns the request-handling boundary; the client issues requests and receives responses through the ROS service transport.
   - Several Python variants show different callback styles and asynchronous usage, while the C++ examples show minimal and async client patterns.

5. **Long-running goal-based interaction: actions**
   - `actions/minimal_action_server` and `actions/minimal_action_client` demonstrate the action protocol.
   - The data flow is more complex than services: a goal is accepted, progress feedback may stream back, and the client can cancel or wait for completion.
   - Variants cover single-goal behavior, queued goals, deferred execution, feedback, and composability differences.

6. **Execution and scheduling layer**
   - `executors/` in both languages focuses on how callbacks are scheduled and driven.
   - Python examples include custom callback groups and custom executors, showing the boundary between node logic and callback dispatch.
   - C++ examples include a multithreaded executor and a callback-group-based executor sample (`cbg_executor`), emphasizing concurrency and coordination across callbacks.

7. **Low-level event handling with wait sets**
   - `rclcpp/wait_set` and the wait-set-related examples in `rclcpp/topics/minimal_subscriber` expose a lower-level reactive model than standard executors.
   - These examples show nodes waiting on specific combinations of topics, timers, and events, including static and random-order behavior.
   - Architecturally, this is the “manual event loop” layer of the repo.

8. **Timers and periodic callbacks**
   - `rclcpp/timers/minimal_timer` demonstrates periodic work driven by the ROS timer subsystem.
   - The timer callback is the source of activity, and any publishing or state update happens on that schedule rather than in response to incoming messages.

9. **Node composition and in-process reuse**
   - `rclcpp/composition/minimal_composition` shows how nodes can be built as reusable components and loaded together.
   - It includes publisher/subscriber node classes plus standalone and composed entry points.
   - This package defines the boundary between node implementation and deployment shape: the same node logic can run as separate processes or as composed components.

10. **Launch testing as system-level verification**
   - `launch_testing/launch_testing_examples` is a separate test-oriented subsystem.
   - It uses ROS 2 launch descriptions and runtime assertions to validate behavior of started nodes, parameter setting, message flow, and rosbag recording.
   - This is the integration-test layer of the repo: it exercises whole-node behavior rather than unit-level library logic.

11. **Cross-cutting ROS 2 infrastructure**
   - All examples sit on top of ROS 2 concepts: nodes, publishers/subscribers, services, actions, executors, callback groups, timers, and launch.
   - The runtime boundary is the ROS graph and middleware transport, so diagramming should show packages as independent nodes/processes connected through ROS topics, services, actions, or test launch orchestration.

12. **Repo-wide packaging and quality tooling**
   - Many packages include `CHANGELOG.rst`, `README.md`, and test directories.
   - Python packages commonly include lint/style tests such as flake8, pep257, xmllint, and copyright checks.
   - These are supporting concerns, not runtime subsystems, but they reinforce that each example is maintained as a distributable ROS package.

In short: this repo is a catalog of small, self-contained ROS 2 packages demonstrating specific communication and execution patterns, with the main architectural boundaries defined by language (C++ vs Python), interaction model (topic/service/action/timer/wait set), and deployment shape (standalone vs composed vs launch-tested).

Main entry points: [`launch_testing/launch_testing_examples`](https://github.com/ros2/examples/tree/rolling/launch_testing/launch_testing_examples) (Launch tests), [`rclcpp/topics/minimal_publisher`](https://github.com/ros2/examples/tree/rolling/rclcpp/topics/minimal_publisher) (Topic pub), [`rclpy/topics/minimal_publisher`](https://github.com/ros2/examples/tree/rolling/rclpy/topics/minimal_publisher) (Topic pub), [`rclcpp/services/minimal_service`](https://github.com/ros2/examples/tree/rolling/rclcpp/services/minimal_service) (Service srv)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_g_rclcpp["rclcpp"]
  node_n_cpp_topics_pub["Topic pub"]
  node_n_cpp_topics_sub["Topic sub"]
  node_n_cpp_services_server["Service srv"]
  node_n_cpp_services_client["Service cli"]
  node_n_cpp_actions_server["Action srv"]
  node_n_cpp_actions_client["Action cli"]
  node_n_cpp_executors["Executors"]
  node_n_cpp_waitset["Wait set"]
  node_n_cpp_timers["Timers"]
  node_n_cpp_composition["Composition"]
end

subgraph group_g_rclpy["rclpy"]
  node_n_py_topics_pub["Topic pub"]
  node_n_py_topics_sub["Topic sub"]
  node_n_py_services_server["Service srv"]
  node_n_py_services_client["Service cli"]
  node_n_py_actions_server["Action srv"]
  node_n_py_actions_client["Action cli"]
  node_n_py_executors["Executors"]
  node_n_py_guard["Guard cond."]
end

subgraph group_g_launch["launch_testing"]
  node_n_launch["Launch tests"]
end

node_n_runtime(("ROS 2 runtime<br/>middleware/runtime"))

node_n_cpp_topics_pub -->|"publishes topics"| node_n_runtime
node_n_runtime -->|"delivers topics"| node_n_cpp_topics_sub
node_n_py_topics_pub -->|"publishes topics"| node_n_runtime
node_n_runtime -->|"delivers topics"| node_n_py_topics_sub
node_n_cpp_services_client -->|"calls service"| node_n_runtime
node_n_runtime -->|"handles service"| node_n_cpp_services_server
node_n_py_services_client -->|"calls service"| node_n_runtime
node_n_runtime -->|"handles service"| node_n_py_services_server
node_n_cpp_actions_client -->|"sends goal"| node_n_runtime
node_n_runtime -->|"executes goal"| node_n_cpp_actions_server
node_n_py_actions_client -->|"sends goal"| node_n_runtime
node_n_runtime -->|"executes goal"| node_n_py_actions_server
node_n_cpp_executors -->|"schedules callbacks"| node_n_runtime
node_n_py_executors -->|"schedules callbacks"| node_n_runtime
node_n_cpp_waitset -->|"waits on events"| node_n_runtime
node_n_cpp_timers -->|"triggers timers"| node_n_runtime
node_n_cpp_composition -->|"loads components"| node_n_runtime
node_n_py_guard -->|"triggers guard"| node_n_runtime
node_n_launch -->|"launches tests"| node_n_runtime
node_n_launch -.->|"tests"| node_n_cpp_topics_pub
node_n_launch -.->|"tests"| node_n_py_topics_pub
node_n_launch -.->|"tests"| node_n_cpp_services_server
node_n_launch -.->|"tests"| node_n_py_services_server

click node_n_cpp_topics_pub "https://github.com/ros2/examples/tree/rolling/rclcpp/topics/minimal_publisher"
click node_n_cpp_topics_sub "https://github.com/ros2/examples/tree/rolling/rclcpp/topics/minimal_subscriber"
click node_n_cpp_services_server "https://github.com/ros2/examples/tree/rolling/rclcpp/services/minimal_service"
click node_n_cpp_services_client "https://github.com/ros2/examples/tree/rolling/rclcpp/services/minimal_client"
click node_n_cpp_actions_server "https://github.com/ros2/examples/tree/rolling/rclcpp/actions/minimal_action_server"
click node_n_cpp_actions_client "https://github.com/ros2/examples/tree/rolling/rclcpp/actions/minimal_action_client"
click node_n_cpp_executors "https://github.com/ros2/examples/tree/rolling/rclcpp/executors/cbg_executor"
click node_n_cpp_waitset "https://github.com/ros2/examples/tree/rolling/rclcpp/wait_set"
click node_n_cpp_timers "https://github.com/ros2/examples/tree/rolling/rclcpp/timers/minimal_timer"
click node_n_cpp_composition "https://github.com/ros2/examples/tree/rolling/rclcpp/composition/minimal_composition"
click node_n_py_topics_pub "https://github.com/ros2/examples/tree/rolling/rclpy/topics/minimal_publisher"
click node_n_py_topics_sub "https://github.com/ros2/examples/tree/rolling/rclpy/topics/minimal_subscriber"
click node_n_py_services_server "https://github.com/ros2/examples/tree/rolling/rclpy/services/minimal_service"
click node_n_py_services_client "https://github.com/ros2/examples/tree/rolling/rclpy/services/minimal_client"
click node_n_py_actions_server "https://github.com/ros2/examples/tree/rolling/rclpy/actions/minimal_action_server"
click node_n_py_actions_client "https://github.com/ros2/examples/tree/rolling/rclpy/actions/minimal_action_client"
click node_n_py_executors "https://github.com/ros2/examples/tree/rolling/rclpy/executors"
click node_n_py_guard "https://github.com/ros2/examples/tree/rolling/rclpy/guard_conditions"
click node_n_launch "https://github.com/ros2/examples/tree/rolling/launch_testing/launch_testing_examples"

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_n_cpp_topics_pub,node_n_cpp_topics_sub,node_n_cpp_services_server,node_n_cpp_services_client,node_n_cpp_actions_server,node_n_cpp_actions_client,node_n_cpp_executors,node_n_cpp_waitset,node_n_cpp_timers,node_n_cpp_composition toneBlue
class node_n_py_topics_pub,node_n_py_topics_sub,node_n_py_services_server,node_n_py_services_client,node_n_py_actions_server,node_n_py_actions_client,node_n_py_executors,node_n_py_guard toneAmber
class node_n_launch toneMint
class node_n_runtime toneNeutral
```

## Components

### rclcpp

C++ ROS 2 example packages

- [Topic pub](https://github.com/ros2/examples/tree/rolling/rclcpp/topics/minimal_publisher): package · C++ minimal publisher variants · `rclcpp/topics/minimal_publisher`
- [Topic sub](https://github.com/ros2/examples/tree/rolling/rclcpp/topics/minimal_subscriber): package · C++ minimal subscriber variants plus wait-set-driven subscriber samples · `rclcpp/topics/minimal_subscriber`
- [Service srv](https://github.com/ros2/examples/tree/rolling/rclcpp/services/minimal_service): package · C++ minimal service server variants · `rclcpp/services/minimal_service`
- [Service cli](https://github.com/ros2/examples/tree/rolling/rclcpp/services/minimal_client): package · C++ minimal and async service client variants · `rclcpp/services/minimal_client`
- [Action srv](https://github.com/ros2/examples/tree/rolling/rclcpp/actions/minimal_action_server): package · C++ action server variants · `rclcpp/actions/minimal_action_server`
- [Action cli](https://github.com/ros2/examples/tree/rolling/rclcpp/actions/minimal_action_client): package · C++ action client variants · `rclcpp/actions/minimal_action_client`
- [Executors](https://github.com/ros2/examples/tree/rolling/rclcpp/executors/cbg_executor): package · C++ executor and callback-group scheduling examples · `rclcpp/executors/cbg_executor`
- [Wait set](https://github.com/ros2/examples/tree/rolling/rclcpp/wait_set): package · C++ manual event-loop and wait-set examples · `rclcpp/wait_set`
- [Timers](https://github.com/ros2/examples/tree/rolling/rclcpp/timers/minimal_timer): package · C++ periodic timer examples · `rclcpp/timers/minimal_timer`
- [Composition](https://github.com/ros2/examples/tree/rolling/rclcpp/composition/minimal_composition): package · C++ component and standalone deployment examples · `rclcpp/composition/minimal_composition`

### rclpy

Python ROS 2 example packages

- [Topic pub](https://github.com/ros2/examples/tree/rolling/rclpy/topics/minimal_publisher): package · Python minimal publisher variants and pointcloud publisher · `rclpy/topics/minimal_publisher`
- [Topic sub](https://github.com/ros2/examples/tree/rolling/rclpy/topics/minimal_subscriber): package · Python minimal subscriber variants · `rclpy/topics/minimal_subscriber`
- [Service srv](https://github.com/ros2/examples/tree/rolling/rclpy/services/minimal_service): package · Python minimal service server variants · `rclpy/services/minimal_service`
- [Service cli](https://github.com/ros2/examples/tree/rolling/rclpy/services/minimal_client): package · Python synchronous and asynchronous service clients · `rclpy/services/minimal_client`
- [Action srv](https://github.com/ros2/examples/tree/rolling/rclpy/actions/minimal_action_server): package · Python action server variants · `rclpy/actions/minimal_action_server`
- [Action cli](https://github.com/ros2/examples/tree/rolling/rclpy/actions/minimal_action_client): package · Python action client variants · `rclpy/actions/minimal_action_client`
- [Executors](https://github.com/ros2/examples/tree/rolling/rclpy/executors): package · Python callback-group and custom executor examples · `rclpy/executors`
- [Guard cond.](https://github.com/ros2/examples/tree/rolling/rclpy/guard_conditions): package · Python guard condition trigger example · `rclpy/guard_conditions`

### launch_testing

Launch-based system testing examples

- [Launch tests](https://github.com/ros2/examples/tree/rolling/launch_testing/launch_testing_examples): package · Launch-based integration and system test examples · `launch_testing/launch_testing_examples`

### Other components

- **ROS 2 runtime**: middleware/runtime · Shared ROS graph, message transport, and callback scheduling boundary for all examples

## Connections

- Topic pub → ROS 2 runtime: publishes topics · C++ publishers send messages into the ROS graph
- ROS 2 runtime → Topic sub: delivers topics · Subscribers receive messages from the ROS graph
- Topic pub → ROS 2 runtime: publishes topics · Python publishers send messages into the ROS graph
- ROS 2 runtime → Topic sub: delivers topics · Subscribers receive messages from the ROS graph
- Service cli → ROS 2 runtime: calls service · C++ clients issue service requests through ROS transport
- ROS 2 runtime → Service srv: handles service · Servers receive requests and return responses
- Service cli → ROS 2 runtime: calls service · Python clients issue service requests through ROS transport
- ROS 2 runtime → Service srv: handles service · Servers receive requests and return responses
- Action cli → ROS 2 runtime: sends goal · Action clients submit goals and receive feedback/results
- ROS 2 runtime → Action srv: executes goal · Action servers accept goals and manage progress
- Action cli → ROS 2 runtime: sends goal · Action clients submit goals and receive feedback/results
- ROS 2 runtime → Action srv: executes goal · Action servers accept goals and manage progress
- Executors → ROS 2 runtime: schedules callbacks · Executor and callback-group behavior sits above ROS entities
- Executors → ROS 2 runtime: schedules callbacks · Custom executors and callback groups drive callback dispatch
- Wait set → ROS 2 runtime: waits on events · Manual wait-set loops react to specific ROS events
- Timers → ROS 2 runtime: triggers timers · Periodic callbacks drive activity through the ROS timer subsystem
- Composition → ROS 2 runtime: loads components · Composable nodes can run in-process or standalone
- Guard cond. → ROS 2 runtime: triggers guard · Guard conditions integrate with ROS event handling
- Launch tests → ROS 2 runtime: launches tests · Launch descriptions start nodes and assert runtime behavior
- Launch tests → Topic pub: tests · Launch tests exercise node behavior
- Launch tests → Topic pub: tests · Launch tests exercise node behavior
- Launch tests → Service srv: tests · Launch tests exercise node behavior
- Launch tests → Service srv: tests · Launch tests exercise node behavior
