---
created: 2025-10-10T11:28:08Z
last_updated: 2025-10-24T10:49:44Z
version: 2.2
author: Claude Code PM System
---

# Technology Context

## Core Technologies

### Language & Runtime
- **TypeScript**: 5.9.3 (Primary language for backend/frontend)
- **Node.js**: v22+ (Runtime environment)
- **JavaScript**: ES2022+ (Target compilation)
- **Python**: 3.11+ (Voice agent & bot runtime)

### Package Management
- **pnpm**: 10.18.1+ (Node.js package manager)
- **Workspace**: Monorepo with pnpm workspaces
- **uv**: Python package manager (screenshare bot)
  - Modern dependency management
  - Uses `[dependency-groups]` format (replaces deprecated `[tool.uv]`)

### Build System
- **Nx**: 21.6.5 (Monorepo orchestration) - **Updated from 21.4.0**
  - Caching and task scheduling
  - Dependency graph management
  - Incremental builds
  - Parallel execution
  - **Nx Cloud disabled** (using local caching only)

## Frontend Technologies

### UI Frameworks
- **React**: 19.1.1 (UI library)
- **React DOM**: 19.1.1
- **Vite**: 6.3.6 (Build tool and dev server)

### UI Component Libraries
- **Radix UI**: Multiple components
  - `@radix-ui/themes`: 3.2.1
  - `@radix-ui/react-dialog`: 1.1.14
  - `@radix-ui/react-dropdown-menu`: 2.1.15
  - `@radix-ui/react-icons`: 1.3.2
  - `@radix-ui/react-tabs`: 1.1.12
  - Other Radix components

### Styling
- **Tailwind CSS**: 4.1.13 (Utility-first CSS)
- **UnoCSS**: 66.5.2 (Atomic CSS engine)
- **Framer Motion**: 12.23.12 (Animation library)
- **class-variance-authority**: 0.7.1 (CVA for variants)
- **clsx**: 2.1.1 (Classname utility)
- **tailwind-merge**: 3.3.1 (Merge Tailwind classes)

### State Management
- **Jotai**: 2.15.0 (Atomic state management)

### Internationalization (NEW - October 2024)
- **i18next**: 25.6.0 (Industry-standard i18n library)
  - Framework-agnostic translation system
  - Used in `@buzztrail-ai/gating` for multi-language support
  - 5 languages implemented: English, Norwegian, German, Spanish, French
  - Supports 32 Tavus-supported languages total (ISO 639-1 codes)
  - Features: Pluralization, interpolation, nesting
  - CDN-ready for script tag usage

### Validation (NEW - October 2024)
- **validator**: 13.15.15 (String validation library)
  - Email format validation (RFC-compliant via isEmail)
  - Used in `@buzztrail-ai/gating` for form validation
  - Tree-shakable (~2 KB when using isEmail only)
  - Zero dependencies
- **@types/validator**: 13.15.3 (TypeScript types for validator)

## Backend Technologies

### Frameworks
- **Express**: 4.21.2 (Web framework)
- **Motia**: 0.8.2-beta.139 (AI workflow platform)
  - `@motiadev/core`: 0.8.2-beta.139
  - Backend workflow automation

### APIs & Integration
- **Axios**: 1.6.0+ (HTTP client)
- **node-fetch**: 2.7.0 (Fetch API for Node.js)

### Security & Middleware
- **Helmet**: 8.1.0 (Security headers)
- **CORS**: 2.8.5 (Cross-origin resource sharing)
- **express-rate-limit**: 8.1.0 (Rate limiting)
- **Morgan**: 1.10.1 (HTTP request logger)

## Database & Real-time

### Database
- **Supabase**: 2.74.0 (PostgreSQL database)
  - `@supabase/supabase-js`: Client library
  - Real-time subscriptions
  - Row-level security
  - RESTful API

### Tables

**Core Session Tables**:
- `conversation_sessions` - Session lifecycle tracking (updated Oct 2024)
  - Added `client_uuid` (FK to buzztrail_clients)
  - Added `agent_uuid` (FK to buzztrail_agents)
