# tconbeer/harlequin architecture

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

- Interactive diagram: https://gitdiagram.com/tconbeer/harlequin
- Repository: https://github.com/tconbeer/harlequin

## Overview

##### Main Components

a. Core Application Layer:
- Terminal UI (built with Textual, evident from .tcss files)
- Command Line Interface (cli.py)
- Configuration Management (config.py)
- Plugin System (plugins.py)

b. Editor Components:
- Code Editor with SQL syntax highlighting
- Results Viewer
- Data Catalog Browser
- Query History Manager
- Help System

c. Database Layer:
- Abstract Adapter Interface (adapter.py)
- Built-in Adapters:
- DuckDB Implementation
- SQLite Implementation
- Plugin System for External Adapters

d. Support Systems:
- Autocomplete Engine
- Cache Management
- Export Functionality
- History Management

**┌─ User Interface Layer ─────────────────────┐**
- Terminal UI (Textual)                      │
- ┌─────────────┐ ┌──────────┐ ┌──────────┐ │
- Code Editor │ │ Data     │ │ Results  │ │
- Catalog  │ │ Viewer   │ │
- ┘ └──────────┘ └──────────┘ │
- ┤
- Core Application Layer                      │
- ┌─────────────┐ ┌──────────┐ ┌──────────┐ │
- Config      │ │ Plugin   │ │ Cache    │ │
- Management  │ │ System   │ │ System   │ │
- ┘ └──────────┘ └──────────┘ │
- ┤
- Database Abstraction Layer                  │
- ┌─────────────┐ ┌──────────┐ ┌──────────┐ │
- Base        │ │ Query    │ │ Schema   │ │
- Adapter     │ │ Engine   │ │ Manager  │ │
- ┘ └──────────┘ └──────────┘ │
- ┤
- Database Implementations                    │
- ┌─────────────┐ ┌──────────┐ ┌──────────┐ │
- DuckDB      │ │ SQLite   │ │ External │ │
- Adapter     │ │ Adapter  │ │ Adapters │ │
- ┘ └──────────┘ └──────────┘ │
- ┘

##### Important Details to Highlight
- Plugin architecture for database adapters
- File system interactions for query history and caching
- Configuration flow from CLI to components
- Autocomplete system integration
- Export functionality paths

## Diagram (Mermaid)

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

    %% User Interface Layer
    subgraph UI["User Interface Layer"]
        TUI["Terminal UI"]
        CodeEditor["Code Editor"]
        DataCatalog["Data Catalog Browser"]
        ResultsViewer["Results Viewer"]
        HistoryScreen["Query History"]
        HelpSystem["Help System"]
        CLI["CLI Interface"]
    end

    %% Core Application Layer
    subgraph Core["Core Application Layer"]
        Config["Configuration Management"]
        PluginSystem["Plugin System"]
        Cache["Cache System"]
        AutoComplete["Autocomplete Engine"]
        Export["Export System"]
        History["History Management"]
    end

    %% Database Abstraction Layer
    subgraph DBAbstraction["Database Abstraction Layer"]
        BaseAdapter["Base Adapter Interface"]
        QueryEngine["Query Engine"]
        SchemaManager["Schema Manager"]
    end

    %% Database Implementations
    subgraph DBImpl["Database Implementations"]
        DuckDB["DuckDB Adapter"]
        SQLite["SQLite Adapter"]
        ExtAdapters["External Adapters"]
    end

    %% Relationships
    CLI --> TUI
    TUI --> CodeEditor
    TUI --> DataCatalog
    TUI --> ResultsViewer
    TUI --> HistoryScreen
    TUI --> HelpSystem
    
    Config --> TUI
    PluginSystem --> BaseAdapter
    Cache --> ResultsViewer
    AutoComplete --> CodeEditor
    History --> HistoryScreen
    Export --> ResultsViewer

    BaseAdapter --> QueryEngine
    BaseAdapter --> SchemaManager
    
    DuckDB --> BaseAdapter
    SQLite --> BaseAdapter
    ExtAdapters -.-> BaseAdapter

    %% Click Events
    click CLI "https://github.com/tconbeer/harlequin/blob/main/src/harlequin/cli.py"
    click Config "https://github.com/tconbeer/harlequin/blob/main/src/harlequin/config.py"
    click PluginSystem "https://github.com/tconbeer/harlequin/blob/main/src/harlequin/plugins.py"
    click CodeEditor "https://github.com/tconbeer/harlequin/blob/main/src/harlequin/components/code_editor.py"
    click ResultsViewer "https://github.com/tconbeer/harlequin/blob/main/src/harlequin/components/results_viewer.py"
    click DataCatalog "https://github.com/tconbeer/harlequin/tree/main/src/harlequin/components/data_catalog/"
    click HistoryScreen "https://github.com/tconbeer/harlequin/blob/main/src/harlequin/components/history_screen.py"
    click HelpSystem "https://github.com/tconbeer/harlequin/blob/main/src/harlequin/components/help_screen.py"
    click BaseAdapter "https://github.com/tconbeer/harlequin/blob/main/src/harlequin/adapter.py"
    click DuckDB "https://github.com/tconbeer/harlequin/tree/main/src/harlequin_duckdb/"
    click SQLite "https://github.com/tconbeer/harlequin/tree/main/src/harlequin_sqlite/"
    click AutoComplete "https://github.com/tconbeer/harlequin/tree/main/src/harlequin/autocomplete/"
    click Cache "https://github.com/tconbeer/harlequin/blob/main/src/harlequin/cache.py"
    click Export "https://github.com/tconbeer/harlequin/blob/main/src/harlequin/export.py"
    click History "https://github.com/tconbeer/harlequin/blob/main/src/harlequin/history.py"
    click TUI "https://github.com/tconbeer/harlequin/blob/main/src/harlequin/app.tcss"

    %% Style Applications
    class TUI,CodeEditor,DataCatalog,ResultsViewer,HistoryScreen,HelpSystem,CLI ui
    class Config,PluginSystem,AutoComplete,Export,History core
    class Cache,Config critical
    class BaseAdapter,QueryEngine,SchemaManager abstraction
    class DuckDB,SQLite,ExtAdapters db
```
