Platform Architecture

Complete system design, monorepo structuur, tech stack en data flows van het TeezU v3.0 platform

v3.0 April 2026 pnpm Monorepo + Turborepo

πŸ—οΈ System Overview β€” v3.0

TeezU v3.0 is gebouwd als een pnpm monorepo met Turborepo voor build-orchestratie. De codebase is opgesplitst in apps/, services/ en packages/ voor maximale herbruikbaarheid en type-safety over de volledige stack.

TeezU Monorepo (pnpm workspaces + Turborepo)
β”‚
β”œβ”€β”€ apps/
β”‚   └── web/                  β†’ React 19 + Vite 7 + Tailwind CSS 4
β”‚                               (main PWA frontend, mobile-first)
β”‚
β”œβ”€β”€ services/
β”‚   └── api/                  β†’ Fastify 5 + Drizzle ORM + PostgreSQL 16
β”‚                               (backend REST API + Socket.IO)
β”‚
└── packages/
    β”œβ”€β”€ ui/                   β†’ Shared React components (Radix UI + CVA)
    β”œβ”€β”€ types/                β†’ Shared TypeScript types + Zod schemas
    β”œβ”€β”€ api-client/           β†’ Type-safe API client (fetch wrapper)
    └── utils/                β†’ Shared utilities (formatters, helpers)
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                  FRONTEND  (apps/web)                   β”‚
β”‚  React 19 Β· Vite 7 Β· TypeScript 5.9 Β· Tailwind CSS 4   β”‚
β”‚  Zustand 5 Β· TanStack Query v5 Β· React Hook Form + Zod  β”‚
β”‚  Socket.IO Client Β· WebRTC Β· PWA (VitePWA)              β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                             ↕  REST + WebSocket
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                  BACKEND  (services/api)                β”‚
β”‚  Node.js 22 Β· Fastify 5 Β· TypeScript 5.9                β”‚
β”‚  Drizzle ORM Β· Lucia Auth Β· Socket.IO Β· Zod validation  β”‚
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
       ↕              ↕              ↕
β”Œβ”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ PostgreSQL  β”‚ β”‚   Redis    β”‚ β”‚  MongoDB               β”‚
β”‚     16      β”‚ β”‚  (RT state β”‚ β”‚  (AI configs /         β”‚
β”‚ (relational)β”‚ β”‚  sessions) β”‚ β”‚   chat logs)           β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
       ↕                              ↕
β”Œβ”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”             β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  S3 /       β”‚             β”‚  Vector DB                 β”‚
β”‚  Cloudinary β”‚             β”‚  (Pinecone / Weaviate)     β”‚
β”‚  (media)    β”‚             β”‚  (AI matching / search)    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜             β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

βš›οΈ Frontend Architecture β€” apps/web

Core Stack

  • β€’ React 19 β€” UI framework (concurrent features)
  • β€’ TypeScript 5.9 β€” Type safety
  • β€’ Vite 7 β€” Ultra-fast build tool + HMR
  • β€’ Tailwind CSS 4 β€” Utility-first styling
  • β€’ React Router v7 β€” Client-side routing

State Management

  • β€’ Zustand 5 β€” Global state (slices: user / wallet / ui / chat)
  • β€’ TanStack Query v5 β€” Server state + caching
  • β€’ React Hook Form + Zod β€” Form validation
  • β€’ Socket.IO Client β€” Real-time sync

Real-time & Media

  • β€’ Socket.IO β€” Chat, notifications, live events
  • β€’ WebRTC β€” Video/voice livestreams
  • β€’ MediaStream API β€” Camera & microphone
  • β€’ VitePWA β€” Service worker + offline support

UI & Performance

  • β€’ Radix UI β€” Accessible headless components (packages/ui)
  • β€’ CVA β€” Class Variance Authority for variants
  • β€’ React.lazy + Suspense β€” Route-level code splitting
  • β€’ Virtual scrolling β€” Performance for long lists

Zustand Store Slices

useAppStore  (persist middleware for ui slice)
β”œβ”€β”€ user   slice β†’ { profile, role, session }        actions: setUser, clearUser
β”œβ”€β”€ wallet slice β†’ { balance, transactions }          actions: updateWallet
β”œβ”€β”€ ui     slice β†’ { sidebar, language, theme }       actions: toggleSidebar, setLanguage
└── chat   slice β†’ { activeRoom, messages, typing }   actions: sendMessage, setTyping

πŸ–₯️ Backend Architecture β€” services/api

Core Stack

  • β€’ Node.js 22 β€” Runtime (LTS)
  • β€’ Fastify 5 β€” High-performance HTTP server
  • β€’ TypeScript 5.9 β€” Strict type safety
  • β€’ Socket.IO β€” Real-time WebSocket layer
  • β€’ Zod β€” Runtime schema validation

