# m1h1r-a/ddl-migration-conversion architecture

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

- Interactive diagram: https://gitdiagram.com/m1h1r-a/ddl-migration-conversion
- Repository: https://github.com/m1h1r-a/ddl-migration-conversion

## Overview

##### Project Type and Purpose
- This is a command‐line Python-based DDL (Data Definition Language) migration/conversion tool.
- Purpose: extract DDL statements from a source database (MySQL, Postgres, or Snowflake), convert them to the target dialect, then import the converted DDL into the destination database.

##### File Structure
- Top‐level:
- src/ – application source
- requirements.txt – Python dependencies
- README.md – high‐level description
- src/config/
- db.ini – database connection settings
- src/extractors/ – strategies to pull DDL from each source DB
- mysql_extractor.py
- postgres_extractor.py
- snowflake_extractor.py
- src/converters/ – translation logic between dialects
- to_mysql.py
- to_postgres.py
- to_snowflake.py
- src/importers/ – strategies to apply DDL to each target DB
- mysql_importer.py
- postgres_importer.py
- snowflake_importer.py
- src/main.py – orchestrates the extract→convert→import workflow

##### Insights from README
- Workflow is three‐step: Extraction → Conversion → Import
- Supports multiple dialects, designed to be extended for new clients/databases.

a. Main Components
1. CLI/Entry Point (main.py)
2. Configuration Module (db.ini + config loader)
3. Extraction Layer (Extractors for each source)
4. Conversion Layer (Converters for each target dialect)
5. Import Layer (Importers for each destination)
6. Logging & Error Handling
7. External Systems: Source DB and Target DB instances
b. Relationships & Data Flow
- The CLI reads command‐line args and loads configuration.
- Based on source type, it invokes the appropriate Extractor to fetch DDL.
- Extracted DDL is passed to the Converter module, which selects the correct dialect transformer.
- Converted DDL is then fed to the Importer module which applies it to the target DB.
- Throughout, a Logging component records progress and errors (to ddl_migration.log).
c. Architectural Patterns & Principles
- Strategy Pattern: each extractor/converter/importer implements a common interface for polymorphic selection.
- Layered Architecture: clear separation of concerns (Extract → Convert → Import).
- Configuration‐Driven: supports new DB types by adding new modules and updating config.
d. Key Technologies & Libraries
- Python 3.x
- ConfigParser (for db.ini)
- DB client libraries (mysql‐connector, psycopg2, snowflake‐connector)
- Logging module

##### Key Details to Capture
- Module interfaces (e.g., IExtractor, IConverter, IImporter) if present
- Configuration-driven dispatch logic
- Error handling path (e.g., exception flow to logger)
- Extensibility: e.g., “Add new extractor here” annotation

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Entry Point
    Main["CLI (main.py)"]:::io

    %% Configuration & Logging
    subgraph "Configuration & Logging"
        Config["Config Loader (db.ini)"]:::config
        Logger["Logger & Error Handling"]:::config
    end

    %% Processing Layers
    subgraph "Extraction Layer"
        MySQLExtractor["MySQLExtractor"]:::process
        PostgresExtractor["PostgresExtractor"]:::process
        SnowflakeExtractor["SnowflakeExtractor"]:::process
    end

    subgraph "Conversion Layer"
        ToMySQL["ToMySQL Converter"]:::process
        ToPostgres["ToPostgres Converter"]:::process
        ToSnowflake["ToSnowflake Converter"]:::process
    end

    subgraph "Import Layer"
        MySQLImporter["MySQLImporter"]:::process
        PostgresImporter["PostgresImporter"]:::process
        SnowflakeImporter["SnowflakeImporter"]:::process
    end

    %% External Systems
    SourceDB["Source Databases"]:::io
    TargetDB["Target Databases"]:::io

    %% Documentation & Dependencies
    subgraph "Docs & Dependencies"
        Requirements["Requirements"]:::docs
        RequirementsSrc["Requirements (src)"]:::docs
        README["Project README"]:::docs
    end

    %% Data Flow
    Main --> Config
    Main --> Requirements
    Main --> README

    Config --> MySQLExtractor
    Config --> PostgresExtractor
    Config --> SnowflakeExtractor

    SourceDB --> MySQLExtractor
    SourceDB --> PostgresExtractor
    SourceDB --> SnowflakeExtractor

    MySQLExtractor --> ToMySQL
    PostgresExtractor --> ToPostgres
    SnowflakeExtractor --> ToSnowflake

    ToMySQL --> MySQLImporter
    ToPostgres --> PostgresImporter
    ToSnowflake --> SnowflakeImporter

    MySQLImporter --> TargetDB
    PostgresImporter --> TargetDB
    SnowflakeImporter --> TargetDB

    %% Logging flows
    Config --> Logger
    MySQLExtractor --> Logger
    PostgresExtractor --> Logger
    SnowflakeExtractor --> Logger
    ToMySQL --> Logger
    ToPostgres --> Logger
    ToSnowflake --> Logger
    MySQLImporter --> Logger
    PostgresImporter --> Logger
    SnowflakeImporter --> Logger

    %% Click Events
    click Main "https://github.com/m1h1r-a/ddl-migration-conversion/blob/main/src/main.py"
    click Config "https://github.com/m1h1r-a/ddl-migration-conversion/blob/main/src/config/db.ini"
    click MySQLExtractor "https://github.com/m1h1r-a/ddl-migration-conversion/blob/main/src/extractors/mysql_extractor.py"
    click PostgresExtractor "https://github.com/m1h1r-a/ddl-migration-conversion/blob/main/src/extractors/postgres_extractor.py"
    click SnowflakeExtractor "https://github.com/m1h1r-a/ddl-migration-conversion/blob/main/src/extractors/snowflake_extractor.py"
    click ToMySQL "https://github.com/m1h1r-a/ddl-migration-conversion/blob/main/src/converters/to_mysql.py"
    click ToPostgres "https://github.com/m1h1r-a/ddl-migration-conversion/blob/main/src/converters/to_postgres.py"
    click ToSnowflake "https://github.com/m1h1r-a/ddl-migration-conversion/blob/main/src/converters/to_snowflake.py"
    click MySQLImporter "https://github.com/m1h1r-a/ddl-migration-conversion/blob/main/src/importers/mysql_importer.py"
    click PostgresImporter "https://github.com/m1h1r-a/ddl-migration-conversion/blob/main/src/importers/postgres_importer.py"
    click SnowflakeImporter "https://github.com/m1h1r-a/ddl-migration-conversion/blob/main/src/importers/snowflake_importer.py"
    click Logger "https://github.com/m1h1r-a/ddl-migration-conversion/blob/main/src/ddl_migration.log"
    click Requirements "https://github.com/m1h1r-a/ddl-migration-conversion/blob/main/requirements.txt"
    click RequirementsSrc "https://github.com/m1h1r-a/ddl-migration-conversion/blob/main/src/requirements.txt"
    click README "https://github.com/m1h1r-a/ddl-migration-conversion/blob/main/README.md"

    %% Styles
    classDef io fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef process fill:#90EE90,stroke:#333,stroke-width:1px
    classDef config fill:#D3D3D3,stroke:#333,stroke-width:1px
    classDef docs fill:#FFFACD,stroke:#333,stroke-width:1px
```
