# elokus/whatsappagent architecture

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

- Interactive diagram: https://gitdiagram.com/elokus/whatsappagent
- Repository: https://github.com/elokus/whatsappagent

## Overview

##### Main Components

a) Client Layer:
- Command Line Interface
- Future WhatsApp Webhook Integration (mentioned in README)

b) Application Core:
- Message Service (Central Coordinator)
- Agent System
- Tools System
- Database Layer

##### Detailed Component Breakdown

a) Domain Layer (Core Business Logic):
- Agent System:
- Routing Agent (Controller)
- Task Agent
- Demo Agent
- Base Agent (Abstract)

- Tools System:
- Query Tool
- Tool
- Report Tool
- Base Tool (Abstract)

b) Infrastructure Layer:
- LLM Service (OpenAI Integration)

c) Persistence Layer:
- Database Connection
- Data Models
- Mock Data Service

##### Component Relationships

Key interactions:

**User Input → Message Service → Routing Agent → Task/Demo Agent → Tools → Database**
- ↑
- LLM Service (OpenAI)

##### Technical Details

- Python/Pydantic as the core framework
- OpenAI API integration
- Database connection
- Environment configuration

##### Persistence Layer (Bottom)

This system design should capture the essence of a domain-driven design architecture with clear separation between domain logic, infrastructure, and persistence layers, while highlighting the unique aspects of the AI agent routing system and its interaction with external services.

Remember to maintain a balance between showing enough detail to understand the system's architecture while keeping it clean and readable. The focus should be on the interaction between the routing agent, task agents, and their tools, as this appears to be the core functionality of the system.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles
    classDef ui fill:#B8D4FF,stroke:#2E75B6,stroke-width:2px
    classDef service fill:#B5CEA8,stroke:#548235,stroke-width:2px
    classDef agent fill:#9BC2E6,stroke:#2E75B6,stroke-width:2px
    classDef tool fill:#FFE699,stroke:#BF8F00,stroke-width:2px
    classDef infra fill:#F8CBAD,stroke:#C65911,stroke-width:2px
    classDef db fill:#E2EFDA,stroke:#548235,stroke-width:2px

    %% Client Layer
    CLI["Command Line Interface"]:::ui
    WhatsApp["WhatsApp Webhook"]:::ui

    %% Application Core
    EntryPoint["Application Entry Point"]:::service
    MessageService["Message Service"]:::service
    Exceptions["Domain Exceptions"]:::service
    Schema["Schema Definitions"]:::service

    %% Agent System
    subgraph AgentSystem["Agent System"]
        BaseAgent["Base Agent"]:::agent
        RoutingAgent["Routing Agent"]:::agent
        TaskAgent["Task Agent"]:::agent
        DemoAgent["Demo Agent"]:::agent
    end

    %% Tools System
    subgraph ToolSystem["Tools System"]
        BaseTool["Base Tool"]:::tool
        QueryTool["Query Tool"]:::tool
        AddTool["Add Tool"]:::tool
        ReportTool["Report Tool"]:::tool
    end

    %% Infrastructure Layer
    LLMService["LLM Service"]:::infra

    %% Persistence Layer
    subgraph PersistenceLayer["Persistence Layer"]
        DBConnection["Database Connection"]:::db
        DataModels["Data Models"]:::db
        MockData["Mock Data Service"]:::db
    end

    %% Relationships
    CLI --> EntryPoint
    WhatsApp -.-> EntryPoint
    EntryPoint --> MessageService
    MessageService --> RoutingAgent
    RoutingAgent --> TaskAgent
    RoutingAgent --> DemoAgent
    TaskAgent --> ToolSystem
    DemoAgent --> ToolSystem
    ToolSystem --> PersistenceLayer
    RoutingAgent <--> LLMService

    BaseAgent --> Exceptions
    BaseTool --> Exceptions
    MessageService --> Schema

    %% Click Events
    click EntryPoint "https://github.com/elokus/WhatsappAgent/blob/main/app/main.py"
    click MessageService "https://github.com/elokus/WhatsappAgent/blob/main/app/domain/message_service.py"
    click BaseAgent "https://github.com/elokus/WhatsappAgent/blob/main/app/domain/agents/base.py"
    click RoutingAgent "https://github.com/elokus/WhatsappAgent/blob/main/app/domain/agents/routing.py"
    click TaskAgent "https://github.com/elokus/WhatsappAgent/blob/main/app/domain/agents/task.py"
    click DemoAgent "https://github.com/elokus/WhatsappAgent/blob/main/app/domain/agents/demo_agent.py"
    click BaseTool "https://github.com/elokus/WhatsappAgent/blob/main/app/domain/tools/base.py"
    click QueryTool "https://github.com/elokus/WhatsappAgent/blob/main/app/domain/tools/query.py"
    click AddTool "https://github.com/elokus/WhatsappAgent/blob/main/app/domain/tools/add.py"
    click ReportTool "https://github.com/elokus/WhatsappAgent/blob/main/app/domain/tools/report_tool.py"
    click LLMService "https://github.com/elokus/WhatsappAgent/blob/main/app/infrastructure/llm.py"
    click DBConnection "https://github.com/elokus/WhatsappAgent/blob/main/app/persistance/db.py"
    click DataModels "https://github.com/elokus/WhatsappAgent/blob/main/app/persistance/models.py"
    click MockData "https://github.com/elokus/WhatsappAgent/blob/main/app/persistance/mock_data.py"
    click Exceptions "https://github.com/elokus/WhatsappAgent/blob/main/app/domain/exceptions.py"
    click Schema "https://github.com/elokus/WhatsappAgent/blob/main/app/schema.py"

    %% Legend
    subgraph Legend
        UI["User Interface"]:::ui
        SVC["Services"]:::service
        AGT["Agents"]:::agent
        TL["Tools"]:::tool
        INF["Infrastructure"]:::infra
        DB["Database"]:::db
    end
```
