# jeffser/alpaca architecture

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

- Interactive diagram: https://gitdiagram.com/jeffser/alpaca
- Repository: https://github.com/jeffser/alpaca

## Overview

##### Main Components

a. Frontend Layer:
- GTK-based User Interface (indicated by .ui files and GTK dependencies)
- Custom Widgets (src/custom_widgets/)
- Resource Management (src/alpaca.gresource.xml)

b. Core Application Layer:
- Model Management System
- Connection Handler (src/connection_handler.py)
- SQL Manager (src/sql_manager.py)
- Internal Utilities (src/internal.py)

c. External Integration Layer:
- Ollama Service Integration
- Search Provider Integration
- File System Integration

##### Component Relationships

**[User Interface Layer]**
- ↑↓
**[Core Application Layer]**
- ↑↓
**[External Integration Layer]**
- ↑↓
**[Ollama Service]**

##### Specific Component Details

a. UI Components (Rectangle, Blue):
- Chat Widget
- Dialog Widget
- Message Widget
- Model Manager Widget
- Table Widget
- Terminal Widget

b. Core Services (Hexagon, Green):
- Connection Handler
- SQL Manager
- Model Management
- Search Provider

- Ollama API
- File System
- YouTube Integration
- Website Parser

##### Data Flow Indicators

- User input flow
- Model responses
- File operations
- Database operations
- External API calls

##### Special Features to Highlight

- Image Recognition
- Document Recognition
- Code Highlighting
- YouTube Recognition
- Website Recognition
- Chat Import/Export

##### Configuration and Resources

A small section showing:
- Settings Management (GSchema)
- Internationalization (po/ directory)
- Resource Bundling

##### Deployment Options

Packaging options as deployment endpoints:
- Flatpak
- Snap
- Nix

Key Considerations:

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph UI["User Interface Layer"]
        direction TB
        UI_Main["Main Window"]:::ui
        UI_Custom["Custom Widgets"]:::ui
        UI_Resources["Resource Management"]:::ui
        
        subgraph Widgets["Custom Widget Components"]
            direction TB
            Chat["Chat Widget"]:::widget
            Dialog["Dialog Widget"]:::widget
            Message["Message Widget"]:::widget
            ModelMgr["Model Manager Widget"]:::widget
            Table["Table Widget"]:::widget
            Terminal["Terminal Widget"]:::widget
        end
        
        UI_Main --> Widgets
        UI_Custom --> Widgets
    end
    
    subgraph Core["Core Application Layer"]
        direction TB
        ConnHandler["Connection Handler"]:::core
        SQLMgr["SQL Manager"]:::core
        ModelMgmt["Model Management"]:::core
        Internal["Internal Utilities"]:::core
        SearchProv["Search Provider"]:::core
    end
    
    subgraph External["External Integration Layer"]
        direction TB
        OllamaInt["Ollama Integration"]:::external
        FileSystem["File System"]:::external
        YouTube["YouTube Integration"]:::external
        WebParser["Website Parser"]:::external
    end
    
    subgraph Config["Configuration & Resources"]
        direction TB
        Settings["Settings (GSchema)"]:::config
        I18n["Internationalization"]:::config
        Resources["Resource Bundle"]:::config
    end
    
    subgraph Deploy["Deployment Options"]
        direction TB
        Flatpak["Flatpak"]:::deploy
        Snap["Snap"]:::deploy
        Nix["Nix"]:::deploy
    end
    
    UI --> Core
    Core --> External
    External --> OllamaAPI["Ollama API"]:::external
    
    %% Component Mappings
    click UI_Custom "https://github.com/Jeffser/Alpaca/tree/main/src/custom_widgets"
    click Chat "https://github.com/Jeffser/Alpaca/blob/main/src/custom_widgets/chat_widget.py"
    click Dialog "https://github.com/Jeffser/Alpaca/blob/main/src/custom_widgets/dialog_widget.py"
    click Message "https://github.com/Jeffser/Alpaca/blob/main/src/custom_widgets/message_widget.py"
    click ModelMgr "https://github.com/Jeffser/Alpaca/blob/main/src/custom_widgets/model_manager_widget.py"
    click Table "https://github.com/Jeffser/Alpaca/blob/main/src/custom_widgets/table_widget.py"
    click Terminal "https://github.com/Jeffser/Alpaca/blob/main/src/custom_widgets/terminal_widget.py"
    click UI_Main "https://github.com/Jeffser/Alpaca/blob/main/src/window.py"
    click UI_Resources "https://github.com/Jeffser/Alpaca/blob/main/src/alpaca.gresource.xml"
    click ConnHandler "https://github.com/Jeffser/Alpaca/blob/main/src/connection_handler.py"
    click SQLMgr "https://github.com/Jeffser/Alpaca/blob/main/src/sql_manager.py"
    click Internal "https://github.com/Jeffser/Alpaca/blob/main/src/internal.py"
    click ModelMgmt "https://github.com/Jeffser/Alpaca/blob/main/src/available_models.json"
    click SearchProv "https://github.com/Jeffser/Alpaca/blob/main/src/alpaca_search_provider.py.in"
    click Settings "https://github.com/Jeffser/Alpaca/blob/main/data/com.jeffser.Alpaca.gschema.xml"
    click I18n "https://github.com/Jeffser/Alpaca/tree/main/po"
    click Snap "https://github.com/Jeffser/Alpaca/blob/main/snap/snapcraft.yaml"
    click Flatpak "https://github.com/Jeffser/Alpaca/blob/main/com.jeffser.Alpaca.json"
    
    %% Styling
    classDef ui fill:#2196F3,stroke:#1565C0,color:white
    classDef widget fill:#42A5F5,stroke:#1565C0,color:white
    classDef core fill:#4CAF50,stroke:#2E7D32,color:white
    classDef external fill:#9E9E9E,stroke:#616161,color:white
    classDef config fill:#FFC107,stroke:#FFA000,color:black
    classDef deploy fill:#7E57C2,stroke:#4527A0,color:white
    
    %% Legend
    subgraph Legend
        direction TB
        L1["UI Components"]:::ui
        L2["Core Services"]:::core
        L3["External Services"]:::external
        L4["Configuration"]:::config
        L5["Deployment"]:::deploy
    end
```
