HyperSaaS
BackendDatabase

Data Model

Complete entity-relationship overview of all Django models.

Entity Relationships

User
├── owns → Workspace (via owner FK)
├── member of → Workspace (via WorkspaceMembership M2M)
├── has one → StripeUser → Subscription → SubscriptionItem → Price → Product
├── has one → UserCost (legacy, unused for limits)
└── has many → AIUsage (per-call cost logs)

Workspace
├── has many → ChatSession
├── has many → KnowledgeBase
├── has many → Document
├── has many → Team → TeamMembership
├── has many → Invitation
├── has many → Folder
├── has one → Subscription (FK) → its plan
└── has many → AIUsage (counted against its credit), WorkspaceCost (legacy)

ChatSession
├── has many → Message → MessageFeedback
├── has many → ChatSessionShare
└── attached to → KnowledgeBase (via ChatSessionKnowledgeBase M2M)

KnowledgeBase
├── has many → Document (via KnowledgeBaseDocument M2M)
└── has many → KnowledgeBaseTeamAccess

Document
├── has many → DocumentChunk (text + embedding vector)
└── has many → DocumentProcessingTask

Model Summary

AppModelPrimary KeyKey Relationships
usersUserBigAutoFieldemail (unique, ignoring case), USERNAME_FIELD
usersUserCostBigAutoFieldOneToOne → User (legacy)
workspacesWorkspaceUUIDowner → User, subscription → Subscription
workspacesWorkspaceMembershipBigAutoFieldworkspace + user (unique together)
workspacesTeamBigAutoFieldworkspace → Workspace, owner → User
workspacesTeamMembershipBigAutoFieldteam + user (unique together)
workspacesInvitationBigAutoFieldworkspace/team → inviter → invitee
workspacesFolderBigAutoFieldworkspace → Workspace, user → User
workspacesAIUsageUUIDworkspace + user + chat_session, purpose
workspacesWorkspaceCostBigAutoFieldworkspace → Workspace (legacy)
chatChatSessionUUIDworkspace → Workspace, user → User
chatMessageUUIDsession → ChatSession, sequence_number
chatChatSessionShareUUIDchat_session + shared_with_user
chatMessageFeedbackUUIDmessage + user (one rating each)
documentsKnowledgeBaseUUIDworkspace → Workspace
documentsDocumentUUIDworkspace → Workspace
documentsDocumentChunkUUIDdocument → Document, embedding (1536d vector)
documentsKnowledgeBaseDocumentBigAutoFieldknowledge_base + document
documentsChatSessionKnowledgeBaseBigAutoFieldchat_session + knowledge_base
documentsDocumentProcessingTaskBigAutoFielddocument → Document, task_id (Celery)
subscriptionsStripeUserUser PKOneToOne → User
subscriptionsProductproduct_id (str)Stripe product ID, plan key
subscriptionsPriceprice_id (str)product → Product
subscriptionsSubscriptionsubscription_id (str)stripe_user → StripeUser
subscriptionsSubscriptionItemsub_item_id (str)subscription + price
subscriptionsFeaturefeature_id (str)Stripe feature
subscriptionsProductFeatureBigAutoFieldproduct + feature

Multi-Tenancy Model

HyperSaaS uses workspace-based multi-tenancy:

  • Every resource (chat, document, knowledge base) belongs to a Workspace
  • Users access workspaces through WorkspaceMembership
  • The WorkspaceAwareModel abstract mixin provides a workspace FK for any model that needs scoping
  • Every workspace-scoped endpoint checks membership of the workspace in the URL, and refuses non-members with 403
  • A workspace's plan sets its limits, and its AI usage is counted against its own credit
class WorkspaceAwareModel(models.Model):
    workspace = models.ForeignKey(Workspace, on_delete=models.CASCADE)

    class Meta:
        abstract = True

On this page