# cheshire-cat-ai/core architecture

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

- Interactive diagram: https://gitdiagram.com/cheshire-cat-ai/core
- Repository: https://github.com/cheshire-cat-ai/core

## Overview

##### Main System Components

a) Core Components:
- Looking Glass Module (/cat/looking_glass/) - Main conversation handling
- Mad Hatter Module (/cat/mad_hatter/) - Plugin system
- Memory System (/cat/memory/) - Long-term and working memory
- Agents System (/cat/agents/) - Different specialized agents
- Database Layer (/cat/db/) - Data persistence
- API Layer (/cat/routes/) - REST and WebSocket endpoints

b) External Integrations:
- Language Models (LLM) interface
- Embedding Models interface
- Authentication System
- Plugin Registry

##### Component Relationships

**[Client Layer]**
- ↑↓ HTTP/WebSocket
**[API Gateway]**
- ↑↓
**[Core Processing Layer]**

- → [Looking Glass]
- → [Agents System]

- → [Mad Hatter]
- → [Plugin System]

- → [Memory System]
- → [Vector Store]
- → [Working Memory]

- → [External Services]
- → [LLM Provider]
- → [Embeddings Provider]

##### Key Technical Details
- Docker container boundary
- REST API endpoints
- WebSocket connections
- Database connections
- Plugin loading paths
- Memory vector store
- Authentication flow

##### Implementation Notes
- Use standardized UML notation where appropriate
- Clear data flow directions
- Component version information
- Document main configuration points
- Scaling considerations

This architecture represents a modern AI assistant framework with emphasis on extensibility, memory management, and plugin support, making it suitable for both development and production environments.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client["Client Layer"]
        UI[Client Interface]
    end

    subgraph API["API Gateway"]
        WS["WebSocket Handler"]:::api
        REST["REST Endpoints"]:::api
        AUTH["Authentication"]:::api
    end

    subgraph Core["Core Processing Layer"]
        LG["Looking Glass"]:::core
        MH["Mad Hatter"]:::core
        MS["Memory System"]:::core
        AS["Agents System"]:::core
    end

    subgraph Plugins["Plugin System"]
        PR["Plugin Registry"]:::plugin
        PH["Plugin Hooks"]:::plugin
        PT["Plugin Tools"]:::plugin
    end

    subgraph Memory["Memory Layer"]
        LTM["Long-term Memory"]:::memory
        WM["Working Memory"]:::memory
        VS["Vector Store"]:::memory
    end

    subgraph Agents["Agents Layer"]
        MA["Main Agent"]:::agent
        FA["Form Agent"]:::agent
        MEA["Memory Agent"]:::agent
        PA["Procedures Agent"]:::agent
    end

    subgraph External["External Services"]
        LLM["LLM Provider"]:::external
        EMB["Embeddings Provider"]:::external
    end

    subgraph DB["Database Layer"]
        DBO["Database Operations"]:::db
        DBM["Database Models"]:::db
    end

    %% Relationships
    UI --> WS & REST
    WS & REST --> AUTH
    AUTH --> LG
    LG --> MH & MS & AS
    MH --> PR
    PR --> PH & PT
    MS --> LTM & WM & VS
    AS --> MA & FA & MEA & PA
    LG --> LLM & EMB
    MS --> DBO
    DBO --> DBM

    %% Click Events
    click LG "https://github.com/cheshire-cat-ai/core/tree/main/core/cat/looking_glass/"
    click MH "https://github.com/cheshire-cat-ai/core/tree/main/core/cat/mad_hatter/"
    click MS "https://github.com/cheshire-cat-ai/core/tree/main/core/cat/memory/"
    click AS "https://github.com/cheshire-cat-ai/core/tree/main/core/cat/agents/"
    click WS "https://github.com/cheshire-cat-ai/core/blob/main/core/cat/routes/websocket.py"
    click AUTH "https://github.com/cheshire-cat-ai/core/blob/main/core/cat/auth/auth_utils.py"
    click PR "https://github.com/cheshire-cat-ai/core/blob/main/core/cat/mad_hatter/registry.py"
    click PT "https://github.com/cheshire-cat-ai/core/blob/main/core/cat/mad_hatter/core_plugin/tools.py"
    click LTM "https://github.com/cheshire-cat-ai/core/blob/main/core/cat/memory/long_term_memory.py"
    click WM "https://github.com/cheshire-cat-ai/core/blob/main/core/cat/memory/working_memory.py"
    click VS "https://github.com/cheshire-cat-ai/core/blob/main/core/cat/memory/vector_memory.py"
    click MA "https://github.com/cheshire-cat-ai/core/blob/main/core/cat/agents/main_agent.py"
    click FA "https://github.com/cheshire-cat-ai/core/blob/main/core/cat/agents/form_agent.py"
    click MEA "https://github.com/cheshire-cat-ai/core/blob/main/core/cat/agents/memory_agent.py"
    click PA "https://github.com/cheshire-cat-ai/core/blob/main/core/cat/agents/procedures_agent.py"
    click DBO "https://github.com/cheshire-cat-ai/core/blob/main/core/cat/db/crud.py"
    click DBM "https://github.com/cheshire-cat-ai/core/blob/main/core/cat/db/models.py"
    click LLM "https://github.com/cheshire-cat-ai/core/blob/main/core/cat/factory/llm.py"
    click EMB "https://github.com/cheshire-cat-ai/core/blob/main/core/cat/factory/embedder.py"

    %% Styling
    classDef core fill:#2196F3,color:white
    classDef api fill:#757575,color:white
    classDef plugin fill:#FF9800,color:white
    classDef memory fill:#9C27B0,color:white
    classDef agent fill:#00BCD4,color:white
    classDef external fill:#4CAF50,color:white
    classDef db fill:#607D8B,color:white

    %% Legend
    subgraph Legend
        L1[Core Components]:::core
        L2[API Layer]:::api
        L3[Plugin System]:::plugin
        L4[Memory Components]:::memory
        L5[Agent Components]:::agent
        L6[External Services]:::external
        L7[Database Components]:::db
    end
```
