# databendlabs/bendsql architecture

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

- Interactive diagram: https://gitdiagram.com/databendlabs/bendsql
- Repository: https://github.com/databendlabs/bendsql

## Overview

##### Main Components Overview

a. Core Components (Primary Layer):
- Core Module (RestAPI Client)
- Driver Module (SQL Client)
- CLI Module (Command Line Interface)
- Frontend Module (Web Interface)
- Bindings (Python and NodeJS)

##### Architectural Patterns to Highlight

Layer 1 - Client Interfaces:
**[CLI Interface] [Web Frontend] [Python Binding] [NodeJS Binding]**

Layer 2 - Driver Layer:
**[Driver Module]**

**[REST API Client] [FlightSQL Client]**

Layer 3 - Core Implementation:
**[Core Module]**
- Authentication
- Session Management
- Request/Response Handling
- Error Handling

##### Key Relationships

- Data flow between components
- Dependencies between modules
- Protocol communications (REST/FlightSQL)

##### Specific Implementation Details

**Configuration Management:**
- DSN Support
- TLS Configuration
- Connection Settings

**Query Execution:**
- Query Processing
- Result Formatting
- Progress Tracking

##### External Integration Points

Connections to:
**[Databend Server]**
- REST API Endpoint
- FlightSQL Endpoint

##### Technical Details

Annotations for:
- Supported protocols (REST, FlightSQL)
- Authentication methods
- Data formats (CSV, TSV, NDJSON, Parquet, XML)
- Configuration options

##### Implementation Notes

- The modular architecture (core, driver, cli, bindings)
- The dual protocol support (REST and FlightSQL)
- The extensive configuration options
- The multiple client interface options

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Clients
        CLI["CLI Interface"]:::cli
        WEB["Web Frontend"]:::frontend
        PY["Python Binding"]:::binding
        NODE["NodeJS Binding"]:::binding
    end

    subgraph "Driver Layer"
        DRIVER["Driver Module"]:::driver
        REST["REST API Client"]:::protocol
        FLIGHT["FlightSQL Client"]:::protocol
    end

    subgraph "Core Implementation"
        CORE["Core Module"]:::core
        AUTH["Authentication"]:::core
        SESS["Session Management"]:::core
        REQ["Request Handling"]:::core
        RESP["Response Handling"]:::core
    end

    subgraph "SQL Implementation"
        SQL["SQL Module"]:::sql
        SCHEMA["Schema Handling"]:::sql
        VALUES["Value Types"]:::sql
        ROWS["Row Processing"]:::sql
        ERRORS["Error Handling"]:::sql
    end

    subgraph "External System"
        DB["Databend Server"]:::external
        DB_REST["REST Endpoint"]:::external
        DB_FLIGHT["FlightSQL Endpoint"]:::external
    end

    CLI --> DRIVER
    WEB --> DRIVER
    PY --> DRIVER
    NODE --> DRIVER

    DRIVER --> REST
    DRIVER --> FLIGHT

    REST --> CORE
    FLIGHT --> CORE

    CORE --> AUTH
    CORE --> SESS
    CORE --> REQ
    CORE --> RESP

    REST --> DB_REST
    FLIGHT --> DB_FLIGHT

    DB_REST --> DB
    DB_FLIGHT --> DB

    DRIVER --> SQL
    SQL --> SCHEMA
    SQL --> VALUES
    SQL --> ROWS
    SQL --> ERRORS

    %% Click Events
    click CLI "https://github.com/databendlabs/bendsql/blob/main/cli/src/main.rs"
    click WEB "https://github.com/databendlabs/bendsql/tree/main/frontend"
    click PY "https://github.com/databendlabs/bendsql/tree/main/bindings/python"
    click NODE "https://github.com/databendlabs/bendsql/tree/main/bindings/nodejs"
    click DRIVER "https://github.com/databendlabs/bendsql/tree/main/driver"
    click REST "https://github.com/databendlabs/bendsql/blob/main/driver/src/rest_api.rs"
    click FLIGHT "https://github.com/databendlabs/bendsql/blob/main/driver/src/flight_sql.rs"
    click CORE "https://github.com/databendlabs/bendsql/tree/main/core"
    click AUTH "https://github.com/databendlabs/bendsql/blob/main/core/src/auth.rs"
    click SESS "https://github.com/databendlabs/bendsql/blob/main/core/src/session.rs"
    click REQ "https://github.com/databendlabs/bendsql/blob/main/core/src/request.rs"
    click RESP "https://github.com/databendlabs/bendsql/blob/main/core/src/response.rs"
    click SQL "https://github.com/databendlabs/bendsql/tree/main/sql"
    click SCHEMA "https://github.com/databendlabs/bendsql/blob/main/sql/src/schema.rs"
    click VALUES "https://github.com/databendlabs/bendsql/blob/main/sql/src/value.rs"
    click ROWS "https://github.com/databendlabs/bendsql/blob/main/sql/src/rows.rs"
    click ERRORS "https://github.com/databendlabs/bendsql/blob/main/sql/src/error.rs"

    %% Styling
    classDef core fill:#2374ab
    classDef driver fill:#048ba8
    classDef cli fill:#0db39e
    classDef frontend fill:#16db93
    classDef binding fill:#83e377
    classDef protocol fill:#b9e769
    classDef sql fill:#efea5a
    classDef external fill:#f1c453

    %% Legend
    subgraph Legend
        L1["Core Components"]:::core
        L2["Driver Layer"]:::driver
        L3["CLI Interface"]:::cli
        L4["Frontend"]:::frontend
        L5["Language Bindings"]:::binding
        L6["Protocols"]:::protocol
        L7["SQL Components"]:::sql
        L8["External Systems"]:::external
    end
```
