# pipecat-ai/gemini-multimodal-live-demo architecture

> Architecture diagram of the GitHub repository pipecat-ai/gemini-multimodal-live-demo, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-02-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/pipecat-ai/gemini-multimodal-live-demo
- Repository: https://github.com/pipecat-ai/gemini-multimodal-live-demo

## Overview

##### Main Components
- Client Application: Located in the "client" folder. This React/TypeScript front end handles UI components like ChatControls, ChatMessages, LiveMessages, and various utility UI and SVG components. It calls API methods (client.action(), client.connect()) and uses hooks (like useRTVIClientEvent) to manage events.
- API Backend / Server: Found under the "server" directory. It is a FastAPI backend with endpoints under "server/webapp/api" (e.g., bots.py, conversations.py).
- Bot Pipelines: Two major bot pipelines are implemented:
- HTTP single-turn pipeline (from bots/http/bot_pipeline.py) for one-off interactions.
- WebRTC connected multi-turn pipeline (from bots/webrtc/bot_pipeline.py) for ongoing sessions.
- Database Storage: The project uses a SQLite database (server/sesame.db) to persist conversation history, defined in common/models.py and managed by persistent_context.py.
- External Services: Integration with Gemini API for multimodal capabilities and potentially Daily API (for WebRTC specific functionality). These will be configured via environment variables (.env) and defined in configuration files (server/common/config.py).

##### Relationships and Interactions
- Clients initiate chat messages (HTTP or WebRTC) using UI components.
- For HTTP mode:
- The client sends a POST to the /api/bot/action endpoint.
- The HTTP pipeline (in bots/http/bot_pipeline.py) processes the message via the Pipecat SDK that calls the Gemini model.
- Responses get stored in SQLite.
- For WebRTC mode:
- The client calls client.connect() to initiate a connection.
- The server’s /connect endpoint (in server/webapp/api/bots.py) starts a persistent bot process via bot_launch() in bots/webrtc/bot.py.
- The WebRTC pipeline (in bots/webrtc/bot_pipeline.py) manages the session.
- The server handles backend logic (configuration, security, and session management) and interacts with the database.

##### Important Architectural Patterns and Design Principles
- Separation of Concerns: Clear division between client-side (front-end UI/UX) and server-side (backend APIs, bot pipelines, persistent storage).
- Modular Architecture: The server code splits functionality into discrete modules (bots, common, webapp), making it easier to extend or modify bot behavior.
- Dual Communication Patterns: A hybrid pattern implementing both HTTP RESTful endpoints for single-turn interactions and persistent WebRTC sessions for real-time, continuous engagement.
- Use of Pipelines: Both bot functionalities for HTTP and WebRTC are implemented as Pipecat pipelines, which encapsulate message processing and potentially enrich processing logic.

##### Relevant Technologies, Frameworks, and Libraries
- Client: React, Vite (bundler), TypeScript, tailwind CSS, and several custom UI components.
- Server: FastAPI (for API endpoints), Python (3.10 to 3.12), Uvicorn (for ASGI server), and SQLite as the database.
- Bot Pipelines and SDKs: Pipecat SDK is employed to manage actions and events; integration with Gemini Multimodal Live API adds AI capabilities, and Daily API can be optionally used for WebRTC functionalities.

##### Additional Recommendations
- Use annotations or callouts to reference key files (e.g., indicate that “server/common/config.py” holds the configuration or that “client/src/components/ClientPage.tsx” creates the RTVIClient).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Legend
    subgraph "Legend"
        LEG1["Rectangle: Service Component"]:::client
        LEG2["Cylinder: Database"]:::db
        LEG3["Rounded Box: External Service"]:::external
    end

    %% Client Layer
    subgraph "Client Layer"
        CLIENT_APP["Client - React App (React, TypeScript, Vite)"]:::client
        UI_COMP["UI Components (ChatControls, ChatMessages, LiveMessages, etc.)"]:::client
    end

    %% Server Layer
    subgraph "Server - FastAPI Backend"
        API_EP["API Endpoints (/action, /connect)"]:::server
        HTTP_PIPE["HTTP Bot Pipeline (bots/http/bot.py)"]:::server
        WEBRTC_PIPE["WebRTC Bot Pipeline (bots/webrtc/bot_pipeline.py)"]:::server
        CONFIG_COMMON["Config & Common Libs (server/common/config.py)"]:::server
    end

    %% Database
    DATABASE["Database (SQLite) (server/common/models.py)"]:::db

    %% External Services
    GEMINI["Gemini API"]:::external
    DAILY["Daily API (Optional)"]:::external

    %% Data Flows
    CLIENT_APP -->|"client.action() / HTTP POST"| API_EP
    CLIENT_APP -->|"client.connect() (WebRTC)"| API_EP
    UI_COMP -->|"Triggers UI events"| CLIENT_APP

    API_EP -->|"Processes HTTP request"| HTTP_PIPE
    API_EP -->|"Initiates WebRTC session"| WEBRTC_PIPE
    API_EP -->|"Loads configuration"| CONFIG_COMMON

    HTTP_PIPE -->|"Calls Gemini model"| GEMINI
    WEBRTC_PIPE -->|"Calls Gemini API"| GEMINI
    WEBRTC_PIPE -->|"Invokes"| DAILY

    HTTP_PIPE -->|"Stores/Retrieves data"| DATABASE
    WEBRTC_PIPE -->|"Stores/Retrieves data"| DATABASE

    %% Click Events
    click CLIENT_APP "https://github.com/pipecat-ai/gemini-multimodal-live-demo/tree/main/client/"
    click UI_COMP "https://github.com/pipecat-ai/gemini-multimodal-live-demo/tree/main/client/src/components/"
    click API_EP "https://github.com/pipecat-ai/gemini-multimodal-live-demo/tree/main/server/webapp/"
    click HTTP_PIPE "https://github.com/pipecat-ai/gemini-multimodal-live-demo/blob/main/server/bots/http/bot.py"
    click WEBRTC_PIPE "https://github.com/pipecat-ai/gemini-multimodal-live-demo/blob/main/server/bots/webrtc/bot_pipeline.py"
    click DATABASE "https://github.com/pipecat-ai/gemini-multimodal-live-demo/blob/main/server/common/models.py"
    click CONFIG_COMMON "https://github.com/pipecat-ai/gemini-multimodal-live-demo/blob/main/server/common/config.py"

    %% Class Definitions for styling
    classDef client fill:#bbdefb,stroke:#0d47a1,stroke-width:2px;
    classDef server fill:#ffcdd2,stroke:#b71c1c,stroke-width:2px;
    classDef db fill:#c8e6c9,stroke:#1b5e20,stroke-width:2px;
    classDef external fill:#ffe082,stroke:#ff6f00,stroke-width:2px;
```
