# ros2torial/ros2_basics architecture

> Architecture diagram of the GitHub repository ros2torial/ros2_basics, 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/ros2torial/ros2_basics
- Repository: https://github.com/ros2torial/ros2_basics

## Overview

1. **Repository purpose**
   - This is a small **ROS 2 training/demo workspace** showing the same core patterns in **C++ and Python**: topic-based pub/sub, service-based request/response, custom interfaces, and launch orchestration.

2. **Package layout is the main architectural boundary**
   - The repo is split into independent ROS 2 packages:
     - `cpp_topic`, `py_topic` for topic examples
     - `cpp_service`, `py_service` for service examples
     - `custom_interfaces` for shared message/service definitions
     - `launch` for multi-node startup composition
     - `nodejs_ui` for a static UI artifact
   - This separation is important because ROS 2 packages are the deployment/build units, not just folders.

3. **Topic subsystem**
   - `cpp_topic` and `py_topic` each contain a **publisher node** and a **subscriber node**.
   - The publisher examples generate a **spiral-style stream of data/commands**; the subscriber examples consume that stream.
   - The same pattern is implemented twice, once in C++ and once in Python, which makes it useful as a language-comparison demo.

4. **Service subsystem**
   - `cpp_service` and `py_service` each contain a **service server** and a **service client**.
   - The flow is synchronous: the client sends a request, the server performs the computation/response, and the client receives the result.
   - Again, the repo duplicates the pattern across C++ and Python to demonstrate ROS 2 service mechanics in both runtimes.

5. **Shared interface contract**
   - `custom_interfaces` centralizes the application-level ROS contracts:
     - `msg/IOStatus.msg`
     - `srv/OutputControl.srv`
   - This package is the cross-language boundary that lets C++ and Python nodes interoperate cleanly without duplicating type definitions.
   - In architecture terms, it is the **schema layer** for the rest of the workspace.

6. **Launch layer**
   - The `launch/` folder contains `turtlesim_two_turtle.py` and parameter/remapping variants.
   - These files represent the **composition layer**: they assemble multiple ROS nodes into one runtime, inject parameters, and optionally remap topics.
   - The presence of “two turtle” launch files strongly suggests these demos are intended to run against a **turtlesim-style simulation environment**.

7. **Runtime data flow**
   - The primary flows are:
     - **Topic flow:** publisher node → ROS topic → subscriber node
     - **Service flow:** client node → service request → server node → service response
     - **Launch flow:** launch file → multiple nodes with parameters/remaps → coordinated demo
   - Nothing here suggests a central backend; interaction is through the ROS graph.

8. **Language/runtime split**
   - C++ nodes live under `src/` with `CMakeLists.txt` and `package.xml`.
   - Python nodes live in package modules with `setup.py`, `setup.cfg`, and `package.xml`.
   - `custom_interfaces` uses CMake because ROS 2 must generate code for shared interfaces across languages.
   - This mixed build model is a key architectural feature of ROS 2 workspaces.

9. **NodeJS UI**
   - `nodejs_ui/io_control.html` is a standalone HTML asset, likely intended as a simple control/dashboard surface.
   - There is no visible backend in the tree, so it should be treated as a UI experiment or integration artifact rather than a core runtime component.

10. **What to show in an architecture diagram**
   - Draw `custom_interfaces` as the shared contract layer beneath both C++ and Python nodes.
   - Show separate pub/sub and client/server pairs for each language.
   - Show `launch/` as the composition entrypoint that starts multiple nodes and applies parameters/remappings.
   - If including the simulator, place turtlesim as an external runtime dependency that the launch files and nodes interact with through ROS topics/services.

11. **Overall shape**
   - This repo is not a single application; it is a **collection of ROS 2 examples** organized around reusable communication patterns.
   - The architectural emphasis is on **inter-process messaging, shared interface definitions, and launch-time composition**, with C++ and Python used side by side to demonstrate the same concepts.

