# vocodedev/vocode-core architecture

> Architecture diagram of the GitHub repository vocodedev/vocode-core, 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/vocodedev/vocode-core
- Repository: https://github.com/vocodedev/vocode-core

## Overview

##### Main Components
- Core Library – “vocode”:
– Streaming Module: Contains submodules for agents (e.g., ChatGPTAgent, AnthropicAgent), actions (e.g., DTMF, end_conversion, transfer, email recording, etc.), input/output devices, transcribers, synthesizers, and conversation management.
– Turn-based Module: Offers a similar context for non-streaming interactions (mirroring agents, input devices, and output devices).
– Utilities: Helper modules, configurations (including logging, state management, singleton pattern, etc.), and integration code (e.g., for telephony, vector databases).
- Apps / Demos:
– “client_backend”, “langchain_agent”, “livekit”, “telegram_bot”, “telephony_app”, “voice_rag”: These directories contain Dockerfiles, .env templates, and example implementations which illustrate how to wire the core library into concrete applications.
- External Integrations:
– Transcription services (Deepgram, AssemblyAI, Whisper, etc.)
– Synthesis services (Azure, Eleven Labs, gTTS, etc.)
– Telephony services (Twilio, Vonage, Zoom dial-in, etc.)
– Langchain and other LLM integrations.

##### Relationships and Data Flow
- Application Layer (Apps):
– Each demo app uses a combination of the core library’s conversation engine, agents, transcribers, synthesizers, and sometimes telephony servers.
- Core Library:
– The streaming conversation is built around a pipeline where:
1. Audio Input (from devices such as microphones or telephony clients) is fed to a Transcriber.
2. Transcribed text is sent to a Voice Assistant Agent (e.g., ChatGPTAgent) which processes it according to predefined actions.
3. The agent’s text response is converted back into audio by a Synthesizer.
4. The Audio Output is then routed to the appropriate output device (speaker, phone call, etc.).
– Additional modules (actions, telephony client, livekit integrations) interact via defined interfaces.
- External Service Calls:
- Configuration/Orchestration:

##### Architectural Patterns and Design Principles
- Modular Design – The segregated “apps” and “vocode” library demonstrate clear separation of concerns.
- Plug-and-Play Architecture – The use of abstract factories (in agents, actions, synthesizers, transcribers) and dependency injection (via settings and configuration) make integration of different services straightforward.
- Microservices/Containerization – Dockerfiles and docker-compose files in various apps suggest that containerization is used for deployment.
- Real-Time Streaming Pipeline – Illustrate the streaming pipeline (audio input → transcription → agent processing → synthesis → audio output) that is central to the project.

##### Relevant Technologies, Frameworks, and Libraries
- Python (as the primary language) and its ecosystem (pyproject.toml hints)
- Docker for containerization, as seen in Dockerfiles across apps.
- Integration with third-party APIs: OpenAI, Anthropic, Deepgram, Azure, Twilio, etc.
- Testing frameworks (pytest noted from tests/ directory) and continuous integration (GitHub workflows)

- Components and Modules:
- Transcribers
- Agents (LLM handlers)
- Synthesizers
- Action/Telephony modules
- Utilities / Config
- API calls to external services.
- Labels & Distinctions:

