# dmitri-wm/resources architecture

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

- Interactive diagram: https://gitdiagram.com/dmitri-wm/resources
- Repository: https://github.com/dmitri-wm/resources

## Overview

##### Main Components

a) Core Layer:
- Resources::Relation (central component)
- Resources::Dataset (data source abstraction)
- Resources::Registry (component registration)
- Resources::Initializer (system initialization)

b) Adapter Layer:
- SQL Adapter (for database operations)
- Service Adapter (for external services)
- Array Dataset (for in-memory operations)

c) Association System:
- Association Definitions
- Association Types (BelongsTo, HasMany, HasOne, Through variants)
- Polymorphic Associations

d) Query Building System:
- Query Methods
- Transformers
- Visitors

**[Client Application Layer]**
- ↓
**[Interface Layer]**
- Relations
- Associations DSL
- Query Interface
- ↓
**[Core Processing Layer]**
- Query Builder
- Transformer System
- Registry
- ↓
**[Adapter Layer]**
- SQL Adapter
- Service Adapter
- Array Adapter
- ↓
**[Data Sources]**
- Databases
- External Services
- In-Memory Data

##### Component Relationships

**[Transformer System]**
- Array Transformations
- Hash Transformations
- Coercions
- Conditional Logic

**[Associations]**
- Abstract Definitions
- Concrete Implementations
- Through Relationships
- Polymorphic Handling

##### Implementation Details

Technical details in smaller notes:
- Ruby type system integration (sig/ directory)
- Support for both SQL and service-based queries
- Lazy evaluation system
- Connection pooling (from Sequel integration)

##### Key Patterns to Highlight

- Adapter Pattern (for different data sources)
- Visitor Pattern (for query building)
- Builder Pattern (for query construction)
- Observer Pattern (for data loading)

##### The transformation pipeline

Remember to show both the static structure (components and their relationships) and dynamic aspects (data flow and query execution path).

