# startadam/bluemarz architecture

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

- Interactive diagram: https://gitdiagram.com/startadam/bluemarz
- Repository: https://github.com/startadam/bluemarz

## Overview

##### Project Type and Purpose
- Bluemarz is an open-source Python library (SDK) that provides a stateless management and orchestration layer for AI agents.
- It enables you to create Agents, manage Sessions, assign Agents to Sessions, execute reusable Tools, and support Retrieval-Augmented Generation (RAG) across multiple LLM Providers (OpenAI, Claude, Gemini, etc.).

##### File Structure Analysis
- top-level:
- pyproject.toml / LICENSE / README.md / docs/ → project metadata and documentation
- src/bluemarz/ → the primary Python package
- test/ → unit tests and mocks
- src/bluemarz/api:
- Provider-specific wrappers (e.g., openai.py)
- src/bluemarz/core:
- Key abstractions (Agent, Session, Assignment)
- Registries (class_registry, spec_registry)
- Middleware, interfaces, exception classes, data models
- src/bluemarz/lib:
- Low-level clients and components for interacting with LLM Providers
- src/bluemarz/utils:
- HTTP client, model utilities
- src/bluemarz/examples:
- End-user usage samples
- test/:
- Unit tests grouped by core, services, mocks

##### Architectural Patterns and Design Principles
- Layered architecture:
- api layer delegates to lib
- core layer orchestrates Agents, Sessions, Assignments
- utils provide shared helper functions
- Plugin/Registry pattern for dynamically registering Agent types, Tools, and RAG specs
- Middleware pipeline in core for cross-cutting concerns (logging, authentication, tool execution)
- Asynchronous execution using asyncio for non-blocking API calls
- Stateless session management—state resides on the LLM provider

##### Main Components and Their Relationships
- User code (your scripts or application)
↕
- bluemarz SDK:
- Agent: encapsulates an LLM model instance (via api → lib → HTTP)
- Session: represents a dialogue container
- Assignment: binds one or more Agents to a Session and drives the conversation
- Tool Execution: centralized component invoked by core when an Agent calls a tool
- RAG (Agent-level & Assignment-level): fetches external data and injects context
↕
- External LLM Providers (OpenAI, Claude, Gemini)
- External Data Sources (databases, document stores for RAG)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User Layer
    User["User Application / Scripts"]

    %% API Layer
    subgraph "API Layer"
        direction TB
        OpenAI_API["OpenAI API Wrapper"]:::apiLayer
    end

    %% Core Layer
    subgraph "Core Layer"
        direction TB
        Agent["Agent Abstraction"]:::coreLayer
        Session["Session Management"]:::coreLayer
        Assignment["Assignment Orchestration"]:::coreLayer
        Middleware["Middleware Pipeline"]:::coreLayer
        ClassReg["Class Registry"]:::registry
        SpecReg["Spec Registry"]:::registry
        Interfaces["Interfaces Definitions"]:::coreLayer
        Exceptions["Exception Classes"]:::coreLayer
    end

    %% Library Layer
    subgraph "Library Layer"
        direction TB
        OA_Client["OpenAI HTTP Client"]:::libLayer
        OA_Models["OpenAI Data Models"]:::libLayer
        OA_Comp["OpenAI Helper Components"]:::libLayer
    end

    %% Utilities
    subgraph "Utilities"
        direction TB
        HTTP_Client["HTTP Client Wrapper"]:::utilLayer
        Model_Utils["Model Utilities"]:::utilLayer
    end

    %% Examples / Docs
    subgraph "Examples / Docs"
        direction TB
        Examples["Usage Samples"]:::external
    end

    %% External Services
    LLM["External LLM Providers"]:::external
    DataStore["External Data Stores (RAG)"]:::external

    %% Data / Control Flow
    User -->|invokes| OpenAI_API
    OpenAI_API -->|delegates| OA_Client
    OA_Client -->|uses| HTTP_Client
    OA_Client -->|model data| OA_Models
    OA_Client -->|components| OA_Comp
    OA_Client -->|calls| LLM
    LLM -->|response| OA_Client
    OpenAI_API -->|initializes| Agent
    Agent -->|creates| Session
    Session -->|binds| Assignment
    Assignment -->|runs| Middleware
    Assignment -->|executes RAG| SpecReg
    SpecReg -->|fetch| DataStore
    DataStore -->|provides| SpecReg
    Assignment -->|invokes| OA_Client
    OA_Client -->|query| LLM
    LLM -->|results| OA_Client
    Assignment -->|returns| User

    %% Registries & Extensions
    ClassReg --- Agent
    Interfaces --- Middleware
    Exceptions --- Assignment

    %% Click Events
    click OpenAI_API "https://github.com/startadam/bluemarz/blob/main/src/bluemarz/api/openai.py"
    click Agent "https://github.com/startadam/bluemarz/blob/main/src/bluemarz/core/models.py"
    click Session "https://github.com/startadam/bluemarz/blob/main/src/bluemarz/core/models.py"
    click Assignment "https://github.com/startadam/bluemarz/blob/main/src/bluemarz/core/assignments.py"
    click ClassReg "https://github.com/startadam/bluemarz/blob/main/src/bluemarz/core/class_registry.py"
    click SpecReg "https://github.com/startadam/bluemarz/blob/main/src/bluemarz/core/spec_registry.py"
    click Middleware "https://github.com/startadam/bluemarz/blob/main/src/bluemarz/core/middleware.py"
    click Interfaces "https://github.com/startadam/bluemarz/blob/main/src/bluemarz/core/interfaces.py"
    click Exceptions "https://github.com/startadam/bluemarz/blob/main/src/bluemarz/core/exceptions.py"
    click OA_Client "https://github.com/startadam/bluemarz/blob/main/src/bluemarz/lib/openai/client.py"
    click OA_Models "https://github.com/startadam/bluemarz/blob/main/src/bluemarz/lib/openai/models.py"
    click OA_Comp "https://github.com/startadam/bluemarz/blob/main/src/bluemarz/lib/openai/components.py"
    click HTTP_Client "https://github.com/startadam/bluemarz/blob/main/src/bluemarz/utils/http_client.py"
    click Model_Utils "https://github.com/startadam/bluemarz/blob/main/src/bluemarz/utils/model_utils.py"
    click Examples "https://github.com/startadam/bluemarz/blob/main/src/bluemarz/examples/examples.py"

    %% Styles
    classDef apiLayer fill:#D0E8FF,stroke:#0366d6
    classDef coreLayer fill:#A0C4FF,stroke:#023e8a
    classDef libLayer fill:#89CFF0,stroke:#0077b6
    classDef utilLayer fill:#B0E0E6,stroke:#005f73
    classDef external fill:#CCCCCC,stroke:#444444
    classDef registry fill:#FFFFFF,stroke:#000000,stroke-dasharray: 5 5
```
