# kysely-org/kysely architecture

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

- Interactive diagram: https://gitdiagram.com/kysely-org/kysely
- Repository: https://github.com/kysely-org/kysely

## Overview

##### Main Components

a. Core Query Building Layer:
- QueryBuilder components (found in src/query-builder/)
- To the Expression Builder system (src/expression/)

b. Dialect Layer:
- This as a separate layer below the core
- Four supported dialects (PostgreSQL, MySQL, SQLite, MSSQL)
- Dialect-specific adapters and query compilers

c. Driver Layer:
- Connection management components
- Database connection interfaces

d. Plugin System:
- This as a side component
- Built-in plugins (CamelCase, DeduplicateJoins, etc.)
- Extension points

##### Component Relationships

**[Query Building Interface]**
- ↓
**[Operation Node Layer]**
- ↓
**[Query Compiler]**
- ↓
**[Dialect Adapter]**
- ↓
**[Database Driver]**

##### Detailed Elements

a. Query Building Layer:
**┌─ Query Building Interface ─┐**
- SelectQueryBuilder       │
- InsertQueryBuilder      │
- UpdateQueryBuilder      │
- DeleteQueryBuilder      │
- MergeQueryBuilder       │
- ┘

b. Operation Node System:
**┌─ Operation Nodes ─────────┐**
- SelectNode             │
- WhereNode             │
- JoinNode              │
- etc.                  │
- ┘

c. Dialect Support:
**┌─ Dialect Layer ──────────┐**
- ┌─────┐ ┌─────┐ ┌─────┐ │
- PG  │ │MySQL│ │MSSQL│ │
- ┘ └─────┘ └─────┘ │
- ┘

##### Special Features to Highlight

- Type Safety System
- Migration System
- Plugin Architecture
- Runtime Environment Support

- → Data Flow             │
- ⇢ Type Information     │
- ⚡ Async Boundary       │
- 🔌 Plugin Point         │
- ┘

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Core["Core Query Building Layer"]
        QB["Query Builders"]
        EXP["Expression System"]
        ON["Operation Nodes"]
        QB --> ON
        EXP --> ON
    end

    subgraph Compilation["Query Compilation"]
        QC["Query Compiler"]
        DQC["Default Query Compiler"]
        QC --> DQC
    end

    subgraph Dialects["Dialect Layer"]
        DBase["Dialect Base"]
        PG["PostgreSQL"]
        MySQL["MySQL"]
        SQLite["SQLite"]
        MSSQL["MSSQL"]
        DBase --> PG & MySQL & SQLite & MSSQL
    end

    subgraph Drivers["Driver Layer"]
        DI["Driver Interface"]
        CM["Connection Management"]
        CP["Connection Provider"]
        DI --> CM
        CM --> CP
    end

    subgraph Plugins["Plugin System"]
        PI["Plugin Interface"]
        CCP["CamelCase Plugin"]
        DJP["DeduplicateJoins Plugin"]
        PJP["ParseJsonResults Plugin"]
        PI --> CCP & DJP & PJP
    end

    subgraph Migration["Migration System"]
        MIG["Migrator"]
        FMP["File Migration Provider"]
        MIG --> FMP
    end

    Core --> Compilation
    Compilation --> Dialects
    Dialects --> Drivers
    Plugins --> Core
    Migration --> Drivers

    classDef core fill:#blue,stroke:#333,stroke-width:2px
    classDef dialect fill:#green,stroke:#333,stroke-width:2px
    classDef driver fill:#orange,stroke:#333,stroke-width:2px
    classDef plugin fill:#purple,stroke:#333,stroke-width:2px
    classDef migration fill:#gray,stroke:#333,stroke-width:2px

    class QB,EXP,ON core
    class DBase,PG,MySQL,SQLite,MSSQL dialect
    class DI,CM,CP driver
    class PI,CCP,DJP,PJP plugin
    class MIG,FMP migration

    click QB "https://github.com/kysely-org/kysely/tree/master/src/query-builder/"
    click EXP "https://github.com/kysely-org/kysely/tree/master/src/expression/"
    click ON "https://github.com/kysely-org/kysely/tree/master/src/operation-node/"
    click DBase "https://github.com/kysely-org/kysely/blob/master/src/dialect/dialect.ts"
    click PG "https://github.com/kysely-org/kysely/tree/master/src/dialect/postgres/"
    click MySQL "https://github.com/kysely-org/kysely/tree/master/src/dialect/mysql/"
    click SQLite "https://github.com/kysely-org/kysely/tree/master/src/dialect/sqlite/"
    click MSSQL "https://github.com/kysely-org/kysely/tree/master/src/dialect/mssql/"
    click DI "https://github.com/kysely-org/kysely/blob/master/src/driver/driver.ts"
    click CM "https://github.com/kysely-org/kysely/blob/master/src/driver/database-connection.ts"
    click CP "https://github.com/kysely-org/kysely/blob/master/src/driver/connection-provider.ts"
    click PI "https://github.com/kysely-org/kysely/blob/master/src/plugin/kysely-plugin.ts"
    click CCP "https://github.com/kysely-org/kysely/tree/master/src/plugin/camel-case/"
    click DJP "https://github.com/kysely-org/kysely/tree/master/src/plugin/deduplicate-joins/"
    click PJP "https://github.com/kysely-org/kysely/tree/master/src/plugin/parse-json-results/"
    click QC "https://github.com/kysely-org/kysely/blob/master/src/query-compiler/query-compiler.ts"
    click DQC "https://github.com/kysely-org/kysely/blob/master/src/query-compiler/default-query-compiler.ts"
    click MIG "https://github.com/kysely-org/kysely/blob/master/src/migration/migrator.ts"
    click FMP "https://github.com/kysely-org/kysely/blob/master/src/migration/file-migration-provider.ts"
```
