# itiwll/network-rc architecture

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

- Interactive diagram: https://gitdiagram.com/itiwll/network-rc
- Repository: https://github.com/itiwll/network-rc

## Overview

##### Project Type and Purpose
- This project is a full-stack application dedicated to remote controlling an RC car via a Raspberry Pi. It incorporates live network video transmission, low-latency control, multiple hardware interfaces (e.g., camera, microphone, GPIO for motors/LEDs), and real-time audio communication.
- The README highlights dependencies for multimedia (ffmpeg, pulseaudio) and Node.js, and the file tree indicates both a front-end (React-like) and back-end (NodeJS with hardware interfacing and servers) components.

##### Analyzing the File Structure
- Top-level directories:
- front-end: Contains all the client-side code, components, assets, and configuration files. This section shows a rich set of UI components (e.g., Ai.js, Gamepad.js, Camera.js, ObjectDetection.js) and client-side logic.
- lib: Houses various server modules like AudioServer.js, CameraServer.js, MicrophoneServer.js, TTS (text-to-speech), GPIO handling, and a WebRTC subdirectory, which suggests the back-end’s role in interfacing with hardware and managing streaming.
- test: Contains tests for hardware features (camera, gpio, led, audio, TTS), confirming a hardware interfacing backend.
- Other files like index.js and deploy.js hint at the main entry point and deployment strategies.

##### Key Architectural Components
a. Front-End Client:
- Built using React (or a similar library) with component-based design.
- Components include controls like joystick, gamepad integration, audio player, and UI settings.
- Handles the user interface for video streaming, control commands, and status monitoring.
- Uses additional libraries (e.g., WebRTC on the client to manage low latency video) and state management (store modules) for handling device and UI states.

b. Back-End / Server:
- Node.js entry point (index.js) that runs on the Raspberry Pi.
- Includes hardware interface modules in the lib directory:
- AudioServer, CameraServer, MicrophoneServer to provide real-time media streaming/control.
- GPIO, LED, and channel modules for interfacing with the car's physical hardware.
- FRPC integration suggests potential usage for remote forwarding (perhaps to overcome network boundaries).
- TTS services for voice broadcasting.
- Uses WebRTC modules in both front-end and back-end for real-time data transmission.

c. External Dependencies & Environment:
- The system relies on external tools such as ffmpeg for media processing and pulseaudio for audio handling.
- Configuration files (e.g., .env, craco.config.js) help manage variables and build configurations.
- CI/CD workflows in the .github directory support ongoing integration and release management.

##### Relationships and Flow
- Users interact with the front-end (via web browsers) which sends control commands (touch, keyboard, gamepad, or RC transmitter inputs) over the network.
- The front-end communicates with the back-end (via HTTP and WebSocket/WebRTC channels), sending commands and receiving real-time video/audio streams.
- The backend, using its dedicated servers (AudioServer, CameraServer, etc.), translates these commands to hardware-level actions such as controlling the motors, LED, and reading sensors.
- There is a clear separation between the UI handling in the front-end and hardware/interfacing logic in the back-end.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Front-End Client
    subgraph "Front-End Client"
        FE_UIC["UI Components"]:::frontend
        FE_WebRTC_FE["WebRTC Client (Front-End)"]:::frontend
        FE_State["State Management (Stores)"]:::frontend
    end

    %% Back-End Server
    subgraph "Back-End Server"
        subgraph "API/Control Logic"
            API["Node.js API (index.js & lib/app.js)"]:::backend
        end
        subgraph "Hardware Interface Layer"
            GPIO["GPIO Controls"]:::backend
            LED["LED Controls"]:::backend
        end
        subgraph "Media Servers"
            AudioServer["Audio Server"]:::backend
            CameraServer["Camera Server"]:::backend
            MicrophoneServer["Microphone Server"]:::backend
            TTS["TTS Service"]:::backend
        end
        subgraph "Communication/Streaming"
            BE_WebRTC["WebRTC Module (Back-End)"]:::backend
            Channel["Channel Module"]:::backend
            FRPC["FRPC Module"]:::backend
        end
    end

    %% External and Physical Nodes
    ExternalTools["Multimedia Tools (ffmpeg & pulseaudio)"]:::external
    Documentation["Documentation & Config"]:::external
    PhysicalRC["Physical RC Car Components"]:::physical

    %% Relationships and Data Flow
    FE_UIC -->|"control"| API
    FE_State -->|"state_updates"| API

    FE_WebRTC_FE <-->|"streaming"| AudioServer
    FE_WebRTC_FE <-->|"streaming"| CameraServer
    FE_WebRTC_FE <-->|"streaming"| MicrophoneServer
    FE_WebRTC_FE <-->|"streaming"| TTS

    API -->|"hardware_cmds"| GPIO
    API -->|"hardware_cmds"| LED
    API -->|"stream_ctrl"| BE_WebRTC

    BE_WebRTC -->|"channel"| Channel
    BE_WebRTC -->|"frpc"| FRPC

    ExternalTools -->|"supports"| AudioServer
    ExternalTools -->|"supports"| CameraServer
    ExternalTools -->|"supports"| MicrophoneServer
    ExternalTools -->|"supports"| TTS

    GPIO -->|"drives"| PhysicalRC
    LED -->|"lights"| PhysicalRC

    %% Click Events
    click FE_UIC "https://github.com/itiwll/network-rc/tree/master/front-end/src/components"
    click FE_WebRTC_FE "https://github.com/itiwll/network-rc/tree/master/front-end/src/lib/WebRTC"
    click FE_State "https://github.com/itiwll/network-rc/tree/master/front-end/src/store"
    click API "https://github.com/itiwll/network-rc/blob/master/index.js"
    click API "https://github.com/itiwll/network-rc/blob/master/lib/app.js"
    click GPIO "https://github.com/itiwll/network-rc/blob/master/lib/gpio.js"
    click LED "https://github.com/itiwll/network-rc/blob/master/lib/led.js"
    click AudioServer "https://github.com/itiwll/network-rc/blob/master/lib/AudioServer.js"
    click CameraServer "https://github.com/itiwll/network-rc/blob/master/lib/CameraServer.js"
    click MicrophoneServer "https://github.com/itiwll/network-rc/blob/master/lib/MicrophoneServer.js"
    click TTS "https://github.com/itiwll/network-rc/tree/master/lib/tts"
    click BE_WebRTC "https://github.com/itiwll/network-rc/tree/master/lib/WebRTC"
    click Channel "https://github.com/itiwll/network-rc/blob/master/lib/channel.js"
    click FRPC "https://github.com/itiwll/network-rc/tree/master/lib/frpc"
    click Documentation "https://github.com/itiwll/network-rc/tree/master/docs"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef backend fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef external fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef physical fill:#f8d7da,stroke:#721c24,stroke-width:2px;
```
