# padiazg/ollama-tools architecture

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

- Interactive diagram: https://gitdiagram.com/padiazg/ollama-tools
- Repository: https://github.com/padiazg/ollama-tools

## Overview

##### Main Components
- CLI Interface (Commands Layer):
- Represented by the files in the cmd directory (e.g., estimate.go, list_models.go, root.go). These files define the command-line behavior and are the entry points into the application.
- Business Logic / Internal Modules:
- The internals directory, especially internals/models and internals/tools, implements core functionalities such as fetching model data, formatting output, and calculating memory estimates. These packages encapsulate the core domain logic.
- Model Definitions and Data Structures:
- The models directory holds definitions and representations of different models (e.g., in models/ollama) along with related documentation. This separation distinguishes the data structures from the control logic.
- Configuration and Versioning:
- Files like the Makefile, go.mod, go.sum, and the version modules (in models/version) indicate build and versioning concerns.
- Testing Components:
- Evident by the *_test.go files in both cmd and internals/models, showcasing the emphasis on unit testing.

##### Relationships and Interactions
- The CLI commands (e.g., list-models, estimate) are the entry points. They read input parameters and pass them to appropriate functions in the internal packages.
- internals/models handles retrieving data from the Ollama server using an internal generator/reader/worker pattern. This module then formats the received data (for instance, listing model details or producing memory breakdowns).
- internals/tools provides the estimation functionality. It takes parameters (like parameter count, context length, and quantization level) and computes the RAM requirements accordingly.
- The models packages contain the domain types and helper functions for model details. The CLI and internal logic rely on these definitions to validate, process, and present information.

##### Architectural Patterns and Design Principles
- Layered Architecture: There is a clear separation between the user interface (CLI), business logic (internals), and data/model definitions (models). This helps maintain modularity.
- Command Pattern: The commands are defined in their own directory (cmd) to encapsulate each action (list models, estimate) as a separate command-line subcommand.
- Concurrency Pattern: Concurrency is applied within internals/models/models_list.go, using a generator/reader/worker pattern via Go routines and channels.
- Configuration Management: The tool allows configuration via environment variables or a YAML file, a common pattern for CLI apps.

##### Relevant Technologies and Frameworks
- The project is written in Go (golang), and the go.mod file shows dependency management.
- YAML for configuration files, and potential use of standard libraries for HTTP calls when interfacing with the Ollama server.

- Top Layer – CLI Interface (cmd):
- Middle Layer – Business Logic and Processing (internals):
- Lower Layer – Data Structures (models):
- External Components:
- Additional Notes:
- Configuration handling mechanisms (environment variables/YAML config) linked to the CLI commands.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% CLI Layer
    subgraph "CLI Layer"
        CLI["CLI Commands – cmd"]
    end

    %% Business Logic Layer
    subgraph "Business Logic Layer"
        ModelOps["Model Operations – internals/models"]
        Estimation["Estimation Tools – internals/tools"]
    end

    %% Data Models Layer
    subgraph "Data Structures Layer"
        DataModels["Ollama Model Definitions – models/ollama"]
    end

    %% Configuration & Versioning
    subgraph "Configuration & Versioning"
        BuildConfig["Build Config"]
        Version["Version Info – models/version"]
        Makefile["Makefile"]
        Gomod["go.mod"]
        Gosum["go.sum"]
    end

    %% External Component
    OllamaServer["Ollama Server"]

    %% Connections from CLI to Business Logic and Config
    CLI -->|"InputParsing"| ModelOps
    CLI -->|"TriggerEstimation"| Estimation
    CLI -->|"LoadConfig"| BuildConfig

    %% Business Logic interactions
    ModelOps -->|"FetchData"| DataModels
    ModelOps -->|"APICall"| OllamaServer

    %% Build Config breakdown
    BuildConfig --> Makefile
    BuildConfig --> Gomod
    BuildConfig --> Gosum

    %% Class Styles
    classDef cli fill:#add8e6,stroke:#000,stroke-width:1px;
    classDef business fill:#90ee90,stroke:#000,stroke-width:1px;
    classDef data fill:#f4a460,stroke:#000,stroke-width:1px;
    classDef config fill:#d3d3d3,stroke:#000,stroke-width:1px;
    classDef external fill:#ffcccb,stroke:#000,stroke-width:1px;

    %% Assign classes to nodes
    class CLI cli;
    class ModelOps,Estimation business;
    class DataModels data;
    class BuildConfig,Version,Makefile,Gomod,Gosum config;
    class OllamaServer external;

    %% Click Events
    click CLI "https://github.com/padiazg/ollama-tools/tree/master/cmd/"
    click ModelOps "https://github.com/padiazg/ollama-tools/tree/master/internals/models/"
    click Estimation "https://github.com/padiazg/ollama-tools/tree/master/internals/tools/"
    click DataModels "https://github.com/padiazg/ollama-tools/tree/master/models/ollama/"
    click Version "https://github.com/padiazg/ollama-tools/tree/master/models/version/"
    click Makefile "https://github.com/padiazg/ollama-tools/tree/master/Makefile"
    click Gomod "https://github.com/padiazg/ollama-tools/blob/master/go.mod"
    click Gosum "https://github.com/padiazg/ollama-tools/blob/master/go.sum"
```
