# oleoneto/dm architecture

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

- Interactive diagram: https://gitdiagram.com/oleoneto/dm
- Repository: https://github.com/oleoneto/dm

## Overview

##### Main Components

a) Core Components:
- CLI Interface
- API Server
- Migration Engine
- Storage Layer
- Configuration Manager

b) External Components:
- Database Systems (PostgreSQL)
- File System (Migration Files)

##### Component Relationships

**User Interactions -> Interface Layer**
- ↓
**Business Logic Layer**
- ↓
**Data Layer -> Database/File System**

##### Specific Implementation Details

- Rectangles: Core components
- Folders: File system components
- Hexagons: External interfaces
- Diamonds: Decision points in migration flow

- Blue: Interface components
- Green: Processing components
- Yellow: Storage components
- Gray: External systems

##### Key Flows to Highlight

a) Migration Flow:
**CLI/API Request -> Configuration Loading -> Migration Engine ->**
**Database Adapter -> Migration Execution -> State Update**

b) Validation Flow:
**Migration File -> Validator -> Schema Verification ->**
**Duplicate Detection -> Validation Result**

##### Important Architectural Elements

Specific components based on the file structure:
- Controllers (/api/controllers)
- Middleware (/api/middleware)
- Command handlers (/cli/cmd)
- Migration engine (/migrations)
- Store adapters (/stores)

##### Additional Details

Annotations for:
- Default ports (3809)
- Supported database types (PostgreSQL)
- File formats (YAML)
- Configuration options
- CORS settings
- API versions

##### Technical Specifications

Technical aspects:
- Go-based implementation
- RESTful API architecture
- Swagger documentation integration
- Environment variable configuration
- Docker support

Remember to emphasize the separation between the command-line interface and the API server, while showing how they share the same underlying migration engine and database interactions.

This system design should clearly illustrate how the tool manages both the migration files and their execution state, showing the flow from file generation through validation and execution to state tracking in the database.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Interface
        CLI["CLI Interface"]
        API["API Server"]
        SWAG["Swagger Documentation"]
    end

    subgraph Business
        ME["Migration Engine"]
        MR["Migration Runner"]
        VS["Validation System"]
        MSM["Migration Store Manager"]
        ML["Migration List Handler"]
        SQL["SQL Operations"]
        MCL["Migration Core Logic"]
        LOG["Logger"]
    end

    subgraph Data
        PG[("PostgreSQL Adapter")]
        MF[("Migration Files")]
        MST[("Migration State Table")]
    end

    subgraph Config
        CM["Configuration Manager"]
        CORS["CORS Settings"]
        ENV["Environment Variables"]
    end

    %% Relationships
    CLI --> ME
    API --> ME
    SWAG --> API
    
    ME --> MR
    ME --> VS
    ME --> MSM
    ME --> ML
    ME --> SQL
    ME --> MCL
    
    MR --> LOG
    VS --> LOG
    MSM --> LOG
    
    MSM --> PG
    MSM --> MF
    MSM --> MST
    
    ME --> CM
    API --> CM

    %% Click Events
    click CLI "https://github.com/oleoneto/dm/tree/main/cli/cmd/"
    click API "https://github.com/oleoneto/dm/blob/main/api/server/server.go"
    click SWAG "https://github.com/oleoneto/dm/blob/main/api/server/public/swagger.yaml"
    click ME "https://github.com/oleoneto/dm/blob/main/migrations/engine.go"
    click MR "https://github.com/oleoneto/dm/blob/main/migrations/runner.go"
    click VS "https://github.com/oleoneto/dm/blob/main/cli/cmd/validate.go"
    click MSM "https://github.com/oleoneto/dm/blob/main/migrations/store.go"
    click PG "https://github.com/oleoneto/dm/blob/main/stores/postgresql.go"
    click CM "https://github.com/oleoneto/dm/tree/main/config/"
    click MCL "https://github.com/oleoneto/dm/blob/main/migrations/migration.go"
    click ML "https://github.com/oleoneto/dm/blob/main/migrations/migration_list.go"
    click SQL "https://github.com/oleoneto/dm/blob/main/migrations/sql.go"
    click LOG "https://github.com/oleoneto/dm/blob/main/logger/logger.go"

    %% Styling
    classDef interface fill:#2374AB
    classDef business fill:#45B7D1
    classDef data fill:#F7A072
    classDef config fill:#D8D8D8
    
    class CLI,API,SWAG interface
    class ME,MR,VS,MSM,ML,SQL,MCL,LOG business
    class PG,MF,MST data
    class CM,CORS,ENV config

    %% Legend
    subgraph Legend
        L1["Interface Components"]:::interface
        L2["Business Logic"]:::business
        L3["Data Storage"]:::data
        L4["Configuration"]:::config
    end
```
