# fatduckai/ai architecture

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

## Overview

##### Main Components

a) Core System Layer:
- AI Core Manager (src/core/ai.ts)
- Character Management System (src/core/managers/character.ts)
- Memory Management System (src/core/managers/memory.ts)
- LLM Provider Interface (src/core/managers/llm.ts)
- Event System (src/core/services/Event.ts)
- Quantum State Manager (src/core/services/quantum-state.ts)

b) Platform Integration Layer:
- Telegram Integration (src/core/platform/telegram)
- Twitter Integration (src/core/platform/twitter)
- API Server (src/core/platform/api)

c) Database Layer:
- SQL Database (using Drizzle ORM)
- Migration System
- Schema Definitions

d) Tools & Utilities:
- Token Management
- Real-time Data Tools (e.g., BTC price)
- IBM Quantum Integration

**┌─────────────────────────────────────────────────────────┐**
- Client Platforms                       │
- (Twitter, Telegram, API Endpoints)                    │
- ┤
- Platform Adapters                      │
- (Format-specific handlers and response types)         │
- ┤
- Core System                         │
- ┌─────────────┐  ┌──────────────┐  ┌──────────────┐   │
- AI Manager  │  │  Character   │  │   Memory     │   │
- ◄─►│  Manager    │◄─►│   Manager   │   │
- ┘  └──────────────┘  └──────────────┘   │
- ┌─────────────┐  ┌──────────────┐  ┌──────────────┐   │
- Event     │  │   Quantum    │  │    Tools     │   │
- System     │◄─►│    State    │◄─►│   Manager   │   │
- ┘  └──────────────┘  └──────────────┘   │
- ┤
- Database Layer                        │
- (Character Data, Interactions, Memory Storage)        │
- ┘

##### Data Flow Indicators

- Character interaction flow
- Memory management processes
- Platform-specific response formatting
- Tool integration points
- Database operations

##### Component Relationships

- Character Manager ↔ Memory Manager
- AI Core ↔ Platform Adapters
- Tools Manager ↔ External Services
- Event System ↔ All Components
- Quantum State ↔ Character Personality

##### Additional Elements

- Character creation flow
- Interaction processing pipeline
- Platform-specific response formatting
- Memory management system
- Tool integration process

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client["Client Platforms"]
        TW["Twitter Client"]:::client
        TG["Telegram Client"]:::client
        API["API Client"]:::client
    end

    subgraph Platform["Platform Integration Layer"]
        TWA["Twitter Adapter"]:::platform
        TGA["Telegram Adapter"]:::platform
        APIA["API Server"]:::platform
    end

    subgraph Core["Core System Layer"]
        AIM["AI Core Manager"]:::core
        CMS["Character Manager"]:::core
        MMS["Memory Manager"]:::core
        LLM["LLM Provider"]:::core
        EVS["Event System"]:::core
        QSM["Quantum State Manager"]:::core
        QPS["Quantum Personality System"]:::core
        CCS["Character Creation System"]:::core
        CONV["Conversation Manager"]:::core
        IMG["Image Manager"]:::core
        TOOL["Tools Manager"]:::core
    end

    subgraph Tools["Tools & Utilities"]
        TKN["Token Management"]:::tool
        BTC["BTC Price Tool"]:::tool
        IBM["IBM Quantum Integration"]:::tool
    end

    subgraph DB["Database Layer"]
        DBC["Database Core"]:::db
        SCH["Schema Definitions"]:::db
        MIG["Migration System"]:::db
    end

    %% Client to Platform connections
    TW --> TWA
    TG --> TGA
    API --> APIA

    %% Platform to Core connections
    TWA & TGA & APIA --> AIM

    %% Core internal connections
    AIM <--> CMS
    CMS <--> MMS
    CMS <--> QSM
    QSM <--> QPS
    CMS <--> CCS
    AIM <--> CONV
    CMS <--> IMG
    EVS <--> AIM & CMS & MMS & QSM & TOOL
    LLM <--> AIM

    %% Tools connections
    TOOL --> TKN & BTC & IBM
    QPS --> IBM

    %% Database connections
    DBC --> SCH
    DBC --> MIG
    CMS & MMS & CONV --> DBC

    %% Styles
    classDef client fill:#FF9900,stroke:#333,stroke-width:2px
    classDef platform fill:#90EE90,stroke:#333,stroke-width:2px
    classDef core fill:#87CEEB,stroke:#333,stroke-width:2px
    classDef tool fill:#FFD700,stroke:#333,stroke-width:2px
    classDef db fill:#DDA0DD,stroke:#333,stroke-width:2px

    %% Click events
    click AIM "https://github.com/fatduckai/ai/blob/master/src/core/ai.ts"
    click CMS "https://github.com/fatduckai/ai/blob/master/src/core/managers/character.ts"
    click MMS "https://github.com/fatduckai/ai/blob/master/src/core/managers/memory.ts"
    click LLM "https://github.com/fatduckai/ai/blob/master/src/core/managers/llm.ts"
    click EVS "https://github.com/fatduckai/ai/blob/master/src/core/services/Event.ts"
    click QSM "https://github.com/fatduckai/ai/blob/master/src/core/services/quantum-state.ts"
    click TGA "https://github.com/fatduckai/ai/blob/master/src/core/platform/telegram/telegram.ts"
    click TWA "https://github.com/fatduckai/ai/blob/master/src/core/platform/twitter/twitter.ts"
    click APIA "https://github.com/fatduckai/ai/blob/master/src/core/platform/api/server.ts"
    click SCH "https://github.com/fatduckai/ai/blob/master/src/db/schema/schema.ts"
    click MIG "https://github.com/fatduckai/ai/blob/master/src/db/migrate.ts"
    click DBC "https://github.com/fatduckai/ai/blob/master/src/db/index.ts"
    click TKN "https://github.com/fatduckai/ai/blob/master/src/agent/ai/tools/token.ts"
    click BTC "https://github.com/fatduckai/ai/blob/master/src/agent/ai/arhieve/btc-price/btc-price.ts"
    click IBM "https://github.com/fatduckai/ai/blob/master/src/core/utils/IBMRest.ts"
    click QPS "https://github.com/fatduckai/ai/blob/master/src/core/managers/quantum-personality.ts"
    click CCS "https://github.com/fatduckai/ai/blob/master/src/create-character/builder.ts"
    click CONV "https://github.com/fatduckai/ai/blob/master/src/core/managers/conversation.ts"
    click IMG "https://github.com/fatduckai/ai/blob/master/src/core/managers/image.ts"
    click TOOL "https://github.com/fatduckai/ai/blob/master/src/core/managers/tools.ts"
```
