This project is an advanced, open-source boilerplate demonstrating a comprehensive architecture for building scalable SaaS (Software as a Service) applications with Laravel 12.
Beyond standard multi-tenancy, this application is built on three core pillars:
-
🏢 Multi-Tenant Foundation: Each client (tenant) operates with a completely isolated database, ensuring data privacy and security, all managed from a central application. (Powered by
stancl/tenancy) -
📦 Multi-Module Architecture: The backend is organized into independent modules (e.g.,
School,Billing). This approach ensures superior maintainability and scalability, allowing development teams to work on features in isolation and keeping the core application lean. (Implemented withnwidart/laravel-modules) -
🎨 Multi-Theme System: Offer true customization to your clients. Each tenant can have a unique visual identity with a dynamic theming system that loads tenant-specific Blade views, components, and assets (CSS/JS) compiled with Vite.
This powerful combination provides a solid foundation for any ambitious SaaS project.
This repository serves as a practical companion to the full course available here:
- Multi-Tenant Architecture: Complete data isolation for each client using the
stancl/tenancypackage. - Central Database: Manages tenants, their domains, and global application settings.
- Automated Tenant Setup: On-the-fly creation, migration, and seeding of tenant databases.
- Modular Architecture: The codebase is organized into modules (e.g.,
School,Billing) usingnwidart/laravel-modulesfor better maintainability. - Dynamic Theming System: Each tenant can be assigned a unique visual theme, with assets (CSS/JS) compiled via Vite.js.
- Performance: Uses Redis for handling cache, sessions, and queues.
- Admin Panel: A complete CRUD interface in the central application to manage tenants and their domains.
- Framework: Laravel 12
- Multi-Tenancy:
stancl/tenancy - Modularity:
nwidart/laravel-modules - Database: MySQL
- Cache & Sessions: Redis (
predis/predis) - Frontend: Blade, Tailwind CSS, Alpine.js
- Asset Compilation: Vite.js
-
Clone the project
git clone https://github.com/ousrah/multitenants.git cd multitenants -
Install dependencies
composer install npm install
-
Environment Setup
- Copy the
.env.examplefile to.env. - Configure your central database credentials (
DB_*). - Configure your Redis server connection details (
REDIS_*).
cp .env.example .env php artisan key:generate
- Copy the
-
Run central migrations This command will create the
tenants,domains, and other central tables in your main database.php artisan migrate
-
Compile assets
npm run build
-
Configure your
hostsfile (for local testing) Add your test domains to yourhostsfile to point them to your local machine.- Windows:
C:\Windows\System32\drivers\etc\hosts - macOS/Linux:
/etc/hosts
127.0.0.1 central.manar.com # Central domain 127.0.0.1 school1.manar.com # Example tenant domain - Windows:
-
Start the server
php artisan serve --host=0.0.0.0 --port=8000
You can now access the central application at
http://central.manar.com:8000.
This project was developed and is maintained by:
- Name: Rahmouni Oussama
- Title: Trainer in Software Development & Data Science, ISMO
- Email: ousrah@hotmail.com
- Phone: +212 6 12 96 24 66
Feel free to reach out with any questions or for collaboration opportunities.