# atostek/rustdds architecture

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

- Interactive diagram: https://gitdiagram.com/atostek/rustdds
- Repository: https://github.com/atostek/rustdds

## Overview

##### Main system layers and components
- Core DDS Implementation: Central to the system, located in the src directory.
- DDS API Layer: Includes abstractions such as DataReader, DataWriter, and topic/key handling. This is largely implemented in src/dds and related modules.
- Message and Serialization Modules: Managed within src/messages and src/serialization. These modules define the RTPS submessages, header structures, and the interface to the serde-based serialization (using the CDR adapter).
- Network and RTPS Transport: Found in src/network and src/rtps. This module handles UDP transport, control of non-blocking I/O (using the mio crate), and network utilities.
- Discovery Service: Located in src/discovery, which manages peer discovery (SPDP/SEDP) and built-in endpoints for domain discovery.
- Security Services: Found in the src/security tree. This handles authentication, access control, and cryptographic functions. Although security is still under ongoing testing and evolution, the architecture must include these components.
- Support and Integration Layers: Some integration is shown for ROS2 compatibility (in src/ros2), plus example programs in the examples directory to demonstrate functionality and interoperability.

##### Component interactions and data flow
- Data written by the API flows into the Message Module where payloads are serialized (using serde coupled with the CDR adapter) and shaped into RTPS submessages.
- Discovery mechanisms in the Discovery Module continuously exchange announcements using RTPS. Show bidirectional communication between Discovery and Network.
- The Security Module “wraps” or “intercepts” parts of the data flow to add authentication, cryptographic transformations, and access control.
- Finally, point out that examples and interoperability tests (including the FastDDS_interop_test folder) serve as consumers or demonstrators of the core architecture. They simulate external DDS systems or serve as integration validations.

##### Architectural patterns and design principles
- Modular design: Each subcomponent (DDS, messages, network, security, discovery) is well-isolated within its own namespace/folder. This separation makes it easier to update or replace implementations in each layer.
- Layered architecture: High-level DDS API calls are gradually transformed through serialization, network transport, and security checks.
- Non-blocking I/O: Highlight the integration with the mio crate as a critical element that enables event-based, asynchronous processing.

##### Relevant technologies, frameworks, and supporting assets
- Mention Rust’s Cargo for package management (indicated by Cargo.toml).
- Integrations with external crates: serde for serialization (and its CDR format adapter), mio for non-blocking network I/O, and possibly others (like Rust’s log facilities).
- The .github directory indicates CI/CD workflows, static checks, and tests—all showing the project’s commitment to quality.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Components
    Edc["Example/Demo Clients"]:::external
    Its["Interoperability Test Suite"]:::external
    Ros["ROS2 Integration"]:::external

    %% Core Layers
    Api["DDS API Layer"]:::api
    Core["Core DDS Implementation"]:::core
    Msg["Message and Serialization Modules"]:::serialization
    Sec["Security Services"]:::security
    Net["Network and RTPS Transport"]:::network
    Disc["Discovery Service"]:::discovery

    %% Data Flow Connections
    Edc -->|"uses"| Api
    Its -->|"tests"| Api
    Ros -->|"integrates"| Api

    Api -->|"invokes"| Core
    Core -->|"processes"| Msg
    Msg -->|"wrappedBy"| Sec
    Sec -->|"transmitsTo"| Net

    %% Bidirectional Discovery <--> Networking interaction
    Net <-->|"exchanges"| Disc

    %% Click Events
    click Core "https://github.com/atostek/rustdds/blob/master/src/lib.rs"
    click Api "https://github.com/atostek/rustdds/tree/master/src/dds"
    click Msg "https://github.com/atostek/rustdds/tree/master/src/messages"
    click Net "https://github.com/atostek/rustdds/tree/master/src/network"
    click Disc "https://github.com/atostek/rustdds/tree/master/src/discovery"
    click Sec "https://github.com/atostek/rustdds/tree/master/src/security"
    click Ros "https://github.com/atostek/rustdds/tree/master/src/ros2"
    click Edc "https://github.com/atostek/rustdds/tree/master/examples"
    click Its "https://github.com/atostek/rustdds/tree/master/FastDDS_interop_test"

    %% Styling
    classDef core fill:#add8e6,stroke:#333,stroke-width:2px;
    classDef api fill:#90ee90,stroke:#333,stroke-width:2px;
    classDef serialization fill:#ffc0cb,stroke:#333,stroke-width:2px;
    classDef network fill:#f4a460,stroke:#333,stroke-width:2px;
    classDef discovery fill:#87cefa,stroke:#333,stroke-width:2px;
    classDef security fill:#ffd700,stroke:#333,stroke-width:2px;
    classDef external fill:#98fb98,stroke:#333,stroke-width:2px;
```