Database & ORM

  • β€’ PostgreSQL 16 β€” Primary relational DB
  • β€’ Drizzle ORM β€” Type-safe SQL-first ORM
  • β€’ Redis β€” Real-time state, sessions, pub/sub
  • β€’ MongoDB β€” AI configs & chat logs
  • β€’ Pinecone / Weaviate β€” Vector DB for AI matching

Authentication

  • β€’ Lucia Auth β€” Session-based authentication
  • β€’ bcrypt β€” Password hashing
  • β€’ RBAC middleware β€” Role-based access control
  • β€’ 2FA β€” Two-factor authentication (TOTP)

Media & Storage

  • β€’ S3 / Cloudinary β€” Media file storage
  • β€’ Sharp β€” Image processing & thumbnails
  • β€’ FFmpeg β€” Video transcoding
  • β€’ CDN β€” Global asset distribution

πŸ”„ Data Flow

REST API Flow (Fastify 5)

Client (TanStack Query) β†’ HTTP Request β†’ Fastify Route
  ↓
Lucia Auth Middleware β†’ RBAC Role Check
  ↓
Zod Schema Validation β†’ Controller β†’ Service Layer
  ↓
Drizzle ORM β†’ PostgreSQL 16
  ↓
Response ← JSON Serialize ← Query Result

Real-time Flow (Socket.IO + Redis)

Client (Socket.IO) ↔ Fastify WebSocket Server
  ↓                              ↓
Room / Namespace Management   Redis Pub/Sub (multi-instance)
  ↓                              ↓
Event Handlers ← β†’ Chat / Stream Service ← β†’ PostgreSQL
  ↓
Live State pushed to all connected clients in room

Media Upload Flow

Client β†’ Multipart Upload β†’ Fastify Multipart Plugin
  ↓
Zod MIME / Size Validation
  ↓
Sharp (image resize) / FFmpeg (video transcode)
  ↓
S3 / Cloudinary Upload β†’ CDN distribution
  ↓
Drizzle ORM β†’ PostgreSQL (media record + metadata)

Auth Session Flow (Lucia Auth)

Login Request β†’ Zod validate β†’ bcrypt verify password
  ↓
Lucia Auth β†’ create Session β†’ store in PostgreSQL
  ↓
Session cookie (HttpOnly, Secure) β†’ Client
  ↓
Subsequent requests β†’ Lucia validateSession() β†’ user context
  ↓
RBAC middleware β†’ check role β†’ allow / deny

πŸ—„οΈ Database Schema β€” PostgreSQL 16 + Drizzle ORM

Het primaire schema draait op PostgreSQL 16 via Drizzle ORM (SQL-first, volledig type-safe). AI-configs en chat logs leven in MongoDB. Real-time state en sessies in Redis. Matching- en zoekfeatures gebruiken een Vector DB (Pinecone / Weaviate).

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚         CORE β€” PostgreSQL 16                  β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ β€’ users            (id, role, email, …)       β”‚
β”‚ β€’ profiles         (bio, avatar, cover, …)    β”‚
β”‚ β€’ sessions         (Lucia Auth sessions)      β”‚
β”‚ β€’ consent_records  (age verification, ToS)    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚         RBAC & ACCESS                         β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ β€’ roles            (super_admin … viewer)     β”‚
β”‚ β€’ permissions      (resource + action)        β”‚
β”‚ β€’ user_roles       (join table)               β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚         SOCIAL & CONTENT                      β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ β€’ follows          (follower_id, creator_id)  β”‚
β”‚ β€’ posts            (type, media_url, …)       β”‚
β”‚ β€’ media            (s3_key, cdn_url, mime)    β”‚
β”‚ β€’ stories          (expires_at, …)            β”‚
β”‚ β€’ comments / likes                            β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚         STREAMING & LIVE                      β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ β€’ streams          (creator_id, status, …)    β”‚
β”‚ β€’ stream_viewers   (join, view_duration)      β”‚
β”‚ β€’ stream_events    (type, payload, ts)        β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚         COMMERCE & WALLET                     β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ β€’ wallets          (user_id, balance)         β”‚
β”‚ β€’ transactions     (type, amount, status)     β”‚
β”‚ β€’ subscriptions    (tier, start, end)         β”‚
β”‚ β€’ tips             (from, to, token_amount)   β”‚
β”‚ β€’ payouts          (creator_id, status)       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚         CHAT  β€” MongoDB                       β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ β€’ chat_messages    (room_id, sender, content) β”‚
β”‚ β€’ ai_configs       (persona, model settings)  β”‚
β”‚ β€’ chat_logs        (session replay, metadata) β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ‘₯ RBAC β€” Role-Based Access Control

Alle gebruikers hebben één of meerdere rollen. Rechten worden afgedwongen via Fastify middleware op elke route.

πŸ›‘οΈ Super Admin

Volledige systeemtoegang. Platform configuratie, user management, alle data.

βš™οΈ Admin

Content moderatie, creator goedkeuring, rapportage en analytics.

πŸ” Moderator

