Skip to main content

Sites

Sites (also known as tenants) are isolated cloud environments within Taruvi Cloud. Each site represents a separate workspace with its own database schema, users, and data, providing complete data isolation.

Slug-Based URLs

All site endpoints now use slug-based URLs (e.g., /api/cloud/sites/production-site/) instead of UUID-based URLs. Slugs are human-readable identifiers automatically generated from the site name. UUIDs are still supported for backward compatibility.

Overview

A site is a fully isolated cloud environment that belongs to an organization. Sites enable:

  • Multi-tenancy: Each site has its own database schema
  • Data Isolation: Complete separation of data between sites
  • Custom Configuration: Site-specific settings and environments
  • Domain Management: Multiple domains can point to a single site

Key Features

Schema-Based Multi-Tenancy

Sites use django-tenants for schema-based isolation:

  • Each site gets its own PostgreSQL schema
  • Data is completely isolated at the database level
  • Sites can have different configurations and settings

Environment Types

Sites can be configured for different purposes using the environment field:

  • production: Live production environment
  • staging: Pre-production testing environment
  • development: Development and testing
  • testing: Automated testing environment

Site Settings

Each site can store custom configuration in the site_settings JSON field:

{
"site_settings": {
"feature_flags": {"analytics": true},
"branding": {"primary_color": "#007bff"},
"integrations": {"stripe_enabled": true}
}
}

Flexible Configuration

Each site can have:

  • Custom settings stored in JSON format
  • Multiple domains pointing to it
  • Organization association
  • Active/inactive status for soft deletion

Using Sites

Creating a Site

Create a new site within an organization:

POST /api/cloud/organizations/{org_slug}/sites/
Content-Type: application/json
Authorization: Bearer YOUR_ACCESS_TOKEN

{
"name": "Production Site",
"description": "Main production environment",
"environment": "production",
"site_settings": {
"feature_flags": {
"analytics": true,
"notifications": true
}
}
}

Example:

POST /api/organizations/acme-corp/sites/

Response:

{
"uuid": "750e8400-e29b-41d4-a716-446655440000",
"slug": "production-site",
"name": "Production Site",
"description": "Main production environment",
"schema_name": "production_site",
"environment": "production",
"is_active": true,
"site_settings": {
"feature_flags": {
"analytics": true,
"notifications": true
}
},
"created_at": "2024-01-15T10:30:00Z",
"modified_at": "2024-01-15T10:30:00Z"
}

Listing Sites

Get all sites within an organization:

GET /api/cloud/organizations/{org_slug}/sites/
Authorization: Bearer YOUR_ACCESS_TOKEN

Example:

GET /api/organizations/acme-corp/sites/

Query Parameters:

  • environment: Filter by environment type (production, staging, development, testing)
  • is_active: Filter by active status
    • true or 1: Only active sites (default)
    • false or 0: Only inactive sites
    • all or *: All sites regardless of status
  • search: Search by name or schema_name
  • ordering: Sort results (e.g., name, -created_at, updated_at)

Retrieving Site Details

Get details of a specific site:

GET /api/cloud/sites/{slug}/
Authorization: Bearer YOUR_ACCESS_TOKEN

Example:

GET /api/cloud/sites/production-site/

Updating a Site

Update site configuration:

PUT /api/cloud/sites/{slug}/
Content-Type: application/json
Authorization: Bearer YOUR_ACCESS_TOKEN

{
"name": "Production Site - Updated",
"description": "Updated production environment",
"is_active": true,
"site_settings": {
"feature_flags": {
"analytics": true,
"notifications": true,
"beta_features": false
}
}
}

Example:

PUT /api/cloud/sites/production-site/

Deleting a Site

Delete a site permanently (this will drop the database schema):

DELETE /api/cloud/sites/{slug}/
Authorization: Bearer YOUR_ACCESS_TOKEN

Example:

DELETE /api/cloud/sites/production-site/

Warning: Deleting a site:

  • Permanently deletes the database schema and all data
  • Removes all associated domains
  • Removes all site permissions
  • Cannot be undone

