# manozzo/ai-telegram-bot architecture

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

- Interactive diagram: https://gitdiagram.com/manozzo/ai-telegram-bot
- Repository: https://github.com/manozzo/ai-telegram-bot

## Overview

##### Component Details

a) Client Layer:

b) Application Layer (Core):
- TelegramBotService (from telegramBotService.js)
- OllamaService (from ollamaService.js)

c) AI Processing Layer:
- Llama 3.2 model representation within Ollama

##### Connection Flows

**Telegram Clients → Telegram API → TelegramBotService**
- ↓
- OllamaService
- ↓
- Ollama
- ↓
- Llama 3.2

##### Additional Elements

- User requests
- Bot responses
- Internal service communications
- Model inference

##### Technical Details

Annotations showing:
- Node.js v18+ requirement
- PM2 process management
- Telegram Bot API version
- Ollama API endpoints
- Environment variables required

Create clear boundaries between:
- External Services (Telegram)
- Application Core (Node.js + PM2)
- AI Processing (Ollama + Llama)

Remember to include a title: "Ollama Telegram Bot Companion - System Architecture" and a brief description of the main data flow: User → Telegram → Bot → Ollama → Response.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Title
    title[("Ollama Telegram Bot Companion<br/>System Architecture")]:::title
    
    %% Client Layer
    subgraph ClientLayer["Client Layer"]
        Users[("Telegram Users")]:::client
        TelegramAPI["Telegram API"]:::telegram
    end
    
    %% Application Layer
    subgraph AppLayer["Application Layer"]
        PM2["PM2 Process Manager"]:::infra
        
        subgraph NodeApp["Node.js Application"]
            TelegramBot["Telegram Bot Service"]:::service
            OllamaService["Ollama Service"]:::service
            EnvConfig[".env Configuration"]:::config
        end
    end
    
    %% AI Processing Layer
    subgraph AILayer["AI Processing Layer"]
        Ollama["Ollama Instance"]:::ai
        LLama["Llama 3.2 Model"]:::model
    end
    
    %% Connections
    Users --> TelegramAPI
    TelegramAPI --> TelegramBot
    TelegramBot --> OllamaService
    OllamaService --> Ollama
    Ollama --> LLama
    LLama --> Ollama
    Ollama --> OllamaService
    OllamaService --> TelegramBot
    TelegramBot --> TelegramAPI
    TelegramAPI --> Users
    EnvConfig -.-> TelegramBot
    EnvConfig -.-> OllamaService
    PM2 -.-> NodeApp
    
    %% Click Events
    click TelegramBot "https://github.com/manozzo/ai-telegram-bot/blob/main/src/services/telegramBotService.js"
    click OllamaService "https://github.com/manozzo/ai-telegram-bot/blob/main/src/services/ollamaService.js"
    click EnvConfig "https://github.com/manozzo/ai-telegram-bot/blob/main/.env.example"
    click NodeApp "https://github.com/manozzo/ai-telegram-bot/blob/main/package.json"
    click NodeApp "https://github.com/manozzo/ai-telegram-bot/tree/main/src/services/"
    
    %% Styles
    classDef title fill:#f9f,stroke:#333,stroke-width:4px
    classDef client fill:#85C1E9,stroke:#333
    classDef telegram fill:#3498DB,stroke:#333
    classDef service fill:#82E0AA,stroke:#333
    classDef config fill:#BFC9CA,stroke:#333
    classDef infra fill:#D7BDE2,stroke:#333
    classDef ai fill:#C39BD3,stroke:#333
    classDef model fill:#BB8FCE,stroke:#333
    
    %% Legend
    subgraph Legend
        L1[("User Icon")]:::client
        L2["Service Component"]:::service
        L3["AI Component"]:::ai
        L4["Infrastructure"]:::infra
    end
```
