# deltartificial/react-three-agents architecture

> Architecture diagram of the GitHub repository deltartificial/react-three-agents, 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/deltartificial/react-three-agents
- Repository: https://github.com/deltartificial/react-three-agents

## Overview

##### Main Components
- Client (Frontend): Located under example/client, this is a React-based application that uses React Three Fiber to render 3D environments. It includes multiple components such as CharacterModel, Environment elements (FloatingPlatform, Floor, Slopes, etc.) and assets (models and textures).
- WebSocket Server: In the packages/react-three-agents folder, check the file WebSocketServer.ts. The server is a core element that manages real-time communication between the React client and the Python agent.
- Python Agent: Found under packages/sdk-python, this package provides the SDK for RL agents. It is used to run the agents’ training scripts (see example/r3f_agents_example) and to integrate with the client/server infrastructure.
- RL Models: The models directory contains pre-trained models. This indicates that the training cycle is central to the system, and the models are used by the agents for either initialization or evaluation.

##### Relationships and Interactions
- The React client (front-end) sends and receives data to and from the WebSocket server.
- The WebSocket server acts as an intermediary by passing commands, state information, or results between the React client and the Python agent.
- The Python agent (or the training scripts in example/r3f_agents_example) interacts with the server to send training updates and receive visualized data.
- There is an SDK for Python that developers can use to customize or extend agent behavior and training protocols.

##### Architectural Patterns and Principles
- Separation of Concerns: Notice a clear separation between the front-end client, the WebSocket server, and the Python-based RL agent.
- Modular Design: The project is split into multiple packages (e.g., react-three-agents for front-end components and sdk-python for the Python SDK). This suggests that each module is designed to be independently developed and tested.
- Communication Layer: A dedicated communication layer using WebSockets indicates a real-time data flow between components.
- Extensibility: The modular package setup (with both JavaScript/TypeScript and Python components) implies that the system is designed to be extensible for additional agents or additional visualization/customization features.

##### Relevant Technologies and Frameworks
- React & React Three Fiber for the 3D visualization.
- TypeScript for the core libraries and client-side code.
- Node.js for managing the build and running the WebSocket server.
- Python for the RL agent training and logic (with the Python SDK provided in packages/sdk-python).
- WebSocket protocol for real-time communication.

##### Elements
- Components with clear labels such as:
- "React Client (3D Viewer)" for example/client.
- "WebSocket Server (Communication Hub)" for packages/react-three-agents/src/server/WebSocketServer.ts (and example/server.js).
- "Python Agent (RL Engine)" for packages/sdk-python.
- "Pre-trained RL Models" for the models directory.
- Data flow from Client ⇄ WebSocket Server.
- Data exchange between WS Server ⇄ Python Agent.
- Including notations for technology stacks (React/TypeScript, Node.js, Python) near the respective components.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Client Layer"
        RC["React Client (3D Viewer)"]:::frontend
    end

    subgraph "Communication Layer"
        WSS["WebSocket Server (Communication Hub)"]:::server
    end

    subgraph "Agent Layer"
        PA["Python Agent (RL Engine)"]:::python
        PTM["Pre-trained RL Models"]:::models
    end

    RC <-->|"WebSocketMessage"| WSS
    WSS <-->|"Command/StateUpdate"| PA
    PA -->|"UsesModels"| PTM

    click RC "https://github.com/deltartificial/react-three-agents/tree/main/example/client"
    click WSS "https://github.com/deltartificial/react-three-agents/blob/main/packages/react-three-agents/src/server/WebSocketServer.ts"
    click PA "https://github.com/deltartificial/react-three-agents/tree/main/packages/sdk-python"
    click PTM "https://github.com/deltartificial/react-three-agents/tree/main/models"

    classDef frontend fill:#FFA07A,stroke:#333,stroke-width:2px;
    classDef server fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef python fill:#90EE90,stroke:#333,stroke-width:2px;
    classDef models fill:#FFD700,stroke:#333,stroke-width:2px;
```
