PHPackages                             amrshah/tenant-engine - 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. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. amrshah/tenant-engine

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

amrshah/tenant-engine
=====================

Production-ready Laravel package for multi-tenant SaaS applications with Super Admin and Tenant Admin capabilities

1.0.0(5mo ago)03MITPHPPHP ^8.1

Since Nov 24Pushed 3mo agoCompare

[ Source](https://github.com/amrshah/Larave-Tenant-Engine)[ Packagist](https://packagist.org/packages/amrshah/tenant-engine)[ Docs](https://github.com/amrshah/tenant-engine)[ RSS](/packages/amrshah-tenant-engine/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (13)Versions (2)Used By (0)

TenantEngine - Multi-Tenant SaaS API Package for Laravel
========================================================

[](#tenantengine---multi-tenant-saas-api-package-for-laravel)

[![Latest Version](https://camo.githubusercontent.com/d26fa283fa69a85355a3171be05225ba0da976edcf9eafb4fd8032f6717a903b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616d72736861682f74656e616e742d656e67696e652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/amrshah/tenant-engine)[![Total Downloads](https://camo.githubusercontent.com/eee8a48d2528ac7eee5cc1dbce7ecc3e952162b933b426398ed076b60e12f848/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f616d72736861682f74656e616e742d656e67696e652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/amrshah/tenant-engine)[![License](https://camo.githubusercontent.com/41da9c51e02b9b2961695dc0399c3f8e21c7bc7642e3e40d5c49ed810f9939a7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f616d72736861682f74656e616e742d656e67696e652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/amrshah/tenant-engine)

**Production-ready Laravel package for building Multi-Tenant SaaS APIs with Super Admin and Tenant Admin capabilities.**

---

Features
--------

[](#features)

### Multi-Tenancy

[](#multi-tenancy)

- ✔ **Path-based tenant identification** (`/tenant-slug/api/...`)
- ✔ **Automatic database isolation** per tenant (powered by Stancl/Tenancy)
- ✔ **Tenant-aware caching** (Redis)
- ✔ **Tenant-specific storage** (S3/local)
- ✔ **Complete tenant isolation**

### Three-Level Access System

[](#three-level-access-system)

1. **Super Admin Level** - Manage all tenants, system analytics, global settings
2. **Central Level** - Authentication, tenant selection, user profile
3. **Tenant Level** - Tenant admin manages tenant resources

### Authentication &amp; Authorization

[](#authentication--authorization)

- ✔ **Laravel Sanctum** - Token-based authentication
- ✔ **OAuth 2.0** - Google, Microsoft, LinkedIn, Facebook
- ✔ **Laravel ARBAC** - Advanced RBAC + ABAC hybrid
- ✔ **Multi-tenant user access** - Users can belong to multiple tenants
- ✔ **Email verification** &amp; password reset

### External ID System

[](#external-id-system)

- ✔ **Nano ID** with custom prefixes (`USR_xxx`, `TNT_xxx`, `CLI_xxx`)
- ✔ **Never expose internal database IDs**
- ✔ **URL-safe, collision-resistant**
- ✔ **Automatic generation** via model trait

### API Standards

[](#api-standards)

- ✔ **JSON:API v1.1 compliant** responses
- ✔ **RESTful** design principles
- ✔ **API versioning** (`/api/v1/...`)
- ✔ **Cursor-based pagination** for scalability
- ✔ **Filtering, sorting, and including** relationships

### API Documentation

[](#api-documentation)

- ✔ **Swagger/OpenAPI 3.0** specification
- ✔ **Interactive API documentation** (Swagger UI)
- ✔ **Auto-generated** from code annotations

### System Health Monitoring

[](#system-health-monitoring)

- ✔ **Health check endpoints** (`/health`, `/ping`, `/version`, `/status`)
- ✔ **Database, Redis, Storage, Queue monitoring**
- ✔ **Performance metrics**

### Security

[](#security)

- ✔ **Rate limiting** (per user, per tenant, super admin)
- ✔ **CORS** configuration
- ✔ **Security headers** (CSP, X-Frame-Options, etc.)
- ✔ **SQL injection prevention** (Eloquent ORM)
- ✔ **XSS protection**

### Performance

[](#performance)

- ✔ **Redis caching** (tenant-aware)
- ✔ **Database query optimization** (indexes, eager loading)
- ✔ **Queue support** for heavy operations
- ✔ **Horizontal scalability**

---

Requirements
------------

[](#requirements)

- **PHP:** 8.1 or higher
- **Laravel:** 10.x, 11.x, or 12.x
- **MySQL:** 8.0+ or **PostgreSQL:** 13+
- **Redis:** 6.0+ (for caching and queues)
- **Composer:** 2.5+

### PHP Extensions

[](#php-extensions)

- BCMath, Ctype, Fileinfo, JSON, Mbstring, OpenSSL, PDO, Tokenizer, XML, cURL, Redis

---

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

[](#installation)

```
# Install via Composer
composer require amrshah/tenant-engine

# Publish configuration and migrations
php artisan vendor:publish --provider="Amrshah\TenantEngine\Providers\TenantEngineServiceProvider"

# Run installation command
php artisan tenant-engine:install
```

The installation command will:

- ✔ Publish configuration files
- ✔ Publish and run migrations
- ✔ Create default roles and permissions
- ✔ Generate Swagger documentation
- ✔ Set up example tenant (optional)

---

✔ Configuration
---------------

[](#-configuration)

Add to your `.env` file:

```
# Multi-Tenant Configuration
TENANT_ENGINE_ENABLED=true
TENANT_DB_PREFIX=tenant_

# OAuth Providers (Optional)
GOOGLE_CLIENT_ID=your-google-client-id
GOOGLE_CLIENT_SECRET=your-google-client-secret
GOOGLE_REDIRECT_URI="${APP_URL}/api/v1/auth/oauth/google/callback"

MICROSOFT_CLIENT_ID=your-microsoft-client-id
MICROSOFT_CLIENT_SECRET=your-microsoft-client-secret
MICROSOFT_REDIRECT_URI="${APP_URL}/api/v1/auth/oauth/microsoft/callback"

# API Configuration
API_RATE_LIMIT=1000
API_RATE_LIMIT_TENANT=10000
```

---

Quick Start
-----------

[](#quick-start)

### Create Super Admin

[](#create-super-admin)

```
php artisan tenant-engine:create-super-admin \
    --name="Admin" \
    --email="admin@example.com" \
    --password="SecurePassword123!"
```

### Create First Tenant

[](#create-first-tenant)

```
php artisan tenant-engine:tenant:create \
    --name="Acme Corporation" \
    --email="admin@acme.com" \
    --slug="acme-corp"
```

### Access API Documentation

[](#access-api-documentation)

Navigate to:

```
http://localhost:8000/api/documentation

```

---

API Endpoints
-------------

[](#api-endpoints)

### Super Admin APIs

[](#super-admin-apis)

```
# Tenant Management
GET    /api/v1/super-admin/tenants
POST   /api/v1/super-admin/tenants
GET    /api/v1/super-admin/tenants/{tenant}
PATCH  /api/v1/super-admin/tenants/{tenant}
DELETE /api/v1/super-admin/tenants/{tenant}
POST   /api/v1/super-admin/tenants/{tenant}/suspend
POST   /api/v1/super-admin/tenants/{tenant}/activate

# System Analytics
GET    /api/v1/super-admin/analytics/overview
GET    /api/v1/super-admin/analytics/tenants
GET    /api/v1/super-admin/analytics/users

# User Impersonation
POST   /api/v1/super-admin/impersonate/{user}
POST   /api/v1/super-admin/stop-impersonation
```

### Central APIs

[](#central-apis)

```
# Authentication
POST   /api/v1/auth/register
POST   /api/v1/auth/login
POST   /api/v1/auth/logout
GET    /api/v1/auth/me

# OAuth
GET    /api/v1/auth/oauth/{provider}
GET    /api/v1/auth/oauth/{provider}/callback

# Tenant Selection
GET    /api/v1/tenants
POST   /api/v1/tenants/{tenant}/switch
```

### Tenant Admin APIs

[](#tenant-admin-apis)

```
# User Management
GET    /{tenant}/api/v1/users
POST   /{tenant}/api/v1/users
GET    /{tenant}/api/v1/users/{user}
PATCH  /{tenant}/api/v1/users/{user}
DELETE /{tenant}/api/v1/users/{user}

# Role & Permission Management
GET    /{tenant}/api/v1/roles
POST   /{tenant}/api/v1/roles
GET    /{tenant}/api/v1/permissions

# Tenant Settings
GET    /{tenant}/api/v1/settings
PATCH  /{tenant}/api/v1/settings
```

### System Health

[](#system-health)

```
GET    /api/v1/health    # System health check
GET    /api/v1/ping      # Simple ping
GET    /api/v1/version   # Version info
GET    /api/v1/status    # System status (authenticated)
```

---

Documentation
-------------

[](#documentation)

- [Installation Guide](docs/installation.md)
- [Configuration Guide](docs/configuration.md)
- [Super Admin Guide](docs/super-admin-guide.md)
- [Tenant Admin Guide](docs/tenant-admin-guide.md)
- [API Reference](docs/api-reference.md)
- [Deployment Guide](docs/deployment.md)

---

Testing
-------

[](#testing)

```
# Run all tests
composer test

# Run with coverage
composer test:coverage

# Run Pest tests
composer test:pest

# Run static analysis
composer analyse

# Format code
composer format
```

---

Contributing
------------

[](#contributing)

Contributions are welcome! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for details.

---

Security
--------

[](#security-1)

If you discover any security-related issues, please email  instead of using the issue tracker.

---

License
-------

[](#license)

The MIT License (MIT). Please see [LICENSE](LICENSE) for more information.

---

Author
------

[](#author)

**Ali Raza** (a.k.a Amr Shah)

- GitHub: [@amrshah](https://github.com/amrshah)
- Email:
- Website: [amrshah.github.io](https://amrshah.github.io)

---

Acknowledgments
---------------

[](#acknowledgments)

This package is built on top of excellent open-source packages:

- [Laravel](https://laravel.com) - The PHP framework
- [Stancl/Tenancy](https://tenancyforlaravel.com) - Multi-tenancy for Laravel
- [Laravel Sanctum](https://laravel.com/docs/sanctum) - API authentication
- [Laravel Socialite](https://laravel.com/docs/socialite) - OAuth authentication
- [Laravel ARBAC](https://github.com/amrshah/laravel-arbac) - Advanced RBAC + ABAC
- [L5-Swagger](https://github.com/DarkaOnLine/L5-Swagger) - Swagger documentation
- [Nano ID](https://github.com/ai/nanoid) - Unique ID generator

---

**Made with ❤️ by Ali Raza (Amr Shah)**

**Version:** 1.0.0-alpha
**Last Updated:** 2025-11-23

###  Health Score

35

—

LowBetter than 79% of packages

Maintenance81

Actively maintained with recent releases

Popularity3

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity43

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

Unknown

Total

1

Last Release

166d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/90f157c51295d6bdcd833529eef62bcba7502ad24fb320678e8183bde3c01f40?d=identicon)[amrshah](/maintainers/amrshah)

---

Top Contributors

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

---

Tags

apilaravelswaggeroauthsanctumrbacsaasmulti-tenanttenancyabac

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/amrshah-tenant-engine/health.svg)

```
[![Health](https://phpackages.com/badges/amrshah-tenant-engine/health.svg)](https://phpackages.com/packages/amrshah-tenant-engine)
```

###  Alternatives

[andrewdwallo/filament-companies

A comprehensive Laravel authentication and authorization system designed for Filament, focusing on multi-tenant company management.

34450.0k2](/packages/andrewdwallo-filament-companies)[hasinhayder/tyro

Tyro - The ultimate Authentication, Authorization, and Role &amp; Privilege Management solution for Laravel 12 &amp; 13

6712.1k2](/packages/hasinhayder-tyro)

PHPackages © 2026

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