- `slidev_decks` - Deck metadata
- `slide_control_commands` - Real-time commands
- `active_bots` - Running bot instances
- `session_metrics` - Cost, latency, and success tracking (Oct 2025)
  - Cost tracking (STT, LLM, TTS, LiveKit)
  - Latency metrics (session init, voice response, slide control)
  - Success rate monitoring
  - Migration: `20251022_add_session_metrics.sql`

**Client Registry Tables** (NEW - October 2024):
- `buzztrail_clients` - Customer/client registry with domain locking
  - Dual ID system: UUID `id` (for FKs) + VARCHAR `client_id` (human-readable)
  - Example clients: 'buzztrail', 'norsk-unloc'
  - `allowed_domains` JSONB for security (server-side validation)
  - `ui` JSONB for widget configuration
  - `gating` JSONB for lead capture settings
- `buzztrail_agents` - Provider-agnostic agent configurations
  - Dual ID system: UUID `id` + VARCHAR `agent_id`
  - Example agents: 'tom-insurance', 'sarah-support', 'tom-insurance-no'
  - `capabilities` JSONB (video, voice, text, slides, screenshare)
  - `providers` JSONB (Tavus persona IDs, LiveKit config, etc.)
  - System prompts NOT stored in DB (in code/env vars for security)
- `buzztrail_client_agents` - Many-to-many junction table
  - One client can have multiple agents
  - `is_default` flag for default agent selection
  - `context` JSONB for agent-specific metadata
- `buzztrail_themes` - Custom theme definitions
- `buzztrail_analytics` - Usage tracking and analytics

