# mattsroufe/esp32_rc_cars architecture

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

- Interactive diagram: https://gitdiagram.com/mattsroufe/esp32_rc_cars
- Repository: https://github.com/mattsroufe/esp32_rc_cars

## Overview

##### Main Components

a) Hardware Layer:
- ESP32-CAM module
- Motor & ESC (Electronic Speed Control)
- Servo
- Power Supply System (7.4V battery setup)
- Bluetooth Gamepad (PS4 controller)

b) Software Components:
- ESP32 Firmware
- Python WebSocket Server
- Web Interface
- Video Stream Processing Pipeline

**[Web Browser Interface] -----> [Bluetooth Gamepad]**

**[Python WebSocket Server]**
- Video Stream Processing
- Client Management
- Control Command Distribution

**[ESP32-CAM]**
- Camera Module
- Motor Control
- Servo Control

##### Data Flow Representation

- WebSocket communication (⟷): Bidirectional data flow
- Video stream (→): One-way data flow
- Control commands (⇢): One-way control signals

##### Detailed Component Breakdown

ESP32 FIRMWARE SECTION:
**[Camera Module] → [Video Processing] → [WebSocket Client]**
**[Motor Control] ← [Command Handler] ← [WebSocket Client]**
**[Servo Control] ← [Command Handler] ← [WebSocket Client]**

SERVER SECTION:
**[WebSocket Server]**
- ↓
**[Video Stream Processor]**
- ↓
**[Client Manager]**
- ↓
**[Web Interface Generator]**

##### Important Elements to Highlight

a) Communication Protocols:
- WebSocket connections (ws://)
- Wi-Fi connectivity
- Bluetooth control interface

b) Data Processing Points:
- Video frame processing
- Control command parsing
- Timeout handling mechanism

##### Technical Specifications to Note

- Motor control range (-255 to 255)
- Servo angle range (0 to 180)
- Video stream format
- WebSocket command structure

##### Implementation Details

- Relationship between .cpp and .h files
- Web_socket_server directory structure
- Static asset management

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        WB["Web Browser Interface"]:::client
        BG["Bluetooth Gamepad"]:::client
    end

    subgraph "Server Layer"
        WS["WebSocket Server"]:::server
        VSP["Video Stream Processor"]:::server
        CM["Client Manager"]:::server
        WIG["Web Interface Generator"]:::server
        TS["Test Stream Module"]:::server
    end

    subgraph "ESP32 Hardware"
        ESP["ESP32-CAM Module"]:::hardware
        subgraph "Control Systems"
            MC["Motor Control System"]:::hardware
            SC["Servo Control System"]:::hardware
            BC["Bluetooth Control"]:::hardware
        end
        CAM["Camera Module"]:::hardware
        PS["Power Supply (7.4V)"]:::hardware
    end

    subgraph "Frontend Components"
        WI["Web Interface"]:::frontend
        FS["Frontend Styling"]:::frontend
        FL["Frontend Logic"]:::frontend
    end

    %% Connections
    WB <--> WS
    BG <--> BC
    WS --> VSP
    VSP --> CM
    CM --> WIG
    WIG --> WI
    WI --> FS
    WI --> FL

    ESP --> WS
    CAM --> ESP
    BC --> MC
    BC --> SC
    PS --> ESP
    PS --> MC
    PS --> SC

    %% Click Events
    click MC "https://github.com/mattsroufe/esp32_rc_cars/blob/main/Esc.cpp"
    click SC "https://github.com/mattsroufe/esp32_rc_cars/blob/main/ServoControl.cpp"
    click BC "https://github.com/mattsroufe/esp32_rc_cars/blob/main/bluetooth_control.h"
    click WS "https://github.com/mattsroufe/esp32_rc_cars/blob/main/web_socket_server/web_socket_server.py"
    click WI "https://github.com/mattsroufe/esp32_rc_cars/blob/main/web_socket_server/index.html"
    click FS "https://github.com/mattsroufe/esp32_rc_cars/blob/main/web_socket_server/static/app.css"
    click FL "https://github.com/mattsroufe/esp32_rc_cars/blob/main/web_socket_server/static/app.js"
    click TS "https://github.com/mattsroufe/esp32_rc_cars/blob/main/web_socket_server/test_stream.py"
    click ESP "https://github.com/mattsroufe/esp32_rc_cars/blob/main/esp32_rc_cars.ino"

    %% Styles
    classDef client fill:#ff9900,stroke:#333,stroke-width:2px
    classDef server fill:#00ff00,stroke:#333,stroke-width:2px
    classDef hardware fill:#0099ff,stroke:#333,stroke-width:2px
    classDef frontend fill:#ff66cc,stroke:#333,stroke-width:2px

    %% Legend
    subgraph Legend
        L1["Client Components"]:::client
        L2["Server Components"]:::server
        L3["Hardware Components"]:::hardware
        L4["Frontend Components"]:::frontend
    end
```
