mixin

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 10, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package mixin provides reusable Ent schema mixins for SystemForge entities.

Package mixin provides Ent mixins for composing SystemForge identity fields into application schemas.

Package mixin provides Ent mixins for composing SystemForge fields into application schemas.

Package mixin provides Ent mixins for composing SystemForge identity fields into application schemas.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MembershipRoles

func MembershipRoles() []string

MembershipRoles returns all standard membership roles.

func PrincipalTypes

func PrincipalTypes() []string

PrincipalTypes returns all valid principal types for use in Ent enum fields.

Types

type APIKey

type APIKey struct {
	mixin.Schema
}

APIKey provides common fields for API key entities. Apps use this mixin in their Ent schema and implement EntClientInterface to connect SystemForge's EntStore to their generated Ent client.

Example usage in app schema:

func (APIKey) Mixin() []ent.Mixin {
    return []ent.Mixin{
        mixin.APIKey{},
    }
}

func (APIKey) Fields

func (APIKey) Fields() []ent.Field

Fields of the APIKey mixin.

func (APIKey) Indexes

func (APIKey) Indexes() []ent.Index

Indexes of the APIKey mixin.

type AgentMixin

type AgentMixin struct {
	mixin.Schema
}

AgentMixin provides fields for the Agent entity (AI agents). Agent extends Principal with AI agent-specific data. Use this mixin for AI agents that act on behalf of humans or organizations.

func (AgentMixin) Fields

func (AgentMixin) Fields() []ent.Field

Fields returns the Agent fields.

func (AgentMixin) Indexes

func (AgentMixin) Indexes() []ent.Index

Indexes returns indexes for the Agent entity.

type ApplicationMixin

type ApplicationMixin struct {
	mixin.Schema
}

ApplicationMixin provides fields for the Application entity (OAuth clients). Application extends Principal with OAuth client-specific data. Use this mixin for OAuth2 client applications.

Apps must define:

  • principal_id field (FK to Principal)
  • Edge from Principal to Application

func (ApplicationMixin) Fields

func (ApplicationMixin) Fields() []ent.Field

Fields returns the Application fields.

func (ApplicationMixin) Indexes

func (ApplicationMixin) Indexes() []ent.Index

Indexes returns indexes for the Application entity.

type BFFSession

type BFFSession struct {
	mixin.Schema
}

BFFSession provides common fields for BFF session entities. Apps use this mixin in their Ent schema and implement EntClientInterface to connect SystemForge's EntStore to their generated Ent client.

Example usage in app schema:

func (BFFSession) Mixin() []ent.Mixin {
    return []ent.Mixin{
        mixin.BFFSession{},
    }
}

func (BFFSession) Fields

func (BFFSession) Fields() []ent.Field

Fields of the BFFSession mixin.

func (BFFSession) Indexes

func (BFFSession) Indexes() []ent.Index

Indexes of the BFFSession mixin.

type BaseMixin

type BaseMixin struct {
	mixin.Schema
}

BaseMixin combines UUID and Timestamp mixins for convenience. This is the most commonly used mixin for SystemForge-compatible entities.

func (BaseMixin) Fields

func (BaseMixin) Fields() []ent.Field

Fields returns combined UUID and timestamp fields.

type CreatorOrgMixin

type CreatorOrgMixin struct {
	mixin.Schema
}

CreatorOrgMixin provides fields for creator/publisher organizations. Use this mixin for organizations that create and sell products on the marketplace. This is separate from OrganizationBase which is for consumer organizations.

func (CreatorOrgMixin) Fields

func (CreatorOrgMixin) Fields() []ent.Field

Fields returns the creator organization fields.

type HumanMixin

type HumanMixin struct {
	mixin.Schema
}

HumanMixin provides fields for the Human entity. Human extends Principal with human-specific data (email, name, avatar, etc.). Use this mixin to create Human entities in your app.

Apps must define:

  • principal_id field (FK to Principal)
  • Edge from Principal to Human

Example usage:

type Human struct {
    ent.Schema
}

func (Human) Mixin() []ent.Mixin {
    return []ent.Mixin{
        cfmixin.HumanMixin{},
    }
}

func (Human) Fields() []ent.Field {
    return []ent.Field{
        // App-specific fields (e.g., bio, headline, username)
    }
}

func (Human) Edges() []ent.Edge {
    return []ent.Edge{
        edge.From("principal", Principal.Type).
            Ref("human").
            Field("principal_id").
            Unique().
            Required().
            Immutable(),
    }
}

func (HumanMixin) Fields

func (HumanMixin) Fields() []ent.Field

Fields returns the Human fields.

func (HumanMixin) Indexes

func (HumanMixin) Indexes() []ent.Index

Indexes returns indexes for the Human entity.

type LicenseMixin

type LicenseMixin struct {
	mixin.Schema
}

LicenseMixin provides the core fields for marketplace licenses. Apps can use this mixin to create their own License schema while adding app-specific fields and edges.

func (LicenseMixin) Fields

func (LicenseMixin) Fields() []ent.Field

