# jeremychone/rust-genai architecture

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

- Interactive diagram: https://gitdiagram.com/jeremychone/rust-genai
- Repository: https://github.com/jeremychone/rust-genai

## Overview

##### Main Components Identification
The system should be divided into these key components:

a) Client Layer
- Entry point for all interactions
- Handles configuration and builder patterns
- Located in src/client/

b) Adapter Layer
- Core component managing different AI providers
- Contains provider-specific implementations
- Located in src/adapter/adapters/

c) Chat System
- Handles chat messages and responses
- Manages streaming capabilities
- Located in src/chat/

d) Resolver System
- Handles authentication, endpoints, and model mapping
- Located in src/resolver/

**[Client Layer]**
- ↓
**[Resolver Layer]**
- ↓
**[Adapter Layer] ←→ [External AI Services]**
- ↑
**[Chat System]**

##### Component Details

Client Layer:
- ClientBuilder
- Config management
- ServiceTarget resolution

Adapter Layer:
- Supported providers (OpenAI, Anthropic, Gemini, etc.)
- Adapter dispatcher
- Streaming capabilities

Chat System:
- Message handling
- Tool support
- Response formatting

Resolver System:
- Auth resolution
- Model mapping
- Endpoint management

##### Data Flow Representation

- Request flow: Client → Resolver → Adapter → External Service
- Response flow: External Service → Adapter → Chat System → Client
- Authentication flow: Client → Resolver → Adapter
- Model resolution flow: Client → Resolver → Adapter

##### Integration Points

Connections to:
- OpenAI
- Anthropic
- Gemini
- Ollama
- Groq
- Cohere
- DeepSeek
- xAI

##### Important Notes

