# gaurav-gosain/gollama architecture

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

- Interactive diagram: https://gitdiagram.com/gaurav-gosain/gollama
- Repository: https://github.com/gaurav-gosain/gollama

## Overview

##### Project Type & Purpose
- Gollama is a terminal application written in Go that provides both a chat TUI and CLI mode to interact with Ollama’s models.
- It combines chat functionalities, offline conversation history (with local SQLite storage as mentioned in the README), and Ollama model management (via the integrated Ollamanager library).
- External libraries (e.g., Bubble Tea for TUI, Glamour for markdown rendering, Lipgloss for style management) define much of the user interface and experience.

##### File Structure for Architectural Clues
- Top-level Files & Folders: You have general configuration files (.github workflows, Dockerfile, go.mod, go.sum) for CI/CD, containerization, and dependency management.
- Core Application Entry Points: main.go and ollamanager.go that likely kick off primary routines.
- internal/ Folder: Contains subdirectories such as:
- internal/api: Handles interactions with the Ollama API.
- internal/chat: Manages chat logic, conversation flows, and possibly handling session data (chat.go, keys.go, newchat.go).
- internal/client: Likely wraps client-side interactions with the Ollama server.
- internal/chatpicker: Manages the selection/display of chats.
- internal/roles and internal/utils: Provide modularized functionality and shared utilities.
- Additional files such as flags.go, generate.go, and tui.go suggest command-line flag parsing and terminal UI routines.

##### Key Components
a. Terminal User Interface (TUI):
- Build this component to include the chat interface.
- Chat display, chat picker, and modal management screens referenced in the README.

b. API & Client Integration:
- An API component for interacting with the Ollama servers.
- Internal/api module (handling requests/responses) in combination with internal/client.
- Dependency on Ollama’s official Go SDK, which can be wrapped in your client logic.

c. Model Management:
- Model management module, driven by the integrated Ollamanager library.
- This module handles installing, updating, and monitoring models.

d. Chat Management & Persistence:
- Although not explicitly detailed in the file tree, the README mentions storing previous conversations locally (SQLite).
- Demonstrate how chat sessions are saved, retrieved, and manipulated by the internal/chat and possibly other helper utilities.

e. External Dependencies/Services:
- External services such as the Ollama server (running either locally or remotely) as an external dependency that the client interacts with.
- That API interactions use the env variable (OLLAMA_HOST) for connectivity.

f. Build & Deployment:
- Components for CI/CD using GitHub Actions/workflows (from the .github/workflows directory).
- Mention containerization (Dockerfile and docker-publish.yml) which allow Gollama to be run in Docker.

- UI sends user commands/input to the chat logic (internal/chat) which then may call client functions (internal/client) to interact with the Ollama API.
- The model management section interacts with the external Ollamanager library for model installation and maintenance.
- Persistence (SQLite) receives data from chat sessions for future retrieval.
- Distinctly label components (e.g., “Chat TUI”, “API Wrapper”, “Model Manager”, “Local Persistence”, “External Ollama Server”).

## Diagram (Mermaid)

```mermaid
graph TD
    %% Terminal Interface
    subgraph "Terminal Interface"
        TUI["Terminal UI (TUI/CLI)"]:::ui
        ChatPicker["Chat Picker"]:::ui
    end

    %% Business Logic Layer
    subgraph "Business Logic Layer"
        %% Chat Management
        subgraph "Chat Management"
            Chat["Chat Handler (chat.go)"]:::logic
            ChatKeys["Chat Keys (keys.go)"]:::logic
            NewChat["New Chat (newchat.go)"]:::logic
        end
        %% API & Client Integration
        subgraph "API & Client Integration"
            API["API Wrapper (api.go)"]:::logic
            Client["Client Handler (client.go)"]:::logic
        end
        ModelManager["Model Manager (Ollamanager)"]:::logic
    end

    %% External Services
    subgraph "External Services"
        OllamaServer["Ollama Server"]:::external
        LocalDB["Local SQLite DB"]:::db
    end

    %% Build & Deployment
    subgraph "Build & Deployment"
        CI_CD["CI/CD Workflows (.github/workflows)"]:::infra
        Docker["Docker Containerization (Dockerfile)"]:::infra
        CLIFlags["CLI Flags Parsing (flags.go)"]:::infra
        Generate["Generate Script (generate.go)"]:::infra
        GoModules["Go Modules (go.mod & go.sum)"]:::infra
    end

    %% Data Flow Connections
    TUI -->|"user input"| Chat
    ChatPicker -->|"select chat"| Chat
    Chat -->|"sends data"| API
    Chat -->|"sends data"| Client
    API -->|"API call"| OllamaServer
    Client -->|"client call"| OllamaServer
    ModelManager -->|"manages"| OllamaServer
    Chat -->|"persist chat"| LocalDB

    %% Build & Deployment Initialization Flow
    CLIFlags -->|"parses args"| TUI
    CLIFlags -->|"parses args"| Chat
    Generate -->|"generates config"| GoModules

    %% Styling Classes
    classDef ui fill:#cce5ff,stroke:#003366,stroke-width:2px;
    classDef logic fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef external fill:#f8d7da,stroke:#721c24,stroke-width:2px;
    classDef db fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef infra fill:#e2e3e5,stroke:#6c757d,stroke-width:2px;

    %% Click Events for Terminal Interface
    click TUI "https://github.com/gaurav-gosain/gollama/blob/main/tui.go"
    click ChatPicker "https://github.com/gaurav-gosain/gollama/blob/main/internal/chatpicker/chatpicker.go"

    %% Click Events for API & Client Integration
    click API "https://github.com/gaurav-gosain/gollama/blob/main/internal/api/api.go"
    click Client "https://github.com/gaurav-gosain/gollama/blob/main/internal/client/client.go"

    %% Click Event for Model Management
    click ModelManager "https://github.com/gaurav-gosain/gollama/blob/main/ollamanager.go"

    %% Click Events for Chat Management & Persistence
    click Chat "https://github.com/gaurav-gosain/gollama/blob/main/internal/chat/chat.go"
    click ChatKeys "https://github.com/gaurav-gosain/gollama/blob/main/internal/chat/keys.go"
    click NewChat "https://github.com/gaurav-gosain/gollama/blob/main/internal/chat/newchat.go"

    %% Click Events for Build & Deployment
    click CI_CD "https://github.com/gaurav-gosain/gollama/tree/main/.github/workflows"
    click Docker "https://github.com/gaurav-gosain/gollama/tree/main/Dockerfile"
    click CLIFlags "https://github.com/gaurav-gosain/gollama/blob/main/flags.go"
    click Generate "https://github.com/gaurav-gosain/gollama/blob/main/generate.go"
    click GoModules "https://github.com/gaurav-gosain/gollama/blob/main/go.mod"
```