Fields returns the core license fields.

type ListingMixin

type ListingMixin struct {
	mixin.Schema
}

ListingMixin provides the core fields for marketplace listings. Apps can use this mixin to create their own Listing schema while adding app-specific fields and edges.

Example usage:

type Listing struct {
    ent.Schema
}

func (Listing) Mixin() []ent.Mixin {
    return []ent.Mixin{
        mixin.ListingMixin{},
    }
}

func (Listing) Fields() []ent.Field {
    return []ent.Field{
        // App-specific fields
        field.UUID("course_id", uuid.UUID{}).Optional(),
    }
}

func (ListingMixin) Fields

func (ListingMixin) Fields() []ent.Field

Fields returns the core listing fields.

type MembershipBase

type MembershipBase struct {
	mixin.Schema
}

MembershipBase provides the core membership fields for composition. Apps can use this mixin to get SystemForge-compatible membership fields while customizing role values for their domain.

func (MembershipBase) Fields

func (MembershipBase) Fields() []ent.Field

Fields returns the core membership fields.

type MembershipRole

type MembershipRole string

MembershipRole defines the standard roles for organization membership.

const (
	// MembershipRoleOwner has full control including billing and deletion.
	MembershipRoleOwner MembershipRole = "owner"
	// MembershipRoleAdmin can manage members and most settings.
	MembershipRoleAdmin MembershipRole = "admin"
	// MembershipRoleEditor can create and modify content.
	MembershipRoleEditor MembershipRole = "editor"
	// MembershipRoleViewer can only view content.
	MembershipRoleViewer MembershipRole = "viewer"
)

type OAuthAccountMixin

type OAuthAccountMixin struct {
	mixin.Schema
}

OAuthAccountMixin provides fields for the OAuthAccount entity. OAuthAccount stores OAuth provider connections for principals. Use this mixin to create OAuthAccount entities in your app.

Apps must define:

  • principal_id field (FK to Principal)
  • Edge from Principal to OAuthAccount

Example usage:

type OAuthAccount struct {
    ent.Schema
}

func (OAuthAccount) Mixin() []ent.Mixin {
    return []ent.Mixin{
        cfmixin.OAuthAccountMixin{},
    }
}

func (OAuthAccount) Edges() []ent.Edge {
    return []ent.Edge{
        edge.From("principal", Principal.Type).
            Ref("oauth_accounts").
            Field("principal_id").
            Unique().
            Required(),
    }
}

func (OAuthAccountMixin) Fields

func (OAuthAccountMixin) Fields() []ent.Field

Fields returns the OAuthAccount fields.

func (OAuthAccountMixin) Indexes

func (OAuthAccountMixin) Indexes() []ent.Index

Indexes returns indexes for the OAuthAccount entity.

type OrganizationBase

type OrganizationBase struct {
	mixin.Schema
}

OrganizationBase provides the core organization fields for composition. Apps can use this mixin to get SystemForge-compatible organization fields while adding their own custom fields or renaming to match their domain (e.g., Team, Tenant, Workspace).

func (OrganizationBase) Fields

func (OrganizationBase) Fields() []ent.Field

Fields returns the core organization fields.

type PrincipalMembershipMixin

type PrincipalMembershipMixin struct {
	mixin.Schema
}

PrincipalMembershipMixin provides fields for the PrincipalMembership entity. PrincipalMembership links Principals to Organizations with roles. Use this mixin to create PrincipalMembership entities in your app.

Apps must define:

  • Edges from Principal and Organization to PrincipalMembership

Example usage:

type PrincipalMembership struct {
    ent.Schema
}

func (PrincipalMembership) Mixin() []ent.Mixin {
    return []ent.Mixin{
        cfmixin.PrincipalMembershipMixin{},
    }
}

func (PrincipalMembership) Edges() []ent.Edge {
    return []ent.Edge{
        edge.From("principal", Principal.Type).
            Ref("memberships").
            Field("principal_id").
            Unique().
            Required(),
        edge.From("organization", Organization.Type).
            Ref("principal_memberships").
            Field("organization_id").
            Unique().
            Required(),
    }
}

func (PrincipalMembershipMixin) Fields

func (PrincipalMembershipMixin) Fields() []ent.Field

Fields returns the PrincipalMembership fields.

func (PrincipalMembershipMixin) Indexes

func (PrincipalMembershipMixin) Indexes() []ent.Index

Indexes returns indexes for the PrincipalMembership entity.

type PrincipalMixin

type PrincipalMixin struct {
	mixin.Schema
}

PrincipalMixin provides fields for the Principal entity. Principal is the unified identity type representing any actor in the system. Use this mixin to create Principal entities in your app.

Apps must define edges to:

  • Human (one-to-one, optional) - for human-specific data
  • OAuthAccount (one-to-many) - for OAuth connections
  • RefreshToken (one-to-many) - for token management
  • PrincipalMembership (one-to-many) - for organization membership

Example usage:

type Principal struct {
    ent.Schema
}

