{"id":27771632,"url":"https://github.com/webreinvent/vaahcms-module-saas","last_synced_at":"2025-04-29T22:44:48.740Z","repository":{"id":45301483,"uuid":"308719574","full_name":"webreinvent/vaahcms-module-saas","owner":"webreinvent","description":"Multi-tenant SaaS Module for VaahCMS","archived":false,"fork":false,"pushed_at":"2024-12-23T05:17:50.000Z","size":5280,"stargazers_count":21,"open_issues_count":1,"forks_count":3,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-29T22:44:43.110Z","etag":null,"topics":["multi-tenancy","multi-tenant","multi-tenant-database","saas","vaahcms"],"latest_commit_sha":null,"homepage":"https://vaah.dev/saas","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/webreinvent.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-10-30T19:00:06.000Z","updated_at":"2025-04-07T16:28:29.000Z","dependencies_parsed_at":"2022-09-02T22:20:22.547Z","dependency_job_id":"e2e29496-0e3a-4b1d-8d5f-e268655a2002","html_url":"https://github.com/webreinvent/vaahcms-module-saas","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webreinvent%2Fvaahcms-module-saas","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webreinvent%2Fvaahcms-module-saas/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webreinvent%2Fvaahcms-module-saas/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webreinvent%2Fvaahcms-module-saas/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/webreinvent","download_url":"https://codeload.github.com/webreinvent/vaahcms-module-saas/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251596613,"owners_count":21615014,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["multi-tenancy","multi-tenant","multi-tenant-database","saas","vaahcms"],"created_at":"2025-04-29T22:44:48.271Z","updated_at":"2025-04-29T22:44:48.732Z","avatar_url":"https://github.com/webreinvent.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# VaahSaaS - vaahcms-module-saas\n\u003e Module for multi-tenancy SaaS product development\n\n---\n## Features\n\n### Completed\n:white_check_mark: Support for DigitalOcean Database (Requires PHP version =\u003e 7.4 \u0026 `ssl_ca_path` \nis path of ssl certificate which is also required)\n\n:white_check_mark: CRUD for Database servers | Type: MySql \u0026 Cpanel MySql\n\n:white_check_mark: CRUD for Tenant\n\n:white_check_mark: Identify Tenant via Sub-Domain  | `tenant1.example.com` or `tenant2.example.com`\n\n:white_check_mark: Identify Tenant via Path  | `example.com/tenant1` or `example.com/tenant2`\n\n\n\n### Planned\n\n:black_square_button: Identify Tenant via Domain  | `example.com`\n\n\n---\n\n## Usages\n\n### Identify Tenant via `URL` and `middleware`\n\n**- By Path**\n\nAdd `tenant_by_path` middleware and `path` parameter is required to identify the `tenant`\n```php\nRoute::group(\n[\n    'prefix'     =\u003e '/\u003cURI\u003e/{path}',\n    'middleware' =\u003e ['web', 'tenant_by_path'],\n    'namespace' =\u003e 'Frontend',\n],\nfunction () {\n    //------------------------------------------------\n    Route::get( '/', 'TenantController@index' )\n        -\u003ename( 'vh.frontend.tenant' );\n    //------------------------------------------------\n});\n```\n\n**- By Sub-domain**\n\nAdd `tenant_by_sub_domain` middleware to identify the `tenant`\n```php\nRoute::group(\n    [\n        'domain' =\u003e '{sub_domain}.domain.com',\n        'prefix'     =\u003e '/\u003croot-uri-sub-domain\u003e', //this should not conflict with root domain\n        'middleware' =\u003e ['web', 'tenant_by_sub_domain'],\n        'namespace' =\u003e 'Frontend',\n    ],\n    function () {\n        //------------------------------------------------\n        Route::get( '/', 'TenantController@index' )\n            -\u003ename( 'vh.tenant' );\n        //------------------------------------------------\n    });\n```\n\n**- By domain - Pending for Future Release**\n\nAdd `tenant_by_domain` middleware to identify the `tenant`\n```php\nRoute::group(\n[\n    'middleware' =\u003e ['web', 'tenant_by_domain'],\n    'namespace' =\u003e 'Frontend',\n],\nfunction () {\n    //------------------------------------------------\n    Route::get( '/', 'TenantController@index' )\n        -\u003ename( 'vh.frontend.tenant' );\n    //------------------------------------------------\n});\n```\n\n### Identify Tenant via `Tenant` model instance\n\n```php\n$tenant = Tenant::find($id);\n\n$tenancy = new Tenancy($tenant);\n\n//to connect tenant database\n$tenancy-\u003estart();\n\n//disconnect to tenant database and reconnect to central database\n$tenancy-\u003eend();\n\n```\n\n### Tenant `Database` operations\n\n```php\n$tenant = Tenant::find(2);\n\n$db_manager = new DatabaseManager();\n//$created = $db_manager-\u003ecreateDatabase($tenant);\n//$created = $db_manager-\u003edeleteDatabase($tenant);\n//$created = $db_manager-\u003edatabaseExists($tenant);\n\n```\n\n### Tenant `migrations` \u0026 `seeds` operations\n```php\n$inputs = [\n   'command' =\u003e '',\n   'path' =\u003e '',\n];\n\n\nTenant::migrate($inputs, $tenant_id);\n\n\n\n$inputs = [\n   'command' =\u003e '',\n   'class' =\u003e '',\n];\n\n\nTenant::seed($inputs, $tenant_id);\n\n```\n\n### Share Cache with Sub Domains\nAdd following to your `.env` file:\n```dotenv\nSESSION_DOMAIN=.domain.com\n```\nReplace `domain.com` with you actual domain. Clear cache `php artisan config:cache` so that new setting can be applied.\n\n### Add Prefix to Tenant's Database and Username\n```dotenv\nSAAS_DB_PREFIX=example\n```\nThis will result in database name like:\n```dotenv\nexample_tenant_database\nexample_tenant_database_user\n```\n\n---\n\n#### For hot reload\nAPP_MODULE_SAAS_ENV=develop\n\n---\n\n## Setup wildcard sub domains on CPanel for Laravel\n\nWild Card SSL: https://certifytheweb.com/\n \nOther SSL Sources: https://letsencrypt.org/docs/client-options/ \n\n- Login `CPanel \u003e\u003e Subdomains`, enter `*` in subdomain, in `domain` choose `top level domain`, \nremove `_wildcard_` from `Document Root`.\n\nAfter this if you visit any subdomain it will show SSL error, to resolve it we need to install\n`wildcard ssl`. \n- Visit `https://www.sslforfree.com/` and enter `*.yourdomain.com` and click `Create Free Certificate`\n- Add `A` record to domain as per the instruction. On next page it will show all there SSL Certificate strings.\n- Login `CPanel \u003e\u003e SSL/TLS \u003e\u003e Manage SSL sites \u003e\u003e Install an SSL Website` and choose `*.yourdomain.com` and enter SSL Certificate string to respective section and save.\n- Now try to visit any sub domain all of them should be working.\n- Before deploying VaahSaas, create a folder `vaahsaas` and move all files and folder in that except `public`\n- Rename `public` folder to `public_html` and change the content to following:\n```php\nrequire __DIR__.'/../vaahsaas/vendor/autoload.php';\n$app = require_once __DIR__.'/../vaahsaas/bootstrap/app.php';\n```\n- So in root folder you will have two folder `vaahsaas` and `public_html` which can been deployed to the `root` of cpanel\n\n\n---\n### Xampp - Custom domain \n\n- Open `\u003cxampp\u003e\\apache\\conf\\extra\\httpd-vhosts.conf` add following code:\n```shell\n\u003cVirtualHost yourdomain.com\u003e\n  DocumentRoot \"\u003cxampp-path\u003e/htdocs/vaahsaas_director/public\"\n  ServerName yourdomain.com\n\n  \u003cDirectory \"\u003cxampp-path\u003e/htdocs/vaahsaas_director/public\"\u003e\n    Options Indexes FollowSymLinks\n    AllowOverride All\n    Order allow,deny\n    Allow from all\n  \u003c/Directory\u003e\n\u003c/VirtualHost\u003e\n\n\u003cVirtualHost test.yourdomain.com\u003e\n  DocumentRoot \"\u003cxampp-path\u003e/htdocs/vaahsaas_director/public\"\n  ServerName test.yourdomain.com\n\n  \u003cDirectory \"\u003cxampp-path\u003e/htdocs/vaahsaas_director/public\"\u003e\n    Options Indexes FollowSymLinks\n    AllowOverride All\n    Order allow,deny\n    Allow from all\n  \u003c/Directory\u003e\n\u003c/VirtualHost\u003e\n```\n\n- Then open `notepad` as administrator `C:\\Windows\\System32\\drivers\\etc\\host`\n- Add following lines:\n```shell\n127.0.0.1 yourdomain.com\n127.0.0.1 test.yourdomain.com\n```\n- You may see some error`test.yourdomain.com` like `Tenancy Not Identified` if you have already \nnot created any tenancy for the domain.\n\n---\n\n## To deploy the project locally, please follow these steps:\n\n**1. Install VaahCMS:**\n\n- VaahCMS is the foundation for our project, and Saas is a module within it.\n- Follow the installation guide provided [here](https://docs.vaah.dev/vaahcms-2x/getting-started/installation) to set up VaahCMS on your local system.\n\u003e **_NOTE:_**  VaahCMS Doc Link: https://docs.vaah.dev/vaahcms-2x\n\n\n**2. Integrate Saas Module:**\n\n- Once VaahCMS is successfully installed, navigate to the VaahCMS directory located at `\u003croot-path\u003e/VaahCms/Modules`.\n- Create a new folder named `Saas`.\n- Clone the Saas repository into this newly created folder.\n\n\u003e **_NOTE:_**  Ensure that the module directory's name does not contain any spaces, as this could affect the namespace.\n\n**Activation Process:**\n\nNow, let's activate the Saas module to utilize its functionalities:\n\n1. Access the VaahCMS backend by visiting `\u003cbase-url\u003e/public/backend#/vaah/modules`.\n2. Locate the Saas module in the list of available modules.\n3. Click on the \"activate\" button next to the Saas module.\n4. Once activated successfully, you'll see the module link appearing in the sidebar section of Vaah CMS.\n\n---\n\n## Resource\n- https://tenancyforlaravel.com/docs/v3/tenants/\n\n---\n## Commands\n```shell script\nphp artisan migrate --path=/VaahCms/Modules/Saas/Database/Migrations\n\nphp artisan migrate:rollback  --path=/VaahCms/Modules/Saas/Database/Migrations\n\nphp artisan db:seed --class=VaahCms\\Modules\\Saas\\Database\\Seeds\\SampleDataTableSeeder\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebreinvent%2Fvaahcms-module-saas","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwebreinvent%2Fvaahcms-module-saas","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebreinvent%2Fvaahcms-module-saas/lists"}