# flexrobotics/roboflex architecture

> Architecture diagram of the GitHub repository flexrobotics/roboflex, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/flexrobotics/roboflex
- Repository: https://github.com/flexrobotics/roboflex

## Overview

##### Main Components

a) Core Components:
- Message System
- Node System
- Serialization Layer
- Core Nodes Implementation
- Python Bindings

b) Key Architectural Elements:
- Message Flow Architecture
- Node Communication Patterns
- Serialization Mechanisms
- Threading Model

**┌─ Core System ──────────────────────────┐**
- ┌─────────┐    ┌──────┐    ┌────────┐ │
- Messages │←→  │Nodes │←→  │Signals │ │
- ┘    └──────┘    └────────┘ │
- ┘

**┌─ Message Implementation ─┐  ┌─ Node Types ──────────┐**
- 8-byte RFLX header    │  │ - Base Node           │
- Flexbuffer payload    │  │ - RunnableNode        │
- Meta data             │  │ - Specialized Nodes    │
- ┘  └─────────────────────-─┘

##### Specific Elements to Highlight

a) Message Flow:
- 'RFLX' header structure
- FlexBuffer serialization
- Zero-copy functionality

b) Node Hierarchy:
- Base Node
- RunnableNode
- Specialized Nodes (FrequencyGenerator, MapFun, etc.)

c) Threading Model:
- Thread boundaries
- Message passing between threads

##### Key Relationships

- Node-to-Node connections (pub-sub pattern)
- Message serialization flow
- Python-C++ binding interface
- Threading boundaries

##### Implementation Details

**┌─ Core Headers ─────┐  ┌─ Implementation ────┐**
- core.h            │  │ message.cpp         │
- message.h         │  │ node.cpp            │
- node.h            │  │ serialization/*.cpp │
- ┘  └───────────────────-─┘

##### The serialization mechanism

Remember to maintain a balance between detail and clarity, focusing on the core message-passing architecture while showing how the various components interact to form a complete system.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Core["Core Infrastructure"]
        MS["Message System"]:::core
        NS["Node System"]:::core
        MS <--> NS
    end

    subgraph Serialization["Serialization Services"]
        SL["Serialization Layer"]:::serialization
        ES["Eigen Support"]:::serialization
        XS["XTensor Support"]:::serialization
        FB["Flex Buffer"]:::serialization
        SL --> ES
        SL --> XS
        SL --> FB
    end

    subgraph NodeTypes["Core Node Types"]
        PN["Producer Nodes"]:::nodes
        FN["Filter Nodes"]:::nodes
        CN["Callback Nodes"]:::nodes
        BN["Base Node Implementations"]:::nodes
    end

    subgraph DataHandling["Data Handling"]
        UDS["Universal Data Saver"]:::data
        UDP["Universal Data Player"]:::data
        TB["Tensor Buffer"]:::data
    end

    subgraph Utils["Core Utilities"]
        CU["Core Utils"]:::utils
        UUID["UUID"]:::utils
        EV["Event System"]:::utils
        PM["Process Memory"]:::utils
    end

    subgraph Monitoring["Performance Monitoring"]
        MT["Metrics"]:::monitoring
    end

    subgraph Python["Python Integration"]
        PB["Python Bindings"]:::python
        DF["DynoFlex"]:::python
        FP["FlexBuffers Python"]:::python
    end

    Core --> Serialization
    Core --> NodeTypes
    NodeTypes --> DataHandling
    Core --> Utils
    NodeTypes --> Monitoring
    Core --> Python

    %% Click events for component mapping
    click MS "https://github.com/flexrobotics/roboflex/blob/main/include/roboflex_core/message.h"
    click NS "https://github.com/flexrobotics/roboflex/blob/main/include/roboflex_core/node.h"
    click SL "https://github.com/flexrobotics/roboflex/blob/main/include/roboflex_core/serialization/serialization.h"
    click ES "https://github.com/flexrobotics/roboflex/blob/main/include/roboflex_core/serialization/flex_eigen.h"
    click XS "https://github.com/flexrobotics/roboflex/blob/main/include/roboflex_core/serialization/flex_xtensor.h"
    click PN "https://github.com/flexrobotics/roboflex/blob/main/include/roboflex_core/core_nodes/producer.h"
    click FN "https://github.com/flexrobotics/roboflex/blob/main/include/roboflex_core/core_nodes/filter_fun.h"
    click CN "https://github.com/flexrobotics/roboflex/blob/main/include/roboflex_core/core_nodes/callback_fun.h"
    click BN "https://github.com/flexrobotics/roboflex/blob/main/include/roboflex_core/core_nodes/core_nodes.h"
    click PB "https://github.com/flexrobotics/roboflex/blob/main/include/roboflex_core/pybindings.h"
    click DF "https://github.com/flexrobotics/roboflex/blob/main/python/dynoflex.py"
    click FP "https://github.com/flexrobotics/roboflex/blob/main/python/flexbuffers.py"
    click CU "https://github.com/flexrobotics/roboflex/blob/main/include/roboflex_core/util/utils.h"
    click UUID "https://github.com/flexrobotics/roboflex/blob/main/include/roboflex_core/util/uuid.h"
    click EV "https://github.com/flexrobotics/roboflex/blob/main/include/roboflex_core/util/event.h"
    click PM "https://github.com/flexrobotics/roboflex/blob/main/include/roboflex_core/util/get_process_memory_usage.h"
    click UDS "https://github.com/flexrobotics/roboflex/blob/main/include/roboflex_core/core_nodes/universal_data_saver.h"
    click UDP "https://github.com/flexrobotics/roboflex/blob/main/include/roboflex_core/core_nodes/universal_data_player.h"
    click TB "https://github.com/flexrobotics/roboflex/blob/main/include/roboflex_core/core_nodes/tensor_buffer.h"
    click MT "https://github.com/flexrobotics/roboflex/blob/main/include/roboflex_core/core_nodes/metrics.h"

    classDef core fill:#2374ab
    classDef serialization fill:#ffb703
    classDef nodes fill:#52b788
    classDef data fill:#9b5de5
    classDef utils fill:#00b4d8
    classDef monitoring fill:#ef233c
    classDef python fill:#fb8500

    %% Legend
    subgraph Legend
        L1[Core Components]:::core
        L2[Serialization]:::serialization
        L3[Node Types]:::nodes
        L4[Data Handling]:::data
        L5[Utilities]:::utils
        L6[Monitoring]:::monitoring
        L7[Python]:::python
    end
```