##### Final Advice
- Be very detailed. Break down the core library into as many logical subcomponents as possible to accurately capture the internal streaming pipeline.
- Don’t overcomplicate it – the idea is to illustrate the overall blueprint with clear separations for each module that interacts in real time.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Applications / Demos
    subgraph "Applications / Demos"
        A1["Client Backend Demo"]
        A2["Langchain Agent Integration Demo"]
        A3["Livekit Integration Demo"]
        A4["Telegram Bot Demo"]
        A5["Telephony App Demo"]
        A6["Voice RAG Demo"]
    end

    %% vocode Core Library
    subgraph "vocode Core Library"
        CL["Core Library"]

        subgraph "Streaming Module (Voice Streaming Engine)"
            S1["Audio Input"]
            S2["Transcriber"]
            S3["Agent (LLM Handler)"]
            S4["Synthesizer"]
            S5["Audio Output"]
            S6["Telephony Module"]
        end

        subgraph "Turn-Based Module"
            TB1["Input Device"]
            TB2["Agent"]
            TB3["Synthesizer"]
            TB4["Output Device"]
        end

        subgraph "Utilities & Config"
            UT1["Helper Functions"]
            UT2["Logging"]
            UT3["Utils"]
        end
    end

    %% External Integrations
    subgraph "External Integrations"
        E1["Transcription APIs"]
        E2["Synthesis APIs"]
        E3["Telephony APIs"]
        E4["LLM Providers"]
    end

    %% Data Flow: Applications -> Core Library
    A1 -->|"feeds audio"| S1
    A2 -->|"feeds audio"| S1
    A3 -->|"feeds audio"| S1
    A4 -->|"feeds audio"| S1
    A5 -->|"feeds audio"| S1
    A6 -->|"feeds audio"| S1

    %% Streaming Pipeline within Core Library
    S1 -->|"transcribes"| S2
    S2 -->|"sends text"| S3
    S3 -->|"generates response"| S4
    S4 -->|"outputs audio"| S5

    %% Telephony Module Integration
    S1 -->|"routes call"| S6

    %% Turn-Based Pipeline Flow
    TB1 -->|"sends request"| TB2
    TB2 -->|"processes"| TB3
    TB3 -->|"delivers response"| TB4

    %% External API Calls from Streaming Module
    S2 -->|"call"| E1
    S4 -->|"call"| E2
    S6 -->|"call"| E3
    S3 -->|"call"| E4

    %% Utilities influence
    UT1 ---|"configures"| S1
    UT2 ---|"logs activity"| CL
    UT3 ---|"supports"| CL

    %% Click Events
    click CL "https://github.com/vocodedev/vocode-core/tree/main/vocode/"
    click S1 "https://github.com/vocodedev/vocode-core/tree/main/vocode/streaming/"
    click S2 "https://github.com/vocodedev/vocode-core/tree/main/vocode/streaming/transcriber/"
    click S3 "https://github.com/vocodedev/vocode-core/tree/main/vocode/streaming/"
    click S4 "https://github.com/vocodedev/vocode-core/tree/main/vocode/streaming/synthesizer/"
    click S6 "https://github.com/vocodedev/vocode-core/tree/main/vocode/streaming/telephony/"
    click TB1 "https://github.com/vocodedev/vocode-core/tree/main/vocode/turn_based/"
    click TB3 "https://github.com/vocodedev/vocode-core/tree/main/vocode/turn_based/synthesizer/"
    click UT1 "https://github.com/vocodedev/vocode-core/blob/main/vocode/helpers.py"
    click UT2 "https://github.com/vocodedev/vocode-core/blob/main/vocode/logging.py"
    click UT3 "https://github.com/vocodedev/vocode-core/tree/main/vocode/utils/"
    click A1 "https://github.com/vocodedev/vocode-core/tree/main/apps/client_backend/"
    click A2 "https://github.com/vocodedev/vocode-core/tree/main/apps/langchain_agent/"
    click A3 "https://github.com/vocodedev/vocode-core/tree/main/apps/livekit/"
    click A4 "https://github.com/vocodedev/vocode-core/tree/main/apps/telegram_bot/"
    click A5 "https://github.com/vocodedev/vocode-core/tree/main/apps/telephony_app/"
    click A6 "https://github.com/vocodedev/vocode-core/tree/main/apps/voice_rag/"

    %% Styles
    class A1,A2,A3,A4,A5,A6 apps
    class CL,S1,S2,S3,S4,S5,S6,TB1,TB2,TB3,TB4 core
    class E1,E2,E3,E4 external
    class UT1,UT2,UT3 utils

    classDef apps fill:#ffcccc,stroke:#cc0000,stroke-width:2px;
    classDef core fill:#ccffcc,stroke:#006600,stroke-width:2px;
    classDef external fill:#ccccff,stroke:#000099,stroke-width:2px;
    classDef utils fill:#ffffcc,stroke:#999900,stroke-width:2px;
```