Main entry points: [`custom_interfaces`](https://github.com/ros2torial/ros2_basics/tree/master/custom_interfaces) (Interfaces), [`launch/turtlesim_two_turtle.py`](https://github.com/ros2torial/ros2_basics/blob/master/launch/turtlesim_two_turtle.py) (Launch), [`cpp_topic`](https://github.com/ros2torial/ros2_basics/tree/master/cpp_topic) (C++ topic), [`cpp_topic/src/cpp_topic_publisher_spiral.cpp`](https://github.com/ros2torial/ros2_basics/blob/master/cpp_topic/src/cpp_topic_publisher_spiral.cpp) (Spiral pub)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_grp_cpp["C++ packages"]
  node_cpp_topic["C++ topic<br/>ROS2 package"]
  node_cpp_pub(("Spiral pub<br/>publisher node"))
  node_cpp_sub(("Spiral sub<br/>subscriber node"))
  node_cpp_service["C++ service<br/>ROS2 package"]
  node_cpp_client(("Polar client<br/>service client"))
  node_cpp_server(("Polar server<br/>service server"))
end

subgraph group_grp_py["Python packages"]
  node_py_topic["Python topic<br/>ROS2 package"]
  node_py_pub(("Spiral pub<br/>publisher node"))
  node_py_sub(("Spiral sub<br/>subscriber node"))
  node_py_service["Python service<br/>ROS2 package"]
  node_py_client(("Polar client<br/>service client"))
  node_py_server(("Polar server<br/>service server"))
end

subgraph group_grp_shared["Shared layer"]
  node_custom_interfaces[("Interfaces<br/>ROS2 interface package")]
  node_io_status["IOStatus<br/>msg schema<br/>[IOStatus.msg]"]
  node_output_control["OutputControl<br/>srv schema<br/>[OutputControl.srv]"]
  node_launch["Launch<br/>composition layer"]
end

subgraph group_grp_ui["UI artifact"]
  node_nodejs_ui["IO control<br/>HTML UI<br/>[io_control.html]"]
end

subgraph group_grp_ext["External runtime"]
  node_turtlesim(("Turtlesim<br/>external simulator"))
end

node_custom_interfaces -->|"defines"| node_io_status
node_custom_interfaces -->|"defines"| node_output_control
node_launch -->|"starts"| node_turtlesim
node_launch -->|"runs"| node_cpp_topic
node_launch -->|"runs"| node_py_topic
node_launch -->|"runs"| node_cpp_service
node_launch -->|"runs"| node_py_service
node_cpp_topic -->|"contains"| node_cpp_pub
node_cpp_topic -->|"contains"| node_cpp_sub
node_cpp_pub -->|"topic flow"| node_cpp_sub
node_py_topic -->|"contains"| node_py_pub
node_py_topic -->|"contains"| node_py_sub
node_py_pub -->|"topic flow"| node_py_sub
node_cpp_service -->|"contains"| node_cpp_client
node_cpp_service -->|"contains"| node_cpp_server
node_cpp_client -->|"service flow"| node_cpp_server
node_py_service -->|"contains"| node_py_client
node_py_service -->|"contains"| node_py_server
node_py_client -->|"service flow"| node_py_server
node_cpp_pub -->|"uses"| node_custom_interfaces
node_cpp_sub -->|"uses"| node_custom_interfaces
node_cpp_client -->|"uses"| node_custom_interfaces
node_cpp_server -->|"uses"| node_custom_interfaces
node_py_pub -->|"uses"| node_custom_interfaces
node_py_sub -->|"uses"| node_custom_interfaces
node_py_client -->|"uses"| node_custom_interfaces
node_py_server -->|"uses"| node_custom_interfaces
node_nodejs_ui -.->|"pairs with"| node_launch

click node_custom_interfaces "https://github.com/ros2torial/ros2_basics/tree/master/custom_interfaces"
click node_io_status "https://github.com/ros2torial/ros2_basics/blob/master/custom_interfaces/msg/IOStatus.msg"
click node_output_control "https://github.com/ros2torial/ros2_basics/blob/master/custom_interfaces/srv/OutputControl.srv"
click node_launch "https://github.com/ros2torial/ros2_basics/blob/master/launch/turtlesim_two_turtle.py"
click node_cpp_topic "https://github.com/ros2torial/ros2_basics/tree/master/cpp_topic"
click node_cpp_pub "https://github.com/ros2torial/ros2_basics/blob/master/cpp_topic/src/cpp_topic_publisher_spiral.cpp"
click node_cpp_sub "https://github.com/ros2torial/ros2_basics/blob/master/cpp_topic/src/cpp_topic_subscriber_spiral.cpp"
click node_cpp_service "https://github.com/ros2torial/ros2_basics/tree/master/cpp_service"
click node_cpp_client "https://github.com/ros2torial/ros2_basics/blob/master/cpp_service/src/cpp_service_client_polar.cpp"
click node_cpp_server "https://github.com/ros2torial/ros2_basics/blob/master/cpp_service/src/cpp_service_server_polar.cpp"
click node_py_topic "https://github.com/ros2torial/ros2_basics/tree/master/py_topic"
click node_py_pub "https://github.com/ros2torial/ros2_basics/blob/master/py_topic/py_topic/py_topic_publisher_spiral.py"
click node_py_sub "https://github.com/ros2torial/ros2_basics/blob/master/py_topic/py_topic/py_topic_subscriber_spiral.py"
click node_py_service "https://github.com/ros2torial/ros2_basics/tree/master/py_service"
click node_py_client "https://github.com/ros2torial/ros2_basics/blob/master/py_service/py_service/py_service_client_polar.py"
click node_py_server "https://github.com/ros2torial/ros2_basics/blob/master/py_service/py_service/py_service_server_polar.py"
click node_nodejs_ui "https://github.com/ros2torial/ros2_basics/blob/master/nodejs_ui/io_control.html"

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_cpp_topic,node_cpp_pub,node_cpp_sub,node_cpp_service,node_cpp_client,node_cpp_server toneBlue
class node_py_topic,node_py_pub,node_py_sub,node_py_service,node_py_client,node_py_server toneAmber
class node_custom_interfaces,node_io_status,node_output_control,node_launch toneMint
class node_nodejs_ui toneRose
class node_turtlesim toneIndigo
```

## Components

### C++ packages

ROS 2 examples implemented in C++.

- [C++ topic](https://github.com/ros2torial/ros2_basics/tree/master/cpp_topic): ROS2 package · C++ pub/sub example package. · `cpp_topic`
- [Spiral pub](https://github.com/ros2torial/ros2_basics/blob/master/cpp_topic/src/cpp_topic_publisher_spiral.cpp): publisher node · C++ topic publisher generating spiral-style output. · `cpp_topic/src/cpp_topic_publisher_spiral.cpp`
- [Spiral sub](https://github.com/ros2torial/ros2_basics/blob/master/cpp_topic/src/cpp_topic_subscriber_spiral.cpp): subscriber node · C++ topic subscriber consuming the spiral stream. · `cpp_topic/src/cpp_topic_subscriber_spiral.cpp`
- [C++ service](https://github.com/ros2torial/ros2_basics/tree/master/cpp_service): ROS2 package · C++ client/server example package. · `cpp_service`
- [Polar client](https://github.com/ros2torial/ros2_basics/blob/master/cpp_service/src/cpp_service_client_polar.cpp): service client · C++ client sending synchronous requests. · `cpp_service/src/cpp_service_client_polar.cpp`
- [Polar server](https://github.com/ros2torial/ros2_basics/blob/master/cpp_service/src/cpp_service_server_polar.cpp): service server · C++ service server handling requests and responses. · `cpp_service/src/cpp_service_server_polar.cpp`

### Python packages

ROS 2 examples implemented in Python.

- [Python topic](https://github.com/ros2torial/ros2_basics/tree/master/py_topic): ROS2 package · Python pub/sub example package. · `py_topic`
- [Spiral pub](https://github.com/ros2torial/ros2_basics/blob/master/py_topic/py_topic/py_topic_publisher_spiral.py): publisher node · Python topic publisher generating spiral-style output. · `py_topic/py_topic/py_topic_publisher_spiral.py`
- [Spiral sub](https://github.com/ros2torial/ros2_basics/blob/master/py_topic/py_topic/py_topic_subscriber_spiral.py): subscriber node · Python topic subscriber consuming the spiral stream. · `py_topic/py_topic/py_topic_subscriber_spiral.py`
- [Python service](https://github.com/ros2torial/ros2_basics/tree/master/py_service): ROS2 package · Python client/server example package. · `py_service`
- [Polar client](https://github.com/ros2torial/ros2_basics/blob/master/py_service/py_service/py_service_client_polar.py): service client · Python client sending synchronous requests. · `py_service/py_service/py_service_client_polar.py`
- [Polar server](https://github.com/ros2torial/ros2_basics/blob/master/py_service/py_service/py_service_server_polar.py): service server · Python service server handling requests and responses. · `py_service/py_service/py_service_server_polar.py`

### Shared layer

Interface definitions and composition assets used across examples.

- [Interfaces](https://github.com/ros2torial/ros2_basics/tree/master/custom_interfaces): ROS2 interface package · Shared message and service contracts for the workspace. · `custom_interfaces`
- [IOStatus](https://github.com/ros2torial/ros2_basics/blob/master/custom_interfaces/msg/IOStatus.msg): msg schema · Shared status message definition. · `custom_interfaces/msg/IOStatus.msg`
- [OutputControl](https://github.com/ros2torial/ros2_basics/blob/master/custom_interfaces/srv/OutputControl.srv): srv schema · Shared service definition for output control requests. · `custom_interfaces/srv/OutputControl.srv`
- [Launch](https://github.com/ros2torial/ros2_basics/blob/master/launch/turtlesim_two_turtle.py): composition layer · Launch files that assemble multi-node demos with parameters and remappings. · `launch/turtlesim_two_turtle.py`

### UI artifact

Standalone browser-facing control surface.

- [IO control](https://github.com/ros2torial/ros2_basics/blob/master/nodejs_ui/io_control.html): HTML UI · Standalone browser UI artifact for IO control or experimentation. · `nodejs_ui/io_control.html`

### External runtime

Outside simulator/runtime dependency used by the demos.

- **Turtlesim**: external simulator · External ROS 2 simulation environment targeted by the launch demos.

## Connections

- Interfaces → IOStatus: defines · Message contract exported to ROS nodes.
- Interfaces → OutputControl: defines · Service contract exported to ROS nodes.
- Launch → Turtlesim: starts · Launch composition targets the simulator runtime.
- Launch → C++ topic: runs · Launch can coordinate demo nodes.
- Launch → Python topic: runs · Launch can coordinate demo nodes.
- Launch → C++ service: runs · Launch can coordinate demo nodes.
- Launch → Python service: runs · Launch can coordinate demo nodes.
- C++ topic → Spiral pub: contains · C++ publisher example.
- C++ topic → Spiral sub: contains · C++ subscriber example.
- Spiral pub → Spiral sub: topic flow · Publisher stream is consumed by the subscriber.
- Python topic → Spiral pub: contains · Python publisher example.
- Python topic → Spiral sub: contains · Python subscriber example.
- Spiral pub → Spiral sub: topic flow · Publisher stream is consumed by the subscriber.
- C++ service → Polar client: contains · C++ service client example.
- C++ service → Polar server: contains · C++ service server example.
- Polar client → Polar server: service flow · Client request is handled by the server.
- Python service → Polar client: contains · Python service client example.
- Python service → Polar server: contains · Python service server example.
- Polar client → Polar server: service flow · Client request is handled by the server.
- Spiral pub → Interfaces: uses · C++ nodes share ROS contracts from the interface package.
- Spiral sub → Interfaces: uses · C++ nodes share ROS contracts from the interface package.
- Polar client → Interfaces: uses · C++ service client uses shared service schema.
- Polar server → Interfaces: uses · C++ service server uses shared service schema.
- Spiral pub → Interfaces: uses · Python nodes share ROS contracts from the interface package.
- Spiral sub → Interfaces: uses · Python nodes share ROS contracts from the interface package.
- Polar client → Interfaces: uses · Python service client uses shared service schema.
- Polar server → Interfaces: uses · Python service server uses shared service schema.
- IO control → Launch: pairs with · UI is a standalone control artifact alongside the demo launch layer.
