Skip to content

Conversation

@zeyadrezk
Copy link

@zeyadrezk zeyadrezk commented Nov 14, 2025

Development Environment Tenant Selection System - Summary

What Was Added

I've implemented a development tenant selection system that allows developers to easily switch between organizations during local development without needing subdomain
routing.

The Problem It Solves

Before:

  • In local development, switching between organizations required manually changing subdomains or database configurations
  • Testing multiple organizations was cumbersome
  • New developers had difficulty understanding which organization they were working with

Now:

  • Developers see a beautiful selection page when they start
  • Easy switching between organizations with a single click
  • Clear visual feedback showing which organization is active
  • No need for subdomain configuration in local development

Key Features

  1. Automatic Tenant Detection
    - When you visit the app without a selected tenant, you're automatically redirected to the selection page
    - Once you select an organization, it's remembered in your session
  2. Beautiful UI
    - Wide cards with prominent borders showing all organizations
    - Each card displays: organization name, subdomain, and number of branches
    - Hover effects with pointer cursor for clear interactivity
    - Active tenant is clearly marked with a badge
    - Loading states when switching organizations
  3. Easy Switching
    - Visit /select-tenant anytime to switch organizations
    - Clear current selection option available
    - No page reloads needed after selection
  4. Production Safe
    - Only activates when APP_ENV=local
    - In production, the system is completely bypassed
    - Production continues using subdomain-based routing

Technical Implementation

New Files Added:

  • TenantSelectorController - Handles organization selection
  • TenantResolverService - Manages session-based tenant resolution
  • TenantRepository - Data access for organizations
  • TenantConfig - Configuration helper
  • SelectTenantRequest - Form validation
  • tenant-selector.blade.php - Beautiful UI page

Routes Added:

  • GET /select-tenant - Display selection page
  • POST /select-tenant/select - Save selection
  • POST /select-tenant/clear - Clear selection

How It Works:

  • Session-based tenant storage (uses tenant_id and tenant_subdomain)
  • Middleware checks for tenant on every request
  • Tenant is injected into request and app container for easy access
  • Only active in local environment

Benefits for Development Team

  1. Faster Development - No more subdomain configuration
  2. Easier Testing - Switch between organizations instantly
  3. Better Onboarding - New developers can immediately see and select organizations
  4. Visual Clarity - Always know which organization you're working with
  5. No Production Impact - Completely isolated to local development

How Developers Use It

  1. Start the app in local environment (APP_ENV=local)
  2. Visit any route - redirected to organization selector
  3. Click an organization card to select it
  4. Start working - tenant is active
  5. Switch anytime by visiting /select-tenant

This system makes local development much smoother and removes the complexity of managing subdomains while keeping production behavior unchanged.

image

  Implemented a comprehensive tenant selection system for local development, allowing developers to easily switch between organizations without subdomain routing. Includes
  a polished UI with organization cards featuring prominent borders, hover effects, and visual feedback.

  Key features:
  - Tenant selector page with enhanced visual design
  - TenantResolverService for managing current tenant context
  - Session-based tenant identification for development
  - Repository pattern for tenant data access
  - Clear selection workflow with visual indicators
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant