AI Avatar Live Commerce Platform
An AI avatar live commerce platform for Thai SMEs. It is an integration/orchestration layer on top of an existing Avatar Engine, adding Live Studio, a real-time Console, an auto-reply pipeline and a multi-tenant back office to close the loop. Built as a monorepo (Next.js 16 · NestJS/Fastify · Drizzle/Postgres RLS) with TDD + contract-first

An operating system for AI avatar live selling. It is an integration / orchestration layer on top of an existing Avatar Engine (TTS · lip-sync · render · RAG) that adds the missing parts: Live Studio, a real-time Console, an auto-reply pipeline and a multi-tenant back office, closing the loop from setting the scene to closing the sale
The problem
Why can't SME shops keep a live stream going "continuously" when every live hour is a chance to sell?

Human hosts can only stream so long. They need breaks, nobody is around after hours, and many small shops have no host at all. Every hour without a stream is sales that simply disappear. Meanwhile most AI avatar tools on the market can only "record a video", not "go live", and they have no commerce loop: they can't answer live comments, switch products or close a sale
Hosts can only stream limited hours
People need rest and sleep, so streaming after hours or late at night is almost impossible. Idle hours with no stream are demand left on the table, especially for shops without a regular host
Multiple host shifts are expensive
Covering the whole day means hiring several people across shifts, which SMEs can't afford. So they only stream at certain times and miss the hours with good traffic but no host
Comments pile up faster than anyone can answer
At peak, dozens of customers ask about price, stock and promotions at once. A slow answer loses the sale, and a wrong or overstated claim about a product carries legal risk
AI avatar tools are async, not live
Existing avatar video tools can't interact in real time and have no live commerce loop (product switching, CTA timing, live comment replies), so they can't close sales on a real live stream
Many shops and workspaces, data must stay strictly separate
A platform where an agency manages many clients can't leak even one row across shops. Doing isolation by hand is easy to get wrong and hard to audit
The solution
Don't build a new AI core. Build on the existing Avatar Engine and fill in what's missing to close the live commerce loop

Integration layer on top of the Avatar Engine
The existing engine already has TTS / lip-sync / render / RAG. The AI avatar live platform wires the trigger logic, feeds script and product context, and manages the session lifecycle, without rebuilding a duplicate avatar core
Live Studio for scene setup + streaming from real devices
Compose scenes, layers and products free-form on one canvas, then broadcast from the shop's own devices (phone-as-camera). The avatar speaks from a script tied to each product
Auto-reply pipeline with a Risk Filter
Comment → intent detection → Risk Keyword block before replying → Reply Burst priority queue (price/stock jump ahead) so the avatar answers live within a set latency budget
Live Console real-time (SSE)
Managers watch avatar status, stream health, the comment feed and the risk panel live, through an SSE stream that survives reconnects, keeps order and drops duplicate events
Multi-tenant data isolation at the database level
Every query is bound to workspace_id, with Postgres RLS as the last line of defense (Model B tenancy: authority lives in a central hub, identity is handled separately by Zitadel). Isolation is non-negotiable and covered by negative tests
How it works, in 4 steps
From preparing the avatar and products to closing the sale and reviewing results

Setup
Pick an avatar/voice, build the product catalog + risk words, set the live schedule
Compose Studio
Arrange scenes, layers and products + write the script yourself or let AI generate it
Broadcast
Stream from real devices, with the avatar following a script tied to each product
Engage + recap
Auto-reply to comments + monitor in the Console → Post-Live Recap
Tech Stack & Architecture
Monorepo (pnpm workspaces): Next.js PWA + NestJS/Fastify API + Drizzle/Postgres, plus external integrations

