# jyjblrd/low-cost-mocap architecture

> Architecture diagram of the GitHub repository jyjblrd/low-cost-mocap, 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/jyjblrd/low-cost-mocap
- Repository: https://github.com/jyjblrd/low-cost-mocap

## Overview

##### Main Components
- Frontend (User Interface):
- Located in the computer_code directory, mainly under src (with React components written in TypeScript such as App.tsx, CameraWireframe.tsx, Toolbar.tsx, etc.).
- This layer provides the interactive dashboard through which users can view motion capture data, trajectory planning, and charts.
- Backend / API Server:
- The Python code in computer_code/api (e.g., index.py, KalmanFilter.py, LowPassFilter.py) processes camera inputs, performs motion capture computations, and serves the processed data to the frontend.
- It is started separately (using “python3 api/index.py”) and handles integration with external libraries (like pseyepy and OpenCV’s structure from motion module).
- Hardware & Firmware:
- Receiver and sender directories contain ESP32 Arduino code (.ino files) which likely interface with camera sensors or control data transmission between components.
- 3D Models / CAD Data:
- Found in the 3d_files directory, these components provide the physical design elements (for example, camera parts) used in building the hardware aspects of the system.
- External Dependencies:
- Integration with external libraries (pseyepy, OpenCV SFM) and infrastructure (the external YouTube demo and additional blog posts) as documented in the README.

##### Relationships and Data Flow
- Data Flow from Cameras to Processing:
- API Interaction:
- The backend receives and processes this streamed data (applying filters like Kalman and low-pass filters) then makes the processed data available to the UI.
- User Interaction:
- The frontend, built with modern web technologies (React/TypeScript), retrieves processed data from the API server (over RESTful endpoints or sockets, as hinted by the socket scripts in src/shared/styles/scripts/socket.ts) to update visualizations in real time.
- Hardware Design Feedback:
- The physical hardware (3D printed camera parts) might be iteratively designed and verified against system models, which can be annotated as a supporting component for overall system development.

##### Architectural Patterns/Design Principles
- Separation of Concerns:
- Clearly separate the presentation layer (React UI) from the application/business logic (Python API) and hardware control (ESP32 firmware).
- Modular Design:
- Each piece (frontend, backend, communication modules, and hardware) is implemented as a separate module, facilitating maintainability.
- Integration of Real-time Data:
- Emphasis on real-time data processing and communication between modules, potentially using websockets (as seen in the scripts for socket communications) and standard RESTful API endpoints.
- Dependency Management:

- Within the Application Logic, add sub-components for data processing (filter modules, API endpoints) and note interactions with both the external camera streams and the UI.
- In the Hardware section, represent both the transmitter (sender_esp32) and receiver (receiver_esp32) units, linking these to the sensors/camera streams and noting any communication protocols used (wired/wireless).
- Optionally, include a layer showing how the 3D physical designs (from the 3d_files directory) feed into the hardware manufacturing process.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "User Interface (Frontend)"
        UI["React/TypeScript Dashboard"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend / API Server"
        API["Python API & Processing (KalmanFilter, LowPassFilter)"]:::backend
    end

    %% Hardware & Firmware Layer
    subgraph "Hardware & Firmware"
        REC["Receiver Firmware (ESP32)"]:::firmware
        SEN["Sender Firmware (ESP32)"]:::firmware
    end

    %% 3D Models / CAD Data
    subgraph "3D Models / CAD"
        CAD["Camera CAD Files"]:::cad
    end

    %% External Dependencies
    EXT["External Dependencies (pseyepy, OpenCV, Websockets)"]:::external

    %% Data Flow Connections
    REC -->|"streamsData"| API
    SEN -->|"streamsData"| API
    API -->|"providesData"| UI
    EXT -->|"usedBy"| API
    CAD -.->|"influencesDesign"| REC
    CAD -.->|"influencesDesign"| SEN

    %% Styling for clarity
    classDef frontend fill:#F8BBD0,stroke:#C2185B,stroke-width:2px;
    classDef backend fill:#BBDEFB,stroke:#1976D2,stroke-width:2px;
    classDef firmware fill:#C8E6C9,stroke:#388E3C,stroke-width:2px;
    classDef cad fill:#FFF9C4,stroke:#FBC02D,stroke-width:2px;
    classDef external fill:#D7CCC8,stroke:#5D4037,stroke-width:2px;

    %% Click Events for Component Mapping
    click UI "https://github.com/jyjblrd/low-cost-mocap/tree/main/computer_code/src"
    click API "https://github.com/jyjblrd/low-cost-mocap/tree/main/computer_code/api"
    click REC "https://github.com/jyjblrd/low-cost-mocap/blob/main/receiver_esp32/receiver_esp32.ino"
    click SEN "https://github.com/jyjblrd/low-cost-mocap/blob/main/sender_esp32/sender_esp32.ino"
    click CAD "https://github.com/jyjblrd/low-cost-mocap/tree/main/3d_files"
```
