# stougeiro/pdo-database architecture

> Architecture diagram of the GitHub repository stougeiro/pdo-database, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/stougeiro/pdo-database
- Repository: https://github.com/stougeiro/pdo-database

## Overview

This is a dialect-agnostic PDO database model library. Its main workflow is configure a named connection, build a model operation into validated query/statement IR, compile that IR with an engine dialect, execute it through PDO, and expose a uniform result. The graph also preserves the declarative query DSL, typed parameter handling, raw SQL and transaction capabilities. Relationships are based on the README and the shown source/reference index; unsampled implementations are represented by their exact paths without claiming their internals were inspected.

Main entry points: [`src/Model/ModelAbstracted.php`](https://github.com/stougeiro/pdo-database/blob/master/src/Model/ModelAbstracted.php) (Model CRUD), [`src/ConnectionRegistry.php`](https://github.com/stougeiro/pdo-database/blob/master/src/ConnectionRegistry.php) (Connection Registry), [`src/Connection/PdoConnection.php`](https://github.com/stougeiro/pdo-database/blob/master/src/Connection/PdoConnection.php) (PDO Connection), [`src/QueryTree/QueryTreeBuilder.php`](https://github.com/stougeiro/pdo-database/blob/master/src/QueryTree/QueryTreeBuilder.php) (Query DSL Builder)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_facade["Model and Registry"]
  node_model["Model CRUD"]
  node_registry["Connection Registry"]
end

subgraph group_query["Query Representation"]
  node_dsl["Query DSL Builder"]
  node_filter["Filter Builder<br/>[FilterBuilder.php]"]
  node_order["Order Builder<br/>[OrderBuilder.php]"]
  node_pagination["Pagination Builder"]
  node_queryir["Query IR<br/>[Query.php]"]
  node_nodes["Query Nodes"]
  node_statement["Validated Statement<br/>[Statement.php]"]
end

subgraph group_execution["SQL Execution"]
  node_connection["PDO Connection<br/>[PdoConnection.php]"]
  node_driver["PDO Driver<br/>[PdoDriver.php]"]
  node_compiler["Statement Compiler<br/>[Compiler.php]"]
  node_conditions["Condition Compiler<br/>[Conditions.php]"]
end

subgraph group_engines["Engine Configuration"]
  node_configs["Engine Configs"]
  node_dialects["SQL Dialects"]
end

subgraph group_values["Values and Results"]
  node_param["Typed Parameters<br/>[Param.php]"]
  node_rawresult["Raw Result<br/>[Raw.php]"]
  node_result["Model Result<br/>[Result.php]"]
end

node_caller(("Application"))
node_database[("SQL Database")]

node_caller -->|"configures"| node_registry
node_caller -->|"calls"| node_model
node_model -->|"resolves"| node_registry
node_registry -->|"builds config"| node_configs
node_registry -->|"selects dialect"| node_dialects
node_registry -->|"creates connection"| node_connection
node_registry -->|"creates driver"| node_driver
node_model -->|"lowers arrays"| node_dsl
node_dsl -->|"builds filters"| node_filter
node_dsl -->|"builds ordering"| node_order
node_dsl -->|"builds pagination"| node_pagination
node_filter -->|"creates nodes"| node_nodes
node_order -->|"creates nodes"| node_nodes
node_pagination -->|"creates nodes"| node_nodes
node_dsl -->|"assembles query"| node_queryir
node_model -->|"creates statement"| node_statement
node_queryir -->|"embedded in"| node_statement
node_model -->|"types values"| node_param
node_driver -->|"compiles statement"| node_compiler
node_compiler -->|"reads IR"| node_statement
node_compiler -->|"compiles conditions"| node_conditions
node_compiler -->|"renders dialect SQL"| node_dialects
node_driver -->|"delegates execution"| node_connection
node_connection -->|"binds values"| node_param
node_connection -->|"executes SQL"| node_database
node_driver -->|"returns raw result"| node_rawresult
node_driver -->|"builds model result"| node_result
node_model -->|"returns result"| node_result
node_caller -->|"runs raw SQL"| node_connection
node_caller -->|"controls transactions"| node_connection

click node_model "https://github.com/stougeiro/pdo-database/blob/master/src/Model/ModelAbstracted.php"
click node_registry "https://github.com/stougeiro/pdo-database/blob/master/src/ConnectionRegistry.php"
click node_configs "https://github.com/stougeiro/pdo-database/tree/master/src/Config"
click node_dialects "https://github.com/stougeiro/pdo-database/tree/master/src/Dialect"
click node_connection "https://github.com/stougeiro/pdo-database/blob/master/src/Connection/PdoConnection.php"
click node_driver "https://github.com/stougeiro/pdo-database/blob/master/src/Driver/PdoDriver.php"
click node_compiler "https://github.com/stougeiro/pdo-database/blob/master/src/Driver/Compiler.php"
click node_conditions "https://github.com/stougeiro/pdo-database/blob/master/src/Driver/Conditions.php"
click node_dsl "https://github.com/stougeiro/pdo-database/blob/master/src/QueryTree/QueryTreeBuilder.php"
click node_filter "https://github.com/stougeiro/pdo-database/blob/master/src/QueryTree/Builder/FilterBuilder.php"
click node_order "https://github.com/stougeiro/pdo-database/blob/master/src/QueryTree/Builder/OrderBuilder.php"
click node_pagination "https://github.com/stougeiro/pdo-database/blob/master/src/QueryTree/Builder/PaginationBuilder.php"
click node_queryir "https://github.com/stougeiro/pdo-database/blob/master/src/QueryTree/Query.php"
click node_nodes "https://github.com/stougeiro/pdo-database/tree/master/src/QueryTree/Node"
click node_statement "https://github.com/stougeiro/pdo-database/blob/master/src/Statement/Statement.php"
click node_param "https://github.com/stougeiro/pdo-database/blob/master/src/Param/Param.php"
click node_rawresult "https://github.com/stougeiro/pdo-database/blob/master/src/Result/Raw.php"
click node_result "https://github.com/stougeiro/pdo-database/blob/master/src/Result/Result.php"

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_model,node_registry toneBlue
class node_dsl,node_filter,node_order,node_pagination,node_queryir,node_nodes,node_statement,node_database toneAmber
class node_connection,node_driver,node_compiler,node_conditions toneMint
class node_configs,node_dialects toneRose
class node_param,node_rawresult,node_result,node_caller toneIndigo
```

## Components

### Model and Registry

- [Model CRUD](https://github.com/stougeiro/pdo-database/blob/master/src/Model/ModelAbstracted.php): `src/Model/ModelAbstracted.php`
- [Connection Registry](https://github.com/stougeiro/pdo-database/blob/master/src/ConnectionRegistry.php): `src/ConnectionRegistry.php`

### Query Representation

- [Query DSL Builder](https://github.com/stougeiro/pdo-database/blob/master/src/QueryTree/QueryTreeBuilder.php): `src/QueryTree/QueryTreeBuilder.php`
- [Filter Builder](https://github.com/stougeiro/pdo-database/blob/master/src/QueryTree/Builder/FilterBuilder.php): `src/QueryTree/Builder/FilterBuilder.php`
- [Order Builder](https://github.com/stougeiro/pdo-database/blob/master/src/QueryTree/Builder/OrderBuilder.php): `src/QueryTree/Builder/OrderBuilder.php`
- [Pagination Builder](https://github.com/stougeiro/pdo-database/blob/master/src/QueryTree/Builder/PaginationBuilder.php): `src/QueryTree/Builder/PaginationBuilder.php`
- [Query IR](https://github.com/stougeiro/pdo-database/blob/master/src/QueryTree/Query.php): `src/QueryTree/Query.php`
- [Query Nodes](https://github.com/stougeiro/pdo-database/tree/master/src/QueryTree/Node): `src/QueryTree/Node`
- [Validated Statement](https://github.com/stougeiro/pdo-database/blob/master/src/Statement/Statement.php): `src/Statement/Statement.php`

### SQL Execution

- [PDO Connection](https://github.com/stougeiro/pdo-database/blob/master/src/Connection/PdoConnection.php): `src/Connection/PdoConnection.php`
- [PDO Driver](https://github.com/stougeiro/pdo-database/blob/master/src/Driver/PdoDriver.php): `src/Driver/PdoDriver.php`
- [Statement Compiler](https://github.com/stougeiro/pdo-database/blob/master/src/Driver/Compiler.php): `src/Driver/Compiler.php`
- [Condition Compiler](https://github.com/stougeiro/pdo-database/blob/master/src/Driver/Conditions.php): `src/Driver/Conditions.php`

### Engine Configuration

- [Engine Configs](https://github.com/stougeiro/pdo-database/tree/master/src/Config): `src/Config`
- [SQL Dialects](https://github.com/stougeiro/pdo-database/tree/master/src/Dialect): `src/Dialect`

### Values and Results

- [Typed Parameters](https://github.com/stougeiro/pdo-database/blob/master/src/Param/Param.php): `src/Param/Param.php`
- [Raw Result](https://github.com/stougeiro/pdo-database/blob/master/src/Result/Raw.php): `src/Result/Raw.php`
- [Model Result](https://github.com/stougeiro/pdo-database/blob/master/src/Result/Result.php): `src/Result/Result.php`

### Other components

- **Application**
- **SQL Database**

## Connections

- Application → Connection Registry: configures (evidence: `README.md`)
- Application → Model CRUD: calls (evidence: `README.md`)
- Model CRUD → Connection Registry: resolves (evidence: `src/Model/ModelAbstracted.php`)
- Connection Registry → Engine Configs: builds config (evidence: `src/ConnectionRegistry.php`)
- Connection Registry → SQL Dialects: selects dialect (evidence: `src/ConnectionRegistry.php`)
- Connection Registry → PDO Connection: creates connection (evidence: `src/ConnectionRegistry.php`)
- Connection Registry → PDO Driver: creates driver (evidence: `src/ConnectionRegistry.php`)
- Model CRUD → Query DSL Builder: lowers arrays (evidence: `src/Model/ModelAbstracted.php`)
- Query DSL Builder → Filter Builder: builds filters (evidence: `src/QueryTree/QueryTreeBuilder.php`)
- Query DSL Builder → Order Builder: builds ordering (evidence: `src/QueryTree/QueryTreeBuilder.php`)
- Query DSL Builder → Pagination Builder: builds pagination (evidence: `src/QueryTree/QueryTreeBuilder.php`)
- Filter Builder → Query Nodes: creates nodes (evidence: `src/QueryTree/Builder/FilterBuilder.php`)
- Order Builder → Query Nodes: creates nodes (evidence: `src/QueryTree/Builder/OrderBuilder.php`)
- Pagination Builder → Query Nodes: creates nodes (evidence: `src/QueryTree/Builder/PaginationBuilder.php`)
- Query DSL Builder → Query IR: assembles query (evidence: `src/QueryTree/QueryTreeBuilder.php`)
- Model CRUD → Validated Statement: creates statement (evidence: `src/Model/ModelAbstracted.php`)
- Query IR → Validated Statement: embedded in (evidence: `README.md`)
- Model CRUD → Typed Parameters: types values (evidence: `README.md`)
- PDO Driver → Statement Compiler: compiles statement (evidence: `src/Driver/PdoDriver.php`)
- Statement Compiler → Validated Statement: reads IR (evidence: `src/Driver/Compiler.php`)
- Statement Compiler → Condition Compiler: compiles conditions (evidence: `src/Driver/Compiler.php`)
- Statement Compiler → SQL Dialects: renders dialect SQL (evidence: `src/Driver/Compiler.php`)
- PDO Driver → PDO Connection: delegates execution (evidence: `README.md`)
- PDO Connection → Typed Parameters: binds values (evidence: `README.md`)
- PDO Connection → SQL Database: executes SQL (evidence: `README.md`)
- PDO Driver → Raw Result: returns raw result (evidence: `README.md`)
- PDO Driver → Model Result: builds model result (evidence: `src/Driver/PdoDriver.php`)
- Model CRUD → Model Result: returns result (evidence: `README.md`)
- Application → PDO Connection: runs raw SQL (evidence: `README.md`)
- Application → PDO Connection: controls transactions (evidence: `README.md`)
