# ldclabs/anda architecture

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

- Interactive diagram: https://gitdiagram.com/ldclabs/anda
- Repository: https://github.com/ldclabs/anda

## Overview

##### Main Components
- Core Library (anda_core): This contains base types, shared interfaces, and models (e.g., completion, embedding, knowledge, thread). It forms the fundamental building blocks that other modules depend on.
- Engine (anda_engine): This module implements the runtime and management of AI agents. It includes subcomponents such as context management (for agents, cache, web3, etc.), extensions (e.g., attention, character, extractor, google integration), and a dedicated model directory supporting various AI providers (e.g., OpenAI, Cohere, Deepseek).
- CLI Interface (anda_cli): A command-line tool enabling interaction with the engine server and agent runtime.
- Engine Server (anda_engine_server): An HTTP-based server that exposes API endpoints to serve and manage one or more Anda engine instances.
- Lancedb Integration (anda_lancedb): Acts as the vector storage/retrieval component for the agents.
- Web3 Client (anda_web3_client): This module supplies the Rust SDK for Web3 integration outside of the TEE environments.
- Agents (e.g., agents/anda_bot): Concrete AI agent implementations—each agent (such as anda_bot) is in its own subdirectory including deployment scripts, Dockerfile (for containerized deployment, or Nitro Enclave support), configuration, and source code.
- Tools (e.g., tools/anda_icp): Utility modules that provide integration with external services like the Internet Computer Protocol (ICP) blockchain.
- Additional Supporting Files: Directories like “characters,” “examples,” and “docs” that provide configuration, example implementations, and extended architecture documentation.

##### Relationships and Interactions
- The Core Library (anda_core) is central—other components (engine, CLI, server, agents) depend on it for shared models, types, and interfaces.
- The Engine (anda_engine) uses the core to provide runtime management, agent orchestration, and extension support. Its “context” and “management” subdirectories indicate a structured approach, likely isolating responsibilities (e.g., communication, caching, state management).
- Agents (in agents/anda_bot, for example) are built using the core and engine libraries, where they incorporate domain-specific logic and TEE configurations (e.g., Nitro enclave setups).
- The Engine Server (anda_engine_server) exposes endpoints (HTTP) for interacting with the engine’s functionalities and orchestrating agent actions at runtime.
- The CLI (anda_cli) provides a developer-friendly interface to interact with these services.
- The Lancedb and Web3 modules represent external service integrations that support persistent memory (storing knowledge and vectors) and blockchain interactions respectively.
- Tools like anda_icp expand the platform’s integration, enabling features such as ledger querying and transfers over ICP.

##### Important Architectural Patterns and Design Principles
- Modularity and Composability: Each component is separated into different crates (modules), which makes the system extensible—new agents, tools, or integrations can be added without significant rework.
- Decoupled Core and Extensions: The core library remains independent while other modules (engine, agents, tools) build on top of it. Extensions (in anda_engine’s extension directory) support additional features like third-party integrations.
- Secure and Decentralized Execution: With TEE support and ICP blockchain integration, the design emphasizes trustworthiness, security, and decentralized memory (perpetual memory powered by blockchain).
- Clear Separation of Concerns: Command line interfaces, server interfaces, and agent-specific logic are well separated.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Nodes
    CORE["Core Library (anda_core)"]
    ENGINE["Engine & Management (anda_engine)"]
    CLI["CLI Interface (anda_cli)"]
    SERVER["Engine Server (HTTP API)"]
    AGENT["Agent Implementation: anda_bot"]
    TEE["TEE & ICP Integration"]
    LANCEDB["Lancedb Integration (anda_lancedb)"]
    WEB3["Web3 Client (anda_web3_client)"]
    ICP_TOOL["Tools: ICP Integration (anda_icp)"]

    %% Relationships
    ENGINE -->|"depends_on"| CORE
    CLI -->|"uses"| ENGINE
    CLI -->|"depends_on"| CORE
    ENGINE -->|"exposes_API"| SERVER
    AGENT -->|"depends_on"| CORE
    AGENT -->|"builds_on"| ENGINE
    ENGINE -->|"integrates_with"| LANCEDB
    ENGINE -->|"integrates_with"| WEB3
    AGENT -->|"secure_exec"| TEE
    TEE -->|"integrates_with"| ICP_TOOL

    %% Click Events
    click CORE "https://github.com/ldclabs/anda/tree/main/anda_core/"
    click ENGINE "https://github.com/ldclabs/anda/tree/main/anda_engine/"
    click CLI "https://github.com/ldclabs/anda/blob/main/anda_cli/src/main.rs"
    click SERVER "https://github.com/ldclabs/anda/blob/main/anda_engine_server/src/handler.rs"
    click AGENT "https://github.com/ldclabs/anda/tree/main/agents/anda_bot/"
    click LANCEDB "https://github.com/ldclabs/anda/tree/main/anda_lancedb/"
    click WEB3 "https://github.com/ldclabs/anda/blob/main/anda_web3_client/src/client.rs"
    click ICP_TOOL "https://github.com/ldclabs/anda/tree/main/tools/anda_icp/src"

    %% Styles
    classDef internal fill:#b3e5fc,stroke:#0277bd,stroke-width:2px;
    classDef interface fill:#fff3cd,stroke:#ffb300,stroke-width:2px;
    classDef agent fill:#ffcdd2,stroke:#e53935,stroke-width:2px;
    classDef external fill:#dcedc8,stroke:#7cb342,stroke-width:2px;
    classDef security fill:#e0e0e0,stroke:#757575,stroke-width:2px;

    %% Apply styles
    class CORE,ENGINE internal;
    class CLI,SERVER interface;
    class AGENT agent;
    class LANCEDB,WEB3,ICP_TOOL external;
    class TEE security;
```
