# jetbrains/exposed architecture

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

- Interactive diagram: https://gitdiagram.com/jetbrains/exposed
- Repository: https://github.com/jetbrains/exposed

## Overview

##### Main Components (Top Level)

**┌─────────────────────────────────────────────────────────────────┐**
- Exposed Framework                        │
- ┬────────────┬────────────────────┬─────────────────┤
- Core     │    DAO     │       DSL          │  Extensions     │
- Module    │   Module   │      Module        │   Modules       │
- ┴────────────┴────────────────────┴─────────────────┘

##### Core Architecture Layers

**┌─────────────────────────────────────────────────────────────────┐**
- Application Layer                          │
- ┤

- Exposed Framework Layer                      │
- ┌──────────┐  ┌──────────┐  ┌──────────┐   ┌──────────────┐  │
- DSL    │  │   DAO    │  │Transaction│   │  Schema      │  │
- Query   │  │  Entity  │  │Management │   │ Management   │  │
- ┘  └──────────┘  └──────────┘   └──────────────┘  │

- ┤
- Database Layer                             │
- ┘

##### Module Dependencies

**┌─────────────────────┐**
- exposed-core      │◄─────────────────┐
- ┘                  │
- ▲                               │

**┌─────────────────────┐    ┌────────────┴────────┐**
- exposed-dao      │    │    exposed-jdbc     │
- ┘    └───────────┬─────────┘
- ▲                             │
- ▼
**┌─────────────────────┐    ┌───────────────────┐**
- Extension Modules  │    │  Database Drivers  │
- ┘    └───────────────────┘

##### Key Components

a. Core Components:
- Table Definitions
- Column Types
- Query Building
- Transaction Management
- Schema Utils

b. DSL Features:
- SQL Expression Builder
- Join Operations
- Where Conditions
- /Order Operations

c. DAO Components:
- Entity Definitions
- Entity ID Management
- References/Relations
- CRUD Operations

d. Extension Support:
- Date/Time Handlers
- JSON Support
- Cryptography
- Spring Integration

##### Database Support Layer

**┌─────────────────────────────────────────────────────────────┐**
- Database Abstraction                      │
- ┬──────────┬───────────┬──────────────┬───────────┤
- H2       │ MySQL    │ PostgreSQL│  SQLServer   │  SQLite   │
- ┴──────────┴───────────┴──────────────┴───────────┘

##### Integration Points

**┌─────────────────────────────────────────────────────────────┐**
- Framework Integration                     │
- ┬────────────────┬──────────────┬─────────────┤
- Spring Boot  │    Ktor        │   Kotlin     │   Java      │
- Starter     │  Integration   │   Coroutines │   Time      │
- ┴────────────────┴──────────────┴─────────────┘

Important Considerations:

