# leighklotz/boxy architecture

> Architecture diagram of the GitHub repository leighklotz/boxy, 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/leighklotz/boxy
- Repository: https://github.com/leighklotz/boxy

## Overview

##### Main Components

A. Core Editor Components:
- Text Editor Interface (boxy.html, style.css)
- Editor Logic Controller (boxy.js)
- Keymap Handler (keymap.js)
- Configuration System (config.js)

B. LLM Integration Module:
- LLM Inference Engine (modules/llm-infer/llm-infer.js)
- LLM Configuration (modules/llm-infer/docs/AICoder.yaml)

**[User Interface Layer]**

- HTML View (boxy.html)
- CSS Styling (style.css)

**[Core Logic Layer]**

- Editor Controller (boxy.js)
- Key Mapping System (keymap.js)
- Configuration Manager (config.js)

**[Module Layer]**

- LLM Integration
- Inference Engine (llm-infer.js)
- LLM Configuration (AICoder.yaml)

##### Key Interactions to Highlight

A. User Input Flow:
- How keyboard/mouse inputs flow through the keymap handler
- How commands are processed by the editor controller

C. LLM Integration:
- Flow from user input to LLM inference
- How responses are integrated back into the editor

##### Implementation Details

- Text selection and manipulation
- LLM prompt handling and response integration
- Command evaluation system (C-|)

##### External Dependencies

- Connection to external LLM services
- Browser APIs being used
- File system interactions for configuration

Remember to emphasize the modular nature of the system, particularly how the LLM integration is implemented as a separate module that extends the core editor functionality.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles and classes
    classDef uiLayer fill:#e1f5fe,stroke:#01579b
    classDef coreLayer fill:#e8f5e9,stroke:#1b5e20
    classDef moduleLayer fill:#f3e5f5,stroke:#4a148c
    classDef external fill:#f5f5f5,stroke:#424242
    
    %% UI Layer
    subgraph UI
        HTML["Text Editor Interface"]
        CSS["CSS Styling"]
        HTML --> CSS
    end
    
    %% Core Logic Layer
    subgraph Core
        Editor["Editor Controller"]
        Keymap["Key Mapping System"]
        Config["Configuration Manager"]
        
        Editor --> Keymap
        Editor --> Config
    end
    
    %% Module Layer
    subgraph Modules
        LLMInfer["LLM Inference Engine"]
        LLMConfig["LLM Configuration"]
        
        LLMInfer --> LLMConfig
    end
    
    %% External Services
    ExternalLLM{{"External LLM API"}}
    
    %% Connections between layers
    HTML --> Editor
    Editor --> LLMInfer
    LLMInfer --> ExternalLLM
    
    %% Data Flow
    UserInput(("User Input"))
    UserInput -.-> HTML
    Editor -.-> HTML
    
    %% Box Operations
    BoxOps["Box Management System"]
    Editor --> BoxOps
    
    %% Command System
    CmdEval["Command Evaluator"]
    Editor --> CmdEval
    
    %% Click events for component mapping
    click HTML "https://github.com/leighklotz/boxy/blob/main/boxy.html"
    click CSS "https://github.com/leighklotz/boxy/blob/main/style.css"
    click Editor "https://github.com/leighklotz/boxy/blob/main/boxy.js"
    click Keymap "https://github.com/leighklotz/boxy/blob/main/keymap.js"
    click Config "https://github.com/leighklotz/boxy/blob/main/config.js"
    click LLMInfer "https://github.com/leighklotz/boxy/blob/main/modules/llm-infer/llm-infer.js"
    click LLMConfig "https://github.com/leighklotz/boxy/blob/main/modules/llm-infer/docs/AICoder.yaml"
    
    %% Style applications
    class HTML,CSS uiLayer
    class Editor,Keymap,Config,BoxOps,CmdEval coreLayer
    class LLMInfer,LLMConfig moduleLayer
    class ExternalLLM external
    
    %% Legend
    subgraph Legend
        UI_Component["UI Component"]:::uiLayer
        Core_Component["Core Component"]:::coreLayer
        Module_Component["Module Component"]:::moduleLayer
        External_Service{{"External Service"}}:::external
    end
```
