# inxo/duckdbm architecture

> Architecture diagram of the GitHub repository inxo/duckdbm, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/inxo/duckdbm
- Repository: https://github.com/inxo/duckdbm

## Overview

Key Components to Include:

##### Core Components
- CLI Interface (Entry Point)
- Migration Manager
- Database Connector
- File System Handler
- Environment Manager
- Macro Processor

##### External Dependencies
- DuckDB Database
- Source Databases (e.g., MySQL for sync operations)
- Environment Files (.env)
- Migration Files

##### Component Details

a. User Interface Layer:
- CLI commands (init, create, apply, rollback, list, sync)
- To Command Handler

b. Processing Layer:
- Migration Manager (central component)
- Macro Processor (for handling {{ENV_VAR}} substitutions)
- Environment Manager (for .env file processing)

c. Storage Layer:
- DuckDB Database
- Migration Files Storage
- External Databases (for sync operations)

##### Specific Elements

a. Tables in DuckDB:
- migrations table
- sync table
- user tables (created by migrations)

b. File System Interactions:
- .env file reading
- SQL migration files
- Macro processing flow

c. External Systems:
- Connection to external databases (MySQL, etc.)
- Environment variable sources

##### Component Interactions

- How CLI commands flow through the system
- How migrations are processed and executed
- How macro substitution occurs
- How database operations are handled
- How sync operations interact with external databases

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "User Interface Layer"
        CLI["CLI Interface"]
        Commands["Command Handler"]
    end

    subgraph "Processing Layer"
        MM["Migration Manager"]
        MP["Macro Processor"]
        EM["Environment Manager"]
    end

    subgraph "Storage Layer"
        DB[(DuckDB)]
        MF[("Migration Files")]
        ExtDB[(External DBs)]
    end

    subgraph "Configuration"
        ENV[".env Files"]
        DC["Container Config"]
    end

    %% Core Flow
    CLI --> Commands
    Commands --> MM
    MM --> MP
    MP --> EM
    EM --> ENV
    MM --> DB
    MM --> MF
    MM -.-> ExtDB

    %% Additional Connections
    MP -.-> ENV
    EM --> DB

    %% Database Tables
    subgraph "DuckDB Tables"
        MT["migrations table"]
        ST["sync table"]
        UT["user tables"]
    end

    DB --- MT
    DB --- ST
    DB --- UT

    %% Styling
    classDef core fill:#2374ab
    classDef storage fill:#2a9d8f
    classDef process fill:#e9c46a
    classDef config fill:#gray

    class CLI,Commands,MM core
    class DB,MF,ExtDB storage
    class MP,EM process
    class ENV,DC config
    class MT,ST,UT storage

    %% Click Events
    click CLI "https://github.com/Inxo/duckdbm/blob/main/src/main.go"
    click MP "https://github.com/Inxo/duckdbm/blob/main/src/process_macros.go"
    click DC "https://github.com/Inxo/duckdbm/tree/main/Dockerfile"

    %% Legend
    subgraph Legend
        L1["Core Components"]:::core
        L2["Storage Systems"]:::storage
        L3["Processing Components"]:::process
        L4["Configuration"]:::config
    end
```
