# microvault/rnl architecture

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

## Overview

##### And Outline the Main Components
- Core Library ("rnl"): The heart of the project is under the “rnl” package which is split into several submodules:
- Agents (rnl/agents): Contains evaluation and decision-making logic.
- Configs (rnl/configs): Manages configuration for robot attributes, sensors, and rewards.
- Engine (rnl/engine): Implements physics, collision handling, environment generation, LIDAR processing, and world management.
- Environment (rnl/environment): Represents the simulation world, robot environment, sensor models, and related functionalities.
- Network (rnl/network): Defines the deep learning model architecture used for training.
- Training (rnl/training): Contains the training routines, callbacks, visualization, and learning interfaces for executing deep reinforcement learning algorithms.

- Entry Points and Demos:
- main.py: Acts as a demo entry point for simulation.
- Benchmarks and tests: Validate functionality (e.g., tests/testing collision, lidar, map2d functionality).

- Data and Models:
- Data directories (data and ros/src/playground/maps): Contain map files (PGM, YAML) used for environmental configurations.
- Models directory (models and ros/src/playground/models): Contains saved/trained models (model.zip files) tracking different training iterations.

- Deployment and Integration:
- Docker directory (docker/Dockerfile) and ROS integration (ros/ directory): These support containerized deployments and interface with ROS for simulation or real-world robotic control.

- Supporting Files:
- Configuration files (pyproject.toml, Makefile, pre-commit-config.yaml) that help build, test, and maintain the project.

##### Relationships and Data Flows
- The Engine (rnl/engine) interacts with Environment and Sensor modules (rnl/environment/sensor.py) to simulate physics, LIDAR scans, collision detection, and map integration.
- The Network module (rnl/network/model.py) works closely with the Training module (rnl/training) to implement learning algorithms (e.g., PPO as shown in the README examples).
- The Agents module (rnl/agents) coordinates evaluations, either during training or inference.
- Main application flows: The demo in main.py and command-line execution “python main.py -m sim” represent the integration point for simulation where the components (robot configuration, sensor data, and environmental controls) come together.

##### Architectural Patterns and Design Principles
- Modularity & Separation of Concerns: The directory structure separates simulation (environment, engine), configuration (configs), training logic (training), and evaluation (agents).
- Extensibility: With components like training callbacks and simulation rendering, the architecture is designed for extensibility.
- Docker and ROS Integration: Separate directories for docker and ROS highlight the emphasis on containerized deployment and real/simulated robotics integration.

##### Supporting Technologies
- Python and PyTorch: The primary programming language and deep learning framework.
- ROS (Robot Operating System): For integrating simulation scenarios and potentially real-world deployments.
- Docker: Used for creating isolated execution environments and easing deployment.

##### Details Without Overcomplicating
- The principal software engineer should focus on identifying the smallest logical components rather than just drawing one big monolith.
- A detailed inset that captures the internal structure of a complex submodule like rnl/training if needed.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Core Library (rnl)
    subgraph "Core Library (rnl)"
        %% Simulation & Environment Layer
        subgraph "Simulation & Environment"
            rnl_configs["Configuration Manager"]:::core
            rnl_environment["Simulation Environment"]:::core
            rnl_engine["Physics & Sensor Engine"]:::core
            rnl_sensor["LIDAR Sensor"]:::core
        end
        %% Training Pipeline Layer
        subgraph "Training Pipeline"
            rnl_training["Training Module"]:::core
            rnl_network["Network Model"]:::core
            rnl_agents["Agent Module"]:::core
        end
    end

    %% Demo Entry Point
    main_demo["Demo Entry (main.py)"]:::external

    %% Data & Models Layer
    subgraph "Data & Models"
        map_data["Map Files"]:::data
        trained_models["Trained Models"]:::data
    end

    %% Deployment & Integration Layer
    subgraph "Deployment & Integration"
        docker["Docker Deployment"]:::deployment
        ros["ROS Integration"]:::deployment
    end

    %% Supporting Files
    subgraph "Supporting Files"
        config_support["pyproject.toml"]:::support
        makefile["Makefile"]:::support
        precommit["pre-commit-config.yaml"]:::support
    end

    %% Quality & Testing
    subgraph "Quality & Testing"
        benchmarks_node["Benchmarks (benchmarks/)"]:::support
        tests_node["Tests (tests/)"]:::support
    end

    %% Relationships and Data Flows
    main_demo -->|"calls"| rnl_configs
    main_demo -->|"initiates"| rnl_engine
    main_demo -->|"triggers"| rnl_training

    rnl_configs -->|"init_sim"| rnl_environment
    rnl_configs -->|"config_train"| rnl_training

    rnl_engine -->|"simulates"| rnl_environment
    rnl_engine -->|"processes"| rnl_sensor
    rnl_engine -->|"integrates_map"| map_data

    rnl_training -->|"updates_model"| rnl_network
    rnl_training -->|"outputs_decision"| rnl_agents
    rnl_training -->|"saves_output"| trained_models

    rnl_agents -->|"deploy_to"| ros
    rnl_network -->|"feeds_to"| ros

    docker -->|"containerizes"| ros
    main_demo -->|"launches_ROS"| ros

    rnl_configs -->|"loads_map"| map_data

    %% Styles
    classDef core fill:#add8e6,stroke:#000,stroke-width:1px;
    classDef external fill:#fce94f,stroke:#000,stroke-width:1px;
    classDef data fill:#c3f583,stroke:#000,stroke-width:1px;
    classDef deployment fill:#ffadad,stroke:#000,stroke-width:1px;
    classDef support fill:#d3c0eb,stroke:#000,stroke-width:1px;

    %% Click Events
    click main_demo "https://github.com/microvault/rnl/blob/main/main.py"
    click rnl_configs "https://github.com/microvault/rnl/tree/main/rnl/configs/"
    click rnl_engine "https://github.com/microvault/rnl/tree/main/rnl/engine/"
    click rnl_environment "https://github.com/microvault/rnl/tree/main/rnl/environment/"
    click rnl_agents "https://github.com/microvault/rnl/tree/main/rnl/agents/"
    click rnl_network "https://github.com/microvault/rnl/blob/main/rnl/network/model.py"
    click rnl_training "https://github.com/microvault/rnl/tree/main/rnl/training/"
    click map_data "https://github.com/microvault/rnl/tree/main/data/map/"
    click trained_models "https://github.com/microvault/rnl/tree/main/models/"
    click docker "https://github.com/microvault/rnl/tree/main/docker/Dockerfile"
    click ros "https://github.com/microvault/rnl/tree/main/ros/"
    click config_support "https://github.com/microvault/rnl/blob/main/pyproject.toml"
    click makefile "https://github.com/microvault/rnl/tree/main/Makefile"
    click precommit "https://github.com/microvault/rnl/blob/main/pre-commit-config.yaml"
    click benchmarks_node "https://github.com/microvault/rnl/tree/main/benchmarks/"
    click tests_node "https://github.com/microvault/rnl/tree/main/tests/"
    click rnl "https://github.com/microvault/rnl/tree/main/rnl/"
```
