# coasys/ad4m architecture

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

- Interactive diagram: https://gitdiagram.com/coasys/ad4m
- Repository: https://github.com/coasys/ad4m

## Overview

##### Main Components of the System
- Core AD4M Logic: This includes the “core” folder (core/) which implements the fundamental types, GraphQL schema, and client libraries (e.g., Ad4mClient). It is the semantic and data modeling layer.
- Executors: There are several executor implementations:
- rust-executor/ (Rust-based, handling agent orchestration, GraphQL server, and interfacing with Holochain, Deno, Prolog, and AI components).
- executor/ (JavaScript executor implementing agent state management, languages, perspectives, and expression logic).
- Language Adapters: The bootstrap-languages/ directory and related “languages” packages implement the pluggable protocols (Languages) that allow data to be stored and retrieved using different underlying protocols (IPFS, Solid, HTTP, etc.).
- Command Line & Client Tools:
- cli/ – Offers CLI tools for initializing the AD4M node, interacting with policies, perspectives, and more.
- / – A helper library for connecting external apps with AD4M executors.
- UI Frontend Components:
- dapp/ – A DApp server that may serve blockchain integrations.
- ui/ – A Tauri-based system tray application (the AD4M Launcher) used for managing nodes.
- Supporting & Testing Infrastructure:
- docs/, tests/, test-runner/ – These provide documentation, integration tests, and automated test frameworks.
- Additional Modules: There are also “hooks”, “patches”, and CI/CD configurations (in .circleci, .github) that keep the development and deployment pipeline in check.

##### Relationships and Interaction Flow
- The Core Component (core/) provides the basic types and APIs (GraphQL, client libraries) that are consumed by the executors.
- The Executors (both rust-executor/ and executor/) implement the “local-first sovereign node.” They interact with:
- The bootstrap languages to abstract communication protocols.
- External services like Holochain (for DHT and p2p networking) and AI capabilities (via Kalosm/Candle).
- Local storage/persistence services (using components like rust-client/ and local storage libraries).
- The CLI and Connect libraries let users and external applications interact with the running AD4M node. They trigger actions like creating perspectives, posting expressions, and executing semantic queries.
- The UI (dapp/ and ui/) serves as the user interface, providing a graphical means of invoking the node’s capabilities.
- The overall data flow is largely decentralized: Agents create expressions (signed data items) that are processed by the executors and spread across the network using pluggable Languages. Perspectives then interpret these expressions to build a semantic view, while Social DNA enables collaborative meaning making.

##### Architectural Patterns & Design Principles
- Agent-Centric, Distributed Architecture: Every user runs a “node” that encapsulates identity, data storage, and protocol handling.
- Self-Recursive Bootstrap: The core concepts (Agents, Languages, Perspectives) are themselves implemented as languages, making the system extensible and evolvable.
- Decoupling & Loose Coupling: The project cleanly separates the UI, API (GraphQL), and execution environments (Rust/JS executors), with clear boundaries for testing and CI/CD.
- Pluggability & Protocol Abstraction: The “bootstrap-languages” and language adapter modules indicate a design where new protocols can be added or swapped without overhauling the core system.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interface Layer
    subgraph "User Interface Layer"
        CLI["CLI Tools"]:::cli
        CONNECT["Connect Library"]:::cli
        DAPP["DApp UI"]:::ui
        UI["UI Frontend"]:::ui
    end

    %% Execution & Application Logic
    subgraph "Execution & Application Logic"
        RUST["Rust Executor"]:::executor
        JS["JavaScript Executor"]:::executor
    end

    %% Core & Data Models
    subgraph "Core & Data Models"
        CORE["Core AD4M Logic"]:::core
    end

    %% Protocol Adaptors
    subgraph "Protocol Adaptors"
        LANG["Language Adapters"]:::adapter
    end

    %% Additional Modules
    subgraph "Additional Modules"
        HOOKS["Hooks & Additional Modules"]:::infra
    end

    %% Supporting Infrastructure
    subgraph "Supporting Infrastructure"
        DOCS["Docs"]:::infra
        TESTS["Tests"]:::infra
        RUNNER["Test Runner"]:::infra
    end

    %% External Services
    EXTERNAL["External Services\\n(Holochain, AI, Deno/V8, Prolog)"]:::external

    %% Connections from UI Layer to Execution Layer
    CLI -->|"uses"| RUST
    CONNECT -->|"connects"| JS
    DAPP -->|"communicates"| RUST
    UI -->|"triggers"| JS

    %% Connections from Execution Layer to Core
    RUST -->|"calls_API"| CORE
    JS -->|"calls_API"| CORE

    %% Core interactions
    CORE -->|"uses_protocol"| LANG
    CORE -->|"extends_with"| HOOKS

    %% Protocol Adaptors to External Services
    LANG -->|"integrates_with"| EXTERNAL

    %% Supporting Infrastructure connections
    DOCS -->|"documents"| CORE
    TESTS -->|"validates"| CORE
    RUNNER -->|"executes_tests_on"| CORE

    %% Styling Classes
    classDef cli fill:#ff99cc,stroke:#333,stroke-width:2px;
    classDef ui fill:#ffcc00,stroke:#333,stroke-width:2px;
    classDef executor fill:#ff6666,stroke:#333,stroke-width:2px;
    classDef core fill:#66ccff,stroke:#333,stroke-width:2px;
    classDef adapter fill:#ccffcc,stroke:#333,stroke-width:2px;
    classDef infra fill:#eeeeee,stroke:#333,stroke-width:2px;
    classDef external fill:#ffd700,stroke:#333,stroke-width:2px;

    %% Click Events
    click CORE "https://github.com/coasys/ad4m/tree/dev/core/"
    click RUST "https://github.com/coasys/ad4m/tree/dev/rust-executor/"
    click JS "https://github.com/coasys/ad4m/tree/dev/executor/"
    click LANG "https://github.com/coasys/ad4m/tree/dev/bootstrap-languages/"
    click CLI "https://github.com/coasys/ad4m/tree/dev/cli/"
    click CONNECT "https://github.com/coasys/ad4m/tree/dev/connect/"
    click DAPP "https://github.com/coasys/ad4m/tree/dev/dapp/"
    click UI "https://github.com/coasys/ad4m/tree/dev/ui/"
    click DOCS "https://github.com/coasys/ad4m/tree/dev/docs/"
    click TESTS "https://github.com/coasys/ad4m/tree/dev/tests/"
    click RUNNER "https://github.com/coasys/ad4m/tree/dev/test-runner/"
    click HOOKS "https://github.com/coasys/ad4m/tree/dev/ad4m-hooks/"
```
