# codesmith28/lazyai architecture

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

- Interactive diagram: https://gitdiagram.com/codesmith28/lazyai
- Repository: https://github.com/codesmith28/lazyai

## Overview

##### Main Components
- Entry Point & Application Core: The main.go file in the lazyAi directory acts as the application’s entry point.
- TUI Dashboard: The “panes” directory contains various files (e.g., apiWindow.go, historyPane.go, inputPane.go, outputPane.go, modelsPane.go, promptPane.go, keybindingsPane.go, sysNavPane.go, layout.go, theme.go) that together build the interactive dashboard.
- Internal Business Logic: The “internal” directory holds several important modules:
- Clipboard Module: Located in internal/clipboard for managing clipboard operations.
- History Manager: Found in internal/history to manage past interactions.
- Query Maker: Inside internal/queryMaker with the logic to build queries for the AI.
- Models & Utility: Various files like internal/models.go and internal/loc.go handle data representations and supplementary logic.
- API Integration: The “api” directory contains files (api.go, analytics.go, checkCred.go) for managing interactions with external AI services, analytics tracking, and possibly credential checking.
- Public Assets & Configurations: The “public” directory is used for assets like screenshots, and there are also configuration files such as go.mod, go.sum, and GitHub Actions config in .github.

##### Relationships and Interactions
- The entry point (main.go) initializes the TUI dashboard and connects all modules.
- The TUI panes interact with the internal modules (e.g., the clipboard module to detect copied text, history module to log interactions, and query maker to format requests).
- When new text is detected (via the clipboard module), the request is passed to the API layer which is responsible for sending the request to the AI service.
- The response from the API is then routed back to the TUI for display (in the outputPane) and may also be re-copied to the clipboard.
- There is integration with external libraries (e.g., clipboard by atotto, tview for TUI management, tcell for terminal control) that enhance the functionality.

##### Architectural Patterns & Design Principles
- Separation of Concerns: The code structure divides responsibilities among a clear set of directories (e.g., UI logic under panes, business logic under internal, API integrations under api).
- Modularity: Components are encapsulated in their respective packages, which facilitates easier maintenance and potential future enhancements.
- Event-Driven: Clipboard events trigger the processing flow—clipboard monitoring initiates query creation, API calls, and UI updates.
- Dependency Isolation: The modular structure ensures that external dependencies and third-party libraries are used in appropriate modules.

## Diagram (Mermaid)

```mermaid
flowchart TD 
    %% Application Core
    A["Application Core (main.go)"]:::core

    %% TUI Dashboard
    subgraph "TUI Dashboard"
        T1["Input Pane"]:::tui
        T2["Output Pane"]:::tui
        T3["History Pane"]:::tui
        T4["Models Pane"]:::tui
        T5["Prompt Pane"]:::tui
        T6["API Window"]:::tui
        T7["Keybindings Pane"]:::tui
        T8["System Nav Pane"]:::tui
        T9["Layout"]:::tui
        T10["Theme"]:::tui
    end

    %% Internal Business Logic
    subgraph "Internal Business Logic"
        C["Clipboard Module"]:::internal
        H["History Manager"]:::internal
        Q["Query Maker"]:::internal
    end

    %% API Integration Layer
    subgraph "API Integration"
        API["API Services"]:::api
    end

    %% Public Assets & Configurations
    subgraph "Public Assets & Configurations"
        PA["Public Assets"]:::public
        CFG["Configurations"]:::public
    end

    %% External Dependencies
    dep1["tcell"]:::external
    dep2["tview"]:::external
    dep3["atotto/clipboard"]:::external

    %% Connections from Application Core to Modules
    A -->|"initializes"| T1
    A -->|"initializes"| T2
    A -->|"initializes"| T3
    A -->|"initializes"| T4
    A -->|"initializes"| T5
    A -->|"initializes"| T6
    A -->|"initializes"| T7
    A -->|"initializes"| T8
    A -->|"initializes"| T9
    A -->|"initializes"| T10
    A -->|"initializes"| C
    A -->|"initializes"| H
    A -->|"initializes"| Q
    A -->|"initializes"| API

    %% Event-driven Flow
    C -->|"clipboardEvent"| Q
    Q -->|"queryCreation"| API
    API -->|"responseUpdate"| T2
    API -->|"logToHistory"| H

    %% External Dependencies Integration
    T2 -->|"uses"| dep1
    T2 -->|"uses"| dep2
    C  -->|"uses"| dep3

    %% Click Events
    click A "https://github.com/codesmith28/lazyai/blob/main/lazyAi/main.go"
    click T1 "https://github.com/codesmith28/lazyai/blob/main/panes/inputPane.go"
    click T2 "https://github.com/codesmith28/lazyai/blob/main/panes/outputPane.go"
    click T3 "https://github.com/codesmith28/lazyai/blob/main/panes/historyPane.go"
    click T4 "https://github.com/codesmith28/lazyai/blob/main/panes/modelsPane.go"
    click T5 "https://github.com/codesmith28/lazyai/blob/main/panes/promptPane.go"
    click T6 "https://github.com/codesmith28/lazyai/blob/main/panes/apiWindow.go"
    click T7 "https://github.com/codesmith28/lazyai/blob/main/panes/keybindingsPane.go"
    click T8 "https://github.com/codesmith28/lazyai/blob/main/panes/sysNavPane.go"
    click T9 "https://github.com/codesmith28/lazyai/blob/main/panes/layout.go"
    click T10 "https://github.com/codesmith28/lazyai/blob/main/panes/theme.go"
    click C "https://github.com/codesmith28/lazyai/blob/main/internal/clipboard/clipboard.go"
    click H "https://github.com/codesmith28/lazyai/blob/main/internal/history/history.go"
    click Q "https://github.com/codesmith28/lazyai/blob/main/internal/queryMaker/queryMaker.go"
    click API "https://github.com/codesmith28/lazyai/blob/main/api/api.go"
    click PA "https://github.com/codesmith28/lazyai/tree/main/public"
    click CFG "https://github.com/codesmith28/lazyai/blob/main/go.mod"

    %% Styles
    classDef core fill:#b3e5fc,stroke:#01579b,stroke-width:2px,color:#000;
    classDef tui fill:#c8e6c9,stroke:#2e7d32,stroke-width:2px,color:#000;
    classDef internal fill:#fff9c4,stroke:#f57f17,stroke-width:2px,color:#000;
    classDef api fill:#ffe0b2,stroke:#e65100,stroke-width:2px,color:#000;
    classDef public fill:#d7ccc8,stroke:#4e342e,stroke-width:2px,color:#000;
    classDef external fill:#f8bbd0,stroke:#880e4f,stroke-width:2px,color:#000;
```