##### Data flow
- Application → DSL/DAO → Transaction Manager → Database
- Error handling paths
- Transaction boundaries

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Application Layer"
        App[Application Code]
    end

    subgraph "Exposed Framework Layer"
        Core["Core Module"]:::core
        DAO["DAO Module"]:::dao
        JDBC["JDBC Integration"]:::jdbc
        
        subgraph "Core Components"
            Trans["Transaction Management"]:::core
            Schema["Schema Management"]:::core
            Table["Table Definitions"]:::core
            Column["Column Types"]:::core
        end
        
        subgraph "DAO Components"
            Entity["Entity System"]:::dao
            EntityClass["Entity Class Management"]:::dao
            EntityID["Entity ID Management"]:::dao
        end
        
        subgraph "Database Support"
            PostgreSQL["PostgreSQL Dialect"]:::db
            MySQL["MySQL Dialect"]:::db
            SQLite["SQLite Dialect"]:::db
        end
        
        subgraph "Extensions"
            JSON["JSON Support"]:::ext
            JavaTime["Java Time Support"]:::ext
            KotlinTime["Kotlin DateTime"]:::ext
            Spring["Spring Integration"]:::ext
            Crypt["Cryptography"]:::ext
        end
        
        subgraph "JDBC Components"
            JDBCConn["JDBC Connection"]:::jdbc
            JDBCStmt["JDBC Statement"]:::jdbc
        end
        
        subgraph "Spring Support"
            SpringTrans["Spring Transaction"]:::spring
            SpringBoot["Spring Boot Starter"]:::spring
        end
    end

    subgraph "Database Layer"
        DB[(Database)]
    end

    %% Relationships
    App --> Core
    App --> DAO
    DAO --> Core
    Core --> JDBC
    JDBC --> DB
    
    %% Core relationships
    Core --> Trans
    Core --> Schema
    Core --> Table
    Core --> Column
    
    %% DAO relationships
    DAO --> Entity
    DAO --> EntityClass
    DAO --> EntityID
    
    %% Database dialect relationships
    Core --> PostgreSQL
    Core --> MySQL
    Core --> SQLite
    
    %% JDBC relationships
    JDBC --> JDBCConn
    JDBC --> JDBCStmt
    
    %% Spring relationships
    Spring --> SpringTrans
    Spring --> SpringBoot

    %% Click events
    click Core "https://github.com/JetBrains/Exposed/tree/main/exposed-core/"
    click Trans "https://github.com/JetBrains/Exposed/blob/main/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/Transaction.kt"
    click Schema "https://github.com/JetBrains/Exposed/blob/main/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/Schema.kt"
    click Table "https://github.com/JetBrains/Exposed/blob/main/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/Table.kt"
    click Column "https://github.com/JetBrains/Exposed/blob/main/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/ColumnType.kt"
    click DAO "https://github.com/JetBrains/Exposed/tree/main/exposed-dao/"
    click Entity "https://github.com/JetBrains/Exposed/blob/main/exposed-dao/src/main/kotlin/org/jetbrains/exposed/dao/Entity.kt"
    click EntityClass "https://github.com/JetBrains/Exposed/blob/main/exposed-dao/src/main/kotlin/org/jetbrains/exposed/dao/EntityClass.kt"
    click EntityID "https://github.com/JetBrains/Exposed/blob/main/exposed-dao/src/main/kotlin/org/jetbrains/exposed/dao/id/EntityID.kt"
    click PostgreSQL "https://github.com/JetBrains/Exposed/blob/main/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/vendors/PostgreSQL.kt"
    click MySQL "https://github.com/JetBrains/Exposed/blob/main/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/vendors/MysqlDialect.kt"
    click SQLite "https://github.com/JetBrains/Exposed/blob/main/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/vendors/SQLiteDialect.kt"
    click JSON "https://github.com/JetBrains/Exposed/tree/main/exposed-json/"
    click JavaTime "https://github.com/JetBrains/Exposed/tree/main/exposed-java-time/"
    click KotlinTime "https://github.com/JetBrains/Exposed/tree/main/exposed-kotlin-datetime/"
    click Spring "https://github.com/JetBrains/Exposed/tree/main/exposed-spring-boot-starter/"
    click Crypt "https://github.com/JetBrains/Exposed/tree/main/exposed-crypt/"
    click JDBC "https://github.com/JetBrains/Exposed/tree/main/exposed-jdbc/"
    click JDBCConn "https://github.com/JetBrains/Exposed/blob/main/exposed-jdbc/src/main/kotlin/org/jetbrains/exposed/sql/statements/jdbc/JdbcConnectionImpl.kt"
    click JDBCStmt "https://github.com/JetBrains/Exposed/blob/main/exposed-jdbc/src/main/kotlin/org/jetbrains/exposed/sql/statements/jdbc/JdbcPreparedStatementImpl.kt"
    click SpringTrans "https://github.com/JetBrains/Exposed/blob/main/spring-transaction/src/main/kotlin/org/jetbrains/exposed/spring/SpringTransactionManager.kt"
    click SpringBoot "https://github.com/JetBrains/Exposed/blob/main/exposed-spring-boot-starter/src/main/kotlin/org/jetbrains/exposed/spring/autoconfigure/ExposedAutoConfiguration.kt"

    %% Styles
    classDef core fill:#2196F3,stroke:#1565C0,color:white
    classDef dao fill:#4CAF50,stroke:#2E7D32,color:white
    classDef jdbc fill:#FF9800,stroke:#EF6C00,color:white
    classDef db fill:#9C27B0,stroke:#6A1B9A,color:white
    classDef ext fill:#FF5722,stroke:#D84315,color:white
    classDef spring fill:#795548,stroke:#4E342E,color:white
```