Soft Delete (Deactivation)

Instead of hard deletion, you can deactivate a site:

PATCH /api/cloud/sites/{slug}/
Content-Type: application/json
Authorization: Bearer YOUR_ACCESS_TOKEN

{
"is_active": false
}

Example:

PATCH /api/cloud/sites/production-site/
{
"is_active": false
}

Schema Management

Auto-Generated Schema Names

When creating a site, a schema name is automatically generated from the site name:

  • Converts to lowercase
  • Replaces spaces and special characters with underscores
  • Ensures uniqueness by appending numbers if needed
  • Must start with a letter or underscore

Examples:

  • "Acme Production" → acme_production
  • "Test Site" → test_site
  • "Test Site" (duplicate) → test_site_1

Manual Schema Names

You can also provide a custom schema name:

POST /api/cloud/organizations/{org_slug}/sites/
Content-Type: application/json
Authorization: Bearer YOUR_ACCESS_TOKEN

{
"name": "Custom Site",
"schema_name": "my_custom_schema"
}

Example:

POST /api/organizations/acme-corp/sites/
{
"name": "Custom Site",
"schema_name": "my_custom_schema"
}

Requirements:

  • Must start with a letter or underscore
  • Can only contain lowercase letters, numbers, and underscores
  • Must be unique across all sites

Auto-Generated Features

When creating a site, the following are automatically generated if not provided:

  1. Schema Name: Auto-generated from site name (converted to lowercase with underscores)
  2. Default Domain: If no domains are specified, creates {site-slug}.taruvi.com as primary domain
  3. Tenant Seeding: Runs default data seeders to initialize admin users, groups, tags, and permissions
# Example: Create site with minimal fields
POST /api/cloud/organizations/acme-corp/sites/
{
"name": "My New Site"
}

# Auto-generates:
# - schema_name: "my_new_site"
# - domain: "my-new-site.taruvi.com" (primary)
# - Seeds default data in the new schema

Site Configuration

Site Settings

The site_settings field accepts any JSON data for custom configuration:

{
"site_settings": {
"feature_flags": {
"analytics": true,
"notifications": false
},
"branding": {
"primary_color": "#007bff",
"logo_url": "https://example.com/logo.png"
},
"integrations": {
"stripe_key": "sk_test_...",
"sendgrid_api_key": "SG..."
}
}
}

Accessing Site Configuration

Retrieve current site configuration:

GET /api/cloud/sites/config/
Authorization: Bearer YOUR_ACCESS_TOKEN

This endpoint returns the configuration for the current tenant based on the domain you're accessing.

Checking Your Permissions

Get your effective permissions on a specific site:

GET /api/cloud/sites/{slug}/privileges/
Authorization: Bearer YOUR_ACCESS_TOKEN

Example:

GET /api/cloud/sites/production-site/privileges/

Response:

{
"permissions": [
"access_site",
"view_site",
"change_site",
"manage_site"
]
}

This endpoint returns all permissions you have on the specified site, including permissions inherited from organization membership and groups.

Permissions

Sites support the following permissions:

PermissionDescription
view_siteView site details
change_siteUpdate site settings
delete_siteDelete the site
access_siteAccess the site environment
manage_siteFull site management access
manage_site_usersManage users within the site
admin_siteSite administrator with full control

Best Practices

  1. Environment Separation: Use different sites for production, staging, and development
  2. Schema Naming: Use descriptive schema names that indicate purpose
  3. Soft Deletes: Deactivate sites instead of deleting when possible
  4. Settings Management: Store all configuration in site_settings for centralized management
  5. Regular Backups: Implement backup strategies for production sites
  6. Access Control: Assign minimal required permissions to users

Use Cases

Multi-Environment Development

Create separate sites for production, staging, and development environments with identical configurations.

White-Label SaaS

Each customer gets their own site with custom branding, settings, and isolated data.

Geographic Isolation

Create separate sites for different regions or countries with region-specific data and compliance.

Feature Testing

Use separate sites to test new features without affecting production environments.