PHPackages                             mohamedhekal/tenantforge - 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. mohamedhekal/tenantforge

ActiveLibrary

mohamedhekal/tenantforge
========================

Shared-database multi-tenancy foundation for Laravel SaaS: tenants, domains, memberships, API keys, and isolation scopes

v0.1.0(1mo ago)00MITPHPPHP ^8.2CI passing

Since Jul 16Pushed 1mo agoCompare

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

READMEChangelogDependencies (12)Versions (2)Used By (0)

TenantForge
===========

[](#tenantforge)

[![CI](https://github.com/mohamedhekal/tenantforge/actions/workflows/tests.yml/badge.svg)](https://github.com/mohamedhekal/tenantforge/actions)[![License: MIT](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](LICENSE)[![PHP](https://camo.githubusercontent.com/c2588b5670f2c910b8cc849ace22a22efda8956b7c2f797d11d2096bbfc7b1f5/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e322532422d3737374242342e737667)](https://www.php.net/)[![Laravel](https://camo.githubusercontent.com/b38aa2ff655206bfa9f97c1aeced06f25bb3e31fb085fa974c79934c25469f41/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d313125324631322d4646324432302e737667)](https://laravel.com/)

**Search terms:** laravel, multitenancy, saas, tenants, api-keys, teams, php, laravel-package, multi-tenant, b2b-saas, isolation.

Shared-database multi-tenancy foundation for Laravel SaaS: tenants, domains, memberships, hashed API keys, plan stubs, and audited impersonation.

This is plumbing—not a finished product. Use it to start a B2B app without reinventing isolation basics.

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

[](#installation)

```
composer require mohamedhekal/tenantforge
php artisan vendor:publish --tag=tenantforge-config
php artisan migrate
```

Provision a tenant
------------------

[](#provision-a-tenant)

```
use Hekal\TenantForge\Facades\TenantForge;

$tenant = TenantForge::provision(
    name: 'Acme',
    ownerUserId: $user->id,
    slug: 'acme',
    domain: 'acme.app.test',
    planSlug: 'pro',
);
```

Scope models
------------

[](#scope-models)

```
use Hekal\TenantForge\Concerns\BelongsToTenant;

class Project extends Model
{
    use BelongsToTenant;
}
```

Initialize tenancy (middleware or manually):

```
Route::middleware('tenantforge.init')->group(...);
// identification: header X-Tenant | domain | subdomain (config)
```

API keys
--------

[](#api-keys)

```
['plain' => $plain, 'key' => $key] = TenantForge::apiKeys()->create($tenant, 'CI');
// store $plain once; only the hash is persisted
```

Middleware alias: `tenantforge.api` (`X-Api-Key`).

Entitlements (stubs)
--------------------

[](#entitlements-stubs)

Plans store a `features` list/map. `TenantForge::allows('webhooks')` checks the tenant’s active subscription.

Wire FlagDeck later for richer targeting; v0.1 keeps plans local and explicit.

Impersonation
-------------

[](#impersonation)

```
$log = TenantForge::impersonation()->start($tenant, $adminId, $userId, reason: 'ticket #12');
TenantForge::impersonation()->stop($log);
```

Limitations (v0.1)
------------------

[](#limitations-v01)

- Shared DB only (no DB-per-tenant driver yet)
- No Stripe/Paddle billing
- No Vue portal or Filament admin bundled
- Without tenant context, `BelongsToTenant` does not filter (intentional for migrations/CLI)—always initialize in HTTP/jobs

Testing
-------

[](#testing)

```
composer install && composer test
```

Isolation tests live under `tests/Feature/TenancyTest.php`.

License
-------

[](#license)

MIT

###  Health Score

34

—

LowBetter than 74% of packages

Maintenance90

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity36

Early-stage or recently created project

 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

Unknown

Total

1

Last Release

45d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a9d7c092a109fe780c7efd87ce4142eae2c0cec0f92fd1e87e769bec5661953b?d=identicon)[mohamedhekal](/maintainers/mohamedhekal)

---

Top Contributors

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

---

Tags

b2blaravellaravel-packagemultitenancyphpsaasphplaravellaravel-packageisolationsaasmulti-tenantmultitenancyTeamsapi keystenantsb2b-saas

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/mohamedhekal-tenantforge/health.svg)

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

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3365.5M359](/packages/psalm-plugin-laravel)[laravel/pulse

Laravel Pulse is a real-time application performance monitoring tool and dashboard for your Laravel application.

1.7k17.6M165](/packages/laravel-pulse)[pressbooks/pressbooks

Pressbooks is an open source book publishing tool built on a WordPress multisite platform. Pressbooks outputs books in multiple formats, including PDF, EPUB, web, and a variety of XML flavours, using a theming/templating system, driven by CSS.

45945.2k1](/packages/pressbooks-pressbooks)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

1.0k2.5M152](/packages/roots-acorn)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

255.2k](/packages/aedart-athenaeum)[laravel/scout

Laravel Scout provides a driver based solution to searching your Eloquent models.

1.7k59.5M712](/packages/laravel-scout)

PHPackages © 2026

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