Skip to content

stevepop/crm-with-sprout

Repository files navigation

Multi-Tenant CRM Demo with Sprout

This repository contains the code for a demonstration CRM application built with Laravel and the Sprout package for multi-tenancy. The demo shows how to implement a multi-tenant architecture where tenant data is isolated within a single database while maintaining a single codebase.

welcome

Features

  • Multi-tenant architecture using the Sprout Laravel package
  • Subdomain-based tenant identification
  • Data isolation within a single database
  • Automatic tenant detection
  • Scoped data access to prevent cross-tenant access

Dashboard Preview

dashboard

Getting Started

Follow these steps to set up the application locally:

Prerequisites

  • PHP 8.1+
  • Composer
  • Node.js & NPM
  • SQLIte or any other Laravel-supported database

Installation

  1. Clone the repository:

    git clone git@github.com:stevepop/crm-with-sprout.git
    cd crm-with-sprout
  2. Copy the environment file:

    cp .env.example .env
  3. Update the .env file with your database credentials and the following settings:

    SESSION_DRIVER=file
    TENANTED_DOMAIN=your-local-domain
    
  4. Install PHP dependencies:

    composer install
  5. Install JavaScript dependencies:

    npm install
  6. Generate application key:

    php artisan key:generate
  7. Run migrations and seeders:

    php artisan migrate --seed
  8. Start the development server:

    php artisan serve
  9. In a separate terminal, compile assets:

    npm run dev

Using the Demo

You can access the demo using the following tenant subdomains:

tenant1.your-local-domain or tenant1.localhost
tenant2.your-local-domain or tenant2.localhost

For local development, you may need to update your hosts file to map these subdomains to your local IP.

How It Works

The application uses Sprout middleware to resolve the current tenant based on the subdomain. While Sprout supports multiple resolution methods (subdomains, paths, headers, session, or cookies), this demo specifically uses the subdomain approach.

Once the tenant is identified, the application automatically scopes all database queries to the current tenant, ensuring data isolation between tenants.

Implementation Details

The multi-tenant architecture is implemented using the Sprout Laravel package, which provides:

  • Tenant resolution via subdomains
  • Automatic query scoping for tenant data isolation
  • Tenant-aware authentication
  • Tenant-aware routes

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is open-sourced software licensed under the MIT license.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages