# jptaylor/mgsx-daily-bots architecture

> Architecture diagram of the GitHub repository jptaylor/mgsx-daily-bots, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-02-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/jptaylor/mgsx-daily-bots
- Repository: https://github.com/jptaylor/mgsx-daily-bots

## Overview

This project is a full-stack web application built using Next.js. Its primary purpose is to provide an “AI Codec Call” interface powered by Daily Bots and integrated with real-time voice and video inference libraries such as RTVI and realtime-ai. The project leverages several front-end components, API routes, and a robust configuration layer to securely interface with external services like the Daily Bots API.

##### Main Components
- Frontend/UI Layer: Represented by the Next.js “src/app” pages and components. This is where the user interface lives. Components such as "App.tsx", "CallNotification", "DeviceSelect", "OSD", and others are responsible for interactive UI behaviors (including displaying call status, mission complete screens, phonebook, etc.).
- API Routes / Backend Layer: Found under “src/app/api”, these routes (e.g., “route.ts”) handle secure server-side communication. They take in configuration information including secret tokens and pass required data to the Daily Bots “start” endpoint.
- Media & Static Assets: The “public” folder holds various audio files (sounds for call signals, gameover, music, etc.) used by the UI to enhance the user experience.
- Configuration & Integration Layer: The “rtvi.config.ts”, package.json, and other config files (e.g., next.config.mjs, tailwind.config.ts) outline both the voice client settings and overall project configuration. These define prompts, services, and dependencies used by external modules like “realtime-ai”, “realtime-ai-react”, and “realtime-ai-daily”.

##### Relationships and Interactions
- The Frontend makes requests to the API routes which act as intermediaries that securely provide the necessary configuration and secrets to communicate with Daily Bots.
- When a user interacts with the UI (for example, initiating a call or a codec event), the corresponding components update the UI state and trigger API requests that are routed to the Daily Bots API.
- External libraries (Daily Bots API, RTVI, realtime-ai) are integrated via the API layer and through client hooks (“src/hooks/usePlayCodecSound.ts”, “src/hooks/useIdleTimer.ts”) used within UI components.
- The static assets (audio files) are referenced by various React components to provide auditory feedback for different user interactions.

##### Architectural Patterns and Technologies
- Standardized API Communication: Emphasize the secured interactions between the UI and the Daily Bots API (rest endpoints provided via API routes) and the usage of configuration files (rtvi.config.ts) that call out individual service parameters.
- Technologies & Frameworks: Include Next.js for primary web framework, React for component rendering, Tailwind CSS for styling, and integration libraries like “realtime-ai” for real-time media processing.

##### Elements
- Clear Labels: Each component should be clearly named (e.g., “Frontend UI”, “API Gateway”, “Daily Bots API”, “Static Media Assets”, “Configuration Module”).
- Detailed Sub-Components: Optionally, provide inner subdivisions for complex modules (e.g., break down “OSD” into its constituent parts like “ArrowButton”, “CenterPanel”, “VolumeIndicator”, etc.) if higher granularity is required by the audience.

a. Start by drawing separate layers or tiers for the Frontend (client), Backend (API routes), and External Services.
b. Within the Frontend, layout the core pages (starting at “src/app/page.tsx” and layout components) and cluster together related UI components (e.g., CallNotification, OSD, DeviceSelect, etc.).
c. Backend API gateway showing “src/app/api/route.ts” and note the optional dial-in/dial-out features.
d. Configuration and integration modules (rtvi.config.ts, environment files) that act as a bridge between the backend API and external services.
f. Optionally, illustrate how audio files and static assets support the UI interactions.

This detailed, component-level layout will provide your engineering colleagues with a clear map of the application's architecture, facilitating easier debugging, extension, and maintenance.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend/UI Layer
    subgraph "Frontend/UI Layer"
        MP["Main Page"]:::frontend
        L["Layout"]:::frontend
        subgraph "UI Components"
            AC["App Component"]:::frontend
            CN["CallNotification"]:::frontend
            DS["DeviceSelect"]:::frontend
            OSD["OSD"]:::frontend
            CSH["Codec Sound Hook"]:::frontend
            ITH["Idle Timer Hook"]:::frontend
        end
    end

    %% Backend/API Layer
    subgraph "Backend/API Layer"
        AG["API Gateway"]:::backend
    end

    %% Configuration & Integration Layer
    subgraph "Configuration & Integration"
        RTC["RT Voice Config"]:::config
        NC["next.config.mjs"]:::config
        TC["tailwind.config.ts"]:::config
        PC["package.json"]:::config
    end

    %% Media & Static Assets
    subgraph "Media & Static Assets"
        AM["Audio & Media Files"]:::media
    end

    %% External Services
    subgraph "External Services"
        DBA["Daily Bots API"]:::external
        RTVI["RTVI"]:::external
        RTA["Realtime-AI"]:::external
    end

    %% Connections
    MP -->|"initiates"| AG
    L -->|"supports layout"| AC

    %% UI Components interactions
    AC -->|"updates based on response"| AG
    CN -->|"triggers audio"| AM
    CSH -->|"activates codec"| AC
    ITH -->|"activates idle behavior"| AC

    %% API Gateway communication
    AG -->|"calls"| DBA
    DBA -->|"response"| AG
    AG -->|"integrates"| RTVI
    AG -->|"integrates"| RTA

    %% Configuration integration
    RTC -->|"configures"| AG
    NC -->|"configures"| AG
    TC -->|"configures"| AG
    PC -->|"manages deps"| AG

    %% Styling Classes
    classDef frontend fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef backend fill:#90EE90,stroke:#333,stroke-width:2px;
    classDef config fill:#DDA0DD,stroke:#333,stroke-width:2px;
    classDef media fill:#E0FFFF,stroke:#333,stroke-width:2px;
    classDef external fill:#FFA07A,stroke:#333,stroke-width:2px;

    %% Click Events
    click MP "https://github.com/jptaylor/mgsx-daily-bots/blob/main/src/app/page.tsx"
    click L "https://github.com/jptaylor/mgsx-daily-bots/blob/main/src/app/layout.tsx"
    click AC "https://github.com/jptaylor/mgsx-daily-bots/blob/main/src/components/App.tsx"
    click CN "https://github.com/jptaylor/mgsx-daily-bots/tree/main/src/components/CallNotification"
    click DS "https://github.com/jptaylor/mgsx-daily-bots/tree/main/src/components/DeviceSelect"
    click OSD "https://github.com/jptaylor/mgsx-daily-bots/tree/main/src/components/OSD"
    click AG "https://github.com/jptaylor/mgsx-daily-bots/blob/main/src/app/api/route.ts"
    click AM "https://github.com/jptaylor/mgsx-daily-bots/tree/main/public/"
    click RTC "https://github.com/jptaylor/mgsx-daily-bots/blob/main/src/rtvi.config.ts"
    click NC "https://github.com/jptaylor/mgsx-daily-bots/blob/main/next.config.mjs"
    click TC "https://github.com/jptaylor/mgsx-daily-bots/blob/main/tailwind.config.ts"
    click PC "https://github.com/jptaylor/mgsx-daily-bots/blob/main/package.json"
    click CSH "https://github.com/jptaylor/mgsx-daily-bots/blob/main/src/hooks/usePlayCodecSound.ts"
    click ITH "https://github.com/jptaylor/mgsx-daily-bots/blob/main/src/hooks/useIdleTimer.ts"
```