- Multiple layers and grouping
- Relationship lines with different styles
- Text annotations
- Export to common formats

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client["Client Application Layer"]
        ClientApp[Client Application]:::client
    end

    subgraph Interface["Interface Layer"]
        Relations["Resources::Relation"]:::interface
        AssociationsDSL["Associations DSL"]:::interface
        QueryInterface["Query Interface"]:::interface
    end

    subgraph Core["Core Processing Layer"]
        Registry["Resources::Registry"]:::core
        Dataset["Resources::Dataset"]:::core
        Initializer["Resources::Initializer"]:::core
        
        subgraph QuerySystem["Query Building System"]
            QueryBuilder["Query Builder"]:::query
            TransformerSystem["Transformer System"]:::query
            Visitors["Query Visitors"]:::query
            GraphVisitor["Graph Visitor"]:::query
            GraphPathVisitor["Graph Path Visitor"]:::query
        end
        
        subgraph Associations["Association System"]
            AssociationBase["Association Base"]:::association
            BelongsTo["BelongsTo"]:::association
            HasMany["HasMany"]:::association
            HasOne["HasOne"]:::association
            Through["Through Associations"]:::association
            Polymorphic["Polymorphic Support"]:::association
        end
    end

    subgraph Adapters["Adapter Layer"]
        SQLAdapter["SQL Adapter"]:::adapter
        ServiceAdapter["Service Adapter"]:::adapter
        ArrayAdapter["Array Dataset"]:::adapter
        
        subgraph SQLComponents["SQL Components"]
            SQLDataset["SQL Dataset"]:::sql
            SQLRelations["SQL Relations"]:::sql
            SQLOperations["SQL Operations"]:::sql
        end
        
        subgraph ServiceComponents["Service Components"]
            ServiceDataset["Service Dataset"]:::service
            ServiceRelation["Service Relation"]:::service
        end
    end

    subgraph Support["Support Systems"]
        TypeSystem["Type System"]:::support
        Memoization["Memoization"]:::support
        ConnectionPool["Connection Pooling"]:::support
    end

    subgraph DataSources["Data Sources"]
        Databases[(Databases)]:::datasource
        ExternalServices[(External Services)]:::datasource
        InMemoryData[(In-Memory Data)]:::datasource
    end

    %% Relationships
    ClientApp --> Relations
    ClientApp --> QueryInterface
    ClientApp --> AssociationsDSL
    
    Relations --> Dataset
    Relations --> Registry
    
    Dataset --> QueryBuilder
    Dataset --> TransformerSystem
    
    QueryBuilder --> Visitors
    Visitors --> GraphVisitor
    Visitors --> GraphPathVisitor
    
    AssociationsDSL --> AssociationBase
    AssociationBase --> BelongsTo & HasMany & HasOne & Through & Polymorphic
    
    SQLAdapter --> SQLComponents
    ServiceAdapter --> ServiceComponents
    
    SQLComponents --> Databases
    ServiceComponents --> ExternalServices
    ArrayAdapter --> InMemoryData

    %% Styles
    classDef client fill:#f9f,stroke:#333
    classDef interface fill:#85C1E9,stroke:#333
    classDef core fill:#3498DB,stroke:#333
    classDef query fill:#F4D03F,stroke:#333
    classDef association fill:#E67E22,stroke:#333
    classDef adapter fill:#2ECC71,stroke:#333
    classDef sql fill:#27AE60,stroke:#333
    classDef service fill:#16A085,stroke:#333
    classDef support fill:#8E44AD,stroke:#333
    classDef datasource fill:#95A5A6,stroke:#333

    %% Click Events
    click Relations "https://github.com/dmitri-wm/resources/blob/main/lib/resources/relation.rb"
    click Dataset "https://github.com/dmitri-wm/resources/blob/main/lib/resources/dataset.rb"
    click Registry "https://github.com/dmitri-wm/resources/blob/main/lib/resources/registry.rb"
    click Initializer "https://github.com/dmitri-wm/resources/blob/main/lib/resources/initializer.rb"
    click SQLAdapter "https://github.com/dmitri-wm/resources/tree/main/lib/resources/sql/"
    click ServiceAdapter "https://github.com/dmitri-wm/resources/tree/main/lib/resources/data_service/"
    click ArrayAdapter "https://github.com/dmitri-wm/resources/blob/main/lib/resources/array_dataset.rb"
    click AssociationBase "https://github.com/dmitri-wm/resources/blob/main/lib/resources/associations/abstract.rb"
    click BelongsTo "https://github.com/dmitri-wm/resources/blob/main/lib/resources/associations/definitions/belongs_to.rb"
    click HasMany "https://github.com/dmitri-wm/resources/blob/main/lib/resources/associations/definitions/has_many.rb"
    click HasOne "https://github.com/dmitri-wm/resources/blob/main/lib/resources/associations/definitions/has_one.rb"
    click Through "https://github.com/dmitri-wm/resources/blob/main/lib/resources/associations/definitions/has_many_through.rb"
    click Polymorphic "https://github.com/dmitri-wm/resources/blob/main/lib/resources/associations/polymorphic_identifier.rb"
    click TransformerSystem "https://github.com/dmitri-wm/resources/tree/main/lib/libs/dry/transformer/"
    click Visitors "https://github.com/dmitri-wm/resources/tree/main/lib/resources/relation/visitors/"
    click GraphVisitor "https://github.com/dmitri-wm/resources/blob/main/lib/resources/relation/visitors/graph_visitor.rb"
    click GraphPathVisitor "https://github.com/dmitri-wm/resources/blob/main/lib/resources/relation/visitors/graph_path_visitor.rb"
    click TypeSystem "https://github.com/dmitri-wm/resources/blob/main/lib/resources/support/types.rb"
    click Memoization "https://github.com/dmitri-wm/resources/blob/main/lib/resources/support/memoizable.rb"
    click ConnectionPool "https://github.com/dmitri-wm/resources/tree/main/lib/libs/sequel/connection_pool/"
    click SQLDataset "https://github.com/dmitri-wm/resources/blob/main/lib/resources/sql/dataset.rb"
    click SQLRelations "https://github.com/dmitri-wm/resources/blob/main/lib/resources/sql/relation.rb"
    click SQLOperations "https://github.com/dmitri-wm/resources/tree/main/lib/resources/sql/dataset/operations/"
    click ServiceDataset "https://github.com/dmitri-wm/resources/blob/main/lib/resources/data_service/dataset.rb"
    click ServiceRelation "https://github.com/dmitri-wm/resources/blob/main/lib/resources/data_service/relation.rb"
```
