Skip to main content

Clients App

The clients app handles customer (tenant) management in Maybern’s multi-tenant architecture.

Overview

Maybern is a multi-tenant application where each customer has isolated data. The clients app provides:
  • Customer model and management
  • User-customer relationships
  • Tenant isolation enforcement

Multi-Tenancy

All customer data is isolated using customer_id:
class CustomerTimeStampedModel(TimeStampedModel):
    """Base model for all tenant-specific data."""
    customer = ForeignKey(Customer, on_delete=CASCADE)
Every query automatically filters by customer:
# customer_id from ctx is automatically applied
entities = MyEntity.objects.filter(ctx=ctx, status="active")

Models

Customer

class Customer(TimeStampedModel):
    """
    Represents a tenant/customer in the system.
    All fund data is scoped to a customer.
    """
    id = MUUIDField(prefix="CUST")
    name = CharField()
    # Configuration fields

User

class User(TimeStampedModel):
    """
    Represents a user who can access the platform.
    Users can have access to multiple customers.
    """
    id = MUUIDField(prefix="USER")
    email = EmailField(unique=True)
    # Authentication fields

CustomerUser

class CustomerUser(TimeStampedModel):
    """
    Links users to customers they have access to.
    """
    customer = ForeignKey(Customer)
    user = ForeignKey(User)
    role = CharField()  # admin, viewer, etc.

Request Context

The RequestCtx carries customer context through all operations:
@dataclass
class RequestCtx:
    customer_id: MUUID  # Current customer
    user_id: MUUID      # Authenticated user
    # ...

Customer Switching

Users with access to multiple customers can switch between them:
# API endpoint to switch customer
POST /api/customers/{customer_id}/switch/

# Updates session with new customer context

Security

All data queries include customer filtering:
  • Managers apply customer_id automatically
  • Cross-customer data access is blocked
Users must have explicit access to customers:
  • CustomerUser relationship required
  • Roles determine permissions
Customer actions are logged:
  • Who accessed what customer
  • When customer context changed