# ashoksahoo/bolna architecture

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

- Interactive diagram: https://gitdiagram.com/ashoksahoo/bolna
- Repository: https://github.com/ashoksahoo/bolna

## Overview

##### Project Purpose and Type
- Bolna is a voice agents orchestration platform built to quickly create LLM-based, voice-first conversational applications.
- Its design integrates multiple external providers: telephony (Twilio, Plivo, etc.), ASR (Deepgram, etc.), LLMs (OpenAI, etc.), and TTS services (AWS Polly, ElevenLabs, etc.). It is an orchestration layer that also serves as the backbone for hosted APIs and a no-code web UI (part of the closed source offerings).

##### File Structure to Identify Key Architectural Components
- The top-level “bolna” directory constitutes the core engine. Its subdirectories hint at the modular and layered design:
- “agent_manager” and “agent_types”: Handle the orchestration and behavior of different agents (e.g., contextual, extraction, summarization, etc.).
- “helpers”: Provide supportive functions like logging, analytics, caching, and utilities.
- “input_handlers” and “output_handlers”: Define how the system interacts with external telephony providers (and likely other data sources) to receive input and deliver output.
- “llms”: Contains abstractions and integrations with various language models.
- “synthesizer”: Manages text-to-speech (TTS) processes using multiple providers.
- “transcriber”: Manages audio transcription (ASR) functionalities.
- “memory”: Implements caching strategies (including modules for in-memory and vector caching).
- “classification” and other modules (e.g., “prompts”, “providers”) enrich processing capabilities.
- The “local_setup” directory holds Docker compose files, Dockerfiles, and sample servers. This containerized setup depicts a multi-container deployment with separate services (e.g., telephony server, Bolna server, ngrok for tunneling, and Redis for caching/persistence).

- Following primary components:
A. Bolna Core Engine:
- Composed of the orchestration logic (agent_manager, agent_types) and processing modules (LLMs, synthesizer, transcriber, classification).
- Includes utility/helpers modules for logging, caching, and analytics.
B. External Provider Interfaces:
- Telephony Providers: Implementations in input_handlers/telephony_providers and output_handlers/telephony_providers (Twilio, Plivo, Exotel, etc.) that manage initiating and receiving calls via websockets.
- ASR, LLM, and TTS Providers: Modules in “llms” for language model integration, “transcriber” for converting voice to text, and “synthesizer” for converting text back to voice.
C. Supporting Services and Containerized Deployment:
- The Docker-based local environment includes:
1. Bolna Server container (hosting the orchestration engine).
2. Telephony API Server container (for either Twilio or Plivo).
3. Ngrok container for secure tunneling.
4. Redis container to persist agent and prompt data.
- This multi-container setup is key for understanding runtime interactions.

##### Architectural Patterns and Design Principles
- Modular/Component-Based Design: Each major function (agent orchestration, provider integration, voice processing) is separated into dedicated modules, facilitating extensibility.
- Abstraction layers: Abstract base classes (for agents, transcribers, synthesizers) allow for easy extension/customization, supporting multiple external providers.
- Containerization: The inclusion of Docker compose setup indicates a microservices-like approach to simplify deployment and testing.
- Clear separation between input (handling incoming voice calls), processing (agent orchestration and LLM interactions), and output (synthesized responses and telephony output).

##### Final Checklist
- Clear labels for each component or module.
- Containerized modules if representing the local setup, including annotations for Docker-compose components (ngrok, Redis, telephony servers).
- Be detailed and avoid oversimplification: indicate as many functional blocks as possible to reflect the project’s modular design.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Providers Group
    subgraph "External Providers"
        TP_Input["Telephony Providers (Input)"]:::external
        TP_Output["Telephony Providers (Output)"]:::external
        ASR_Prov["ASR Providers"]:::external
        LLM_Prov["LLM Providers"]:::external
        TTS_Prov["TTS Providers"]:::external
    end

    %% Bolna Core Engine Group
    subgraph "Bolna Core Engine"
        Core["Bolna Core Engine"]:::core
        IH["Input Handlers"]:::handler
        AM["Agent Manager"]:::core
        AT["Agent Types"]:::core
        HU["Helpers & Utilities"]:::core
        LI["LLM Integration"]:::core
        CL["Classification"]:::core
        TR["Transcriber"]:::core
        SY["Synthesizer"]:::core
        OH["Output Handlers"]:::handler
        MC["Memory & Cache"]:::core
    end

    %% Containerized Deployment Group
    subgraph "Containerized Deployment"
        BS["Bolna Server Container"]:::container
        TAS["Telephony API Server Container"]:::container
        NG["Ngrok Container"]:::container
        RD["Redis Container"]:::container
    end

    %% Data Flow Connections for Core Flow
    TP_Input -->|"feeds"| IH
    IH -->|"routes to"| AM
    ASR_Prov -->|"supplies audio"| TR
    TR -->|"transcribes to"| AM
    AM -->|"orchestrates"| AT
    AM -->|"utilizes"| HU
    MC -->|"supports"| AM
    LLM_Prov -->|"queries"| LI
    AM -->|"calls"| LI
    LI -->|"response to"| SY
    TTS_Prov -->|"assists"| SY
    SY -->|"prepares output"| OH
    OH -->|"sends output"| TP_Output
    %% Additional internal flow
    AM -->|"classification"| CL

    %% Containerized Deployment Connections
    TAS ---|"interfaces with"| BS
    NG -->|"tunnels to"| TAS
    BS -->|"caches via"| RD
    BS ---|"runs"| Core

    %% Styling Classes
    classDef core fill:#E0E0FF,stroke:#000,stroke-width:1px;
    classDef external fill:#FFD580,stroke:#000,stroke-width:1px;
    classDef handler fill:#FAD7A0,stroke:#000,stroke-width:1px;
    classDef container fill:#C4F0C5,stroke:#000,stroke-width:1px;

    %% Click Events for Bolna Core and its Modules
    click Core "https://github.com/ashoksahoo/bolna/tree/master/bolna/"
    click AM "https://github.com/ashoksahoo/bolna/tree/master/bolna/agent_manager/"
    click AT "https://github.com/ashoksahoo/bolna/tree/master/bolna/agent_types/"
    click HU "https://github.com/ashoksahoo/bolna/tree/master/bolna/helpers/"
    click IH "https://github.com/ashoksahoo/bolna/tree/master/bolna/input_handlers/"
    click TP_Input "https://github.com/ashoksahoo/bolna/tree/master/bolna/input_handlers/telephony_providers/"
    click OH "https://github.com/ashoksahoo/bolna/tree/master/bolna/output_handlers/"
    click TP_Output "https://github.com/ashoksahoo/bolna/tree/master/bolna/output_handlers/telephony_providers/"
    click LI "https://github.com/ashoksahoo/bolna/tree/master/bolna/llms/"
    click SY "https://github.com/ashoksahoo/bolna/tree/master/bolna/synthesizer/"
    click TR "https://github.com/ashoksahoo/bolna/tree/master/bolna/transcriber/"
    click MC "https://github.com/ashoksahoo/bolna/tree/master/bolna/memory/"
    click CL "https://github.com/ashoksahoo/bolna/tree/master/bolna/classification/"

    %% Click Events for Containerized Deployment
    click BS "https://github.com/ashoksahoo/bolna/tree/master/local_setup/"
    click TAS "https://github.com/ashoksahoo/bolna/tree/master/local_setup/telephony_server/"
    click NG "https://github.com/ashoksahoo/bolna/tree/master/local_setup/"
    click RD "https://github.com/ashoksahoo/bolna/tree/master/local_setup/"
```
