# headcrab/mssql2file architecture

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

- Interactive diagram: https://gitdiagram.com/headcrab/mssql2file
- Repository: https://github.com/headcrab/mssql2file

## Overview

##### Main Components

a. Core Components:
- Input Layer (Database Connections)
- MSSQL
- MySQL
- ClickHouse

- Processing Layer
- Query Execution
- Data Processing
- Time Period Management

- Export Layer
- Format Processors
- Compression Handlers
- File Writers

b. Supporting Components:
- Configuration Management
- Error Handling
- Command Line Interface

##### Component Relationships

Database Sources → Data Processing → Export Processing → File Destinations

##### Detailed Component Breakdown

A. Input Section:
- Database Connectors (from internal/app)
- Configuration Management (from internal/config)
- Time Period Calculator

B. Processing Section:
- Query Executor
- Data Transformer
- Error Handler (from internal/apperrors)

C. Export Section:
Format Processors (from internal/format):
- JSON Processor
- CSV Processor
- XML Processor

Compression Handlers (from internal/compressor):
- GZip
- LZ4
- None (raw)

File Writers (from internal/file):
- Local File System
- FTP
- SMB

##### Implementation Details

- The modular architecture (visible in the internal/ directory structure)
- The plugin-style format and compression handlers
- The flexible file output system
- Configuration management
- Error handling pathways

##### Core Flow Layer
**Database → Query Execution → Format Processing → Compression → File Output**

##### Component Layer
Internal packages and their relationships:
- app: Main application logic
- config: Configuration management
- format: Data format processors
- compressor: Compression handlers
- file: File system interfaces
- apperrors: Error handling

##### Interface Layer
Interfaces between components:
- Database interfaces
- Format interfaces
- Compression interfaces
- File system interfaces

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Legend
        style Legend fill:#f0f0f0,stroke:#333,stroke-width:2px
        L1[Input Components]:::input
        L2[Processing Components]:::processing
        L3[Export Components]:::export
        L4[Infrastructure Components]:::infrastructure
    end

    subgraph "Input Layer"
        DB_MSSQL[(MSSQL)]:::input
        DB_MySQL[(MySQL)]:::input
        DB_Click[(ClickHouse)]:::input
        Config[Configuration Management]:::input
        CLI[Command Line Interface]:::input
    end

    subgraph "Processing Layer"
        AppLogic[Application Logic]:::processing
        QueryExec[Query Executor]:::processing
        DataProc[Data Processor]:::processing
        TimeCalc[Time Period Calculator]:::processing
        ErrorHandler[Error Handler]:::processing
    end

    subgraph "Format Processing"
        FormatBase[Format Interface]:::export
        JSON[JSON Processor]:::export
        CSV[CSV Processor]:::export
        XML[XML Processor]:::export
    end

    subgraph "Compression Layer"
        CompBase[Compression Interface]:::export
        GZip[GZip Handler]:::export
        LZ4[LZ4 Handler]:::export
        NoComp[No Compression]:::export
    end

    subgraph "Output Layer"
        FileBase[File Interface]:::export
        Local[Local File System]:::export
        FTP[FTP Handler]:::export
        SMB[SMB Handler]:::export
    end

    DB_MSSQL & DB_MySQL & DB_Click --> AppLogic
    CLI --> AppLogic
    Config --> AppLogic
    
    AppLogic --> QueryExec
    QueryExec --> DataProc
    TimeCalc --> DataProc
    
    DataProc --> FormatBase
    FormatBase --> JSON & CSV & XML
    
    JSON & CSV & XML --> CompBase
    CompBase --> GZip & LZ4 & NoComp
    
    GZip & LZ4 & NoComp --> FileBase
    FileBase --> Local & FTP & SMB
    
    ErrorHandler -.-> AppLogic
    
    classDef input fill:#a8d1f0,stroke:#333
    classDef processing fill:#90EE90,stroke:#333
    classDef export fill:#FFB347,stroke:#333
    classDef infrastructure fill:#D3D3D3,stroke:#333

    click Config "https://github.com/Headcrab/mssql2file/blob/master/internal/config/config.go"
    click ErrorHandler "https://github.com/Headcrab/mssql2file/blob/master/internal/apperrors/apperrors.go"
    click AppLogic "https://github.com/Headcrab/mssql2file/blob/master/internal/app/app.go"
    click DataProc "https://github.com/Headcrab/mssql2file/blob/master/internal/exporter/exporter.go"
    click FormatBase "https://github.com/Headcrab/mssql2file/blob/master/internal/format/format.go"
    click JSON "https://github.com/Headcrab/mssql2file/blob/master/internal/format/json.go"
    click CSV "https://github.com/Headcrab/mssql2file/blob/master/internal/format/csv.go"
    click XML "https://github.com/Headcrab/mssql2file/blob/master/internal/format/xml.go"
    click CompBase "https://github.com/Headcrab/mssql2file/blob/master/internal/compressor/compressor.go"
    click GZip "https://github.com/Headcrab/mssql2file/blob/master/internal/compressor/gz.go"
    click LZ4 "https://github.com/Headcrab/mssql2file/blob/master/internal/compressor/lz4.go"
    click NoComp "https://github.com/Headcrab/mssql2file/blob/master/internal/compressor/none.go"
    click FileBase "https://github.com/Headcrab/mssql2file/blob/master/internal/file/file.go"
    click Local "https://github.com/Headcrab/mssql2file/blob/master/internal/file/local.go"
    click FTP "https://github.com/Headcrab/mssql2file/blob/master/internal/file/ftp.go"
    click SMB "https://github.com/Headcrab/mssql2file/blob/master/internal/file/smb.go"
    click CLI "https://github.com/Headcrab/mssql2file/blob/master/cmd/main.go"
    click Config "https://github.com/Headcrab/mssql2file/blob/master/internal/config/mssql2file.cfg"
```
