# thegafo/tripleg architecture

> Architecture diagram of the GitHub repository thegafo/tripleg, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/thegafo/tripleg
- Repository: https://github.com/thegafo/tripleg

## Overview

##### Main Components

A. Core System Components:
- Input Handlers Layer
- Keyboard Listener (keyboard.js)
- Clipboard Monitor (clipboard.js)
- Screenshot Handler (screenshot/screenshot.js)
- OCR Processing (ocr/OCR.swift, ocr.js)

B. AI Provider Integration Layer:
- Provider Adapters
- OpenAI (openai.js)
- Anthropic (anthropic.js)
- Gemini (gemini.js)
- Other supported providers

C. System Integration Layer:
- Status Management (status/Status.swift, status.js)
- Tools Integration (tools.js)
- Utilities (utils.js)
- Watch System (watch.js)

##### Component Relationships

- Input handlers → AI Provider Integration (showing how user input gets processed)
- AI Provider Integration → External AI Services (API calls)
- System Integration Layer ↔ Core Components (bidirectional communication)

##### Data Flow Representation

- User Input → Input Handlers
- Input Handlers → Context Management
- Context → AI Provider Selection
- AI Provider → Completion Generation
- Completion → System Output

##### Specific Elements to Highlight

A. Input Processing:
**[Keyboard Events] → [Trigger Detection (ggg/GGG)] → [Context Collection]**
**[Clipboard Events] → [Context Updates]**
**[Screenshot Events] → [OCR Processing] → [Context Updates]**

B. AI Processing Pipeline:
**[Context] → [Provider Selection] → [API Call] → [Response Processing] → [Output]**

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Legend
        L1[Core Component]:::core
        L2[/Input Handler/]:::input
        L3{{AI Provider}}:::ai
        L4[(External Service)]:::external
        L5([System Integration]):::system
    end

    subgraph "Input Handlers Layer"
        KH[/Keyboard Handler/]:::input
        CM[/Clipboard Monitor/]:::input
        SH[/Screenshot Handler/]:::input
        OCR[/OCR Processing/]:::input
    end

    subgraph "AI Provider Integration"
        OpenAI{{OpenAI Adapter}}:::ai
        Anthropic{{Anthropic Adapter}}:::ai
        Gemini{{Gemini Adapter}}:::ai
        Models[Models Manager]:::core
    end

    subgraph "System Integration Layer"
        Status([Status Management]):::system
        Tools([Tools Integration]):::system
        Utils([Utilities]):::system
        Watch([Watch System]):::system
    end

    subgraph "External Services"
        OpenAIAPI[(OpenAI API)]:::external
        AnthropicAPI[(Anthropic API)]:::external
        GeminiAPI[(Gemini API)]:::external
    end

    Main[Main Entry Point]:::core
    App[Application Root]:::core

    %% Connections
    Main --> KH & CM & SH
    KH & CM & SH --> OCR
    OCR --> Models
    Models --> OpenAI & Anthropic & Gemini
    OpenAI --> OpenAIAPI
    Anthropic --> AnthropicAPI
    Gemini --> GeminiAPI
    Status <--> Main
    Tools <--> Main
    Utils <--> Main
    Watch <--> Main
    App --> Main

    %% Click Events
    click KH "https://github.com/thegafo/tripleg/blob/main/src/keyboard.js"
    click CM "https://github.com/thegafo/tripleg/blob/main/src/clipboard.js"
    click SH "https://github.com/thegafo/tripleg/blob/main/src/screenshot/screenshot.js"
    click OCR "https://github.com/thegafo/tripleg/blob/main/src/ocr/OCR.swift"
    click OpenAI "https://github.com/thegafo/tripleg/blob/main/src/openai.js"
    click Anthropic "https://github.com/thegafo/tripleg/blob/main/src/anthropic.js"
    click Gemini "https://github.com/thegafo/tripleg/blob/main/src/gemini.js"
    click Models "https://github.com/thegafo/tripleg/blob/main/src/models.js"
    click Status "https://github.com/thegafo/tripleg/blob/main/src/status/Status.swift"
    click Tools "https://github.com/thegafo/tripleg/blob/main/src/tools.js"
    click Utils "https://github.com/thegafo/tripleg/blob/main/src/utils.js"
    click Watch "https://github.com/thegafo/tripleg/blob/main/src/watch.js"
    click Main "https://github.com/thegafo/tripleg/blob/main/src/main.js"
    click App "https://github.com/thegafo/tripleg/blob/main/index.js"

    %% Styles
    classDef core fill:#2374ab
    classDef input fill:#57a773
    classDef ai fill:#7d3c98
    classDef system fill:#e67e22
    classDef external fill:#95a5a6
```
