# odutko/idiorm architecture

> Architecture diagram of the GitHub repository odutko/idiorm, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-05). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/odutko/idiorm
- Repository: https://github.com/odutko/idiorm

## Overview

##### Project Type and Purpose
- This is an open-source PHP library (Idiorm) providing a lightweight, zero-configuration object-relational mapper (ORM) and fluent query builder.
- It’s designed to plug into any PHP project via Composer or by including the single `idiorm.php` file.
- Provides a simple API layer on top of PHP’s PDO to build and execute SQL queries safely.

##### File Structure
Top-level:
- `idiorm.php` – the core library file defining the `ORM` class and related helpers.
- `composer.json` – package metadata and autoloading.
- `demo.php` – example usage in a standalone script.
- `README.markdown`, `CONTRIBUTING.md` – project overview and contribution guidelines.
- `.github/workflows/idiorm-workflow.yml` – CI definition for GitHub Actions.
- `phpunit.xml` – PHPUnit configuration for running tests.
Directories:
- `docs/` – Sphinx-based documentation sources (ReStructuredText + Makefile) for site generation.
- `test/` – PHPUnit test suite, including integration tests (`CacheIntegrationTest.php`), unit tests, bootstrap, and a Docker setup for PHP 5.2 compatibility (`test/docker_for_php52/`).

##### README for Additional Insights
- Core class: `ORM`.
- Relies on PDO and prepared statements.
- Supports multiple drivers (SQLite, MySQL, PostgreSQL, Firebird).
- API features: method chaining, raw queries, caching hooks, multiple connections.
- Uses GitHub Actions + Docker for CI across PHP versions.
- Documentation built with Sphinx in `docs/`.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Consumer Layer
    subgraph "Consumer Layer"
        Consumer["Consumer Application"]:::external
        Composer["Composer Integration"]:::external
    end

    %% Project Metadata
    subgraph "Project Metadata"
        README["README.markdown"]:::tooling
        Contrib["CONTRIBUTING.md"]:::tooling
    end

    %% Library Core
    subgraph "Library Core"
        ORM["Idiorm Library<br/>(Core, Query Builder,<br/>Connection & Cache Managers)"]:::core
    end

    %% Dependencies
    subgraph "Dependencies"
        PDO["PDO Extension"]:::external
        subgraph "Database Engines"
            MySQL["MySQL"]:::external
            SQLite["SQLite"]:::external
            PostgreSQL["PostgreSQL"]:::external
            Firebird["Firebird"]:::external
        end
    end

    %% Testing Environment
    subgraph "Testing Environment"
        PHPUnitCfg["PHPUnit Configuration"]:::tooling
        Tests["Test Harness<br/>(Unit & Integration Tests)"]:::tooling
        Legacy["Legacy PHP Support<br/>(Docker for PHP 5.2)"]:::tooling
    end

    %% Documentation
    Docs["Documentation Generator<br/>(Sphinx)"]:::tooling

    %% CI/CD Pipeline
    CI["CI/CD Pipeline<br/>(GitHub Actions)"]:::tooling

    %% Relationships
    Consumer -->|"autoload via Composer"| Composer
    Consumer -->|"calls ORM API"| ORM
    Composer -->|"provides ORM class"| ORM
    ORM -->|"uses"| PDO
    PDO -->|"connects"| MySQL
    PDO -->|"connects"| SQLite
    PDO -->|"connects"| PostgreSQL
    PDO -->|"connects"| Firebird

    Tests -->|"load ORM"| ORM
    Tests -->|"use Docker env"| Legacy
    Tests -->|"execute via"| PDO

    CI -->|"triggers tests & docs"| PHPUnitCfg
    CI -->|"runs Tests"| Tests
    CI -->|"builds docs"| Docs

    %% Click Events
    click Consumer "https://github.com/odutko/idiorm/blob/main/demo.php"
    click ORM "https://github.com/odutko/idiorm/blob/main/idiorm.php"
    click Composer "https://github.com/odutko/idiorm/blob/main/composer.json"
    click Docs "https://github.com/odutko/idiorm/tree/main/docs/"
    click CI "https://github.com/odutko/idiorm/blob/main/.github/workflows/idiorm-workflow.yml"
    click PHPUnitCfg "https://github.com/odutko/idiorm/blob/main/phpunit.xml"
    click Tests "https://github.com/odutko/idiorm/tree/main/test/"
    click Legacy "https://github.com/odutko/idiorm/tree/main/test/docker_for_php52/"
    click README "https://github.com/odutko/idiorm/blob/main/README.markdown"
    click Contrib "https://github.com/odutko/idiorm/blob/main/CONTRIBUTING.md"

    %% Styles
    classDef core fill:#ffcccc,stroke:#aa0000,color:#000000;
    classDef external fill:#ccffcc,stroke:#008800,color:#000000;
    classDef tooling fill:#ccccff,stroke:#0000aa,color:#000000;
```
