定制 amrshah/tenant-engine 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

amrshah/tenant-engine

Composer 安装命令:

composer require amrshah/tenant-engine

包简介

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

README 文档

README

Latest Version Total Downloads License

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

Features

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

  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 & 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 & password reset

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

  • 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

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

System Health Monitoring

  • Health check endpoints (/health, /ping, /version, /status)
  • Database, Redis, Storage, Queue monitoring
  • Performance metrics

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

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

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

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

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

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

Create Super Admin

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

Create First Tenant

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

Access API Documentation

Navigate to:

http://localhost:8000/api/documentation

API Endpoints

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

# 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

# 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

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

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

Contributions are welcome! Please see CONTRIBUTING.md for details.

Security

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

License

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

Author

Ali Raza (a.k.a Amr Shah)

Acknowledgments

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

Made with ❤️ by Ali Raza (Amr Shah)

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

amrshah/tenant-engine 适用场景与选型建议

amrshah/tenant-engine 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 01 月 06 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「api」 「oauth」 「laravel」 「saas」 「rbac」 「multi-tenant」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 amrshah/tenant-engine 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 amrshah/tenant-engine 我们能提供哪些服务?
定制开发 / 二次开发

基于 amrshah/tenant-engine 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 3
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 29
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-06