# vertexstudio/bioma architecture

> Architecture diagram of the GitHub repository vertexstudio/bioma, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/vertexstudio/bioma
- Repository: https://github.com/vertexstudio/bioma

## Overview

##### Main System Components

a) Core Components (Central Layer):
- Bioma Actor System (bioma_actor)
- Behavior Tree Engine (bioma_behavior)
- LLM Integration Layer (bioma_llm)
- Tool System (bioma_tool)

b) Infrastructure Layer (Bottom):
- SurrealDB Database
- File Storage System
- External LLM Services (Ollama)
- Reranking Service

c) Interface Layer (Top):
- REST API Endpoints
- WebSocket Connections
- JavaScript Integration (bioma_js)

##### Component Relationships

a) Data Flow Paths:
- Client → REST API → Actor System
- Actor System ↔ Behavior Tree Engine
- Actor System ↔ LLM Integration Layer
- LLM Integration Layer ↔ External LLM Services
- All Components ↔ SurrealDB

b) Integration Points:
- Tool System → External Services
- LLM Integration Layer → Embeddings Service
- LLM Integration Layer → Reranking Service

##### Detailed Component Breakdown

For each major component, include sub-components:

a) Bioma Actor:
- Actor Engine
- Message System
- Object Store
- Factory System

b) Behavior Tree:
- Actions
- Composites
- Decorators
- Tree Manager

c) LLM Integration:
- Chat Interface
- Embeddings Manager
- Indexer
- Retriever
- RAG System
- PDF Analyzer

d) Tool System:
- Echo Tool
- Fetch Tool
- Memory Tool
- Transport Layer

##### Technical Details

Annotations for:
- REST API endpoints (/upload, /index, /retrieve, /ask, etc.)
- Database schemas (reference sql/ directories)
- File storage patterns
- Configuration points
- Scaling components

##### The extensibility points for tools and behaviors

Keep the abstraction level high enough to be understandable but detailed enough to show the sophisticated integration of behavior trees, utility AI, and LLMs in the context of a multi-agent system.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Interface
        API[REST API]:::api
        WS[WebSocket]:::api
        JS[JavaScript Client]:::api
    end

    subgraph Core
        subgraph ActorSystem[Bioma Actor System]
            AE[Actor Engine]:::core
            MS[Message System]:::core
            OS[Object Store]:::core
            FS[Factory System]:::core
        end

        subgraph BehaviorTree[Behavior Tree Engine]
            Actions[Actions]:::core
            Composites[Composites]:::core
            Decorators[Decorators]:::core
            TreeMgr[Tree Manager]:::core
        end

        subgraph LLMLayer[LLM Integration Layer]
            Chat[Chat Interface]:::core
            Embed[Embeddings Manager]:::core
            Index[Indexer]:::core
            Retrieve[Retriever]:::core
            PDF[PDF Analyzer]:::core
            RAG[RAG System]:::core
        end

        subgraph ToolSystem[Tool System]
            Echo[Echo Tool]:::tool
            Fetch[Fetch Tool]:::tool
            Memory[Memory Tool]:::tool
            Transport[Transport Layer]:::tool
        end
    end

    subgraph Infrastructure
        DB[(SurrealDB)]:::storage
        Files[(File Storage)]:::storage
        Ollama[Ollama LLM]:::external
        Rerank[Reranking Service]:::external
    end

    %% Connections
    API --> ActorSystem
    WS --> ActorSystem
    JS --> API

    ActorSystem <--> BehaviorTree
    ActorSystem <--> LLMLayer
    ActorSystem <--> DB
    
    LLMLayer <--> Ollama
    LLMLayer <--> Rerank
    LLMLayer <--> Files
    
    ToolSystem --> Files
    ToolSystem <--> DB

    %% RAG Pipeline
    PDF --> Index
    Index --> Embed
    Embed --> DB
    DB --> Retrieve
    Retrieve --> RAG
    RAG --> Chat

    %% Click Events
    click ActorSystem "https://github.com/VertexStudio/bioma/tree/main//bioma_actor/"
    click AE "https://github.com/VertexStudio/bioma/blob/main//bioma_actor/src/engine.rs"
    click MS "https://github.com/VertexStudio/bioma/blob/main//bioma_actor/sql/messages_replies.surql"
    click OS "https://github.com/VertexStudio/bioma/blob/main//bioma_actor/examples/object_store.rs"
    click FS "https://github.com/VertexStudio/bioma/blob/main//bioma_actor/src/factory.rs"
    
    click BehaviorTree "https://github.com/VertexStudio/bioma/tree/main//bioma_behavior/"
    click Actions "https://github.com/VertexStudio/bioma/tree/main//bioma_behavior/src/actions/"
    click Composites "https://github.com/VertexStudio/bioma/tree/main//bioma_behavior/src/composites/"
    click Decorators "https://github.com/VertexStudio/bioma/tree/main//bioma_behavior/src/decorators/"
    click TreeMgr "https://github.com/VertexStudio/bioma/blob/main//bioma_behavior/src/tree.rs"
    
    click LLMLayer "https://github.com/VertexStudio/bioma/tree/main//bioma_llm/"
    click Chat "https://github.com/VertexStudio/bioma/blob/main//bioma_llm/src/chat.rs"
    click Embed "https://github.com/VertexStudio/bioma/blob/main//bioma_llm/src/embeddings.rs"
    click Index "https://github.com/VertexStudio/bioma/blob/main//bioma_llm/src/indexer.rs"
    click Retrieve "https://github.com/VertexStudio/bioma/blob/main//bioma_llm/src/retriever.rs"
    click PDF "https://github.com/VertexStudio/bioma/blob/main//bioma_llm/src/pdf_analyzer.rs"
    click RAG "https://github.com/VertexStudio/bioma/blob/main//bioma_llm/examples/rag.rs"
    
    click ToolSystem "https://github.com/VertexStudio/bioma/tree/main//bioma_tool/"
    click Echo "https://github.com/VertexStudio/bioma/blob/main//bioma_tool/src/tools/echo.rs"
    click Fetch "https://github.com/VertexStudio/bioma/blob/main//bioma_tool/src/tools/fetch.rs"
    click Memory "https://github.com/VertexStudio/bioma/blob/main//bioma_tool/src/tools/memory.rs"
    click Transport "https://github.com/VertexStudio/bioma/blob/main//bioma_tool/src/transport.rs"
    
    click JS "https://github.com/VertexStudio/bioma/blob/main//bioma_js/bioma.js"

    %% Styles
    classDef core fill:#a8d1f0,stroke:#333
    classDef api fill:#c9a8f0,stroke:#333
    classDef tool fill:#f0c9a8,stroke:#333
    classDef storage fill:#f0e4a8,stroke:#333
    classDef external fill:#a8f0b8,stroke:#333
```