NestJS 11 + Fastify: the Live Orchestrator is a long-running process (route handlers don't fit), and DI with one module per feature lets the team scale · Drizzle ORM: TS-first, the schema is TypeScript so it matches FE type sharing, and it stays close to raw SQL, which suits multi-tenant queries and audits · PostgreSQL + RLS: 100% data isolation at the database level · Zitadel (identity) + Model B tenancy: identity is separated from workspace/entitlement authority (which lives in the central hub) · pnpm workspaces + OpenAPI → generated client (with a contract drift gate in CI): type safety across packages without a complicated build matrix
What I built: 8 core capabilities
The full loop, from the back office to the live stream and the post-live recap

Multi-tenant Workspace & Roles
4 roles (Owner/Manager/Admin/Agency) + workspace scoping on every query + RLS. Agencies can see several workspaces without data mixing
Catalog & Live Schedule
Product/SKU/Product Set CRUD + Live Schedule tied to a LiveSession state machine with 8 states (Live/Paused/Completed/Interrupted, etc.)
Live Studio (free-form)
Free-form scene compositor: scenes ≤5, layers ≤10/scene, 9 layer types + custom upload + auto-switch when a script ends
AI Script Generation
8 script types + multiple contents per slot (1-5) + a 5-state lifecycle gated by role + a risk check per content + rotation/cool-down/shuffle
AI Avatar Live Broadcasting
Phone-as-camera PWA + WebRTC composition + a 20-minute session cap + preload & seamless handover so the stream keeps running without hiccups
Comment Auto-Reply
Intent detection + Risk Keyword block before replying + Reply Burst ≤6/batch with P1/P2/P3 priority + per-script TTL drop
Live Console (SSE)
Live monitoring: session list + Control Room + comment feed + risk panel over an SSE stream that auto-reconnects and keeps order
Post-Live Recap
Aggregates AI outcomes per session and joins them with raw comments pulled from the source, so it can rebuild from source instead of relying on snapshots alone
What the Live Console looks like
A manager opens the Console and sees avatar status, the comment feed and the risk panel live on one screen

| Comment | Intent | Action | |
|---|---|---|---|
| How much is this one? | price | Reply Burst · P1 jumps ahead | auto |
| Is size L still available? | stock | Reply Burst · P1 | auto |
| I want the same color as yours | chit-chat | P3 · dropped when the next script starts | queued |
directive --force-cta product=SKU-4821 --say 'Add it to your cart now, only 5 left'
Hacking the problems
6 engineering problems I had to design solutions for: multi-tenancy, real time, integration lifecycle

Not a single row can leak across workspaces
Agencies see many shops in one dashboard. One badly scoped query leaks data across clients, which is non-negotiable
workspace_id scoping on every query + Postgres RLS as the last line of defense in the DB, an ESLint guard that blocks unscoped queries, and a negative isolation test proving nothing leaks. Isolation is part of the Definition of Done, not left for hardening at the endWho owns tenancy data? (Model B)
The ecosystem has several products. If each one stores its own workspaces, memberships and subscriptions, they drift out of sync and entitlements go wrong
Comments pile up, but the avatar can only answer one at a time
At peak, dozens of comments arrive at once. It can't, and shouldn't, answer all of them. It has to pick the important ones first within a limited time budget
The Console has to be live, but connections keep dropping and reconnecting
Mobile live streams have shaky connections. If the stream drops and events go missing, repeat or arrive out of order, the manager reads the wrong status and makes the wrong call
Integrating with external engines and services that don't exist yet
The Avatar Engine, comment source and some Hub endpoints weren't ready when development started. Waiting for them before writing the integration would block the whole pipeline
The engine caps sessions at 20 minutes, but the live stream must keep going
The Avatar Engine closes a session every 20 minutes. If it just ends, the picture stutters and the audio cuts out, and viewers notice immediately
Deliberate design decisions
What I chose "not to build" matters as much as what I built

The AI avatar live platform doesn't build a new avatar core. TTS, lip-sync, render, RAG, ≤2s latency and GPU pooling already exist in the Avatar Engine, so the focus is the integration layer: orchestration + the commerce loop + a multi-tenant back office + a real-time console. The positioning was sharp from day one: support the host, not replace them, unlocking hours people can't cover. A clear scope means a focused implementation that's easy to maintain
Build on the existing engine instead of duplicating the avatar core
RLS + workspace scoping + negative tests on every PR
red → green → refactor · tests are part of the DoD
Unlock the hours people can't cover: a clear positioning
Knowledge domains that got stronger
5 areas where my level genuinely moved up through this project

I now understand layered data isolation: workspace_id scoping in the application, Postgres RLS in the database, an ESLint guard that catches mistakes while writing code, and negative tests proving nothing leaks, plus the tenancy authority split (Model B: authority in the hub, identity in Zitadel). Lesson: good isolation is several testable layers, not good intentions
I designed Reply Burst as a priority queue (P1/P2/P3 + TTL drop) so replies land on time within the latency budget, and an SSE console stream that survives reconnects, keeps ordering, dedupes and applies backpressure. Lesson: reliable real time means designing the failure modes (drops, duplicates, falling behind) from the start, not best-effort
I set up pnpm workspaces (apps + shared packages: db/auth/types/api-client/engine-contracts), generated the client from OpenAPI with a drift gate, and wrote network-free (red-first) contract tests against external services that didn't exist yet. Lesson: a contract is the agreement that lets teams and services move in parallel without blocking each other
I designed a layer that wraps the existing Avatar Engine without touching its core, handling preload/handover so the 20-minute session cap looks continuous (audio ≤200ms / visual ≤100ms / pose continuity), with an adapter pattern ready for new providers. Lesson: making existing pieces fit "seamlessly" is harder than writing from scratch, and worth far more
I laid out one module per feature (21 modules) + DI, chose Fastify because the Live Orchestrator is a long-running process, and used Drizzle (a TS-first ORM close to raw SQL) with migration discipline (versioned · idempotent · fail-loud when the schema doesn't match). Lesson: structure enforced by conventions + guards lets a solo dev run a large system without it falling apart
