# luizfelm/unity-python architecture

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

- Interactive diagram: https://gitdiagram.com/luizfelm/unity-python
- Repository: https://github.com/luizfelm/unity-python

## Overview

Based on our analysis of the file tree and the README, the project is a hybrid system that integrates a Python application (using OpenCV for real‑time face detection) with a Unity application (rendering and moving a cube based on received data). In essence, it is a full-stack interactive application where communication occurs over a TCP connection between the two separate systems.

##### Main components
- Python Server:
- Contains scripts such as ia.py (for face detection) and Server.py (handling TCP communication).
- Uses OpenCV to capture webcam input, detect face coordinates, and send these coordinates.
- Acts as the data producer by continuously sending face detection data.
- Unity Client:
- The Unity project (found in directories like Unity-Python and the nested Unity-Python-Project) includes the TCPClient.cs script.
- Receives data via TCP and updates the cube’s position in the Unity scene.
- Has standard Unity configuration, scenes, assets, and scripts that manage rendering and input.
- TCP Communication Channel:
- The Python server and Unity client connect over a TCP socket (using localhost IP 127.0.0.1 on port 5005 per the README).
- Represents the data flow path between the face-detection module and the cube movement controller.

##### Relationships and interactions
- The Python Server initiates the connection, processes the webcam feed, and sends data (face coordinates).
- The Unity Client listens on the designated port, receives the coordinates, and translates them into a movement update for the cube.

##### Architectural patterns and design principles
- Separation of Concerns:
- The face detection logic (Python) is separated from the rendering and interaction logic (Unity).
- Client-Server Model:
- The system leverages a simple client-server paradigm over TCP for inter-process communication.
- Real-Time Data Flow:
- Real-time data from the Python process drives the updates in the Unity scene.

##### Relevant technologies and frameworks
- Python uses OpenCV for computer vision and a TCP socket library for communication.
- Unity, typically with C# (as shown by TCPClient.cs), provides the scene and rendering engine.
- Supporting tools like Git configuration, Visual Studio settings, and Unity packages (e.g., WebSocketSharpFork for potential alternative communications) are also present.

##### Specific elements
- Configuration files or deployment elements (e.g., the TCP port setup) if deemed important for clarity.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Python Side"
        FaceDetection["Face Detection Module (OpenCV)"]:::python
        TCPServer["TCP Server"]:::python
    end

    subgraph "Unity Side"
        TCPClient["TCP Client"]:::unity
        CubeScene["Cube Movement Logic (Unity Scene)"]:::unity
    end

    FaceDetection -->|"sendsData"| TCPServer
    TCPServer -->|"TCPConnection(127.0.0.1:5005)"| TCPClient
    TCPClient -->|"updatesScene"| CubeScene

    click FaceDetection "https://github.com/luizfelm/unity-python/blob/main/Unity-Python-Project/Python/ia.py"
    click TCPServer "https://github.com/luizfelm/unity-python/blob/main/Unity-Python-Project/Python/Server.py"
    click TCPClient "https://github.com/luizfelm/unity-python/blob/main/Unity-Python-Project/Unity-Python/Assets/Scripts/TCPClient.cs"
    click CubeScene "https://github.com/luizfelm/unity-python/blob/main/Unity-Python-Project/Unity-Python/Assets/Scenes/SampleScene.unity"

    classDef python fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef unity fill:#90EE90,stroke:#000,stroke-width:2px;
```
