# kaymen99/ai-voice-assistant architecture

> Architecture diagram of the GitHub repository kaymen99/ai-voice-assistant, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kaymen99/ai-voice-assistant
- Repository: https://github.com/kaymen99/ai-voice-assistant

## Overview

##### Project Type and Purpose
- This is a monolithic Python-based AI Voice Assistant application.
- It provides a command-line (or local) conversational interface using Speech-to-Text (STT) and Text-to-Speech (TTS), powered by large language models (Llama3 via Groq API or Gemini) and a suite of “tools” to manage calendars, contacts, emails, web searches, and a personal knowledge base.

##### High-Level Architecture Overview
- Input Layer: Captures user speech via microphone.
- Processing Layer:
- STT module converts audio → text.
- Conversation Manager orchestrates context, history, and tool selection.
- Agent core (in `src/agents/agent.py`) calls the LLM with prompts (managed in `src/prompts/prompts.py`).
- Tool Executor dispatches calls to individual tools (in `src/tools/*`).
- External Services Layer:
- Deepgram (voice processing)
- Google APIs (Calendar, Contacts, Gmail)
- Tavily Search API
- Groq API / Gemini API (LLM model)
- Local files/embeddings index for KnowledgeBaseTool
- Output Layer: TTS module converts text → speech, played back to the user.

##### Main Components & Relationships
- User Interface (microphone & speaker)
→ feeds audio into
- STT Subsystem (`src/speech_processing/speech_to_text.py`)
→ outputs text to
- Conversation Manager (`src/speech_processing/conversation_manager.py`)
↔ maintains context with
- Agent Core (`src/agents/agent.py`)
→ uses Prompt Manager (`src/prompts/prompts.py`) to build LLM queries
→ calls LLM via Groq/Gemini API
→ inspects LLM response for tool invocation
- Tool Executor (base class in `src/tools/base_tool.py`)
→ dispatches to specific tool modules:
- CalendarTool
- AddContactTool / FetchContactTool
- EmailingTool
- SearchWebTool
- KnowledgeBaseTool (backed by the index created/fetched by `scripts/create_index.py` & `scripts/fetch_index.py`)
→ each tool calls its respective external API (Google, Tavily, local storage)
→ returns structured result to Agent
- Agent Core
→ forwards final text response to
- TTS Subsystem (`src/speech_processing/text_to_speech.py`)
→ plays synthesized audio to user

##### Important Architectural Patterns & Principles
- Layered design (Input → Core Logic → Integration → Output)
- Plugin-like “Tool” architecture: each tool implements a common interface (`BaseTool`), enabling easy extension.
- Separation of concerns: STT/TTS, dialogue management, LLM orchestration, and external integrations are decoupled into distinct modules.
- Asynchronous I/O (if implemented) for non-blocking API calls (optional).