**Migration History**:
- Migration files: `apps/supabase-backend/supabase/migrations/` (7 files)
- Latest: `20251024000000_add_customer_registry.sql` (511 lines)
- Documentation: See `apps/supabase-backend/README.md`
- Nx integration: Use `pnpm nx run supabase-backend:db:push` and other targets
- **Note**: Moved from `apps/slide-system/` (Issue #179, October 2024)

### Monitoring & Observability (NEW - October 2025)
- **Session Metrics Tracking** (`voice-agent-livekit/metrics.py`)
  - Python module for tracking voice agent performance
  - Incremental cost updates per API call
  - Latency measurement (ms precision)
  - Session status tracking (in_progress, completed, failed, abandoned)
- **Supabase Views** (Built-in monitoring)
  - `v_session_metrics_recent` - Last 100 sessions overview
  - `v_session_metrics_cost_stats` - Daily cost aggregations
  - `v_session_metrics_latency_stats` - Daily latency p95
  - `v_session_metrics_success_rate` - Daily success/fail rates
- **MVP Approach**: Using Supabase Dashboard + SQL queries
- **Future**: Migration path to Grafana Cloud documented

## Video & Communication

### Daily.co Integration
- **@daily-co/daily-js**: 0.81.0 (Core SDK)
- **@daily-co/daily-react**: 0.23.2 (React components)
- WebRTC video/audio communication
- Screen sharing capabilities

### Tavus Integration
- **@tavus/cvi-ui**: 0.0.1-beta.5 (Conversation UI)
- Custom API client (internal)
- Video generation and management

### LiveKit Integration
- **@livekit/components-react**: Latest (Official React components)
  - VideoConference - Complete conference UI
  - PreJoin - Pre-room device configuration
  - LiveKitRoom - Room connection wrapper
  - Chat, ControlBar, FocusLayout components
- **@livekit/components-styles**: Official component styles
- **@livekit/components-core**: Core functionality and types
- **@livekit/rtc-node**: 0.10.4+ (Node.js LiveKit SDK for bots)
  - Room connection and authentication
  - Video track publishing
  - Real-time audio/video streaming
  - WebRTC transport layer
- Real-time voice/video communication
- Screen sharing capabilities
- Production-ready UI components
- **URL Structure**: WebSocket URLs must include room name in path: `wss://host.livekit.cloud/room-name`
  - **Critical**: Room name extraction from URL path is required for bot joining
  - Default fallback to 'default-room' if path is empty

## Node.js Bot Technologies (Screenshare Bot) - **NEW October 2025**

### Bot Framework
- **@livekit/rtc-node**: 0.10.4 (LiveKit Node SDK)
  - Room connection with token authentication
  - Video track publishing for screenshare
  - Real-time participant management
  - WebRTC connection handling
- **Express**: 4.21.2 (HTTP server for lifecycle API)
  - Bot spawn/kill endpoints
  - Health check and status monitoring
  - Supabase integration

### Browser Automation
- **Playwright**: 1.48.2 (Headless browser)
  - Chromium-based screenshot capture
  - Page navigation and URL loading
  - Network idle detection
  - High-performance rendering at 10 FPS

### Image Processing
- **Sharp**: 0.33.5 (High-performance image processing)
  - Screenshot format conversion (PNG → RGBA)
  - Image resizing and optimization
  - Memory-efficient pixel buffer handling
- **Canvas**: 2.11.2 (Node.js canvas implementation)
  - RGBA to YUV conversion for video frames
  - Pixel manipulation and rendering
  - Video frame preparation for LiveKit

### Database & Real-time
- **@supabase/supabase-js**: 2.75.0 (TypeScript Supabase client)
  - Real-time subscriptions for slide control commands
  - PostgreSQL database access (active_bots table)
  - Row-level security integration
  - Type-safe database operations

### Type Safety
- **TypeScript**: 5.9.3 (Primary development language)
  - Full type safety across bot implementation
  - Strict null checks and type guards
  - Supabase auto-generated types integration
  - @types/express, @types/node for complete typing

### Architectural Decision (October 2025)
**Replaced Python Pipecat bot with Node.js implementation to solve:**
- Python asyncio hang issues on Railway
- Complex Python dependency management
- Slower iteration cycles
- Limited TypeScript type safety

**Node.js Bot Benefits:**
- Single runtime environment (Node.js 20+)
- Full TypeScript type safety
- Simpler deployment (no Python venv)
- Faster debugging and iteration
- Better Railway/Nx integration

## Browser Extension

### Framework
- **WXT**: 0.20.6 (Web Extension Framework)
- **@wxt-dev/module-react**: 1.1.3 (React integration)
- Cross-browser compatibility (Chrome, Firefox)

### Extension APIs
- **@types/chrome**: 0.1.1 (Chrome API types)

## Testing

### Unit Testing
- **Jest**: 29.7.0 (Test framework)
- **@testing-library/react**: 16.1.0 (React testing)
- **@testing-library/dom**: 10.4.0 (DOM testing)
- **ts-jest**: 29.4.1 (TypeScript support)
- **jest-environment-jsdom**: 30.0.2 (Browser environment)
- **jest-environment-node**: 30.0.2 (Node environment)

### E2E Testing
- **Playwright**: Via @nx/playwright 21.4.0
- **@playwright/test**: Cross-browser testing
- Tests in `tests/e2e/` directory

### Performance Testing
- Custom performance testing scripts
- Concurrent load testing framework
- Metrics tracking and reporting

## Validation & Schema

### Validation Libraries
- **Zod**: 4.0.17 (Schema validation)
- **Joi**: 18.0.1 (Alternative validation)

## Utilities

### Development Tools
- **ts-node**: 10.9.1 (TypeScript execution)
- **@swc/core**: 1.5.7 (Fast TypeScript compiler)
- **esbuild**: 0.19.12 (JavaScript bundler)

### Logging
- **Winston**: 3.17.0 (Logging library)
- Structured logging support
- Multiple transport options

### File Operations
- **fs-extra**: 11.3.1 (Enhanced file system)
- **archiver**: 7.0.1 (Archive creation)

### Utilities
- **uuid**: 10.0.0 (UUID generation)
- **dotenv**: 17.2.1 (Environment variables)
- **crypto-js**: 4.2.0 (Cryptography)
- **defu**: 6.1.4 (Default value merging)
- **commander**: 14.0.0 (CLI framework)

## Code Quality

### Linting (Updated October 2025)
- **ESLint**: 8.57.1 (Linting)
- **@typescript-eslint/eslint-plugin**: 8.40.0
- **@typescript-eslint/parser**: 8.40.0
- **eslint-plugin-react**: 7.37.5
- **eslint-plugin-react-hooks**: 5.2.0

**Zero Tolerance Enforcement** (as of October 20, 2025):
- CI/CD enforces `--max-warnings=0` for all ESLint checks
- 6 quality rules promoted to ERROR level:
  - `@typescript-eslint/no-explicit-any` - Type safety
  - `@typescript-eslint/no-unused-vars` - Code cleanliness
  - `@typescript-eslint/no-floating-promises` - Async safety
  - `@typescript-eslint/no-misused-promises` - Async safety
  - `@typescript-eslint/await-thenable` - Type safety
  - `no-template-curly-in-string` - String safety
- Pre-commit hooks enforce standards locally
- 697 of 727 violations fixed (95.9% success rate)
- 100% of production code lint-clean

**Pre-commit Hook Update** (October 22, 2025):
- TypeScript and ESLint checks temporarily non-blocking (`|| echo "⚠️ errors found"`)
- Change made to enable faster iteration during Railway deployment debugging
- Plan to re-enable blocking checks after deployment stabilizes

### Formatting
- **Prettier**: 2.6.2 (Code formatter)

## Deployment Platforms

### Production Hosting
- **Railway**: Production deployment under `buzztrail-voice-agent` project
  - **Project**: `buzztrail-voice-agent` (ID: 655e15d5-19b0-40a0-b6a4-d556806f3746)
  - **Services**:
    - `slide-system` - Motia API backend for slide generation and bot management (Docker-based)
    - `voice-agent` - LiveKit voice agent application
    - `bot-spawner` - Node.js screenshare bot spawning service (RAILPACK-based)
  - **Important**: Original standalone `slide-system` project was deleted, code moved to service under `buzztrail-voice-agent`
  - **Deployment URLs**:
    - slide-system: https://slide-system-production-5813.up.railway.app
    - bot-spawner: https://bot-spawner-production.up.railway.app
  - Automatic CI/CD from main branch
  - Environment variable management
  - Logs and monitoring

  **bot-spawner Railway Configuration** (October 2025):
  - **Build System**: RAILPACK (Railway's modern Node.js builder)
  - **Root Directory**: `/` (monorepo root)
  - **Build Command**: `pnpm run railway:build:bot-spawner`
    - Installs deps with frozen lockfile
    - Builds with Nx + esbuild (bundled, external deps)
    - Copies package.json to dist
    - Runs `pnpm install --prod` (triggers postinstall for Playwright)
  - **Start Command**: `pnpm run railway:start:bot-spawner`
    - Runs `node dist/apps/bot-spawner/main.js`
  - **Deployment Strategy**: Version-controlled via package.json scripts
  - **Playwright Installation**: Handled by postinstall hook (`playwright install --with-deps chromium`)
  - **Bundle Configuration** (apps/bot-spawner/project.json):
    - `bundle: true` - Single file output with bundled app code
    - `external: ["express", "@supabase/supabase-js", "@livekit/rtc-node", "playwright", "sharp", "canvas"]`
    - External deps installed at runtime via package.json

  **Docker-based builds** (slide-system):
  - Dockerfile in apps/slide-system/
  - **Docker Context Issue**: Only files in `apps/slide-system/` are included in build
    - External monorepo paths (like `libs/`) are not accessible
    - Bots must be self-contained with local copies of shared code

- **Vercel**: `proxy-server` serverless functions
  - Automatic deployments
  - Edge network delivery
  - Serverless function support

- **GitHub Pages**: Slidev presentation hosting
  - Static site hosting
  - CDN delivery
  - Custom domain support

### Database Hosting
- **Supabase Cloud**: PostgreSQL database
  - Managed database service
  - Real-time subscriptions
  - Automatic backups

## Observability

### OpenTelemetry
- **@opentelemetry/api**: 1.9.0
- **@opentelemetry/sdk-node**: 0.203.0
- **@opentelemetry/auto-instrumentations-node**: 0.62.1
- **@opentelemetry/exporter-otlp-http**: 0.26.0
- **@opentelemetry/resources**: 2.0.1
- **@opentelemetry/semantic-conventions**: 1.36.0

Distributed tracing and metrics collection support.

## Git & CI/CD

### Version Control
- **Git**: Primary VCS
- **GitHub**: Repository hosting
  - Repository: `BuzzTrail/video-extension`
  - Branch: `main` (primary)
- **Husky**: 9.1.8+ (Git hooks)
  - Pre-commit hooks for type checking
  - Production code validation (TypeScript + Python)
  - Git GUI client support (SourceTree, Tower)

### CI/CD
- **Nx Cloud**: Disabled (using local caching only)
  - Previously: 68a49d658511b24e2d6eda2a
  - **Reason**: Eliminated third-party url.parse() deprecation warnings

**GitHub Actions Workflow** (`.github/workflows/ci.yml`):
- **TypeScript Type Check**: `tsc` on affected projects
- **ESLint Type-Aware Linting**: `pnpm nx affected --target=lint --max-warnings=0` (Zero Tolerance)
- **Python Type Checking**: mypy + ruff on affected projects
- **Build Affected Projects**: Nx affected builds
- **Test Affected Projects**: Nx affected tests
- Runs in parallel for fast feedback (<3 minutes typical)

### Pre-commit Hooks (Husky)
- **TypeScript**: `tsc` type checking + ESLint (type-aware) on affected files with `--max-warnings=0`
- **Python Production Code**:
  - screenshare-bot: mypy strict checking (production files only)
  - voice-agent-livekit: ruff linting (src/ directory)
  - tool-forwarder: ruff linting (production files only)
- **PATH Setup**: Supports Git GUI clients (SourceTree, Tower) with automatic tool discovery
- **Exit Code Handling**: `set -o pipefail` ensures type errors block commits
- **Enforcement**: Zero tolerance - blocks commits with lint errors or warnings

### GitHub Integration
- **@octokit/rest**: 22.0.0 (GitHub API client)

## Development Workflow Tools

### Task Running
- **npm-run-all**: 4.1.5 (Run scripts in parallel/sequence)

### WebSocket
- **ws**: 8.18.1 (WebSocket library)

### Job Scheduling
- **node-cron**: 4.2.1 (Cron job scheduling)

## Configuration Management

### TypeScript
- Strict mode enabled
- ES2022 target
- Path aliases configured in `tsconfig.base.json`
- Monorepo-aware path resolution

### Nx Configuration
- Task caching enabled
- Dependency graph optimization
- Parallel execution support
- Cloud caching integration

## Browser Targets

- Chrome (latest, via extension)
- Firefox (latest, via extension)
- Modern browsers (for web apps)
- ES2022+ JavaScript support required

## Node.js Version Requirements

- **Minimum**: Node.js v22
- **Package Manager**: pnpm 10.18.1+
- **Corepack**: Enabled for consistent pnpm versions

## Environment Variables

### Required for Development
- `TAVUS_API_KEY` - Tavus API authentication
- `DAILY_API_KEY` - Daily.co API key
- `SUPABASE_URL` - Supabase project URL
- `SUPABASE_SERVICE_KEY` - Supabase service role key
- `MOTIA_API_KEY` - Motia API authentication

### Optional
- `NODE_ENV` - Environment (development/production)
- `PORT` - Server port (defaults provided)
- `ENABLE_EXPERIMENTAL_COREPACK` - For Vercel pnpm support

## API Integrations

### External Services
1. **Tavus API** - Video generation platform
2. **Daily.co** - WebRTC communication
3. **Supabase** - Database and real-time
4. **Motia** - AI workflow automation
5. **GitHub API** - Repository operations

### Internal APIs
- Slide System API (Railway)
- Proxy Server API (Vercel)
- Fake Tavus Server (local development)
