# paulrobello/par_ai_core architecture

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

- Interactive diagram: https://gitdiagram.com/paulrobello/par_ai_core
- Repository: https://github.com/paulrobello/par_ai_core

## Overview

##### Main Components

a) Core Components:
- LLM Provider Interface Layer
- Configuration Management System
- Utility Services Layer
- Output Handling System
- Logging System
- Pricing & Cost Tracking System

b) External Integrations:
- Various LLM Providers (OpenAI, Anthropic, Groq, etc.)
- Search Services (Tavily, Google, etc.)
- Authentication Systems
- LangChain Integration

**┌─ Application Layer (Client Applications) ─────────────────────┐**

- Par AI Core Interface Layer ────────────────────────────────┤
- ┌─ LLM Config ─┐  ┌─ Provider Management ─┐  ┌─ Utils ─┐   │

- ┘  └───────────────────────┘  └─────────┘   │

- Service Layer ───────────────────────────────────────────┐  │
- ┌─ LLM Services ─┐  ┌─ Search Services ─┐               │  │

- ┘  └───────────────────┘               │  │

- Integration Layer ────────────────────────────────────┐ │  │
- ┌─ LangChain ─┐  ┌─ Provider APIs ─┐  ┌─ Tools ─┐    │ │  │

- ┘  └─────────────────┘  └─────────┘    │ │  │
- ┘

##### Component Details

a) LLM Configuration (llm_config.py):
- Configuration flow
- Model selection
- Provider settings
- Environment variable handling

b) Provider Management (llm_providers.py):
- Provider interface
- API key validation
- Model compatibility

c) Utility Services:
- Logging system (par_logging.py)
- Output formatting (output_utils.py)
- Web tools (web_tools.py)
- Search utilities (search_utils.py)

d) Integration Points:
- API connections
- Authentication flow
- Data transformation

##### Data Flow Indicators

- Configuration flow
- API requests/responses
- Error handling paths
- Callback mechanisms

##### Documentation Elements

- Version information
- Required environment variables
- Supported providers
- Key dependencies

##### Implementation Notes

- Maintain consistent styling
- Notes for complex interactions

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client["Application Layer"]
        APP[Client Applications]
    end

    subgraph Core["Par AI Core Interface Layer"]
        LLMConfig["Configuration Management"]:::config
        ProviderMgmt["Provider Management"]:::provider
        Utils["Utility Services"]:::utils
    end

    subgraph Services["Service Layer"]
        LLMServices["LLM Services"]:::llm
        SearchServices["Search Services"]:::search
        ImageServices["Image Processing"]:::image
        TimeServices["Time Management"]:::time
    end

    subgraph Integration["Integration Layer"]
        LangChain["LangChain"]:::external
        ProviderAPIs["Provider APIs"]:::external
        Tools["Tools & Utilities"]:::tools
    end

    %% Connections
    APP --> LLMConfig
    APP --> ProviderMgmt
    APP --> Utils

    LLMConfig --> LLMServices
    ProviderMgmt --> LLMServices
    Utils --> SearchServices
    Utils --> ImageServices
    Utils --> TimeServices

    LLMServices --> LangChain
    LLMServices --> ProviderAPIs
    SearchServices --> Tools
    ImageServices --> Tools
    TimeServices --> Tools

    %% Click Events
    click LLMConfig "https://github.com/paulrobello/par_ai_core/blob/main/src/par_ai_core/llm_config.py"
    click ProviderMgmt "https://github.com/paulrobello/par_ai_core/blob/main/src/par_ai_core/llm_providers.py"
    click Utils "https://github.com/paulrobello/par_ai_core/blob/main/src/par_ai_core/utils.py"
    click SearchServices "https://github.com/paulrobello/par_ai_core/blob/main/src/par_ai_core/search_utils.py"
    click ImageServices "https://github.com/paulrobello/par_ai_core/blob/main/src/par_ai_core/llm_image_utils.py"
    click TimeServices "https://github.com/paulrobello/par_ai_core/blob/main/src/par_ai_core/time_display.py"
    click Tools "https://github.com/paulrobello/par_ai_core/blob/main/src/par_ai_core/web_tools.py"

    %% Styling
    classDef config fill:#f9f,stroke:#333
    classDef provider fill:#bbf,stroke:#333
    classDef utils fill:#ddd,stroke:#333
    classDef llm fill:#bfb,stroke:#333
    classDef search fill:#fbf,stroke:#333
    classDef image fill:#fbb,stroke:#333
    classDef time fill:#bff,stroke:#333
    classDef external fill:#ff9,stroke:#333
    classDef tools fill:#f96,stroke:#333

    %% Legend
    subgraph Legend
        L1["Configuration"]:::config
        L2["Provider Management"]:::provider
        L3["Utilities"]:::utils
        L4["LLM Services"]:::llm
        L5["Search Services"]:::search
        L6["Image Processing"]:::image
        L7["Time Management"]:::time
        L8["External Systems"]:::external
        L9["Tools"]:::tools
    end
```
