# measproem/diesel_async architecture

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

- Interactive diagram: https://gitdiagram.com/measproem/diesel_async
- Repository: https://github.com/measproem/diesel_async

## Overview

##### Main Components

a) Core Components:
- Async Connection Layer
- Query Execution Engine
- Connection Pooling Adapters
- Database-specific Implementations
- Transaction Management
- Statement Cache

b) External Integration Points:
- Diesel ORM Core
- Database Backends (PostgreSQL, MySQL)
- Connection Pool Libraries (deadpool, bb8, mobc)
- TLS/Security Layer

**Top Layer: Application Code**

**Middle Layer: diesel-async Interface**

**Bottom Layer: Database Connections**

##### Specific Component Relationships

a) Core Flow:
**Application Code → AsyncConnection → Database Backend**

b) Connection Pooling:
**Pool Manager → Connection Wrapper → Async Connection → Database**

##### Detailed Component Breakdown

**Core Components:**
- AsyncConnectionWrapper
- RunQueryDsl
- TransactionManager
- StatementCache

**Database-Specific:**
- PostgreSQL Implementation
- MySQL Implementation

**Connection Pooling:**
- BB8 Adapter
- Deadpool Adapter
- Mobc Adapter

##### Important Relationships to Highlight

- How the async connection wrapper interfaces with the synchronous Diesel core
- Transaction flow through the transaction manager
- Demonstrate how connection pooling integrates with the async connections
- Streaming query pathway

##### Implementation Details

Use these symbols:
- Rectangles: Main components
- Diamonds: Decision points (like transaction boundaries)
- Double lines: Interface boundaries

##### Additional Notes

- Notes about feature flags and their effects on the architecture
- Error handling pathways
- Async boundaries clearly

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles
    classDef core fill:#b3d1ff,stroke:#4d88ff
    classDef db fill:#90EE90,stroke:#006400
    classDef pool fill:#FFB366,stroke:#CC5500
    classDef external fill:#E6E6FA,stroke:#483D8B
    classDef error fill:#FFB3B3,stroke:#CC0000

    %% Legend
    subgraph Legend
        L1[Core Components]:::core
        L2[Database Components]:::db
        L3[Connection Pooling]:::pool
        L4[External Interfaces]:::external
        L5[Error Handling]:::error
    end

    %% Main Application Layer
    subgraph Application
        APP[Application Code]
    end

    %% Core diesel-async Layer
    subgraph "Core diesel-async"
        ACW[Async Connection Wrapper]:::core
        SC[Statement Cache]:::core
        TM[Transaction Manager]:::core
        QE[Query Execution Engine]:::core
        SCW[Sync Connection Wrapper]:::core
    end

    %% Connection Pooling Layer
    subgraph "Connection Pooling"
        CP[Connection Pool Manager]:::pool
        BB8[BB8 Adapter]:::pool
        DP[Deadpool Adapter]:::pool
        MB[Mobc Adapter]:::pool
    end

    %% Database Implementation Layer
    subgraph "Database Implementations"
        PG[PostgreSQL Implementation]:::db
        MY[MySQL Implementation]:::db
        PGTB[PG Transaction Builder]:::db
        PGS[PG Serialization]:::db
        MYS[MySQL Serialization]:::db
    end

    %% Error Handling
    subgraph "Error Handling"
        PGE[PostgreSQL Error Helper]:::error
        MYE[MySQL Error Helper]:::error
    end

    %% External Components
    DORM[Diesel ORM]:::external
    DB[(Database)]:::external

    %% Relationships
    APP --> ACW
    ACW --> SC
    ACW --> TM
    ACW --> QE
    ACW --> SCW
    SCW --> DORM
    
    CP --> |Pool Management| ACW
    BB8 --> CP
    DP --> CP
    MB --> CP
    
    ACW --> PG
    ACW --> MY
    PG --> PGTB
    PG --> PGS
    MY --> MYS
    
    PG --> PGE
    MY --> MYE
    
    PG --> DB
    MY --> DB

    %% Click Events
    click ACW "https://github.com/measproem/diesel_async/blob/main/src/async_connection_wrapper.rs"
    click SC "https://github.com/measproem/diesel_async/blob/main/src/stmt_cache.rs"
    click TM "https://github.com/measproem/diesel_async/blob/main/src/transaction_manager.rs"
    click QE "https://github.com/measproem/diesel_async/blob/main/src/run_query_dsl/mod.rs"
    click PG "https://github.com/measproem/diesel_async/blob/main/src/pg/mod.rs"
    click MY "https://github.com/measproem/diesel_async/blob/main/src/mysql/mod.rs"
    click CP "https://github.com/measproem/diesel_async/blob/main/src/pooled_connection/mod.rs"
    click BB8 "https://github.com/measproem/diesel_async/blob/main/src/pooled_connection/bb8.rs"
    click DP "https://github.com/measproem/diesel_async/blob/main/src/pooled_connection/deadpool.rs"
    click MB "https://github.com/measproem/diesel_async/blob/main/src/pooled_connection/mobc.rs"
    click SCW "https://github.com/measproem/diesel_async/blob/main/src/sync_connection_wrapper/mod.rs"
    click PGTB "https://github.com/measproem/diesel_async/blob/main/src/pg/transaction_builder.rs"
    click PGS "https://github.com/measproem/diesel_async/blob/main/src/pg/serialize.rs"
    click MYS "https://github.com/measproem/diesel_async/blob/main/src/mysql/serialize.rs"
    click PGE "https://github.com/measproem/diesel_async/blob/main/src/pg/error_helper.rs"
    click MYE "https://github.com/measproem/diesel_async/blob/main/src/mysql/error_helper.rs"
```
