# heygen-official/interactiveavatarnextjsdemo architecture

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

- Interactive diagram: https://gitdiagram.com/heygen-official/interactiveavatarnextjsdemo
- Repository: https://github.com/heygen-official/interactiveavatarnextjsdemo

## Overview

##### Main Components

a) Client-Side (Browser)
- Next.js Frontend Application
- Interactive Avatar Component
- Theme Management
- User Interface Elements

b) Server-Side (Next.js API Routes)
- Access Token Generation Service
- Environment Configuration

c) External Services
- HeyGen Interactive Avatar API
- OpenAI API (Optional Integration)

##### Specific Component Details

- Rectangle (Blue): React/Next.js Components
- InteractiveAvatar
- NavBar
- ThemeSwitch
- Text Input Components

- Hexagon (Green): API Routes
- get-access-token

- HeyGen Interactive Avatar API
- OpenAI API

##### Key Elements to Highlight

- Authentication Flow:
How the API token from .env flows through the system to authenticate with HeyGen's API

- State Management:
How the application manages avatar sessions and user interactions

- Real-time Communication:
Streaming nature of the avatar interaction

##### Technical Details

Annotations for:
- Next.js 13+ App Router Architecture
- API Route Implementation
- Environment Variable Configuration
- Third-party Integration Points

##### Implementation Notes

- Session Management Limits (3 concurrent sessions for Trial Token)
- Authentication Requirements
- Supported Avatar Types
- API Dependencies

Remember to use clear, consistent styling:
- Clear labels for all components and connections

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Client-Side Layer"
        UI[User Interface]
        IAC[Interactive Avatar Component]:::component
        TM[Theme Management]:::component
        NB[Navigation Bar]:::component
        TI[Text Input Component]:::component
        IC[Icon Components]:::component
        CD[Code Display]:::component
    end

    subgraph "Application Layer"
        RL[Root Layout]:::component
        MP[Main Page]:::component
        EH[Error Handler]:::component
        AP[App Providers]:::component
        GS[Global Styles]:::component
        AC[App Constants]:::component
    end

    subgraph "API Layer"
        ATS[Access Token Service]:::api
        EC[Environment Config]:::config
    end

    subgraph "External Services"
        HAPI[HeyGen Interactive Avatar API]:::external
        OAPI[OpenAI API]:::external
    end

    %% Relationships
    UI --> IAC
    UI --> TM
    UI --> NB
    UI --> TI
    UI --> CD
    
    IAC --> ATS
    TI --> IAC
    IC --> UI
    
    ATS --> EC
    ATS --> HAPI
    IAC --> OAPI
    
    RL --> AP
    MP --> IAC
    AP --> TM
    GS --> UI
    AC --> IAC

    %% Click Events
    click IAC "https://github.com/HeyGen-Official/InteractiveAvatarNextJSDemo/blob/main/components/InteractiveAvatar.tsx"
    click TM "https://github.com/HeyGen-Official/InteractiveAvatarNextJSDemo/blob/main/components/ThemeSwitch.tsx"
    click NB "https://github.com/HeyGen-Official/InteractiveAvatarNextJSDemo/blob/main/components/NavBar.tsx"
    click TI "https://github.com/HeyGen-Official/InteractiveAvatarNextJSDemo/blob/main/components/InteractiveAvatarTextInput.tsx"
    click IC "https://github.com/HeyGen-Official/InteractiveAvatarNextJSDemo/blob/main/components/Icons.tsx"
    click CD "https://github.com/HeyGen-Official/InteractiveAvatarNextJSDemo/blob/main/components/InteractiveAvatarCode.tsx"
    click RL "https://github.com/HeyGen-Official/InteractiveAvatarNextJSDemo/blob/main/app/layout.tsx"
    click MP "https://github.com/HeyGen-Official/InteractiveAvatarNextJSDemo/blob/main/app/page.tsx"
    click EH "https://github.com/HeyGen-Official/InteractiveAvatarNextJSDemo/blob/main/app/error.tsx"
    click AP "https://github.com/HeyGen-Official/InteractiveAvatarNextJSDemo/blob/main/app/providers.tsx"
    click GS "https://github.com/HeyGen-Official/InteractiveAvatarNextJSDemo/blob/main/styles/globals.css"
    click AC "https://github.com/HeyGen-Official/InteractiveAvatarNextJSDemo/blob/main/app/lib/constants.ts"
    click ATS "https://github.com/HeyGen-Official/InteractiveAvatarNextJSDemo/blob/main/app/api/get-access-token/route.ts"
    click EC "https://github.com/HeyGen-Official/InteractiveAvatarNextJSDemo/blob/main/.env"

    %% Styling
    classDef component fill:#2563eb,color:#fff,stroke:#fff
    classDef api fill:#22c55e,color:#fff,stroke:#fff
    classDef external fill:#64748b,color:#fff,stroke:#fff
    classDef config fill:#eab308,color:#000,stroke:#000

    %% Legend
    subgraph Legend
        C1[Component]:::component
        A1[API Service]:::api
        E1[External Service]:::external
        CF1[Configuration]:::config
    end
```
