# dry-rb/dry-types architecture

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

- Interactive diagram: https://gitdiagram.com/dry-rb/dry-types
- Repository: https://github.com/dry-rb/dry-types

## Overview

##### Main Components Identification

a. Core Type System
- Nominal Types (lib/dry/types/nominal.rb)
- Built-in Types (lib/dry/types/core.rb)
- Type Builders (lib/dry/types/builder.rb)

b. Type Categories
- Coercible Types (lib/dry/types/coercions/)
- Constrained Types (lib/dry/types/constrained/)
- Container Registry (lib/dry/types/container.rb)

c. Complex Types
- Array Types (lib/dry/types/array/)
- Hash Types (lib/dry/types/hash/)
- Types (lib/dry/types/map.rb)

d. Extensions
- Maybe Types (lib/dry/types/extensions/maybe.rb)
- Monad Types (lib/dry/types/extensions/monads.rb)

**┌─────────────────────────────────────────────┐**
- Extensions Layer             │
- ┤
- Complex Types Layer            │
- ┤
- Core Types Layer               │
- ┤
- Infrastructure Layer           │
- ┘

##### Component Relationships

a. Type Construction Flow:
- Nominal Types → Constrained Types
- Constrained Types → Coercible Types
- Basic Types → Complex Types (Array, Hash, Map)

b. Extension Integration:
- Core Types → Maybe Extension
- Core Types → Monad Extension

##### Implementation Details

a. Core Operations:
**┌─────────────┐     ┌──────────────┐     ┌────────────┐**
- Type Define │ →   │   Constrain  │ →   │  Coerce    │
- ┘     └──────────────┘     └────────────┘

b. Type Registry System:
**┌─────────────┐     ┌──────────────┐**
- Container  │ ←→  │ Type Builder │
- ┘     └──────────────┘

##### Additional Elements

Supporting components:
- Error handling system (errors.rb)
- Inflector system (inflector.rb)
- Printer system (printer/)
- Result handling (result.rb)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles
    classDef core fill:#d0e1f9,stroke:#333
    classDef extension fill:#fff3cd,stroke:#333
    classDef complex fill:#d4edda,stroke:#333
    classDef infra fill:#e9ecef,stroke:#333

    %% Infrastructure Layer
    subgraph Infrastructure
        ErrorHandling["Error Handling"]:::infra
        Inflector["Inflector System"]:::infra
        Printer["Printer System"]:::infra
        Result["Result Handling"]:::infra
    end

    %% Core Types Layer
    subgraph CoreTypes
        NominalTypes["Nominal Types"]:::core
        BuiltInTypes["Built-in Types"]:::core
        TypeBuilder["Type Builder"]:::core
        BuilderMethods["Builder Methods"]:::core
        Container["Container Registry"]:::core
        PredicateRegistry["Predicate Registry"]:::core
        PredicateInferrer["Predicate Inferrer"]:::core
    end

    %% Type Categories Layer
    subgraph TypeCategories
        Coercions["Coercible Types"]:::core
        Constrained["Constrained Types"]:::core
        Constructor["Constructor"]:::core
        Schema["Schema"]:::core
        Constraints["Constraints"]:::core
    end

    %% Complex Types Layer
    subgraph ComplexTypes
        ArrayTypes["Array Types"]:::complex
        HashTypes["Hash Types"]:::complex
        MapTypes["Map Types"]:::complex
        Intersection["Intersection Types"]:::complex
        SumTypes["Sum Types"]:::complex
        Composition["Type Composition"]:::complex
    end

    %% Extensions Layer
    subgraph Extensions
        MaybeTypes["Maybe Types"]:::extension
        MonadTypes["Monad Types"]:::extension
    end

    %% Relationships
    NominalTypes --> Constrained
    Constrained --> Coercions
    BuiltInTypes --> ComplexTypes
    CoreTypes --> Extensions
    TypeBuilder --> Container
    Container --> ComplexTypes
    PredicateRegistry --> Constrained
    PredicateInferrer --> Constrained
    Constructor --> ComplexTypes
    Schema --> HashTypes
    Constraints --> Constrained

    %% Click Events
    click NominalTypes "https://github.com/dry-rb/dry-types/blob/main/lib/dry/types/nominal.rb"
    click BuiltInTypes "https://github.com/dry-rb/dry-types/blob/main/lib/dry/types/core.rb"
    click TypeBuilder "https://github.com/dry-rb/dry-types/blob/main/lib/dry/types/builder.rb"
    click BuilderMethods "https://github.com/dry-rb/dry-types/blob/main/lib/dry/types/builder_methods.rb"
    click Coercions "https://github.com/dry-rb/dry-types/tree/main/lib/dry/types/coercions/"
    click Constrained "https://github.com/dry-rb/dry-types/tree/main/lib/dry/types/constrained/"
    click Container "https://github.com/dry-rb/dry-types/blob/main/lib/dry/types/container.rb"
    click ArrayTypes "https://github.com/dry-rb/dry-types/tree/main/lib/dry/types/array/"
    click HashTypes "https://github.com/dry-rb/dry-types/tree/main/lib/dry/types/hash/"
    click MapTypes "https://github.com/dry-rb/dry-types/blob/main/lib/dry/types/map.rb"
    click MaybeTypes "https://github.com/dry-rb/dry-types/blob/main/lib/dry/types/extensions/maybe.rb"
    click MonadTypes "https://github.com/dry-rb/dry-types/blob/main/lib/dry/types/extensions/monads.rb"
    click ErrorHandling "https://github.com/dry-rb/dry-types/blob/main/lib/dry/types/errors.rb"
    click Inflector "https://github.com/dry-rb/dry-types/blob/main/lib/dry/types/inflector.rb"
    click Printer "https://github.com/dry-rb/dry-types/tree/main/lib/dry/types/printer/"
    click Result "https://github.com/dry-rb/dry-types/blob/main/lib/dry/types/result.rb"
    click Constructor "https://github.com/dry-rb/dry-types/tree/main/lib/dry/types/constructor/"
    click Schema "https://github.com/dry-rb/dry-types/tree/main/lib/dry/types/schema/"
    click Constraints "https://github.com/dry-rb/dry-types/blob/main/lib/dry/types/constraints.rb"
    click Intersection "https://github.com/dry-rb/dry-types/blob/main/lib/dry/types/intersection.rb"
    click SumTypes "https://github.com/dry-rb/dry-types/blob/main/lib/dry/types/sum.rb"
    click Composition "https://github.com/dry-rb/dry-types/blob/main/lib/dry/types/composition.rb"
    click PredicateRegistry "https://github.com/dry-rb/dry-types/blob/main/lib/dry/types/predicate_registry.rb"
    click PredicateInferrer "https://github.com/dry-rb/dry-types/blob/main/lib/dry/types/predicate_inferrer.rb"
```
