# go-mysql-org/go-mysql architecture

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

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

## Overview

##### Main Components Identification

The system should be divided into these major components:

a. Core Protocol Components:
- Client Module
- Server Module
- Replication Module
- Canal Module
- MySQL Protocol Implementation

b. Supporting Components:
- Driver Implementation
- Utility Services
- Authentication Handlers
- Compression Services

**┌─────────────────────────────────────────────────────────┐**
- Client Applications                    │
- ┘
- ↓
**┌─────────────────────────────────────────────────────────┐**
- Public API Layer                      │
- ┬───────────┬──────────────┬─────────────────┤
- Client   │  Server   │ Replication  │     Canal       │
- Module   │  Module   │   Module     │     Module      │
- ┴───────────┴──────────────┴─────────────────┘
- ↓
**┌─────────────────────────────────────────────────────────┐**
- MySQL Protocol Implementation              │
- ┬───────────┬──────────────┬─────────────────┤
- Packet   │   Auth    │    GTID      │  Binlog Parser  │
- Handling  │ Handling  │   Support    │                 │
- ┴───────────┴──────────────┴─────────────────┘
- ↓
**┌─────────────────────────────────────────────────────────┐**
- Support Services                        │
- ┬───────────┬──────────────┬─────────────────┤
- Connection│   Schema  │ Compression  │     Utils        │
- Pool    │  Handler  │   Service    │                 │
- ┴───────────┴──────────────┴─────────────────┘

##### Specific Implementation Details

Key architectural elements:
- Connection handling (client/conn.go)
- Authentication flow (server/auth.go)
- Replication streaming (replication/binlogstreamer.go)
- Canal event handling (canal/handler.go)

##### Technical Details

Support for:
- Multiple MySQL versions (5.5.x to 8.0.x)
- Different authentication methods
- Various binlog formats
- Connection pooling capabilities

##### Integration Points

Interfaces with:
- External MySQL servers
- Client applications
- Monitoring systems
- Other data systems (Redis, Elasticsearch)

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Client Applications"
        CA["External Client Apps"]
        CMD["Command Line Tools"]:::cmd
    end

    subgraph "Public API Layer"
        CM["Client Module"]:::client
        SM["Server Module"]:::server
        RM["Replication Module"]:::replication
        CNM["Canal Module"]:::canal
    end

    subgraph "MySQL Protocol Implementation"
        PH["Packet Handling"]:::packet
        AH["Auth Handling"]:::auth
        GS["GTID Support"]:::mysql
        BP["Binlog Parser"]:::binlog
    end

    subgraph "Support Services"
        CP["Connection Pool"]:::pool
        SH["Schema Handler"]:::schema
        CS["Compression Service"]:::compress
        UT["Utils"]:::utils
    end

    %% Client Applications to Public API
    CA --> CM
    CA --> SM
    CMD --> CM
    CMD --> RM
    CMD --> CNM

    %% Public API Layer Dependencies
    CM --> PH
    CM --> AH
    SM --> PH
    SM --> AH
    RM --> BP
    RM --> GS
    CNM --> RM
    CNM --> SH

    %% Protocol Implementation Dependencies
    PH --> CP
    PH --> CS
    BP --> UT
    GS --> UT

    %% Support Service Interactions
    CP --> UT
    SH --> UT
    CS --> UT

    %% Styling
    classDef client fill:#90EE90
    classDef server fill:#90EE90
    classDef replication fill:#90EE90
    classDef canal fill:#90EE90
    classDef mysql fill:#ADD8E6
    classDef packet fill:#ADD8E6
    classDef auth fill:#ADD8E6
    classDef binlog fill:#ADD8E6
    classDef pool fill:#FFFFE0
    classDef schema fill:#FFFFE0
    classDef compress fill:#FFFFE0
    classDef utils fill:#D3D3D3
    classDef cmd fill:#FFA07A

    %% Click Events
    click CM "https://github.com/go-mysql-org/go-mysql/tree/master/client"
    click SM "https://github.com/go-mysql-org/go-mysql/tree/master/server"
    click RM "https://github.com/go-mysql-org/go-mysql/tree/master/replication"
    click CNM "https://github.com/go-mysql-org/go-mysql/tree/master/canal"
    click PH "https://github.com/go-mysql-org/go-mysql/tree/master/packet"
    click GS "https://github.com/go-mysql-org/go-mysql/tree/master/mysql"
    click CP "https://github.com/go-mysql-org/go-mysql/blob/master/client/pool.go"
    click SH "https://github.com/go-mysql-org/go-mysql/tree/master/schema"
    click CS "https://github.com/go-mysql-org/go-mysql/tree/master/compress"
    click UT "https://github.com/go-mysql-org/go-mysql/tree/master/utils"
    click CMD "https://github.com/go-mysql-org/go-mysql/tree/master/cmd"

    %% Legend
    subgraph Legend
        L1["Public API Components"]:::client
        L2["Protocol Components"]:::mysql
        L3["Support Services"]:::pool
        L4["Utility Components"]:::utils
        L5["Command Line Tools"]:::cmd
    end
```
