# dushyant60/video_avatar architecture

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

- Interactive diagram: https://gitdiagram.com/dushyant60/video_avatar
- Repository: https://github.com/dushyant60/video_avatar

## Overview

##### Project Type and Purpose
- This is a single-page ReactJS application that integrates Azure Cognitive Services’ Text-to-Speech Avatar feature (and Azure OpenAI) to render lifelike talking avatars in the browser. There is no custom backend—the app calls out directly to Azure services and an optional Coturn TURN server for WebRTC.

##### File-Structure Analysis
- Top-level “FrontEnd” directory contains a standard ReactJS project with:
- public/ – static HTML+assets
- src/ – React components, CSS, and utility modules
- src/components – UI pieces (Avatar, HomePage, MessageDrawer, VideoPicker, etc.)
- src/utility – core integration logic (Utility.js, conversationLogger.js, insightsGenerator.js, sessionutils.js, worker.js)
- Configuration files (.env via config.js, iceservers.txt for TURN servers)
- Dockerfile for containerizing the front end
- No backend folder—external Azure and TURN services provide all server-side functionality.

##### README Insights
- The app must be configured with environment variables for:
- Azure Cognitive Services (region, subscription key, voice/character/style)
- Azure OpenAI endpoint/key
- A script (installCoturn.sh) can set up your own TURN server to replace the retiring Azure TURN service.

##### Main Components
a. Client Browser (React App)
– UI Components: HomePage, UserInfoForm, VideoPicker, MessageDrawer, ScreenshotDrawer, Video_Res
– Utility Modules: conversationLogger (logs chat), insightsGenerator (post-analysis), worker.js (background tasks), sessionutils (state management)
b. Azure Cloud Services
– Azure OpenAI (text generation)
– Azure Cognitive Services Text-to-Speech Avatar (speech + animation)
c. TURN Server
– For WebRTC signaling/ICE traversal (either Azure TURN or your Coturn instance)
d. External Storage/Logging (optional)

##### Component Interactions and Data Flows
1. User enters text or message in the React UI
2. conversationLogger records the input; insightsGenerator may prepare analytics
3. React Utility calls Azure OpenAI endpoint → receives generated text response
4. Utility then calls Azure TTS Avatar API with text + avatar parameters → receives audio stream + animation instructions
5. React app’s worker thread may process the media, then routes the combined audio/video stream into the Video_Res component
6. WebRTC connection (if using real-time avatar) uses ICE servers from iceservers.txt or .env → TURN server for NAT traversal
7. UI displays the avatar talking; ScreenshotDrawer/MessageDrawer let you capture and review sessions

