# mrsparkle-70/emotion-using-react architecture

> Architecture diagram of the GitHub repository mrsparkle-70/emotion-using-react, 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/mrsparkle-70/emotion-using-react
- Repository: https://github.com/mrsparkle-70/emotion-using-react

## Overview

##### Main Components Identification
- Frontend (ReactJS):
- Contains the main UI (files in emotion-recognition/src and public directories).
- Handles video capture from the webcam.
- Establishes a WebSocket connection to stream video frames to the backend and receive prediction responses.
- Backend (FastAPI server):
- The API server (main.py in the server directory) built with FastAPI.
- Responsible for receiving video frames via WebSocket, running the frame through the emotion prediction model, and returning a payload with both detailed prediction probabilities and the dominant emotion.
- Machine Learning Model:
- A pre-built TensorFlow Keras model that classifies the emotion into one of seven categories (happy, sad, neutral, disgusted, surprised, fear, and angry).
- Resides logically within the backend component.
- Communication Layer:
- WebSocket – enables bidirectional streaming between the ReactJS frontend and the FastAPI backend.

##### Relationships and Interactions
- An internal connection within the backend where the incoming data is processed by the TensorFlow Keras model.

##### Architectural Patterns and Design Principles
- Separation of Concerns: Clear division between presentation (ReactJS UI), business logic and API server (FastAPI), and data processing (ML model prediction).
- Real-time Data Flow: Use of WebSocket indicates a design that supports continuous, live data communication.
- Modular Design: The frontend and backend are self-contained, with their own dependencies (e.g., package.json for React; requirements.txt for FastAPI) and responsibilities.
- Extensibility: The pipeline could be improved by swapping the ML model for a more efficient or custom one.

##### Important Notes
- Be as detailed as possible – delineate even internal processes if they add to clarity (e.g., “Frame Processing” inside the backend).
- Placing a simplified version of the architecture from the README's provided HLD image as a starting point, then enhancing it with further details from the file structure and README.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Subgraph
    subgraph "Frontend (ReactJS)"
        F1["ReactJS Frontend"]:::frontend
        F2["Face Detection & Webcam Capture"]:::frontend_utilities
    end

    %% Backend Subgraph
    subgraph "Backend (FastAPI)"
        B1["FastAPI Server (main.py)"]:::backend
        B2["ML Model (TensorFlow Keras)"]:::ml
    end

    %% Communication Between Frontend and Backend
    F1 -->|"Video Frames via WebSocket"| B1
    B1 -->|"Emotion Predictions (predictions & dominant emotion)"| F1

    %% Internal Backend Processing
    B1 -->|"Frame Processing"| B2
    B2 -->|"Return Predictions"| B1

    %% Frontend Internal Flow for Face Detection
    F1 -->|"Capture Frame"| F2
    F2 -->|"Overlay Bounding Boxes"| F1

    %% Click Events
    click F1 "https://github.com/mrsparkle-70/emotion-using-react/tree/main/emotion-recognition/"
    click F2 "https://github.com/mrsparkle-70/emotion-using-react/blob/main/emotion-recognition/src/utilities.js"
    click B1 "https://github.com/mrsparkle-70/emotion-using-react/blob/main/server/main.py"
    click B2 "https://github.com/mrsparkle-70/emotion-using-react/blob/main/server/main.py"

    %% Styles
    classDef frontend fill:#D6EAF8,stroke:#5DADE2,stroke-width:2px;
    classDef frontend_utilities fill:#AED6F1,stroke:#3498DB,stroke-width:2px;
    classDef backend fill:#FADBD8,stroke:#EC7063,stroke-width:2px;
    classDef ml fill:#D5F5E3,stroke:#27AE60,stroke-width:2px;
```
