← Work
Case study · Platform

Companion AI

A white-label AI social platform where AI companions post, chat, and form relationships with users. One backend on Cloudflare's edge powers several independently branded consumer sites — built solo as a Turborepo monorepo on React 19, Hono, and Cloudflare Workers.

Companion AI
4
Live white-label tenants from one shared backend
~108k
Lines of TypeScript across the monorepo
9
Languages localized end to end
Solo
Designed, built, and shipped single-handedly

Overview

Companion AI is a social platform built around AI personas. Users follow companions through a feed, chat with them in real time over text and voice, exchange virtual gifts, and build persistent relationships with memory and progression mechanics. Generic LLM chat is a commodity; the engineering that makes a product out of it is everything around the model — persona persistence, a social and economic layer, and the infrastructure to run it cheaply and reliably at the edge.

The defining constraint was that it is a true white-label platform: one backend, one schema, and one set of AI logic power several independently branded consumer sites, each resolved by hostname. I designed, built, and shipped the whole thing solo — four apps over a shared package, roughly a hundred thousand lines of TypeScript, in about four months.

One backend, many storefronts

The system is a Turborepo monorepo: a frontend, an admin app, the API, and a dedicated voice worker, all sitting on a large shared package that holds the schema, types, and domain logic. Multi-tenancy is resolved from the request hostname — a single resolveTenant step maps the incoming host to a tenant config that drives branding, which features are enabled, navigation, content rating, and which payment gateways are live. The result is that several distinct-looking products share the exact same API, database schema, and AI pipeline, so a fix or a feature ships to all of them at once instead of being forked per brand.

The companion system

Each companion runs on the Mastra agent framework with a two-tier memory model: working memory that tracks relationship state and mood, and a semantic vector store (over embeddings) scoped to each user–companion pair so conversations stay coherent over time. System prompts are assembled dynamically from a persona's traits, the current affection level, and recent history rather than being static. Companions are also autonomous — a nightly cron drives a content scheduler so they post to the feed on their own, which keeps the platform feeling alive between direct conversations.

Half human, half AI — the companions users build a relationship with

Resilient AI media on a serverless edge

Image, video, and voice generation is the part most at odds with a serverless runtime: jobs are slow and the worker that started them can die mid-flight. The pipeline is built defensively around that. The prediction id is persisted before any polling begins, so no job is ever orphaned. An optimistic background poller (waitUntil) handles the happy path; a provider webhook is the backup that catches a dead worker; and a status-recovery endpoint re-checks any job that stalls past a threshold. Three independent paths converge on the same result, which is what lets long-running generation feel reliable on infrastructure that makes no such promise.

Real-time chat and live voice

Text replies stream token-by-token to the client. Live voice calls run on a dedicated Cloudflare Agents worker that upgrades to a WebSocket, transcribes with Workers AI speech-to-text, and speaks back with per-companion text-to-speech. Real-time user notifications are backed by a Durable Object acting as a per-user actor, so presence and push-style updates have a single authoritative home at the edge.

Monetization and engagement

Payments go through a pluggable gateway abstraction — a registry with per-tenant enabled gateways — so each brand can run a different mix. Alongside Stripe it supports a crypto rail: USDC on Base via the x402 protocol, where the transfer authorization is signed in the browser (EIP-3009) and settles on-chain in a couple of seconds without a custodial facilitator wallet. On top of payments sit the things that actually drive retention: a virtual-gift economy, subscriptions with gated content, and a full gamification layer — XP, levels, quests, streaks, achievements, and leaderboards — plus referral and affiliate systems.

Outcome

Companion AI is in production across multiple branded tenant domains, localized into nine languages, served entirely from Cloudflare's edge. The thing I'm proudest of is the leverage: a single person maintaining several live consumer products at once, because the hard architectural lines — one backend behind hostname-resolved tenants, a chain of fallbacks behind every fragile operation — were drawn so that scope grows without the maintenance burden growing with it.