This commit includes: - Django backend with multi-tenancy (django-tenants) - React + TypeScript frontend with Vite - Platform administration API with role-based access control - Authentication system with token-based auth - Quick login dev tools for testing different user roles - CORS and CSRF configuration for local development - Docker development environment setup 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
5.3 KiB
Platform Integration Summary
What We've Completed
✅ Backend (Django)
-
Created Platform App (
smoothschedule/platform/)apps.py- App configurationserializers.py- TenantSerializer, PlatformUserSerializer, PlatformMetricsSerializerpermissions.py- IsPlatformAdmin, IsPlatformUserviews.py- TenantViewSet, PlatformUserViewSeturls.py- URL routing
-
API Endpoints Created
GET /api/platform/businesses/- List all tenantsGET /api/platform/businesses/{id}/- Get specific tenantGET /api/platform/businesses/metrics/- Get platform metricsGET /api/platform/users/- List all usersGET /api/platform/users/{id}/- Get specific user
-
Configuration Updates
- Added
platformtoINSTALLED_APPSinconfig/settings/base.py - Added platform URLs to
config/urls.py
- Added
✅ Frontend (React)
The frontend already has complete implementation from the tarball:
-
Platform Pages
pages/platform/PlatformDashboard.tsx- Metrics and chartspages/platform/PlatformBusinesses.tsx- Tenant list with masqueradepages/platform/PlatformUsers.tsx- User managementpages/platform/PlatformSupport.tsx- Support ticketspages/platform/PlatformSettings.tsx- Platform settings
-
Routing
- Role-based access configured in
App.tsx - Routes protected by user role (SUPERUSER, PLATFORM_MANAGER, etc.)
- Role-based access configured in
-
API Integration
hooks/usePlatform.ts- React Query hooksapi/platform.ts- API client functions
Next Steps
1. Restart Django Server
The Django server needs to be restarted to pick up the new platform app:
# Stop the current server (Ctrl+C in the terminal)
# Then restart it
docker-compose -f docker-compose.local.yml restart django
2. Test API Endpoints
Once the server is restarted, test the endpoints:
# List all tenants (requires authentication)
curl -H "Authorization: Bearer YOUR_TOKEN" http://lvh.me:8000/api/platform/businesses/
# List all users
curl -H "Authorization: Bearer YOUR_TOKEN" http://lvh.me:8000/api/platform/users/
3. Create Platform Admin User
You need a user with platform admin role to access these endpoints:
# In Django shell
from smoothschedule.users.models import User
# Create or update a superuser
user = User.objects.filter(username='admin').first()
if user:
user.role = User.Role.SUPERUSER
user.is_staff = True
user.is_superuser = True
user.save()
4. Test Frontend
- Navigate to
http://platform.lvh.me:5173/ - Login with platform admin credentials
- You should see:
- Platform Dashboard with metrics
- Businesses page showing all tenants
- Users page showing all users
- Support and Settings pages
Known Limitations
Need to Add Tenant Reference to User Model
Currently, the User model doesn't have a direct reference to which Tenant they belong to. This is needed for:
- Showing business name in user list
- Filtering users by business
- Getting accurate owner information
To fix: Add a foreign key to User model:
# In smoothschedule/users/models.py
from core.models import Tenant
class User(AbstractUser):
# ... existing fields ...
tenant = models.ForeignKey(
Tenant,
on_delete=models.CASCADE,
null=True,
blank=True,
related_name='users',
help_text="Tenant this user belongs to (null for platform users)"
)
Then run migrations:
python manage.py makemigrations
python manage.py migrate
Architecture Notes
Multi-Tenancy with django-tenants
- Public Schema: Stores
TenantandDomainmodels - Tenant Schemas: Each tenant gets isolated PostgreSQL schema
- Platform API: Operates on public schema to list all tenants
- User Model: Stored in public schema (shared across tenants)
Permission Model
-
Platform Roles (access all tenants):
SUPERUSER- Full accessPLATFORM_MANAGER- Manage tenants and usersPLATFORM_SUPPORT- View-only accessPLATFORM_SALES- Sales operations
-
Tenant Roles (access single tenant):
TENANT_OWNER- Tenant administratorTENANT_MANAGER- Manage tenant settingsTENANT_STAFF- Use tenant features
-
Customer Role:
CUSTOMER- End user of tenant
File Structure
smoothschedule/
├── platform/ # NEW - Platform management app
│ ├── __init__.py
│ ├── apps.py
│ ├── serializers.py # API serializers
│ ├── permissions.py # Custom permissions
│ ├── views.py # ViewSets
│ └── urls.py # URL routing
├── core/
│ └── models.py # Tenant, Domain models
├── smoothschedule/users/
│ └── models.py # User model
└── config/
├── settings/base.py # Updated INSTALLED_APPS
└── urls.py # Added platform URLs
Testing the Complete Flow
- Backend: Platform API serving tenant/user data
- Frontend: React app consuming API and displaying in UI
- Authentication: Role-based access control
- Multi-tenancy: Proper isolation between tenants
Once the server is restarted and a platform admin user is created, the entire platform section should be functional!