Chat moderatie, content review, melden afhandelen.

🎬 Creator / Creator+

Live streams starten, content uploaden, betaalde abonnementen aanbieden, chattools gebruiken.

🀝 Provider

Externe dienstverleners die content of services aanbieden via het platform.

πŸ‘€ Member (basic / plus / premium / elite)

Geregistreerde gebruikers met gestaffelde toegang. Elite heeft volledige feature-set.

πŸ‘οΈ Viewer

Anonieme of niet-geauthenticeerde bezoeker. Alleen publiek zichtbare content.

βš™οΈ Microservices

De backend is intern opgedeeld in logische service-domeinen die elk hun eigen verantwoordelijkheid hebben. Ze communiceren via interne function calls binnen services/api en via Redis pub/sub voor async events.

services/api/src/services/
β”œβ”€β”€ auth/        β†’ Lucia Auth sessions, login, logout, 2FA
β”œβ”€β”€ user/        β†’ Profiles, follows, RBAC role management
β”œβ”€β”€ stream/      β†’ Live stream lifecycle, HLS, viewer state
β”œβ”€β”€ chat/        β†’ Rooms, messages, Socket.IO events
β”œβ”€β”€ token-tip/   β†’ Token economy, tip flows, gamification
β”œβ”€β”€ wallet/      β†’ Balances, transactions, payout requests
β”œβ”€β”€ ai/          β†’ AI persona configs, matching, vector search
β”œβ”€β”€ consent/     β†’ Age verification, ToS acceptance, GDPR
└── media/       β†’ Upload, processing (Sharp/FFmpeg), CDN

Auth Service

  • β€’ Lucia Auth session management
  • β€’ bcrypt password hashing
  • β€’ TOTP two-factor auth

Stream Service

  • β€’ HLS live stream management
  • β€’ Viewer count via Redis
  • β€’ Stream events & analytics

AI Service

  • β€’ AI persona configuration
  • β€’ Vector search (Pinecone/Weaviate)
  • β€’ Smart matching algoritme

πŸ“ˆ Scalability Strategy

Horizontal Scaling

  • β€’ Load balancer (Nginx / cloud LB)
  • β€’ Meerdere Fastify instances
  • β€’ Stateless design (sessies in Redis)
  • β€’ Turborepo remote caching
  • β€’ Docker containers (auto-scaling)

Caching

  • β€’ Redis voor sessies & real-time state
  • β€’ TanStack Query client-side cache
  • β€’ CDN voor media assets
  • β€’ VitePWA StaleWhileRevalidate (assets)
  • β€’ VitePWA NetworkFirst (API calls)

Database

  • β€’ PostgreSQL 16 read replicas
  • β€’ Drizzle connection pooling
  • β€’ Index-strategie per domein
  • β€’ MongoDB sharding voor chat logs
  • β€’ Vector DB auto-indexing

πŸ”’ Security Measures

Authentication & Authorization

  • β€’ Lucia Auth β€” session-based (geen JWT in localStorage)
  • β€’ RBAC middleware β€” role-based access op elke route
  • β€’ bcrypt β€” wachtwoord hashing (cost factor 12)
  • β€’ TOTP 2FA β€” twee-factor authenticatie

Data Protection

  • β€’ HTTPS/TLS 1.3 end-to-end encryptie
  • β€’ PostgreSQL encryption at rest
  • β€’ HttpOnly + Secure session cookies
  • β€’ GDPR compliance + consent records

API Security

  • β€’ Zod β€” runtime validatie op alle inputs
  • β€’ Fastify rate limiting β€” per IP en per user
  • β€’ CORS whitelist configuratie
  • β€’ SQL injection preventie via Drizzle (parameterized queries)

Monitoring & Compliance

  • β€’ Error tracking (Sentry)
  • β€’ Performance monitoring (Fastify metrics)
  • β€’ Security audit logs (alle auth events)
  • β€’ Automated DB backups + point-in-time recovery

πŸš€ Infrastructure & CI/CD

Monorepo Tooling

  • β€’ pnpm workspaces β€” package management
  • β€’ Turborepo β€” build orchestratie + remote caching
  • β€’ TypeScript project references β€” incremental builds
  • β€’ ESLint + Prettier β€” code kwaliteit

Deployment

  • β€’ Docker β€” containerized services
  • β€’ CI/CD pipeline β€” automatische deploys
  • β€’ CDN β€” globale asset distributie
  • β€’ Horizontal scaling β€” auto-scaling API pods

Turborepo Pipeline

turbo run build
  β”œβ”€β”€ packages/types     β†’ compile TS types (shared)
  β”œβ”€β”€ packages/utils     β†’ compile utilities
  β”œβ”€β”€ packages/ui        β†’ build component library
  β”œβ”€β”€ packages/api-clientβ†’ generate type-safe client
  β”œβ”€β”€ services/api       β†’ build Fastify server
  └── apps/web           β†’ Vite 7 production build β†’ CDN deploy