PHPackages                             kraz/read-model - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. kraz/read-model

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

kraz/read-model
===============

Read Model Domain implementation

1.1.1(3w ago)0153↓100%3MITPHPPHP &gt;=8.4CI passing

Since May 10Pushed 3w agoCompare

[ Source](https://github.com/kraz/read-model)[ Packagist](https://packagist.org/packages/kraz/read-model)[ RSS](/packages/kraz-read-model/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (4)Dependencies (4)Versions (5)Used By (3)

Read Model
==========

[](#read-model)

[![CI](https://github.com/kraz/read-model/actions/workflows/ci.yml/badge.svg)](https://github.com/kraz/read-model/actions/workflows/ci.yml)[![Packagist Version](https://camo.githubusercontent.com/40643b40b78d521ebc7f4343632c14676d113220255be1a7d48f7204f2441aea/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6b72617a2f726561642d6d6f64656c)](https://packagist.org/packages/kraz/read-model)[![GitHub license](https://camo.githubusercontent.com/fd31835f071cbe7dd96b451fe76583b9e8f4a7ba46e3da3f2d1a7cfb558c9d1f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6b72617a2f726561642d6d6f64656c)](LICENSE)

A domain-first Read Model library that provides a uniform API for querying read-only data from multiple backends. Define your query logic once; plug in Doctrine ORM, raw SQL, JSON-RPC APIs, or Elasticsearch — or use the built-in in-memory implementation for fast, dependency-free tests.

Installation
------------

[](#installation)

```
composer require kraz/read-model
```

Additional packages
-------------------

[](#additional-packages)

Install any of the following packages which matches your infrastructure requirements:

PackageDescription[kraz/read-model-doctrine](https://github.com/kraz/read-model-doctrine)Doctrine ORM &amp; raw SQL backend[kraz/read-model-json-rpc](https://github.com/kraz/read-model-json-rpc)JSON-RPC 2.0 API backend *(expects read-model exposed as API)*[kraz/read-model-elastic-search](https://github.com/kraz/read-model-elastic-search)Elasticsearch backendDocumentation
-------------

[](#documentation)

Full documentation lives in the [`docs/`](docs/) directory:

- [Getting Started](docs/getting-started.md)
- [Core Concepts](docs/core-concepts.md)
- [Filtering &amp; Sorting](docs/filtering.md)
- [Pagination &amp; Limits](docs/pagination.md)
- [Specifications](docs/specifications.md)
- [Testing](docs/testing.md)
- [Doctrine Backend](docs/doctrine.md)
- [JSON-RPC Backend](docs/json-rpc.md)
- [Elasticsearch Backend](docs/elasticsearch.md)

Example usage
-------------

[](#example-usage)

### Raw SQL

[](#raw-sql)

```
use Kraz\ReadModel\ReadDataProviderInterface;
use Kraz\ReadModelDoctrine\DataSource;
use Kraz\ReadModelDoctrine\DataSourceBuilder;
use Kraz\ReadModelDoctrine\RawQueryReadDataProvider;

class ProductsReadModel implements ReadDataProviderInterface
{
    use RawQueryReadDataProvider;

    public function __construct(private readonly Connection $connection) {}

    protected function createDataSource(): DataSource
    {
        return new DataSourceBuilder()
            ->withData(em->createQueryBuilder()
            ->select('r.id, r.name, r.price')
            ->from(Product::class, 'r');

        return new DataSource($qb);
    }
}
```

### Querying

[](#querying)

Both styles share the same query API:

```
// Filters and sorting
$products = $readModel
    ->withQueryExpression(
        $readModel->qry()
            ->andWhere($readModel->expr()->greaterThan('price', 10))
            ->andWhere($readModel->expr()->equalTo('category', 'tools'))
            ->sortBy('name', SortExpression::DIR_ASC)
    )
    ->withPagination(page: 1, itemsPerPage: 20)
    ->getResult();

// $result->data   — items on this page
// $result->page   — current page
// $result->total  — total matching rows
```

*The query expression is serializable and can be stored and/or transferred as needed.*

Acknowledgements
----------------

[](#acknowledgements)

The library uses source code from [Doctrine Collections](https://github.com/doctrine/collections) which was modified to meet the required behavior.

License
-------

[](#license)

This library is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.

###  Health Score

46

—

FairBetter than 92% of packages

Maintenance95

Actively maintained with recent releases

Popularity15

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~1 days

Total

4

Last Release

24d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/58638bf409738592e29453577dc33e51e5b97b93b01a6a3ddd32fd3f1e152f41?d=identicon)[kraz1](/maintainers/kraz1)

---

Top Contributors

[![kraz](https://avatars.githubusercontent.com/u/1006092?v=4)](https://github.com/kraz "kraz (53 commits)")

---

Tags

ddddomain-driven-designmodelread-modelmodelreadddddomainread model

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/kraz-read-model/health.svg)

```
[![Health](https://phpackages.com/badges/kraz-read-model/health.svg)](https://phpackages.com/packages/kraz-read-model)
```

###  Alternatives

[aura/payload

A Domain Payload implementation.

55377.9k9](/packages/aura-payload)[thejano/laravel-domain-driven-design

Helps to use domain driven design within laravel

15424.8k](/packages/thejano-laravel-domain-driven-design)[aura/payload-interface

An interface package for Domain Payload implementations.

12400.2k4](/packages/aura-payload-interface)[treshugart/model

Model is a simple, lightweight and easy-to-use Domain Driven Entity framework.

171.4k](/packages/treshugart-model)[devco/model

Model is a simple, lightweight and easy-to-use Domain Driven Entity framework.

171.4k](/packages/devco-model)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
