# ros2/rclcpp architecture

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

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

## Overview

##### Main Components
- rclcpp (core library): Handles basic functionality such as nodes, publishers, subscriptions, services, parameters, clocks, timers, wait sets, and logging. It is the foundation that provides the interfaces most users include with “#include rclcpp/rclcpp.hpp”.
- rclcpp_action: Provides the abstractions for ROS 2 actions (clients, servers, goal handles) and related APIs.
- rclcpp_components: Manages the creation and registration of componentized nodes, enabling dynamic composition of nodes at runtime.
- rclcpp_lifecycle: Implements managed (lifecycle) nodes, with functionalities to control and monitor node states and transitions.
- ROS Middleware Interaction: Although not explicitly a “directory”, the library interfaces with ROS middleware (RMW) through an abstraction layer. Represent this middleware connection as a dedicated component.

##### File Structure for Architectural Relationships
- The core rclcpp module provides most of the header interfaces (for nodes, publishers, subscribers, etc.) and many of the source files implement these abstractions.
- The experimental and detail directories are placeholders for auxiliary or internal implementation details. You may choose to emphasize them as “Utilities” or “Internal Helpers” if needed.

##### Relationships and Data Flow
- rclcpp_components and rclcpp_lifecycle extend rclcpp by adding component-based and lifecycle management capabilities. Represent these as extended modules that integrate with the core.
- Connection between these libraries and ROS Middleware (RMW layer) to indicate that all higher-level abstractions eventually interface with the underlying ROS communication layer.

##### Important Architectural Patterns
- Modularity: The separation of rclcpp into different packages (core, action, components, lifecycle) is by design and should be highlighted.
- Abstraction Layers: The user-facing C++ API abstracts details of the ROS communication mechanism.
- Test and Documentation Driven: The extensive test directories (benchmarks, unit tests) show an architecture that emphasizes reliability and instrumented behavior.

## Diagram (Mermaid)

```mermaid
flowchart TD
    USER["User Application"]:::user
    CORE["Core rclcpp<br/>(Node, Publisher, Subscription,<br/>Service, Timer, WaitSet, Logging)"]:::core

    subgraph "Extension Modules"
        direction TB
        ACT["rclcpp_action<br/>(ROS 2 Actions API)"]:::extension
        COMP["rclcpp_components<br/>(Component Management)"]:::extension
        LIFE["rclcpp_lifecycle<br/>(Lifecycle management)"]:::extension
    end

    RMW["ROS Middleware Layer<br/>(RMW Abstraction)"]:::middleware

    USER -->|"calls"| CORE
    ACT -->|"extends"| CORE
    COMP -->|"integrates"| CORE
    LIFE -->|"manages"| CORE
    CORE -->|"interfaces"| RMW
    ACT -->|"interfaces"| RMW
    COMP -->|"interfaces"| RMW
    LIFE -->|"interfaces"| RMW

    click CORE "https://github.com/ros2/rclcpp/tree/rolling/rclcpp/"
    click ACT "https://github.com/ros2/rclcpp/tree/rolling/rclcpp_action/"
    click COMP "https://github.com/ros2/rclcpp/tree/rolling/rclcpp_components/"
    click LIFE "https://github.com/ros2/rclcpp/tree/rolling/rclcpp_lifecycle/"
    click RMW "https://github.com/ros2/rclcpp/tree/rolling/rclcpp/include/rclcpp/detail/"

    classDef user fill:#FFB6C1,stroke:#333,stroke-width:2px;
    classDef core fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef extension fill:#FFD700,stroke:#333,stroke-width:2px;
    classDef middleware fill:#90EE90,stroke:#333,stroke-width:2px;
```