##### Architectural Patterns and Design Principles
- Single-page application with clear separation between:
- Presentation layer (React components in src/components)
- Integration layer (src/utility modules that orchestrate API calls)
- Background processing (Web Worker in src/utility/worker.js)
- External services are treated as microservices; the app has no own backend
- Use of environment-based configuration for credentials and region settings

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Browser as compute node
    subgraph "Browser (React App)"
        direction TB
        %% Configuration
        Config["Config Loader"]:::config
        click Config "https://github.com/dushyant60/video_avatar/blob/main/FrontEnd/src/utility/config.js"

        %% Presentation Layer
        subgraph "Presentation Layer"
            direction TB
            App["App (App.js)"]:::ui
            click App "https://github.com/dushyant60/video_avatar/blob/main/FrontEnd/src/App.js"
            AppCSS["Global CSS (App.css)"]:::assets
            click AppCSS "https://github.com/dushyant60/video_avatar/blob/main/FrontEnd/src/App.css"
            IndexCSS["Index CSS (index.css)"]:::assets
            click IndexCSS "https://github.com/dushyant60/video_avatar/blob/main/FrontEnd/src/index.css"
            IndexJS["Bootstrap (index.js)"]:::ui
            click IndexJS "https://github.com/dushyant60/video_avatar/blob/main/FrontEnd/src/index.js"

            subgraph "Static Assets"
                direction TB
                IndexHTML["index.html"]:::assets
                click IndexHTML "https://github.com/dushyant60/video_avatar/blob/main/FrontEnd/public/index.html"
                Manifest["manifest.json"]:::assets
                click Manifest "https://github.com/dushyant60/video_avatar/blob/main/FrontEnd/public/manifest.json"
                Robots["robots.txt"]:::assets
                click Robots "https://github.com/dushyant60/video_avatar/blob/main/FrontEnd/public/robots.txt"
            end

            subgraph "UI Components"
                direction TB
                Avatar["Avatar (Avatar.jsx)"]:::ui
                click Avatar "https://github.com/dushyant60/video_avatar/blob/main/FrontEnd/src/components/Avatar.jsx"
                AvatarCSS["Avatar CSS"]:::assets
                click AvatarCSS "https://github.com/dushyant60/video_avatar/blob/main/FrontEnd/src/components/Avatar.css"
                Caption["Caption (Caption.jsx)"]:::ui
                click Caption "https://github.com/dushyant60/video_avatar/blob/main/FrontEnd/src/components/Caption.jsx"
                HomePage["HomePage"]:::ui
                click HomePage "https://github.com/dushyant60/video_avatar/blob/main/FrontEnd/src/components/HomePage.jsx"
                UserInfoForm["UserInfoForm"]:::ui
                click UserInfoForm "https://github.com/dushyant60/video_avatar/blob/main/FrontEnd/src/components/UserInfoForm.jsx"
                UserInfoFormCSS["UserInfoForm CSS"]:::assets
                click UserInfoFormCSS "https://github.com/dushyant60/video_avatar/blob/main/FrontEnd/src/components/UserInfoForm.css"
                VideoPicker["VideoPicker"]:::ui
                click VideoPicker "https://github.com/dushyant60/video_avatar/blob/main/FrontEnd/src/components/VideoPicker.jsx"
                MessageDrawer["MessageDrawer"]:::ui
                click MessageDrawer "https://github.com/dushyant60/video_avatar/blob/main/FrontEnd/src/components/MessageDrawer.jsx"
                ScreenshotDrawer["ScreenshotDrawer"]:::ui
                click ScreenshotDrawer "https://github.com/dushyant60/video_avatar/blob/main/FrontEnd/src/components/ScreenshotDrawer.jsx"
                VideoRes["Video_Res"]:::ui
                click VideoRes "https://github.com/dushyant60/video_avatar/blob/main/FrontEnd/src/components/Video_Res.jsx"
                StyledHelper["StyledComponents"]:::ui
                click StyledHelper "https://github.com/dushyant60/video_avatar/blob/main/FrontEnd/src/components/styledComponents.js"
                IceServersList["iceservers.txt"]:::assets
                click IceServersList "https://github.com/dushyant60/video_avatar/blob/main/FrontEnd/src/components/iceservers.txt"
            end
        end

        %% Integration Layer
        subgraph "Integration Layer"
            direction TB
            Utility["Utility.js"]:::integration
            click Utility "https://github.com/dushyant60/video_avatar/blob/main/FrontEnd/src/utility/Utility.js"
            ConversationLogger["conversationLogger.js"]:::integration
            click ConversationLogger "https://github.com/dushyant60/video_avatar/blob/main/FrontEnd/src/utility/conversationLogger.js"
            InsightsGen["insightsGenerator.js"]:::integration
            click InsightsGen "https://github.com/dushyant60/video_avatar/blob/main/FrontEnd/src/utility/insightsGenerator.js"
            SessionUtils["sessionutils.js"]:::integration
            click SessionUtils "https://github.com/dushyant60/video_avatar/blob/main/FrontEnd/src/utility/sessionutils.js"
            Worker["Web Worker (worker.js)"]:::integration
            click Worker "https://github.com/dushyant60/video_avatar/blob/main/FrontEnd/src/utility/worker.js"
        end

        %% Containerization and metadata
        subgraph "Container & Metadata"
            direction TB
            Dockerfile["Dockerfile"]:::container
            click Dockerfile "https://github.com/dushyant60/video_avatar/tree/main/FrontEnd/dockerfile"
            GitIgnore[".gitignore"]:::container
            click GitIgnore "https://github.com/dushyant60/video_avatar/blob/main/FrontEnd/.gitignore"
            DockerIgnore[".dockerignore"]:::container
            click DockerIgnore "https://github.com/dushyant60/video_avatar/blob/main/FrontEnd/.dockerignore"
            PackageJSON["package.json"]:::metadata
            click PackageJSON "https://github.com/dushyant60/video_avatar/blob/main/FrontEnd/package.json"
            LockFile["package-lock.json"]:::metadata
            click LockFile "https://github.com/dushyant60/video_avatar/blob/main/FrontEnd/package-lock.json"
        end

        %% Testing & Docs
        subgraph "Testing & Docs"
            direction TB
            AppTest["App.test.js"]:::testing
            click AppTest "https://github.com/dushyant60/video_avatar/blob/main/FrontEnd/src/App.test.js"
            WebVitals["reportWebVitals.js"]:::testing
            click WebVitals "https://github.com/dushyant60/video_avatar/blob/main/FrontEnd/src/reportWebVitals.js"
            SetupTests["setupTests.js"]:::testing
            click SetupTests "https://github.com/dushyant60/video_avatar/blob/main/FrontEnd/src/setupTests.js"
            Readme["README.md"]:::metadata
            click Readme "https://github.com/dushyant60/video_avatar/blob/main/README.md"
        end
    end

    %% External Services
    AzureAI["Azure OpenAI"]:::external
    AzureTTS["Azure TTS Avatar"]:::external
    TURN["TURN Server"]:::external

    %% Data flows
    UserInput["User Input"]:::ui -->|logs| ConversationLogger
    ConversationLogger --> InsightsGen
    InsightsGen --> Utility
    Utility -->|"POST /generateText"| AzureAI
    AzureAI -->|"text response"| Utility
    Utility -->|"POST TTS API"| AzureTTS
    AzureTTS -->|"audio+animation"| Worker
    Worker --> VideoRes
    VideoRes -->|"render"| Avatar
    Utility --> SessionUtils
    SessionUtils --> VideoPicker
    SessionUtils --> MessageDrawer
    SessionUtils --> ScreenshotDrawer
    VideoRes --> IceServersList
    IceServersList --> TURN
    TURN --> VideoRes

    Config --> Utility
    Config --> Worker
    Config --> SessionUtils

    %% Styles
    classDef ui fill:#AEDFF7,stroke:#036B99,stroke-width:1px
    classDef integration fill:#FFE7A3,stroke:#B58900,stroke-width:1px
    classDef external fill:#D3F8E2,stroke:#067D68,stroke-width:1px
    classDef config fill:#F0D9FF,stroke:#6A1B9A,stroke-width:1px
    classDef assets fill:#FDE2E4,stroke:#C42B3B,stroke-width:1px
    classDef container fill:#E0E0E0,stroke:#424242,stroke-width:1px
    classDef metadata fill:#FFF4C1,stroke:#A67C00,stroke-width:1px
    classDef testing fill:#E3F6F5,stroke:#1B4965,stroke-width:1px
```
