# sigoden/aichat architecture

> Architecture diagram of the GitHub repository sigoden/aichat, 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/sigoden/aichat
- Repository: https://github.com/sigoden/aichat

## Overview

##### Main Components

a. Core Components:
- CLI Interface Layer
- REPL System
- LLM Client Layer
- RAG (Retrieval-Augmented Generation) System
- HTTP Server Component
- Configuration Management
- Role/Session Management

b. External Integrations:
- Multiple LLM Platforms (OpenAI, Claude, Gemini, etc.)
- File System Integration
- Network Layer (for remote URLs)
- Shell Integration

##### Connection Flows

- File system interactions (dash-dot lines)

##### Component Details

For each major component, include:
- Input/Output interfaces
- Key responsibilities
- Major dependencies
- Configuration options

##### Implementation Notes

Annotations for:
- Cross-platform compatibility
- Shell integration points
- Security considerations
- Configuration flow

- Nested components
- Multiple connection types
- Custom styling
- Export to common formats

Recommended Layout:

**[User Interfaces]**
- ↓
**[Core Processing]**
- ↓
**[LLM Integration Layer]**
- ↓
**[Feature Services]**
- ↓
**[External Systems]**

This structure will effectively communicate the architecture while maintaining the flexibility needed for future additions to the system.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles and Classes
    classDef ui fill:#3498db,stroke:#2980b9,color:white
    classDef core fill:#2ecc71,stroke:#27ae60,color:white
    classDef llm fill:#e67e22,stroke:#d35400,color:white
    classDef feature fill:#9b59b6,stroke:#8e44ad,color:white
    classDef external fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef storage fill:#34495e,stroke:#2c3e50,color:white

    %% User Interface Layer
    subgraph Interface
        CLI["CLI Interface"]:::ui
        REPL["REPL Mode"]:::ui
        HTTP["HTTP Server"]:::ui
        WEB_UI["Web Interfaces"]:::ui
    end

    %% Core Processing Layer
    subgraph Core
        ENGINE["Core Engine"]:::core
        CONFIG["Configuration Management"]:::core
        ROLE["Role Management"]:::core
        SESSION["Session Management"]:::core
        FUNCTION["Function Calling System"]:::core
    end

    %% LLM Integration Layer
    subgraph LLM
        CLIENT["LLM Client Manager"]:::llm
        OPENAI["OpenAI"]:::llm
        CLAUDE["Claude"]:::llm
        GEMINI["Gemini"]:::llm
        AZURE["Azure OpenAI"]:::llm
    end

    %% Features Layer
    subgraph Features
        RAG["RAG System"]:::feature
        SHELL["Shell Assistant"]:::feature
        RENDER["Rendering System"]:::feature
        MARKDOWN["Markdown Renderer"]:::feature
        STREAM["Stream Renderer"]:::feature
    end

    %% External Systems
    subgraph External
        FS["File System"]:::external
        NET["Network Layer"]:::external
        CLIP["Clipboard"]:::external
    end

    %% Connections
    CLI --> ENGINE
    REPL --> ENGINE
    HTTP --> ENGINE
    HTTP --> WEB_UI

    ENGINE --> CONFIG
    ENGINE --> ROLE
    ENGINE --> SESSION
    ENGINE --> FUNCTION

    ENGINE --> CLIENT
    CLIENT --> OPENAI
    CLIENT --> CLAUDE
    CLIENT --> GEMINI
    CLIENT --> AZURE

    ENGINE --> RAG
    ENGINE --> SHELL
    ENGINE --> RENDER
    RENDER --> MARKDOWN
    RENDER --> STREAM

    RAG --> FS
    SHELL --> FS
    CLIENT --> NET
    SHELL --> CLIP

    %% Click Events
    click CLI "https://github.com/sigoden/aichat/blob/main/src/cli.rs"
    click REPL "https://github.com/sigoden/aichat/blob/main/src/repl/mod.rs"
    click HTTP "https://github.com/sigoden/aichat/blob/main/src/serve.rs"
    click CONFIG "https://github.com/sigoden/aichat/blob/main/src/config/mod.rs"
    click ROLE "https://github.com/sigoden/aichat/blob/main/src/config/role.rs"
    click SESSION "https://github.com/sigoden/aichat/blob/main/src/config/session.rs"
    click FUNCTION "https://github.com/sigoden/aichat/blob/main/src/function.rs"
    click CLIENT "https://github.com/sigoden/aichat/blob/main/src/client/mod.rs"
    click OPENAI "https://github.com/sigoden/aichat/blob/main/src/client/openai.rs"
    click CLAUDE "https://github.com/sigoden/aichat/blob/main/src/client/claude.rs"
    click GEMINI "https://github.com/sigoden/aichat/blob/main/src/client/gemini.rs"
    click AZURE "https://github.com/sigoden/aichat/blob/main/src/client/azure_openai.rs"
    click RAG "https://github.com/sigoden/aichat/blob/main/src/rag/mod.rs"
    click RENDER "https://github.com/sigoden/aichat/blob/main/src/render/mod.rs"
    click MARKDOWN "https://github.com/sigoden/aichat/blob/main/src/render/markdown.rs"
    click STREAM "https://github.com/sigoden/aichat/blob/main/src/render/stream.rs"
    click SHELL "https://github.com/sigoden/aichat/tree/main/scripts/shell-integration/"
    click WEB_UI "https://github.com/sigoden/aichat/blob/main/assets/playground.html"
    click CLIP "https://github.com/sigoden/aichat/blob/main/src/utils/clipboard.rs"
```
