# tisu19021997/snipai architecture

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

- Interactive diagram: https://gitdiagram.com/tisu19021997/snipai
- Repository: https://github.com/tisu19021997/snipai

## Overview

##### Main Components

A. User Interface Layer
- Main Window (PyQt-based)
- Key interfaces: Home, Bookmarks, Recents, Settings
- Components: SearchBar, ImageCard, NetworkGraph, WaterfallLayout
- Theme support (Light/Dark modes)

B. Core Services Layer
- Screenshot Service (Keyboard service)
- Storage Service (SQLite with vector extensions)
- AI Services:
- LLM Service (Ollama integration)
- Embedding Service
- Image Processing Service

C. Model Layer
- Image Model
- Database Models
- Configuration Models

D. External Dependencies
- Ollama Models:
- Moondream (image description)
- Qwen2:1.5b (image tagging)
- mxbai-embed-large (text embedding)
- SQLite-vec (vector storage)

**┌─ User Layer ─────────────────────────────────────┐**
- PyQt UI                         │
- ┌─────────────┐ ┌─────────────┐ ┌─────────────┐│
- Home Interface│ │  Bookmarks  │ │  Settings   ││
- ┘ └─────────────┘ └─────────────┘│
- ┬─────────────────────────────┘
- ↓
**┌─ Services Layer ──────────────────────────────────┐**
- ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
- Screenshot   │ │ AI Services │ │   Storage   │ │
- Service      │ │(LLM/Embed)  │ │  Service    │ │
- ┘ └─────────────┘ └─────────────┘ │
- ┬─────────────────────────────┘
- ↓
**┌─ Data Layer ───────────────────────────────────┐**
- ┌─────────────┐    ┌───────────────────────┐  │
- SQLite-vec │    │ Binary Vector Storage │  │
- ┘    └───────────────────────┘  │
- ┘

##### Data Flow Indicators

- Screenshot capture → AI processing → Storage flow
- Search query → Embedding → Vector search → UI display flow
- Settings changes → Configuration → System update flow

##### Technical Details

- PyQt as the UI framework
- SQLite with vector extensions
- Local AI model integration
- Binary embedding optimization
- File system interaction points

##### The data storage and retrieval mechanisms

This will provide a clear understanding of how SnipAI processes screenshots locally while maintaining efficient search capabilities through binary vector embeddings.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles
    classDef ui fill:#3498db,stroke:#2980b9,color:white
    classDef service fill:#2ecc71,stroke:#27ae60,color:white
    classDef data fill:#9b59b6,stroke:#8e44ad,color:white
    classDef ai fill:#f1c40f,stroke:#f39c12,color:black
    classDef config fill:#e74c3c,stroke:#c0392b,color:white

    %% UI Layer
    subgraph UI
        MainWindow["Main Window"]:::ui
        HomeInterface["Home Interface"]:::ui
        BookmarksInterface["Bookmarks Interface"]:::ui
        RecentsInterface["Recents Interface"]:::ui
        SettingsInterface["Settings Interface"]:::ui
        
        %% UI Components
        SearchBar["Search Bar"]:::ui
        ImageCard["Image Card"]:::ui
        NetworkGraph["Network Graph"]:::ui
        WaterfallLayout["Waterfall Layout"]:::ui
    end

    %% Services Layer
    subgraph Services
        ScreenshotService["Screenshot Service"]:::service
        StorageService["Storage Service"]:::service
        
        subgraph AIServices
            LLMService["LLM Service"]:::service
            EmbeddingService["Embedding Service"]:::service
        end
    end

    %% Data Layer
    subgraph Data
        SQLiteVec["SQLite-vec Database"]:::data
        BinaryStorage["Binary Vector Storage"]:::data
        ConfigFiles["Configuration Files"]:::config
    end

    %% External AI Models
    subgraph AIModels
        Moondream["Moondream Model"]:::ai
        Qwen["Qwen2:1.5b Model"]:::ai
        MXBai["mxbai-embed-large"]:::ai
    end

    %% Relationships
    MainWindow --> HomeInterface
    MainWindow --> BookmarksInterface
    MainWindow --> RecentsInterface
    MainWindow --> SettingsInterface
    
    HomeInterface --> SearchBar
    HomeInterface --> ImageCard
    HomeInterface --> NetworkGraph
    HomeInterface --> WaterfallLayout
    
    ScreenshotService --> LLMService
    LLMService --> Moondream
    LLMService --> Qwen
    EmbeddingService --> MXBai
    
    LLMService --> StorageService
    EmbeddingService --> StorageService
    StorageService --> SQLiteVec
    StorageService --> BinaryStorage

    %% Click Events
    click MainWindow "https://github.com/tisu19021997/snipai/blob/main/snipai/src/ui/view/window.py"
    click HomeInterface "https://github.com/tisu19021997/snipai/blob/main/snipai/src/ui/view/home_interface.py"
    click BookmarksInterface "https://github.com/tisu19021997/snipai/blob/main/snipai/src/ui/view/bookmarks_interface.py"
    click RecentsInterface "https://github.com/tisu19021997/snipai/blob/main/snipai/src/ui/view/recents_interface.py"
    click SettingsInterface "https://github.com/tisu19021997/snipai/blob/main/snipai/src/ui/view/settings_interface.py"
    click SearchBar "https://github.com/tisu19021997/snipai/blob/main/snipai/src/ui/components/search_bar.py"
    click ImageCard "https://github.com/tisu19021997/snipai/blob/main/snipai/src/ui/components/image_card.py"
    click NetworkGraph "https://github.com/tisu19021997/snipai/blob/main/snipai/src/ui/components/network_graph.py"
    click WaterfallLayout "https://github.com/tisu19021997/snipai/blob/main/snipai/src/ui/components/waterfall_layout.py"
    click ScreenshotService "https://github.com/tisu19021997/snipai/blob/main/snipai/src/services/keyboard.py"
    click StorageService "https://github.com/tisu19021997/snipai/blob/main/snipai/src/services/storage.py"
    click LLMService "https://github.com/tisu19021997/snipai/blob/main/snipai/src/services/llm.py"
    click EmbeddingService "https://github.com/tisu19021997/snipai/blob/main/snipai/src/services/embed.py"
    click ConfigFiles "https://github.com/tisu19021997/snipai/blob/main/snipai/assets/configs/config.json"

    %% Legend
    subgraph Legend
        UI_Component["UI Component"]:::ui
        Service_Component["Service"]:::service
        Data_Component["Data Storage"]:::data
        AI_Component["AI Model"]:::ai
        Config_Component["Configuration"]:::config
    end
```
