# langbaseinc/baseai architecture

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

- Interactive diagram: https://gitdiagram.com/langbaseinc/baseai
- Repository: https://github.com/langbaseinc/baseai

## Overview

##### High-Level Architecture Components

a. Core Components (Top Level):
- BaseAI CLI (Entry Point)
- BaseAI Server (Development Environment)
- BaseAI Core Framework
- Project Structure Manager

b. Main Functional Layers (Second Level):
- Pipe System (AI Agents)
- Memory System (RAG)
- Tools System
- Provider Integration Layer

##### Detailed Component Breakdown

a. Pipe System:
- ┌─ Pipe Manager ─────────────────┐
- Configuration Handler        │
- Message Processing          │
- Stream Management           │
- Tool Integration           │
- ┘

b. Memory System:
- ┌─ Memory Manager ───────────────┐
- Document Processing         │
- Embedding Generation        │
- Vector Storage             │
- Retrieval System           │
- ┘

c. Provider Integration:
- ┌─ LLM Providers ───────────────┐
- OpenAI                     │
- Anthropic                  │
- Cohere                     │
- Others (Fireworks, etc.)   │
- ┘

##### Data Flow Representation

- User input → Pipe System
- Pipe System ↔ Memory System
- Pipe System ↔ Tools
- Pipe System → LLM Providers
- Results → Stream Handler → Client

##### Integration Points

Integration with:
- Next.js/React (Frontend Framework)
- Node.js Runtime
- External APIs
- Development Tools

##### Development Environment

Development setup:
- ┌─ Development Environment ──────┐
- Local BaseAI Server        │
- Configuration Management   │
- Hot Reloading             │
- Debug Tools               │
- ┘

##### The relationship between pipes, memory, and tools

Key Technical Elements to Include:
- TypeScript/JavaScript Runtime
- API Routes and Endpoints
- Configuration Management
- Stream Processing
- Memory Management
- Tool Integration System

Remember to:
- Use consistent styling
- Brief descriptions for complex components
- Both synchronous and asynchronous flows

This system design should help developers understand both the high-level architecture and the detailed interactions between components while maintaining clarity about the framework's serverless and composable nature.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Legend
        L1[Core Components]:::core
        L2[AI/LLM Components]:::ai
        L3[Memory Components]:::memory
        L4[Integration Points]:::integration
        L5[Development Tools]:::dev
    end

    subgraph "Core Layer"
        CLI["BaseAI CLI"]:::core
        Server["BaseAI Server"]:::core
        Core["BaseAI Core Framework"]:::core
        ProjectMgr["Project Structure Manager"]:::core
    end

    subgraph "Functional Layer"
        subgraph "Pipe System"
            PipeMgr["Pipe Manager"]:::core
            Config["Configuration Handler"]:::core
            MsgProc["Message Processing"]:::core
            StreamMgr["Stream Management"]:::core
            ToolInt["Tool Integration"]:::core
        end

        subgraph "Memory System"
            MemMgr["Memory Manager"]:::memory
            DocProc["Document Processing"]:::memory
            EmbGen["Embedding Generation"]:::memory
            VecStore["Vector Storage"]:::memory
            RetSys["Retrieval System"]:::memory
        end

        subgraph "Provider Integration"
            OpenAI["OpenAI Provider"]:::ai
            Anthropic["Anthropic Provider"]:::ai
            Cohere["Cohere Provider"]:::ai
            Fireworks["Fireworks Provider"]:::ai
        end
    end

    subgraph "Development Environment"
        DevServer["Local BaseAI Server"]:::dev
        ConfigMgmt["Configuration Management"]:::dev
        HotReload["Hot Reloading"]:::dev
        DebugTools["Debug Tools"]:::dev
    end

    subgraph "Integration Layer"
        NextJS["Next.js/React"]:::integration
        NodeRT["Node.js Runtime"]:::integration
        ExtAPI["External APIs"]:::integration
    end

    CLI --> Server
    Server --> Core
    Core --> ProjectMgr
    
    PipeMgr --> |Input Processing| MsgProc
    MsgProc --> StreamMgr
    StreamMgr --> ToolInt
    
    PipeMgr --> MemMgr
    MemMgr --> DocProc
    DocProc --> EmbGen
    EmbGen --> VecStore
    VecStore --> RetSys
    
    PipeMgr --> OpenAI
    PipeMgr --> Anthropic
    PipeMgr --> Cohere
    PipeMgr --> Fireworks
    
    Server --> DevServer
    DevServer --> ConfigMgmt
    DevServer --> HotReload
    DevServer --> DebugTools
    
    Core --> NextJS
    Core --> NodeRT
    Core --> ExtAPI

    %% Style Definitions
    classDef core fill:#2374ab,color:#fff,stroke:#333
    classDef ai fill:#7209b7,color:#fff,stroke:#333
    classDef memory fill:#38b000,color:#fff,stroke:#333
    classDef integration fill:#fb8500,color:#fff,stroke:#333
    classDef dev fill:#6c757d,color:#fff,stroke:#333

    %% Click Events
    click CLI "https://github.com/LangbaseInc/baseai/blob/main/packages/baseai/bin/baseai.js"
    click Server "https://github.com/LangbaseInc/baseai/blob/main/packages/baseai/src/dev/index.ts"
    click Core "https://github.com/LangbaseInc/baseai/blob/main/packages/core/src/index.ts"
    click ProjectMgr "https://github.com/LangbaseInc/baseai/blob/main/packages/baseai/src/init/index.ts"
    click PipeMgr "https://github.com/LangbaseInc/baseai/blob/main/packages/baseai/src/pipe/index.ts"
    click MemMgr "https://github.com/LangbaseInc/baseai/blob/main/packages/baseai/src/memory/index.ts"
    click DocProc "https://github.com/LangbaseInc/baseai/blob/main/packages/baseai/src/utils/memory/chunker.ts"
    click EmbGen "https://github.com/LangbaseInc/baseai/blob/main/packages/baseai/src/utils/memory/generate-embeddings.ts"
    click VecStore "https://github.com/LangbaseInc/baseai/blob/main/packages/baseai/src/utils/memory/db/lib.ts"
    click ToolInt "https://github.com/LangbaseInc/baseai/blob/main/packages/baseai/src/tool/index.ts"
    click OpenAI "https://github.com/LangbaseInc/baseai/blob/main/packages/baseai/src/dev/providers/openai/index.ts"
    click Anthropic "https://github.com/LangbaseInc/baseai/blob/main/packages/baseai/src/dev/providers/anthropic/index.ts"
    click Cohere "https://github.com/LangbaseInc/baseai/blob/main/packages/baseai/src/dev/providers/cohere/index.ts"
    click Fireworks "https://github.com/LangbaseInc/baseai/blob/main/packages/baseai/src/dev/providers/fireworks-ai/index.ts"
    click DevServer "https://github.com/LangbaseInc/baseai/tree/main/packages/baseai/src/dev/routes"
    click ConfigMgmt "https://github.com/LangbaseInc/baseai/blob/main/packages/baseai/src/utils/config/config-handler.ts"
```
