PHPackages                             rudra/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. [Framework](/categories/framework)
4. /
5. rudra/model

ActiveLibrary[Framework](/categories/framework)

rudra/model
===========

Rudra framework

v26.7.27(3w ago)15791MPL-2.0PHPPHP ^8.3CI passing

Since Jun 1Pushed 3w ago2 watchersCompare

[ Source](https://github.com/Jagepard/Rudra-Model)[ Packagist](https://packagist.org/packages/rudra/model)[ RSS](/packages/rudra-model/feed)WikiDiscussions master Synced 6d ago

READMEChangelog (10)Dependencies (24)Versions (13)Used By (1)

[![PHPunit](https://github.com/Jagepard/Rudra-Model/actions/workflows/php.yml/badge.svg)](https://github.com/Jagepard/Rudra-Model/actions/workflows/php.yml)[![Maintainability](https://camo.githubusercontent.com/cbb4ec56f31701cffff8b0b802bc20e1b7350c0cc62291eeb24303c6d24af4ca/68747470733a2f2f716c74792e73682f6261646765732f63613862623539312d666636362d343163332d386631382d3464346139336233656534312f6d61696e7461696e6162696c6974792e737667)](https://qlty.sh/gh/Jagepard/projects/Rudra-Model)[![CodeFactor](https://camo.githubusercontent.com/48c85b6306a90ecd126aed6ad305e05a89bf36c4862cc05f48251ee53afcfd58/68747470733a2f2f7777772e636f6465666163746f722e696f2f7265706f7369746f72792f6769746875622f6a616765706172642f72756472612d6d6f64656c2f6261646765)](https://www.codefactor.io/repository/github/jagepard/rudra-model)[![Coverage Status](https://camo.githubusercontent.com/e7bbd7a62dfe4d7e6213509b313076147815cef86e609f65e6446f3805be7f32/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f4a616765706172642f52756472612d4d6f64656c2f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/Jagepard/Rudra-Model?branch=master)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

[](#)

Rudra-Model | [API](https://github.com/Jagepard/Rudra-Model/blob/master/docs.md "Documentation API")
====================================================================================================

[](#rudra-model--api)

Rudra-Model is a lightweight, transparent, and ORM-free data access layer for the Rudra Framework. Built on the KISS principle, it avoids hidden dependencies and "magic" by providing direct access to PDO and a fluent Query Builder.

Instead of a heavy ORM, it uses a simple and predictable delegation chain: **Entity → Model → Repository**. If a specific Model or Repository is not defined, it seamlessly falls back to the base `Repository` class, giving you out-of-the-box CRUD operations without writing boilerplate code.

Architecture &amp; Delegation
-----------------------------

[](#architecture--delegation)

The component relies on a predictable fallback mechanism to minimize boilerplate:

1. **Entity**: The entry point for your domain objects. You only need to define the table name.
2. **Model**: Business logic layer. Calls are forwarded to the `Repository`.
3. **Repository**: Data access layer. Handles the actual database interaction.

If you don't create a `Model` or `Repository` for your entity, the base `Repository` class automatically handles standard CRUD operations for the specified table.

Usage Examples
--------------

[](#usage-examples)

### 1. Basic Entity Setup (Zero Boilerplate)

[](#1-basic-entity-setup-zero-boilerplate)

Define your entity and specify the table name. You don't need to create Model or Repository classes unless you need custom logic.

```
namespace App\Containers\SomeContainer\Entity;

use Rudra\Model\Entity;

class User extends Entity
{
    public static ?string $table = 'users';
}

// Usage:
$users = User::getAll(); // Calls base Repository::getAll()
$user  = User::find(1);  // Calls base Repository::find()
User::create(['name' => 'John', 'email' => 'john@example.com']);
```

### 2. Custom Repository Logic

[](#2-custom-repository-logic)

If you need custom queries, simply create a Repository class. The Entity will automatically route calls to it.

```
namespace App\Containers\SomeContainer\Repository;

use Rudra\Model\Repository;

class UserRepository extends Repository
{
    public function findActiveUsers(): array
    {
        return $this->qBuilder("SELECT * FROM {$this->table} WHERE active = 1");
    }
}

// Usage:
$activeUsers = User::findActiveUsers(); // Automatically routed to UserRepository
```

### 3. Using the Query Builder (QB)

[](#3-using-the-query-builder-qb)

Build queries fluently. The QB simply builds the SQL string, which is then executed by the Repository.

```
use Rudra\Model\QBFacade as QB;

$query = QB::select('id, name, email')
    ->from('users')
    ->where('status = :status')
    ->and('role = :role')
    ->orderBy('created_at DESC')
    ->limit(10)
    ->get();

// Resulting SQL:
// SELECT id, name, email FROM users WHERE status = :status AND role = :role ORDER BY created_at DESC LIMIT 10;

// Execute via Repository:
$results = User::qBuilder($query, ['status' => 'active', 'role' => 'admin']);
```

### 4. Creating Tables (Schema)

[](#4-creating-tables-schema)

Define your database schema using the Query Builder.

```
use Rudra\Model\Schema;

Schema::create('users', function ($table) {
    $table->integer('id', autoincrement: true)
          ->string('name')
          ->string('email')
          ->text('bio', 'NULL')
          ->createdAt()
          ->updatedAt()
          ->primaryKey('id');
})->execute();
```

### 5. Simple File Caching

[](#5-simple-file-caching)

Cache query results to JSON files to reduce database load. Simple, reliable, and easy to clear.

```
// Cache the result of getAll()
$users = User::cache(['getAll']);

// Cache a custom method with parameters (e.g., '+1 hour' or '+1 day')
$posts = Post::cache(['findBy', ['category', 'news']], '+1 hour');

// Clear cache after data modification (automatically called in create/update/delete)
User::clearCache('database');
```

License
-------

[](#license)

This project is licensed under the **Mozilla Public License 2.0 (MPL-2.0)** — a free, open-source license that:

- Requires preservation of copyright and license notices,
- Allows commercial and non-commercial use,
- Requires that any modifications to the original files remain open under MPL-2.0,
- Permits combining with proprietary code in larger works.

📄 Full license text: [LICENSE](./LICENSE)
🌐 Official MPL-2.0 page:

###  Health Score

56

—

FairBetter than 97% of packages

Maintenance95

Actively maintained with recent releases

Popularity18

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity85

Battle-tested with a long release history

 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 ~270 days

Recently: every ~4 days

Total

12

Last Release

23d ago

Major Versions

v2.0.0 → v25.62025-06-27

v25.12 → v26.12025-12-29

PHP version history (3 changes)v2.0.0PHP &gt;=7.1

v25.6PHP &gt;=8.3

v26.7.1PHP ^8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/75e65761bdd94035d1c783773a706d5722ce3164fe55d9722581c2cb4a642d8c?d=identicon)[jagepard](/maintainers/jagepard)

---

Top Contributors

[![Jagepard](https://avatars.githubusercontent.com/u/4591345?v=4)](https://github.com/Jagepard "Jagepard (208 commits)")

---

Tags

rudramodelrudra

### Embed Badge

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

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

###  Alternatives

[lorenzo/linkable

CakePHP Linkable Behavior

2755.3k](/packages/lorenzo-linkable)[yiisoft/form-model

Provides a base for form models and helps to fill, validate and display them.

1756.4k12](/packages/yiisoft-form-model)

PHPackages © 2026

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