PHPackages                             flametrench/tenancy - 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. flametrench/tenancy

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

flametrench/tenancy
===================

Tenancy primitives for Flametrench: organizations, memberships, invitations. Spec-conformant revoke-and-re-add lifecycle and atomic invitation acceptance.

v0.2.0(1mo ago)0271Apache-2.0PHPPHP ^8.3CI passing

Since Apr 25Pushed 2d agoCompare

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

READMEChangelog (2)Dependencies (2)Versions (9)Used By (1)

flametrench/tenancy
===================

[](#flametrenchtenancy)

[![CI](https://github.com/flametrench/tenancy-php/actions/workflows/ci.yml/badge.svg)](https://github.com/flametrench/tenancy-php/actions/workflows/ci.yml)

Tenancy primitives for [Flametrench](https://flametrench.dev): organizations, memberships, and invitations. Spec-conformant revoke-and-re-add lifecycle, atomic invitation acceptance, sole-owner protection, and a `mem_`/`tup_` duality maintained without drift.

The PHP counterpart of [`@flametrench/tenancy`](https://github.com/flametrench/node/tree/main/packages/tenancy) — same shapes, same invariants, same operations. Both SDKs are exercised against the spec's [conformance suite](https://github.com/flametrench/spec/tree/main/conformance) so applications can move between the two languages with no behavioral surprises.

**Status:** v0.2.0 (stable). PHP 8.3+ required. Includes the production-ready `PostgresTenancyStore` alongside the in-memory reference store; the Postgres adapter mirrors in-memory semantics byte-for-byte at the SDK boundary, and per ADR 0013 cooperates with adopter-side outer transactions via savepoints when nested.

Install
-------

[](#install)

```
composer require flametrench/tenancy
```

Quick start
-----------

[](#quick-start)

```
use Flametrench\Tenancy\InMemoryTenancyStore;
use Flametrench\Tenancy\PreTuple;
use Flametrench\Tenancy\Role;

$store = new InMemoryTenancyStore();

// Alice creates Acme and becomes its owner.
['org' => $org, 'ownerMembership' => $owner] = $store->createOrg('usr_0190...alice');

// Alice invites Carol with a project-scoped grant.
$inv = $store->createInvitation(
    orgId: $org->id,
    identifier: 'carol@example.com',
    role: Role::Guest,
    invitedBy: 'usr_0190...alice',
    expiresAt: new DateTimeImmutable('+7 days'),
    preTuples: [new PreTuple('viewer', 'proj', '0190...project42')],
);

// Carol accepts. Membership and pre-tuples materialize atomically.
$result = $store->acceptInvitation($inv->id, asUsrId: 'usr_0190...carol');
```

API
---

[](#api)

`TenancyStore` defines the contract every backend implements. Both the in-memory reference implementation and the production-ready `PostgresTenancyStore` ship with this package.

OperationReturns`createOrg(creator)``['org' => Organization, 'ownerMembership' => Membership]``getOrg / suspendOrg / reinstateOrg / revokeOrg``Organization``addMember / getMembership / changeRole / suspendMembership / reinstateMembership``Membership``selfLeave(memId, transferTo?)``Membership` (revoked)`adminRemove(memId, adminUsrId)``Membership` (revoked, with `removedBy` set)`transferOwnership(orgId, fromMemId, toMemId)``['fromMembership' => Membership, 'toMembership' => Membership]``listMembers(orgId, cursor?, limit, status?)``Page``createInvitation / getInvitation / declineInvitation / revokeInvitation``Invitation``acceptInvitation(invId, asUsrId?)``['invitation' => Invitation, 'membership' => Membership, 'materializedTuples' => Tuple[]]``listInvitations(orgId, cursor?, limit, status?)``Page``listTuplesForSubject(subjectType, subjectId)``Tuple[]``listTuplesForObject(objectType, objectId, relation?)``Tuple[]`Spec conformance
----------------

[](#spec-conformance)

Mirrors the normative spec: see [`spec/docs/tenancy.md`](https://github.com/flametrench/spec/blob/main/docs/tenancy.md) and the design decisions in [ADR 0002](https://github.com/flametrench/spec/blob/main/decisions/0002-tenancy-model.md) + [ADR 0003](https://github.com/flametrench/spec/blob/main/decisions/0003-invitation-state-machine.md).

The 31 PEST tests in this package cover every sole-owner-protection path, the `replaces` chain on role changes, atomic invitation acceptance with pre-tuple materialization, admin-hierarchy enforcement, ownership transfer atomicity, and `removedBy` attribution.

Errors
------

[](#errors)

Every error is a `Flametrench\Tenancy\Exceptions\TenancyException` subclass with a stable `flametrenchCode` matching the OpenAPI Error envelope:

ClassCode`NotFoundException``not_found``SoleOwnerException``conflict.sole_owner``RoleHierarchyException``forbidden.role_hierarchy``DuplicateMembershipException``conflict.duplicate_membership``AlreadyTerminalException``conflict.already_terminal``InvitationExpiredException``conflict.invitation_expired``InvitationNotPendingException``conflict.invitation_not_pending``ForbiddenException``forbidden``PreconditionException``precondition.`Development
-----------

[](#development)

```
composer install
composer test
```

License
-------

[](#license)

Apache License 2.0. Copyright 2026 NDC Digital, LLC.

###  Health Score

41

—

FairBetter than 87% of packages

Maintenance96

Actively maintained with recent releases

Popularity8

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity44

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

Total

8

Last Release

40d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/19826928?v=4)[Nathan Call](/maintainers/nathancall)[@nathancall](https://github.com/nathancall)

---

Top Contributors

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

---

Tags

multi-tenancytenancyinvitationsmembershipsorganizationsflametrench

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/flametrench-tenancy/health.svg)

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

###  Alternatives

[hyn/multi-tenant

Run multiple websites using the same laravel installation while keeping tenant specific data separated for fully independant multi-domain setups.

2.6k1.2M9](/packages/hyn-multi-tenant)[tenancy/tenancy

Creating multi tenant saas from your Laravel app with ease

1.3k44.9k](/packages/tenancy-tenancy)[gerardojbaez/laraplans

SaaS style recurring plans for Laravel.

17817.8k1](/packages/gerardojbaez-laraplans)[sbine/simple-tenancy

Simple Laravel multi-tenancy in the same database

373.6k](/packages/sbine-simple-tenancy)[codexshaper/laravel-pwa

Laravel Progressive Web App

153.0k](/packages/codexshaper-laravel-pwa)

PHPackages © 2026

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