# rom-rb/rom-sql architecture

> Architecture diagram of the GitHub repository rom-rb/rom-sql, 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/rom-rb/rom-sql
- Repository: https://github.com/rom-rb/rom-sql

## Overview

##### Main Components Identification

The system should be represented with these key components:

a) Core Components:
- Gateway Layer (SQL Connection Handler)
- Relations Layer
- Commands Layer
- Schema Layer
- Migration System
- Plugin System

b) Database Support:
- PostgreSQL Extensions
- MySQL Extensions
- SQLite Extensions

**Top Layer: Application Interface**

**Middle Layers:**
- Relations System
- Reading Operations
- Writing Operations

- Command System
- Create Commands
- Update Commands
- Delete Commands

- Schema System
- Attribute Management
- Index Management
- Type System

**Bottom Layer: Gateway (Database Connections)**

##### Key Relationships to Highlight

- Demonstrate how associations (many-to-many, one-to-many, etc.) interact with relations
- Migration system's interaction with the schema layer

##### Implementation Details

- Association Types (many_to_many, one_to_many, etc.)
- Command Operations (create, update, delete)
- Schema Operations (inferring, attributes, indexes)
- Transaction Support
- Query Interface

**┌─────────────────────────────────────────────┐**
- Public Interface               │
- ┤

- Relations & Commands             │

- ┤
- Schema & Types                 │
- ┤
- Database Adapters                │
- ┘

##### Additional Notes

- Keep the focus on the SQL-specific components rather than the general ROM architecture
- Extensibility points for different databases
- How the plugin system integrates with the core components
- Migration system's relationship with the schema management

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Public Interface"
        API[ROM SQL Interface]:::interface
    end

    subgraph "Relations & Commands"
        Relations["Relations System"]:::core
        click Relations "https://github.com/rom-rb/rom-sql/blob/main/lib/rom/sql/relation.rb"
        
        subgraph "Relations Operations"
            Reading["Reading Operations"]:::operation
            Writing["Writing Operations"]:::operation
            click Reading "https://github.com/rom-rb/rom-sql/blob/main/lib/rom/sql/relation/reading.rb"
            click Writing "https://github.com/rom-rb/rom-sql/blob/main/lib/rom/sql/relation/writing.rb"
        end

        subgraph "Commands"
            CreateCmd["Create"]:::command
            UpdateCmd["Update"]:::command
            DeleteCmd["Delete"]:::command
            click CreateCmd "https://github.com/rom-rb/rom-sql/blob/main/lib/rom/sql/commands/create.rb"
            click UpdateCmd "https://github.com/rom-rb/rom-sql/blob/main/lib/rom/sql/commands/update.rb"
            click DeleteCmd "https://github.com/rom-rb/rom-sql/blob/main/lib/rom/sql/commands/delete.rb"
        end
    end

    subgraph "Schema & Types"
        Schema["Schema Management"]:::core
        click Schema "https://github.com/rom-rb/rom-sql/blob/main/lib/rom/sql/schema.rb"
        
        TypeSystem["Type System"]:::core
        click TypeSystem "https://github.com/rom-rb/rom-sql/blob/main/lib/rom/sql/types.rb"
        
        AttributeMgmt["Attribute Management"]:::schema
        click AttributeMgmt "https://github.com/rom-rb/rom-sql/blob/main/lib/rom/sql/schema/attributes_inferrer.rb"
        
        IndexMgmt["Index Management"]:::schema
    end

    subgraph "Plugins & Extensions"
        PluginSystem["Plugin System"]:::plugin
        Associates["Associates Plugin"]:::plugin
        Pagination["Pagination Plugin"]:::plugin
        Nullify["Nullify Plugin"]:::plugin
        click Associates "https://github.com/rom-rb/rom-sql/blob/main/lib/rom/sql/plugin/associates.rb"
        click Pagination "https://github.com/rom-rb/rom-sql/blob/main/lib/rom/sql/plugin/pagination.rb"
        click Nullify "https://github.com/rom-rb/rom-sql/blob/main/lib/rom/sql/plugin/nullify.rb"
    end

    subgraph "Associations"
        ManyToMany["Many To Many"]:::association
        OneToMany["One To Many"]:::association
        ManyToOne["Many To One"]:::association
        click ManyToMany "https://github.com/rom-rb/rom-sql/blob/main/lib/rom/sql/associations/many_to_many.rb"
        click OneToMany "https://github.com/rom-rb/rom-sql/blob/main/lib/rom/sql/associations/one_to_many.rb"
        click ManyToOne "https://github.com/rom-rb/rom-sql/blob/main/lib/rom/sql/associations/many_to_one.rb"
    end

    subgraph "Migration System"
        Migrator["Migrator"]:::migration
        MigrationRunner["Migration Runner"]:::migration
        click Migrator "https://github.com/rom-rb/rom-sql/blob/main/lib/rom/sql/migration/migrator.rb"
        click MigrationRunner "https://github.com/rom-rb/rom-sql/blob/main/lib/rom/sql/migration/runner.rb"
    end

    subgraph "Database Layer"
        Gateway["Gateway"]:::gateway
        click Gateway "https://github.com/rom-rb/rom-sql/blob/main/lib/rom/sql/gateway.rb"
        
        PostgreSQL["PostgreSQL"]:::database
        MySQL["MySQL"]:::database
        SQLite["SQLite"]:::database
        click PostgreSQL "https://github.com/rom-rb/rom-sql/tree/main/lib/rom/sql/extensions/postgres/"
        click MySQL "https://github.com/rom-rb/rom-sql/tree/main/lib/rom/sql/extensions/mysql/"
        click SQLite "https://github.com/rom-rb/rom-sql/tree/main/lib/rom/sql/extensions/sqlite/"
    end

    %% Relationships
    API --> Relations
    API --> Schema
    Relations --> Reading & Writing
    Relations --> CreateCmd & UpdateCmd & DeleteCmd
    Schema --> AttributeMgmt
    Schema --> IndexMgmt
    Schema --> TypeSystem
    Relations --> ManyToMany & OneToMany & ManyToOne
    Gateway --> PostgreSQL & MySQL & SQLite
    Migrator --> Schema
    MigrationRunner --> Gateway
    PluginSystem --> Associates & Pagination & Nullify

    %% Styles
    classDef interface fill:#f9f,stroke:#333,stroke-width:2px
    classDef core fill:#bbf,stroke:#333,stroke-width:2px
    classDef operation fill:#ddf,stroke:#333
    classDef command fill:#fdd,stroke:#333
    classDef schema fill:#dfd,stroke:#333
    classDef plugin fill:#f8f,stroke:#333
    classDef association fill:#ffd,stroke:#333
    classDef migration fill:#ff9,stroke:#333
    classDef gateway fill:#9cf,stroke:#333
    classDef database fill:#fc9,stroke:#333
```
