# dry-rb/dry-schema architecture

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

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

## Overview

dry-schema is a Ruby library for defining and running schemas that coerce and validate input, returning structured results and errors. The principal workflow starts with an application defining a schema through the public API and DSL, then applying that schema to input. Its domain stages include macro-based rule definition, processor construction, key handling and validation, and result/message production. Extensions add hints, schema metadata, JSON Schema support, monadic results, and struct-derived rules. Source excerpts show DSL construction and macro behavior; links to unsampled runtime components are omitted or marked unverified.

Main entry points: [`lib/dry/schema/processor.rb`](https://github.com/dry-rb/dry-schema/blob/main/lib/dry/schema/processor.rb) (Schema processor), [`lib/dry/schema/dsl.rb`](https://github.com/dry-rb/dry-schema/blob/main/lib/dry/schema/dsl.rb) (Definition DSL), [`lib/dry/schema.rb`](https://github.com/dry-rb/dry-schema/blob/main/lib/dry/schema.rb) (Schema API), [`lib/dry/schema/result.rb`](https://github.com/dry-rb/dry-schema/blob/main/lib/dry/schema/result.rb) (Validation result)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_definition["Schema definition"]
  node_public_api["Schema API<br/>[schema.rb]"]
  node_dsl["Definition DSL<br/>[dsl.rb]"]
  node_macros["Rule macros<br/>[dsl.rb]"]
  node_compiler["Rule compiler<br/>[compiler.rb]"]
end

subgraph group_execution["Schema execution"]
  node_processor["Schema processor<br/>[processor.rb]"]
  node_coercion["Input coercion<br/>[value_coercer.rb]"]
  node_key_handling["Key handling<br/>[key_map.rb]"]
  node_rule_applier["Rule evaluation<br/>[rule_applier.rb]"]
end

subgraph group_errors["Results and messages"]
  node_result["Validation result<br/>[result.rb]"]
  node_message_compiler["Message compiler"]
  node_message_backends["Message backends<br/>[abstract.rb]"]
end

subgraph group_extensions["Extensions"]
  node_hints["Hints extension<br/>[hints.rb]"]
  node_info["Schema info<br/>[info.rb]"]
  node_json_schema["JSON Schema<br/>[json_schema.rb]"]
  node_monads["Monadic results<br/>[monads.rb]"]
  node_struct["Struct integration<br/>[struct.rb]"]
end

node_application(("Application"))

node_application -.->|"defines schema"| node_public_api
node_public_api -.->|"exposes DSL"| node_dsl
node_dsl -->|"builds macros"| node_macros
node_dsl -->|"creates compiler"| node_compiler
node_dsl -->|"builds processor"| node_processor
node_application -.->|"validates input"| node_processor
node_processor -.->|"coerces input"| node_coercion
node_processor -.->|"handles keys"| node_key_handling
node_processor -.->|"applies rules"| node_rule_applier
node_processor -.->|"returns result"| node_result
node_result -.->|"formats errors"| node_message_compiler
node_message_compiler -.->|"uses messages"| node_message_backends
node_application -.->|"enables extension"| node_hints
node_application -.->|"enables extension"| node_info
node_application -.->|"enables extension"| node_json_schema
node_application -.->|"enables extension"| node_monads
node_dsl -.->|"accepts struct rules"| node_struct

click node_public_api "https://github.com/dry-rb/dry-schema/blob/main/lib/dry/schema.rb"
click node_dsl "https://github.com/dry-rb/dry-schema/blob/main/lib/dry/schema/dsl.rb"
click node_macros "https://github.com/dry-rb/dry-schema/blob/main/lib/dry/schema/macros/dsl.rb"
click node_compiler "https://github.com/dry-rb/dry-schema/blob/main/lib/dry/schema/compiler.rb"
click node_processor "https://github.com/dry-rb/dry-schema/blob/main/lib/dry/schema/processor.rb"
click node_coercion "https://github.com/dry-rb/dry-schema/blob/main/lib/dry/schema/value_coercer.rb"
click node_key_handling "https://github.com/dry-rb/dry-schema/blob/main/lib/dry/schema/key_map.rb"
click node_rule_applier "https://github.com/dry-rb/dry-schema/blob/main/lib/dry/schema/rule_applier.rb"
click node_result "https://github.com/dry-rb/dry-schema/blob/main/lib/dry/schema/result.rb"
click node_message_compiler "https://github.com/dry-rb/dry-schema/blob/main/lib/dry/schema/message_compiler.rb"
click node_message_backends "https://github.com/dry-rb/dry-schema/blob/main/lib/dry/schema/messages/abstract.rb"
click node_hints "https://github.com/dry-rb/dry-schema/blob/main/lib/dry/schema/extensions/hints.rb"
click node_info "https://github.com/dry-rb/dry-schema/blob/main/lib/dry/schema/extensions/info.rb"
click node_json_schema "https://github.com/dry-rb/dry-schema/blob/main/lib/dry/schema/extensions/json_schema.rb"
click node_monads "https://github.com/dry-rb/dry-schema/blob/main/lib/dry/schema/extensions/monads.rb"
click node_struct "https://github.com/dry-rb/dry-schema/blob/main/lib/dry/schema/extensions/struct.rb"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_public_api,node_dsl,node_macros,node_compiler toneBlue
class node_processor,node_coercion,node_key_handling,node_rule_applier toneAmber
class node_result,node_message_compiler,node_message_backends toneMint
class node_hints,node_info,node_json_schema,node_monads,node_struct toneRose
class node_application toneIndigo
```

## Components

### Schema definition

- [Schema API](https://github.com/dry-rb/dry-schema/blob/main/lib/dry/schema.rb): `lib/dry/schema.rb`
- [Definition DSL](https://github.com/dry-rb/dry-schema/blob/main/lib/dry/schema/dsl.rb): `lib/dry/schema/dsl.rb`
- [Rule macros](https://github.com/dry-rb/dry-schema/blob/main/lib/dry/schema/macros/dsl.rb): `lib/dry/schema/macros/dsl.rb`
- [Rule compiler](https://github.com/dry-rb/dry-schema/blob/main/lib/dry/schema/compiler.rb): `lib/dry/schema/compiler.rb`

### Schema execution

- [Schema processor](https://github.com/dry-rb/dry-schema/blob/main/lib/dry/schema/processor.rb): `lib/dry/schema/processor.rb`
- [Input coercion](https://github.com/dry-rb/dry-schema/blob/main/lib/dry/schema/value_coercer.rb): `lib/dry/schema/value_coercer.rb`
- [Key handling](https://github.com/dry-rb/dry-schema/blob/main/lib/dry/schema/key_map.rb): `lib/dry/schema/key_map.rb`
- [Rule evaluation](https://github.com/dry-rb/dry-schema/blob/main/lib/dry/schema/rule_applier.rb): `lib/dry/schema/rule_applier.rb`

### Results and messages

- [Validation result](https://github.com/dry-rb/dry-schema/blob/main/lib/dry/schema/result.rb): `lib/dry/schema/result.rb`
- [Message compiler](https://github.com/dry-rb/dry-schema/blob/main/lib/dry/schema/message_compiler.rb): `lib/dry/schema/message_compiler.rb`
- [Message backends](https://github.com/dry-rb/dry-schema/blob/main/lib/dry/schema/messages/abstract.rb): `lib/dry/schema/messages/abstract.rb`

### Extensions

- [Hints extension](https://github.com/dry-rb/dry-schema/blob/main/lib/dry/schema/extensions/hints.rb): `lib/dry/schema/extensions/hints.rb`
- [Schema info](https://github.com/dry-rb/dry-schema/blob/main/lib/dry/schema/extensions/info.rb): `lib/dry/schema/extensions/info.rb`
- [JSON Schema](https://github.com/dry-rb/dry-schema/blob/main/lib/dry/schema/extensions/json_schema.rb): `lib/dry/schema/extensions/json_schema.rb`
- [Monadic results](https://github.com/dry-rb/dry-schema/blob/main/lib/dry/schema/extensions/monads.rb): `lib/dry/schema/extensions/monads.rb`
- [Struct integration](https://github.com/dry-rb/dry-schema/blob/main/lib/dry/schema/extensions/struct.rb): `lib/dry/schema/extensions/struct.rb`

### Other components

- **Application**

## Connections

- Application → Schema API: defines schema
- Schema API → Definition DSL: exposes DSL (evidence: `lib/dry/schema/dsl.rb`)
- Definition DSL → Rule macros: builds macros (evidence: `lib/dry/schema/dsl.rb`)
- Definition DSL → Rule compiler: creates compiler (evidence: `lib/dry/schema/dsl.rb`)
- Definition DSL → Schema processor: builds processor (evidence: `lib/dry/schema/dsl.rb`)
- Application → Schema processor: validates input
- Schema processor → Input coercion: coerces input
- Schema processor → Key handling: handles keys
- Schema processor → Rule evaluation: applies rules
- Schema processor → Validation result: returns result
- Validation result → Message compiler: formats errors
- Message compiler → Message backends: uses messages
- Application → Hints extension: enables extension
- Application → Schema info: enables extension
- Application → JSON Schema: enables extension
- Application → Monadic results: enables extension
- Definition DSL → Struct integration: accepts struct rules