##### Essential Elements Checklist
- Component labels matching code modules (e.g., ConversationManager, PromptManager).
- A note or callout showing where environment variables (API keys) are injected.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Input Layer
    subgraph "Input Layer"
        Main["main.py (Entry Point)"]:::core
    end

    %% Processing Layer
    subgraph "Processing Layer"
        STT["Speech-to-Text\n.wav audio → text"]:::core
        CM["ConversationManager\nmaintains context"]:::core
        Agent["Agent Core"]:::core
        Prompt["PromptManager"]:::core
        ToolExec["ToolExecutor"]:::core
        Utils["Utils (src/utils.py)"]:::core
        subgraph "Tools (Plugin Architecture)"
            CalendarTool["CalendarTool"]:::core
            AddContactTool["AddContactTool"]:::core
            FetchContactTool["FetchContactTool"]:::core
            EmailingTool["EmailingTool"]:::core
            SearchWebTool["SearchWebTool"]:::core
            KnowledgeBaseTool["KnowledgeBaseTool"]:::core
        end
    end

    %% Output Layer
    subgraph "Output Layer"
        TTS["Text-to-Speech\ntext → .wav audio"]:::core
    end

    %% External Services
    subgraph "External Services"
        Deepgram["Deepgram API"]:::external
        GoogleCalendar["Google Calendar API"]:::external
        GoogleContacts["Google Contacts API"]:::external
        GmailAPI["Gmail API"]:::external
        Tavily["Tavily Search API"]:::external
        LLMAPI["Groq/Gemini LLM API"]:::external
    end

    %% Data Store
    subgraph "Data Store"
        IndexStore["Embeddings Index\n(local files)"]:::datastore
    end

    %% Scripts & Offline
    subgraph "Scripts"
        CreateIndex["create_index.py"]:::scripts
        FetchIndex["fetch_index.py"]:::scripts
    end

    %% Environment Variables
    Env["Env Vars\n(API Keys)"]:::external

    %% Legend
    subgraph "Legend"
        CoreNode["Core Modules"]:::core
        ExternalNode["External Services"]:::external
        DataNode["Data Stores"]:::datastore
        ScriptNode["Scripts"]:::scripts
    end

    %% Connections
    Main -->|"audio stream"| STT
    STT -->|"text"| CM
    CM -->|"context & call"| Agent
    Agent -->|"build prompt"| Prompt
    Prompt -->|"text prompt"| LLMAPI
    LLMAPI -->|"response JSON"| Agent
    Agent -->|"invoke tool"| ToolExec
    ToolExec -->|"dispatch"| CalendarTool
    ToolExec -->|"dispatch"| AddContactTool
    ToolExec -->|"dispatch"| FetchContactTool
    ToolExec -->|"dispatch"| EmailingTool
    ToolExec -->|"dispatch"| SearchWebTool
    ToolExec -->|"dispatch"| KnowledgeBaseTool
    CalendarTool -->|"API calls"| GoogleCalendar
    AddContactTool -->|"API calls"| GoogleContacts
    FetchContactTool -->|"API calls"| GoogleContacts
    EmailingTool -->|"API calls"| GmailAPI
    SearchWebTool -->|"API calls"| Tavily
    KnowledgeBaseTool -->|"reads/writes"| IndexStore
    CreateIndex -->|"builds index"| IndexStore
    FetchIndex -->|"fetches index"| IndexStore
    KnowledgeBaseTool -->|"index refresh"| FetchIndex
    Agent -->|"response text"| TTS
    TTS -->|"audio playback"| Main
    Env --> GoogleCalendar
    Env --> GoogleContacts
    Env --> GmailAPI
    Env --> LLMAPI

    %% Click Events
    click Main "https://github.com/kaymen99/ai-voice-assistant/blob/main/main.py"
    click STT "https://github.com/kaymen99/ai-voice-assistant/blob/main/src/speech_processing/speech_to_text.py"
    click CM "https://github.com/kaymen99/ai-voice-assistant/blob/main/src/speech_processing/conversation_manager.py"
    click TTS "https://github.com/kaymen99/ai-voice-assistant/blob/main/src/speech_processing/text_to_speech.py"
    click Agent "https://github.com/kaymen99/ai-voice-assistant/blob/main/src/agents/agent.py"
    click Prompt "https://github.com/kaymen99/ai-voice-assistant/blob/main/src/prompts/prompts.py"
    click ToolExec "https://github.com/kaymen99/ai-voice-assistant/blob/main/src/tools/base_tool.py"
    click CalendarTool "https://github.com/kaymen99/ai-voice-assistant/blob/main/src/tools/calendar/calendar_tool.py"
    click AddContactTool "https://github.com/kaymen99/ai-voice-assistant/blob/main/src/tools/contacts/add_contact_tool.py"
    click FetchContactTool "https://github.com/kaymen99/ai-voice-assistant/blob/main/src/tools/contacts/fetch_contact_tool.py"
    click EmailingTool "https://github.com/kaymen99/ai-voice-assistant/blob/main/src/tools/emails/emailing_tool.py"
    click SearchWebTool "https://github.com/kaymen99/ai-voice-assistant/blob/main/src/tools/search/search_web_tool.py"
    click KnowledgeBaseTool "https://github.com/kaymen99/ai-voice-assistant/blob/main/src/tools/search/knowledge_base_tool.py"
    click CreateIndex "https://github.com/kaymen99/ai-voice-assistant/blob/main/scripts/create_index.py"
    click FetchIndex "https://github.com/kaymen99/ai-voice-assistant/blob/main/scripts/fetch_index.py"
    click Utils "https://github.com/kaymen99/ai-voice-assistant/blob/main/src/utils.py"
    click Requirements "https://github.com/kaymen99/ai-voice-assistant/blob/main/requirements.txt"
    click Readme "https://github.com/kaymen99/ai-voice-assistant/blob/main/README.md"

    %% Styles
    classDef core fill:#D6EAFE,stroke:#0366d6,color:#0366d6,stroke-width:1px;
    classDef external fill:#E3FCEF,stroke:#28a745,color:#28a745,stroke-width:1px;
    classDef datastore fill:#FFF5B1,stroke:#DAA520,color:#DAA520,stroke-width:1px;
    classDef scripts fill:#E5E5E5,stroke:#6a737d,color:#6a737d,stroke-width:1px;
```
