# duckdb/duckdb-ui architecture

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

- Interactive diagram: https://gitdiagram.com/duckdb/duckdb-ui
- Repository: https://github.com/duckdb/duckdb-ui

## Overview

##### Main Components
- DuckDB Shell with Extension – This is the core runtime where the extension is linked. Note that the build process creates a binary (“duckdb”) which automatically loads the extension.
- UI Extension Module – Represented by the files in src/ui_extension.cpp and its header. This module encapsulates the main logic for the user interface integration.
- HTTP Server – With implementation in src/http_server.cpp and its header. This component is responsible for handling web-based requests and serving the UI.
- Event Dispatcher – Implemented in src/event_dispatcher.cpp (and header) to manage event handling across components.
- Utility and Settings Modules – Located under src/include/settings.hpp, state, utils (including encoding, helpers, md_helpers, env, serialization) that provide support functions and configuration management.
- Test Suite – Indicated by the test directory and SQL tests in test/sql that validate the extension’s functionality.
- External Dependency Management – VCPKG is used to manage dependencies (as seen in vcpkg.json and the README instructions). Also, the project references external libraries (like httplib in third_party).

##### Relationships and Interactions
- The DuckDB Shell (core database engine) acts as the host environment. It automatically loads the extension which in turn integrates the UI components.
- The Utility modules and Settings are used across various parts of the extension (UI, HTTP, and event management) to ensure consistency and shared configurations.

##### Architectural Patterns or Design Principles
- Modularity – The separation between UI logic, HTTP handling, event dispatching, and utility modules reflects modular design.
- Extension-Based Integration – The design illustrates how the extension integrates into the DuckDB shell, following the DuckDB extension standard.
- Dependency Injection/Management – Emphasize that VCPKG is used to include dependencies cleanly.

##### Technologies
- C++ as the primary programming language (source files in src/).
- VCPKG for dependency management.
- GitHub Actions (in .github/workflows) for CI tasks.
- The third_party directory shows usage of httplib, indicating lightweight HTTP communication.
- Makefile and CMakeLists.txt, which drive the build process.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Core Runtime
    subgraph "DuckDB Core"
        duckdbShell["DuckDB Shell with Extension"]:::core
    end

    %% UI Components
    subgraph "UI Layer"
        uiExtension["UI Extension Module"]:::module
        httpServer["HTTP Server"]:::module
        eventDispatcher["Event Dispatcher"]:::module
    end

    %% Support Services
    subgraph "Support Services"
        utility["Utility & Settings"]:::utility
    end

    %% External Dependencies and Testing
    externalDependency["External Dependency Manager"]:::external
    testSuite["Test Suite"]:::test

    %% Relationships
    externalDependency -->|"injects"| duckdbShell
    duckdbShell -->|"loads"| uiExtension
    uiExtension -->|"serves"| httpServer
    uiExtension <-->|"communicates"| eventDispatcher
    utility -->|"configures"| uiExtension
    utility -->|"configures"| httpServer
    utility -->|"configures"| eventDispatcher
    testSuite -->|"tests"| duckdbShell
    testSuite -->|"tests"| uiExtension
    testSuite -->|"tests"| httpServer
    testSuite -->|"tests"| eventDispatcher

    %% Click Events
    click duckdbShell "https://github.com/duckdb/duckdb-ui/tree/main/duckdb"
    click uiExtension "https://github.com/duckdb/duckdb-ui/blob/main/src/ui_extension.cpp"
    click httpServer "https://github.com/duckdb/duckdb-ui/blob/main/src/http_server.cpp"
    click eventDispatcher "https://github.com/duckdb/duckdb-ui/blob/main/src/event_dispatcher.cpp"
    click utility "https://github.com/duckdb/duckdb-ui/blob/main/src/include/settings.hpp"
    click testSuite "https://github.com/duckdb/duckdb-ui/blob/main/test/sql/ui.test"
    click externalDependency "https://github.com/duckdb/duckdb-ui/blob/main/vcpkg.json"

    %% Styles
    classDef core fill:#FFD700,stroke:#B8860B,stroke-width:2px;
    classDef module fill:#87CEFA,stroke:#4682B4,stroke-width:2px;
    classDef utility fill:#90EE90,stroke:#006400,stroke-width:2px;
    classDef external fill:#FFB6C1,stroke:#C71585,stroke-width:2px;
    classDef test fill:#D3D3D3,stroke:#696969,stroke-width:2px;
```
