PHPackages                             maatify/data-repository - 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. [Database &amp; ORM](/categories/database)
4. /
5. maatify/data-repository

ActiveLibrary[Database &amp; ORM](/categories/database)

maatify/data-repository
=======================

Unified repository abstraction layer normalizing MySQL, MongoDB, and Redis real drivers and fake drivers.

v1.0.0(5mo ago)00[6 PRs](https://github.com/Maatify/data-repository/pulls)MITPHPPHP &gt;=8.4CI passing

Since Dec 6Pushed 4mo agoCompare

[ Source](https://github.com/Maatify/data-repository)[ Packagist](https://packagist.org/packages/maatify/data-repository)[ RSS](/packages/maatify-data-repository/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (11)Versions (8)Used By (0)

Maatify Data Repository
=======================

[](#maatify-data-repository)

**Unified repository abstraction layer normalizing MySQL, MongoDB, and Redis real &amp; fake drivers.**

[![Maatify.dev](https://camo.githubusercontent.com/bb8bf9ee079d7f823c9d5e94061d1d4c11dc0898e2b1b5cc9a8a7b04d8bfdd7d/68747470733a2f2f7777772e6d6161746966792e6465762f6173736574732f696d672f696d672f6d6161746966795f6c6f676f5f77686974652e737667)](https://camo.githubusercontent.com/bb8bf9ee079d7f823c9d5e94061d1d4c11dc0898e2b1b5cc9a8a7b04d8bfdd7d/68747470733a2f2f7777772e6d6161746966792e6465762f6173736574732f696d672f696d672f6d6161746966795f6c6f676f5f77686974652e737667)

---

[![Version](https://camo.githubusercontent.com/79cb3c021a7619303c829de87101628db5b82af77364ef4f3e32e265538fdbe1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d6161746966792f646174612d7265706f7369746f72793f6c6162656c3d56657273696f6e26636f6c6f723d344331)](https://packagist.org/packages/maatify/data-repository)[![PHP](https://camo.githubusercontent.com/0133a47c01407d2e5507c20731a105f447060adfe2218ef1268262ab9ca37745/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6d6161746966792f646174612d7265706f7369746f72793f6c6162656c3d50485026636f6c6f723d373737424233)](https://packagist.org/packages/maatify/data-repository)[![PHP Version](https://camo.githubusercontent.com/0751c5c7ed417028d6909f393af80b98d84b224db16e8307c3988e7eefc8ecdb/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344382e342d626c7565)](https://camo.githubusercontent.com/0751c5c7ed417028d6909f393af80b98d84b224db16e8307c3988e7eefc8ecdb/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344382e342d626c7565)

[![Build](https://github.com/Maatify/data-repository/actions/workflows/test.yml/badge.svg?label=Build&color=brightgreen)](https://github.com/Maatify/data-repository/actions/workflows/test.yml)

[![Monthly Downloads](https://camo.githubusercontent.com/fd05c01fc7a670716c3bf546245eba3b9e2d8fa6ad1ca97b43d244e14c202a73/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f6d6161746966792f646174612d7265706f7369746f72793f6c6162656c3d4d6f6e74686c79253230446f776e6c6f61647326636f6c6f723d303041384538)](https://camo.githubusercontent.com/fd05c01fc7a670716c3bf546245eba3b9e2d8fa6ad1ca97b43d244e14c202a73/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f6d6161746966792f646174612d7265706f7369746f72793f6c6162656c3d4d6f6e74686c79253230446f776e6c6f61647326636f6c6f723d303041384538)[![Total Downloads](https://camo.githubusercontent.com/5eaf073d008da38b3b7b7559263e100e203f7290e699d06bfdbe12cced1f11b9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d6161746966792f646174612d7265706f7369746f72793f6c6162656c3d546f74616c253230446f776e6c6f61647326636f6c6f723d324141394530)](https://camo.githubusercontent.com/5eaf073d008da38b3b7b7559263e100e203f7290e699d06bfdbe12cced1f11b9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d6161746966792f646174612d7265706f7369746f72793f6c6162656c3d546f74616c253230446f776e6c6f61647326636f6c6f723d324141394530)

[![Stars](https://camo.githubusercontent.com/775e616f8399c938dc5ca52a51301d73238f3135094e35116488a4ae655fca16/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f4d6161746966792f646174612d7265706f7369746f72793f6c6162656c3d537461727326636f6c6f723d464644343342)](https://camo.githubusercontent.com/775e616f8399c938dc5ca52a51301d73238f3135094e35116488a4ae655fca16/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f4d6161746966792f646174612d7265706f7369746f72793f6c6162656c3d537461727326636f6c6f723d464644343342)[![License](https://camo.githubusercontent.com/1b75edc8ef2a26182432fa746315b3fce0f4644debfc83cb69ecaab709103a99/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f4d6161746966792f646174612d7265706f7369746f72793f6c6162656c3d4c6963656e736526636f6c6f723d626c756576696f6c6574)](LICENSE)[![Status](https://camo.githubusercontent.com/7ad747e5eefa3aa1040130a413dd5d018f22edbc45638ea213a3376a278e76f6/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5374617475732d537461626c652d73756363657373)](https://camo.githubusercontent.com/7ad747e5eefa3aa1040130a413dd5d018f22edbc45638ea213a3376a278e76f6/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5374617475732d537461626c652d73756363657373)[![Code Quality](https://camo.githubusercontent.com/788db80d2e2479892b72eb2f9da6090a365a34e0c8832daf81684a865f72a5b5/68747470733a2f2f696d672e736869656c64732e696f2f636f6465666163746f722f67726164652f6769746875622f4d6161746966792f646174612d7265706f7369746f72792f6d61696e3f636f6c6f723d627269676874677265656e)](https://www.codefactor.io/repository/github/Maatify/data-repository)

[![PHPStan](https://camo.githubusercontent.com/f85016b73718ab38275b913dafed1c1ce7f287c3c2ec319445bc29011149f408/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d4c6576656c2532304d61782d344538434145)](https://camo.githubusercontent.com/f85016b73718ab38275b913dafed1c1ce7f287c3c2ec319445bc29011149f408/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d4c6576656c2532304d61782d344538434145)[![Coverage](https://camo.githubusercontent.com/0601c3c19e01220b6d68861b0c845ecc4e02d32ff2cd479ffebad5b23e85f620/68747470733a2f2f696d672e736869656c64732e696f2f656e64706f696e743f75726c3d68747470733a2f2f7261772e67697468756275736572636f6e74656e742e636f6d2f4d6161746966792f646174612d7265706f7369746f72792f6261646765732f636f7665726167652e6a736f6e)](https://camo.githubusercontent.com/0601c3c19e01220b6d68861b0c845ecc4e02d32ff2cd479ffebad5b23e85f620/68747470733a2f2f696d672e736869656c64732e696f2f656e64706f696e743f75726c3d68747470733a2f2f7261772e67697468756275736572636f6e74656e742e636f6d2f4d6161746966792f646174612d7265706f7369746f72792f6261646765732f636f7665726167652e6a736f6e)

[![Changelog](https://camo.githubusercontent.com/32f7664d004132f7e0fb111b5e01bd7270705d1e7247db502287d51910c04cb9/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4368616e67656c6f672d566965772d626c7565)](CHANGELOG.md)[![Security](https://camo.githubusercontent.com/a150750c8b2c6ca6209aa80bdf220d2f0950b984df64c1b859a46ee9152570f3/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f53656375726974792d506f6c6963792d696d706f7274616e74)](SECURITY.md)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

[](#)

🚀 Overview
==========

[](#-overview)

**Maatify Data Repository** separates domain logic from database-specific implementations and provides a unified API supporting:

- **Real Drivers** (`maatify/data-adapters`)
- **Fake Drivers** (`maatify/data-fakes`)

### Why this library?

[](#why-this-library)

- Zero driver lock-in
- Deterministic testing without Docker
- Static analysis with PHPStan Level Max
- Unified CRUD/Filters/Pagination across MySQL, MongoDB, and Redis

### Supported Drivers

[](#supported-drivers)

TypeReal DriversFake DriversMySQLPDO / Doctrine DBALIn-memory SQL-like tablesMongoDBmongodb/mongodbIn-memory BSON-like collectionsRedisredis / predisIn-memory key-value store---

📦 Installation
==============

[](#-installation)

```
composer require maatify/data-repository
```

---

⚡ Quick Usage
=============

[](#-quick-usage)

1) Create a Repository
----------------------

[](#1-create-a-repository)

```
use Maatify\DataRepository\Base\BaseMySQLRepository;

/** @extends BaseMySQLRepository */
class UserRepository extends BaseMySQLRepository
{
    protected string $tableName = 'users';
}
```

2) Use in Production (Real Adapter)
-----------------------------------

[](#2-use-in-production-real-adapter)

```
$resolver = new DatabaseResolver(new EnvironmentConfig(__DIR__));
$adapter  = $resolver->resolve('mysql.main');

$repo = new UserRepository($adapter);
$users = $repo->findBy(['active' => 1]);
```

3) Use in Testing (Fake Adapter)
--------------------------------

[](#3-use-in-testing-fake-adapter)

```
$storage = new FakeStorageLayer();
$adapter = new FakeMySQLAdapter($storage);

$storage->seed('users', [
    ['id' => 1, 'active' => 1, 'name' => 'Alice'],
]);

$repo = new UserRepository($adapter);
$repo->findBy(['active' => 1]); // Alice
```

---

💎 Hydration &amp; DTOs
======================

[](#-hydration--dtos)

```
class UserDto {
    public int $id;
    public string $name;
}

/** @extends BaseHydrator */
class UserHydrator extends BaseHydrator {}

$repo->setHydrator(new UserHydrator());
$user = $repo->findObject(1);
```

---

🧩 Key Features
==============

[](#-key-features)

- **Generic CRUD**: `find`, `findBy`, `findOneBy`, `insert`, `update`, `delete`, `count`, `paginate`.
- **Advanced Filtering**: `IN`, `LIKE`, ranges (`>`, ` **Important**: To ensure predictability, this library enforces strict rules for MongoDB ID casting.

- **Casting is allowed ONLY in `find(id)`**
- **24-char hex strings are cast ONLY in `find(id)`**
- `findBy`, `paginate`, and filters **NEVER** cast automatically
- Explicit `new ObjectId(...)` is required in filters

**Positive Example (Casting happens):**

```
// Automatically converts string "507f1f77bcf86cd799439011" to ObjectId
$repo->find("507f1f77bcf86cd799439011");
```

**Negative Example (No casting happens):**

```
// Remains a literal string "507f1f77bcf86cd799439011"
$repo->findBy(['custom_id' => "507f1f77bcf86cd799439011"]);
```

---

📄 Documentation
===============

[](#-documentation)

- [**New Developer Onboarding**](docs/ONBOARDING.md)
- [**Full Documentation**](docs/README.full.md)
- [**Practical Usage Guide (Examples)**](examples/Examples.md)

**📚 Development History &amp; Phase Details**The development of this library follows a strict phase-based roadmap.

- [**Phase 1: Bootstrap**](docs/phases/README.phase1.md)
- [**Phase 3: Generic CRUD**](docs/phases/README.phase3.md)
- [**Phase 15: Pagination**](docs/phases/README.phase15.md)
- [**Phase 16: Pagination Optimization**](docs/phases/README.phase16.md)
- [**Phase 17: Hydrated Pagination**](docs/phases/README.phase17.md)
- [**Phase 20: SQL &amp; Filter Improvements**](docs/phases/README.phase20.md)
- [**Phase 21: Architecture Decoupling**](docs/phases/README.phase21.md)
- [**Phase 22: FilterParser Extraction**](docs/phases/README.phase22.md)
- [**Phase 26: Public API Tightening**](docs/phases/README.phase26.md)
- [**Phase 28: PHPStan Generics**](docs/phases/README.phase28.md)
- [**Phase 29: Developer Experience**](docs/phases/README.phase29.md)

---

📚 Development History &amp; Phase Details
=========================================

[](#-development-history--phase-details)

**Click to expand**This library evolves through a strict phase-based roadmap.

### Major Completed Phases

[](#major-completed-phases)

- Phase 1 – Bootstrap &amp; Foundation
- Phase 3 – Generic CRUD
- Phase 15–17 – Pagination Improvements &amp; Hydration
- Phase 20 – SQL &amp; Filter Enhancements
- Phase 21 – Architecture Decoupling
- Phase 22 – FilterParser Extraction
- Phase 26 – Public API Tightening
- Phase 28 – PHPStan Generics
- Phase 29 – Developer Experience

Full details available in `docs/phases/`.

---

🧱 Dependencies Overview
=======================

[](#-dependencies-overview)

`maatify/data-repository` relies on Maatify core ecosystem + selected open-source libraries.

---

🧩 Maatify Ecosystem Dependencies
--------------------------------

[](#-maatify-ecosystem-dependencies)

PackageDescriptionRole**maatify/bootstrap**Environment loader, diagnostics, helpersPowers `.env` and adapter bootstrapping**maatify/data-adapters**Real MySQL/Mongo/Redis adaptersProduction database connectivity**maatify/data-fakes**Fake in-memory driversDeterministic, Docker-free testing---

🔌 Direct Open-Source Dependencies
---------------------------------

[](#-direct-open-source-dependencies)

LibraryPurposepsr/logLogging interfacephpunit/phpunitTest suitephpstan/phpstanStatic analysismongodb/mongodbMongoDB driverpredis/predis / php-redisRedis driverdoctrine/dbal *(optional)*MySQL DBAL abstraction---

🔄 Indirect Dependencies (via bootstrap)
---------------------------------------

[](#-indirect-dependencies-via-bootstrap)

LibraryPurposevlucas/phpdotenv`.env` loaderpsr/containerDI compatibility> Special thanks to the maintainers of these open-source libraries for providing the stable foundations that make this project possible. ❤️

---

🧪 Testing
=========

[](#-testing)

```
composer test
```

Runs:

- Real vs Fake consistency checks
- Filter/Order parser tests
- Pagination &amp; Hydration tests
- Architecture tests
- Coverage with Clover output

---

🪪 License
---------

[](#-license)

**[MIT License](LICENSE)**
© [Maatify.dev](https://www.maatify.dev) — Free to use, modify, and distribute with attribution.

---

👤 Author
--------

[](#-author)

Engineered by **Mohamed Abdulalim** ([@megyptm](https://github.com/megyptm))
Backend Lead &amp; Technical Architect —

---

🤝 Contributors
--------------

[](#-contributors)

Special thanks to the Maatify.dev engineering team and all open-source contributors.
Your efforts help make this repository stronger and more reliable.

Contributions are always welcome!
Before opening a Pull Request, please make sure to read our
[Contributing Guide](CONTRIBUTING.md) and [Code of Conduct](CODE_OF_CONDUCT.md).

---

 Built with ❤️ by [Maatify.dev](https://www.maatify.dev) — Unified Ecosystem for Modern PHP Libraries

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance73

Regular maintenance activity

Popularity0

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 70.4% 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

Unknown

Total

1

Last Release

163d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1a885a0810f2762586520ab284c9019aaf0b650b53cdf2a6c13ea10931bb7795?d=identicon)[Maatify](/maintainers/Maatify)

---

Top Contributors

[![megyptm](https://avatars.githubusercontent.com/u/33574895?v=4)](https://github.com/megyptm "megyptm (152 commits)")[![google-labs-jules[bot]](https://avatars.githubusercontent.com/in/842251?v=4)](https://github.com/google-labs-jules[bot] "google-labs-jules[bot] (56 commits)")[![Maatify](https://avatars.githubusercontent.com/u/130119162?v=4)](https://github.com/Maatify "Maatify (8 commits)")

---

Tags

abstractionadaptersclean-architecturedata-layerdbaldesign-patternsdoctrine-dbalmaatifymaatify-ecosystemmongomongodbmysqlpdophpphp8phpredispredisredisrepositoryrepository-patternabstractionmysqlpdoredisadapterpredismongodbrepository patternrepositorydesign patternsphpredismongoclean architecturedoctrine-dbaldata layerdata-repositorymaatifymysql-dbal

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/maatify-data-repository/health.svg)

```
[![Health](https://phpackages.com/badges/maatify-data-repository/health.svg)](https://phpackages.com/packages/maatify-data-repository)
```

###  Alternatives

[doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database schema introspection and management.

9.7k578.4M5.6k](/packages/doctrine-dbal)[phpfastcache/phpfastcache

PHP Abstract Cache Class - Reduce your database call using cache system. Phpfastcache handles a lot of drivers such as Apc(u), Cassandra, CouchBase, Couchdb, Dynamodb, Firestore, Mongodb, Files, (P)redis, Leveldb, Memcache(d), Ravendb, Ssdb, Sqlite, Wincache, Xcache, Zend Data Cache.

2.4k5.0M130](/packages/phpfastcache-phpfastcache)[apix/cache

A thin PSR-6 cache wrapper with a generic interface to various caching backends emphasising cache taggging and indexing to Redis, Memcached, PDO/SQL, APC and other adapters.

114542.8k6](/packages/apix-cache)[mmucklo/queue-bundle

Symfony2/3/4/5 Queue Bundle (for background jobs) supporting Mongo (Doctrine ODM), Mysql (and any Doctrine ORM), RabbitMQ, Beanstalkd, Redis, and ... {write your own}

120839.8k](/packages/mmucklo-queue-bundle)[rybakit/phive-queue

$queue-&gt;push('I can be popped off after', '10 minutes');

16441.5k1](/packages/rybakit-phive-queue)[desarrolla2/cache

Provides an cache interface for several adapters Apc, Apcu, File, Mongo, Memcache, Memcached, Mysql, Mongo, Redis is supported.

1322.5M47](/packages/desarrolla2-cache)

PHPackages © 2026

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