func (Principal) Mixin() []ent.Mixin {
    return []ent.Mixin{
        cfmixin.PrincipalMixin{},
    }
}

func (Principal) Fields() []ent.Field {
    return []ent.Field{
        // App-specific fields if needed
    }
}

func (Principal) Edges() []ent.Edge {
    return []ent.Edge{
        edge.To("human", Human.Type).Unique(),
        edge.To("oauth_accounts", OAuthAccount.Type),
        edge.To("refresh_tokens", RefreshToken.Type),
        edge.To("memberships", PrincipalMembership.Type),
    }
}

func (PrincipalMixin) Fields

func (PrincipalMixin) Fields() []ent.Field

Fields returns the Principal fields.

func (PrincipalMixin) Indexes

func (PrincipalMixin) Indexes() []ent.Index

Indexes returns indexes for the Principal entity.

type PrincipalType

type PrincipalType string

PrincipalType defines the types of principals in the identity system.

const (
	// PrincipalTypeHuman represents a human user.
	PrincipalTypeHuman PrincipalType = "human"
	// PrincipalTypeApplication represents an OAuth application/client.
	PrincipalTypeApplication PrincipalType = "application"
	// PrincipalTypeAgent represents an AI agent or automated actor.
	PrincipalTypeAgent PrincipalType = "agent"
	// PrincipalTypeService represents a service account for system processes.
	PrincipalTypeService PrincipalType = "service"
)

type RefreshTokenMixin

type RefreshTokenMixin struct {
	mixin.Schema
}

RefreshTokenMixin provides fields for the RefreshToken entity. RefreshToken stores refresh tokens for token-based authentication. Use this mixin to create RefreshToken entities in your app.

Apps must define:

  • principal_id field (FK to Principal)
  • Edge from Principal to RefreshToken

Example usage:

type RefreshToken struct {
    ent.Schema
}

func (RefreshToken) Mixin() []ent.Mixin {
    return []ent.Mixin{
        cfmixin.RefreshTokenMixin{},
    }
}

func (RefreshToken) Edges() []ent.Edge {
    return []ent.Edge{
        edge.From("principal", Principal.Type).
            Ref("refresh_tokens").
            Field("principal_id").
            Unique().
            Required(),
    }
}

func (RefreshTokenMixin) Fields

func (RefreshTokenMixin) Fields() []ent.Field

Fields returns the RefreshToken fields.

func (RefreshTokenMixin) Indexes

func (RefreshTokenMixin) Indexes() []ent.Index

Indexes returns indexes for the RefreshToken entity.

type SeatAssignmentMixin

type SeatAssignmentMixin struct {
	mixin.Schema
}

SeatAssignmentMixin provides the core fields for license seat assignments. Apps can use this mixin to track which principals are assigned to license seats.

func (SeatAssignmentMixin) Fields

func (SeatAssignmentMixin) Fields() []ent.Field

Fields returns the seat assignment fields.

type ServicePrincipalMixin

type ServicePrincipalMixin struct {
	mixin.Schema
}

ServicePrincipalMixin provides fields for the ServicePrincipal entity. ServicePrincipal extends Principal for system service accounts. Use this mixin for background jobs, cron tasks, and system processes.

func (ServicePrincipalMixin) Fields

func (ServicePrincipalMixin) Fields() []ent.Field

Fields returns the ServicePrincipal fields.

func (ServicePrincipalMixin) Indexes

func (ServicePrincipalMixin) Indexes() []ent.Index

Indexes returns indexes for the ServicePrincipal entity.

type SubscriptionMixin

type SubscriptionMixin struct {
	mixin.Schema
}

SubscriptionMixin provides the core fields for platform subscriptions. Apps can use this mixin to create their own Subscription schema for tracking organization-level platform access.

func (SubscriptionMixin) Fields

func (SubscriptionMixin) Fields() []ent.Field

Fields returns the core subscription fields.

type TimestampMixin

type TimestampMixin struct {
	mixin.Schema
}

TimestampMixin provides created_at and updated_at timestamp fields. Use this for automatic timestamp tracking in your schema.

func (TimestampMixin) Fields

func (TimestampMixin) Fields() []ent.Field

Fields returns the timestamp fields.

type UUIDMixin

type UUIDMixin struct {
	mixin.Schema
}

UUIDMixin provides a UUID primary key field. Use this when you want UUID-based primary keys in your schema.

func (UUIDMixin) Fields

func (UUIDMixin) Fields() []ent.Field

Fields returns the UUID id field.

type UserBase

type UserBase struct {
	mixin.Schema
}

UserBase provides the core user fields for composition into app schemas. Apps can use this mixin to get SystemForge-compatible user fields while adding their own custom fields.

Example usage:

type User struct {
    ent.Schema
}

func (User) Mixin() []ent.Mixin {
    return []ent.Mixin{
        mixin.UserBase{},
    }
}

func (User) Fields() []ent.Field {
    return []ent.Field{
        // App-specific fields
        field.String("username").Unique(),
    }
}

func (UserBase) Fields

func (UserBase) Fields() []ent.Field

Fields returns the core user fields.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL