# ysfemrealbyrk/ollama-monitor architecture

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

- Interactive diagram: https://gitdiagram.com/ysfemrealbyrk/ollama-monitor
- Repository: https://github.com/ysfemrealbyrk/ollama-monitor

## Overview

##### Project type and purpose
- This is a lightweight Windows system-tray desktop application written in Python.

##### Main architectural components
a. User Interface Layer
- Notification pop-ups (using Windows APIs via Python)
b. Core Monitoring Engine
- Poller/Watcher: periodically sends HTTP requests to the Ollama API
- Status evaluator: maps HTTP responses to status codes (green/blue/red)
- Event emitter: notifies the UI layer of status changes
c. API Client
- Configurable HTTP client (supports proxy, authentication)
- Encapsulates URL formatting, request retries, error handling
d. Configuration Manager
- Reads and writes user settings (API URL, startup preferences)
- Persists config (e.g., in %APPDATA% or registry)
e. Logger
- Centralized logging to file in %APPDATA%/OllamaMonitor/logs
- Separate log levels for info, warnings, errors
f. Build & Packaging
- build.py: compiles the Python code into an executable (e.g., via PyInstaller)
- create_version_info.py and __version__.py: manage version injection

##### External dependencies and services
- Ollama AI service: HTTP endpoint at localhost:11434 or configured proxy
- Windows OS subsystem (system tray, startup registry, notifications)
- Python runtime (3.8+), pystray, requests (or similar HTTP lib)

##### Relationships and interactions
- On launch: Configuration Manager loads settings → Core Monitoring Engine starts polling.
- Poller calls API Client → receives model status → passes to Status Evaluator → triggers Event Emitter.
- Logger records each poll cycle, errors, and user actions.
- UI Layer user actions (Settings, Exit) go back to Configuration Manager or shut down the Engine.
- Build & Packaging scripts do not run at runtime but are part of the CI/build pipeline.

##### Architectural patterns and design principles
- Separation of concerns: UI vs. core logic vs. config vs. logging.
- Observer/Publisher-Subscriber: Event Emitter notifies UI of status changes.
- Single Responsibility: each module (API Client, Config Manager) handles one aspect.
- Adapter: wrap HTTP library calls in a single API client interface.

##### Deliverables
- Runtime flow: launch → poll → update UI → shutdown.
- Build flow: version bump → build.py → dist/OllamaMonitor.exe.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Runtime Components
    subgraph "Runtime Environment"
        direction TB

        subgraph "User Interface Layer"
            direction TB
            UI["User Interface Layer\n(pystray, Notifications)"] 
        end

        subgraph "Core Monitoring Engine"
            direction TB
            CoreEngine["Monitoring Engine\n(Poller, Evaluator, Emitter)"] 
        end

        subgraph "API Client"
            direction TB
            APIClient["API Client\n(HTTP, Retries, Errors)"] 
        end

        subgraph "Configuration Manager"
            direction TB
            Config["Configuration Manager\n(Load/Save Settings)"]
        end

        subgraph "Logger"
            direction TB
            Logger["Logger\n(File Logging)"]
        end

        subgraph "External Systems"
            direction TB
            Ollama["Ollama AI Service"]:::external
            ConfigStore[(Config Store)]:::datastore
            LogStore[(Log Files)]:::datastore
        end
    end

    %% Build & Packaging Components
    subgraph "Build & Packaging" 
        direction TB
        VersionMgr["Version Info Manager\n(create_version_info.py,\n__version__.py)"] 
        Build["Build Script\n(build.py)"] 
        Req["Dependencies\n(requirements.txt)"] 
    end

    %% Runtime Flow
    Config -->|"loads settings"| CoreEngine
    CoreEngine -->|"starts poller"| APIClient
    APIClient -->|"HTTP request"| Ollama
    APIClient -->|"logs events"| Logger
    CoreEngine -->|"maps status"| CoreEngine
    CoreEngine -->|"emits events"| UI
    UI -->|dash| CoreEngine
    UI -->|"settings actions"| Config
    UI -->|"exit action"| CoreEngine
    CoreEngine -->|"writes logs"| Logger
    UI -->|"writes logs"| Logger
    Config -->|"writes logs"| Logger

    %% Persistence
    Config -->|"reads/writes"| ConfigStore
    Logger -->|"writes"| LogStore

    %% Build Flow
    VersionMgr -->|"provides version"| Build
    Req -->|"provides deps"| Build

    %% Click Events
    click UI "https://github.com/ysfemrealbyrk/ollama-monitor/blob/main/ollama_monitor.py"
    click UI "https://github.com/ysfemrealbyrk/ollama-monitor/tree/main/icons/"
    click CoreEngine "https://github.com/ysfemrealbyrk/ollama-monitor/blob/main/ollama_monitor.py"
    click APIClient "https://github.com/ysfemrealbyrk/ollama-monitor/blob/main/ollama_monitor.py"
    click Config "https://github.com/ysfemrealbyrk/ollama-monitor/blob/main/ollama_monitor.py"
    click Logger "https://github.com/ysfemrealbyrk/ollama-monitor/blob/main/ollama_monitor.py"
    click VersionMgr "https://github.com/ysfemrealbyrk/ollama-monitor/blob/main/create_version_info.py"
    click VersionMgr "https://github.com/ysfemrealbyrk/ollama-monitor/blob/main/__version__.py"
    click Build "https://github.com/ysfemrealbyrk/ollama-monitor/blob/main/build.py"
    click Req "https://github.com/ysfemrealbyrk/ollama-monitor/blob/main/requirements.txt"

    %% Styles
    classDef runtime fill:#D6EAF8,stroke:#2980B9
    classDef external fill:#A9DFBF,stroke:#28B463
    classDef datastore fill:#D5D8DC,stroke:#7F8C8D
    classDef build fill:#FCF3CF,stroke:#F1C40F

    class UI,CoreEngine,APIClient,Config,Logger runtime
    class VersionMgr,Build,Req build
```