Callouts for:
- Native implementation approach
- Standardized chat completion APIs
- Authentication flexibility
- Model name resolution
- Streaming support

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Style definitions
    classDef client fill:#b3d9ff,stroke:#333,stroke-width:2px
    classDef resolver fill:#ffd9b3,stroke:#333,stroke-width:2px
    classDef adapter fill:#ffffb3,stroke:#333,stroke-width:2px
    classDef chat fill:#b3ffb3,stroke:#333,stroke-width:2px
    classDef external fill:#f2f2f2,stroke:#333,stroke-width:2px
    classDef stream fill:#e6b3ff,stroke:#333,stroke-width:2px
    classDef web fill:#ffb3d9,stroke:#333,stroke-width:2px
    classDef common fill:#d9d9d9,stroke:#333,stroke-width:2px

    %% Client Layer
    subgraph ClientLayer
        Client["Client Implementation"]:::client
        Builder["Client Builder"]:::client
        Config["Configuration"]:::client
        ServiceTarget["Service Target"]:::client
    end

    %% Resolver Layer
    subgraph ResolverLayer
        AuthResolver["Auth Resolver"]:::resolver
        EndpointResolver["Endpoint Resolver"]:::resolver
        ModelMapper["Model Mapper"]:::resolver
        TargetResolver["Service Target Resolver"]:::resolver
    end

    %% Adapter Layer
    subgraph AdapterLayer
        Dispatcher["Adapter Dispatcher"]:::adapter
        subgraph Adapters
            OpenAI["OpenAI Adapter"]:::adapter
            Anthropic["Anthropic Adapter"]:::adapter
            Gemini["Gemini Adapter"]:::adapter
            Cohere["Cohere Adapter"]:::adapter
            DeepSeek["DeepSeek Adapter"]:::adapter
            Groq["Groq Adapter"]:::adapter
            Ollama["Ollama Adapter"]:::adapter
            XAI["xAI Adapter"]:::adapter
        end
    end

    %% Chat System
    subgraph ChatSystem
        ChatMessage["Chat Message"]:::chat
        ChatRequest["Chat Request"]:::chat
        ChatResponse["Chat Response"]:::chat
        ChatStream["Chat Stream"]:::chat
        subgraph ToolSystem
            ToolBase["Tool Base"]:::chat
            ToolCall["Tool Call"]:::chat
            ToolResponse["Tool Response"]:::chat
        end
    end

    %% Streaming Components
    subgraph StreamingSystem
        InterStream["Inter Stream"]:::stream
        OpenAIStream["OpenAI Streamer"]:::stream
        AnthropicStream["Anthropic Streamer"]:::stream
        GeminiStream["Gemini Streamer"]:::stream
        CohereStream["Cohere Streamer"]:::stream
    end

    %% Web Components
    subgraph WebComponents
        WebClient["Web Client"]:::web
        WebStream["Web Stream"]:::web
    end

    %% Common Components
    subgraph CommonComponents
        ModelName["Model Name"]:::common
        ModelIden["Model Identifier"]:::common
    end

    %% External Services
    subgraph ExternalServices
        OpenAIService["OpenAI API"]:::external
        AnthropicService["Anthropic API"]:::external
        GeminiService["Gemini API"]:::external
        CohereService["Cohere API"]:::external
        DeepSeekService["DeepSeek API"]:::external
        GroqService["Groq API"]:::external
        OllamaService["Ollama API"]:::external
        XAIService["xAI API"]:::external
    end

    %% Relationships
    Client --> Builder
    Builder --> Config
    Builder --> ServiceTarget
    ServiceTarget --> TargetResolver
    TargetResolver --> AuthResolver
    TargetResolver --> EndpointResolver
    TargetResolver --> ModelMapper
    ModelMapper --> ModelName
    ModelMapper --> ModelIden
    AuthResolver --> Dispatcher
    Dispatcher --> OpenAI & Anthropic & Gemini & Cohere & DeepSeek & Groq & Ollama & XAI
    OpenAI --> OpenAIService
    Anthropic --> AnthropicService
    Gemini --> GeminiService
    Cohere --> CohereService
    DeepSeek --> DeepSeekService
    Groq --> GroqService
    Ollama --> OllamaService
    XAI --> XAIService
    ChatMessage --> ChatRequest
    ChatRequest --> ChatResponse
    ChatResponse --> ChatStream
    ToolBase --> ToolCall
    ToolCall --> ToolResponse
    InterStream --> OpenAIStream & AnthropicStream & GeminiStream & CohereStream
    WebClient --> WebStream

    %% Click events
    click Client "https://github.com/jeremychone/rust-genai/blob/main/src/client/client_impl.rs"
    click Builder "https://github.com/jeremychone/rust-genai/blob/main/src/client/builder.rs"
    click Config "https://github.com/jeremychone/rust-genai/blob/main/src/client/config.rs"
    click ServiceTarget "https://github.com/jeremychone/rust-genai/blob/main/src/client/service_target.rs"
    click Dispatcher "https://github.com/jeremychone/rust-genai/blob/main/src/adapter/dispatcher.rs"
    click OpenAI "https://github.com/jeremychone/rust-genai/blob/main/src/adapter/adapters/openai/adapter_impl.rs"
    click Anthropic "https://github.com/jeremychone/rust-genai/blob/main/src/adapter/adapters/anthropic/adapter_impl.rs"
    click Gemini "https://github.com/jeremychone/rust-genai/blob/main/src/adapter/adapters/gemini/adapter_impl.rs"
    click Cohere "https://github.com/jeremychone/rust-genai/blob/main/src/adapter/adapters/cohere/adapter_impl.rs"
    click DeepSeek "https://github.com/jeremychone/rust-genai/blob/main/src/adapter/adapters/deepseek/adapter_impl.rs"
    click Groq "https://github.com/jeremychone/rust-genai/blob/main/src/adapter/adapters/groq/adapter_impl.rs"
    click Ollama "https://github.com/jeremychone/rust-genai/blob/main/src/adapter/adapters/ollama/adapter_impl.rs"
    click XAI "https://github.com/jeremychone/rust-genai/blob/main/src/adapter/adapters/xai/adapter_impl.rs"
    click ChatMessage "https://github.com/jeremychone/rust-genai/blob/main/src/chat/chat_message.rs"
    click ChatRequest "https://github.com/jeremychone/rust-genai/blob/main/src/chat/chat_request.rs"
    click ChatResponse "https://github.com/jeremychone/rust-genai/blob/main/src/chat/chat_response.rs"
    click ChatStream "https://github.com/jeremychone/rust-genai/blob/main/src/chat/chat_stream.rs"
    click ToolBase "https://github.com/jeremychone/rust-genai/blob/main/src/chat/tool/tool_base.rs"
    click ToolCall "https://github.com/jeremychone/rust-genai/blob/main/src/chat/tool/tool_call.rs"
    click ToolResponse "https://github.com/jeremychone/rust-genai/blob/main/src/chat/tool/tool_response.rs"
    click AuthResolver "https://github.com/jeremychone/rust-genai/blob/main/src/resolver/auth_resolver.rs"
    click EndpointResolver "https://github.com/jeremychone/rust-genai/blob/main/src/resolver/endpoint.rs"
    click ModelMapper "https://github.com/jeremychone/rust-genai/blob/main/src/resolver/model_mapper.rs"
    click TargetResolver "https://github.com/jeremychone/rust-genai/blob/main/src/resolver/service_target_resolver.rs"
    click InterStream "https://github.com/jeremychone/rust-genai/blob/main/src/adapter/inter_stream.rs"
    click OpenAIStream "https://github.com/jeremychone/rust-genai/blob/main/src/adapter/adapters/openai/streamer.rs"
    click AnthropicStream "https://github.com/jeremychone/rust-genai/blob/main/src/adapter/adapters/anthropic/streamer.rs"
    click GeminiStream "https://github.com/jeremychone/rust-genai/blob/main/src/adapter/adapters/gemini/streamer.rs"
    click CohereStream "https://github.com/jeremychone/rust-genai/blob/main/src/adapter/adapters/cohere/streamer.rs"
    click WebClient "https://github.com/jeremychone/rust-genai/blob/main/src/webc/web_client.rs"
    click WebStream "https://github.com/jeremychone/rust-genai/blob/main/src/webc/web_stream.rs"
    click ModelName "https://github.com/jeremychone/rust-genai/blob/main/src/common/model_name.rs"
    click ModelIden "https://github.com/jeremychone/rust-genai/blob/main/src/common/model_iden.rs"
```
