Skip to content

System Architecture

This section provides technical deep-dives for advanced developers and architects who need to understand how the FanFest platform components communicate, how events flow through the system, and how authentication works end to end.

High-Level Architecture

The FanFest platform is composed of four major subsystems that communicate through well-defined boundaries:

Component Summary

ComponentTechnologyResponsibility
FanFest SDKTypeScript, ViteEvent tracking, embed management, silent authentication
FanFest Web AppVue.js, ViteFull fan engagement UI rendered inside an iframe
API FunctionNode.js, Express, TypeGraphQL, TypeDIGraphQL API, REST endpoints, business logic
Auth FunctionNode.js, ExpressOIDC provider, token issuance, silent auth flows
EventBridgeAWS EventBridgeAsync event routing between services
Worker FunctionsNode.js LambdaTranslations, email, content moderation, chain publishing
PostgreSQLAWS RDS, Prisma ORMPrimary data store for all domain entities
DynamoDBAWS DynamoDBAuth transaction state (short-lived, TTL-managed)

EventBridge Event Flow

The API publishes domain events to an EventBridge event bus. EventBridge rules route these events to SQS queues, which trigger worker Lambda functions for async processing.

Event Types

The MessageBroker service publishes four event types:

Event TypeSourcePurposeTarget Queue
ContentUpsertedvip.fanfest.apiContent created or updated (shows, threads, quizzes, etc.)Translations, Email
ContentTranslatedvip.fanfest.translationsTranslation completed for contentEmail (notifications)
ContentReportedvip.fanfest.apiUser reports content (chat messages, threads)Content Moderation
UserActionCreatedvip.fanfest.apiUser completed a loyalty actionChain Publisher

Content Types

The event system handles these content types for translation and notification workflows:

Show, Topic, ContestPrize, Raffle, Quiz, QuizQuestion, QuizQuestionOption, Thread, ChatMessage, LeaderboardPrize, ChatRoom, AppAction, ChannelAction, ChannelMembership, ChannelRole.

Authentication Architecture

FanFest implements a custom OIDC provider that supports two authentication channels: external SSO providers (OAuth) and one-time password (OTP) via SMS/email.

OIDC Silent Authentication Flow

The silent auth flow enables seamless SSO where users authenticated on the host site are automatically authenticated in the FanFest embed without any visible login step.

Key Security Properties

  • PKCE (Proof Key for Code Exchange): All authorization flows use SHA-256 code challenges to prevent code interception.
  • Origin Validation: The auth function validates that the requesting origin matches the registered web app origins. Redirect URIs are checked against an allowlist.
  • Token Rotation: Refresh tokens use rotation with parent tracking. Each refresh produces a new token and invalidates the old one.
  • Transaction TTL: Auth transactions in DynamoDB have time-to-live, automatically expiring stale flows.
  • Hidden Iframe Isolation: The silent auth iframe is invisible (1x1px, opacity 0, fixed positioning) and is destroyed after authentication completes.

Authentication Channels

ChannelWhen UsedFlow
External Provider (OAuth)User has an SSO provider configured (Auth0, Keycloak, etc.)Standard OIDC authorize/callback/token flow via the host's identity provider
OTP (One-Time Password)User authenticates via phone number or emaillogin_hint parameter triggers OTP flow; code delivered via Twilio

OIDC Discovery

The auth function exposes standard OIDC discovery endpoints:

  • /.well-known/openid-configuration -- Discovery document
  • /.well-known/jwks.json -- JSON Web Key Set for token verification
  • /auth/authorize -- Authorization endpoint
  • /auth/callback -- Callback endpoint (receives provider redirects)
  • /auth/token -- Token endpoint (authorization_code and refresh_token grants)
  • /oauth/userinfo -- User info endpoint

API Architecture

The main API function serves both GraphQL and REST endpoints, deployed as a single Lambda function behind API Gateway.

Request Flow

  1. API Gateway receives HTTP requests and proxies to the Lambda function via serverless-http
  2. Express routes requests -- GraphQL queries go to the TypeGraphQL schema, REST endpoints go to Express routers
  3. Resolvers are thin wrappers that handle authorization and argument parsing, then delegate to services
  4. Services contain business logic and are injected via TypeDI's @Service() / @Inject() decorators
  5. Repositories encapsulate data access through Prisma ORM
  6. MessageBroker publishes async events to EventBridge for background processing

Lambda Functions Overview

FunctionTriggerPurpose
apiAPI Gateway (HTTP)Main GraphQL + REST API
authAPI Gateway (HTTP)OIDC provider, authentication flows
translations-queueSQSAuto-translate content via AI
email-queueSQSSend notification emails
content-moderation-queueSQSAI-based content moderation
chain-publisher-queueSQSPublish loyalty actions to blockchain
mediaconvert-queueSNSProcess video encoding callbacks
mediaconvert-upload-queueSQSHandle media upload processing
eventbridge-dlq-processorSQS (DLQ)Log and alert on failed event deliveries
api-healthSchedule (1 min)Health monitoring
auth-txn-rotationSchedule (1 hour)Clean up expired auth transactions
auth-vault-rotateSchedule (daily)Rotate signing keys
account-deletion-cronSchedule (12 hours)Process account deletion requests
data-retention-cronSchedule (7 days)Enforce data retention policies

SDK-to-Frontend Communication

The SDK and the FanFest frontend (running inside an iframe) communicate exclusively through the browser's postMessage API. See SDK Internals for the complete PostMessage protocol specification.

The iframe is sandboxed with a restricted permission set: allow-same-origin, allow-scripts, allow-forms, allow-modals, allow-popups. It also declares feature permissions for autoplay, camera, fullscreen, microphone, and clipboard-read/clipboard-write.


Next Steps

Released under the MIT License.