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

# Project Structure

## Overview

BuzzTrail is an **Nx monorepo** containing multiple applications and shared libraries organized for maximum code reuse and maintainability.

## Root Directory Structure

```
buzztrail/extension/
├── .claude/                  # Claude Code configuration and context
│   ├── commands/            # Custom slash commands
│   ├── context/             # Project context files
│   ├── docs/                # Internal documentation
│   ├── epics/               # Epic tracking (completed epics removed after merge)
│   ├── prds/                # Product requirement documents
│   │   ├── .analysis/       # Schema analysis and conflict reports (NEW)
│   │   │   └── schema-conflict-analysis.md  # 537 lines, critical findings
│   │   └── .archived/       # Archived/completed PRDs
│   │       ├── bot-spawner-extraction.md
│   │       └── voice-slide-show-livekit.md
│   ├── rules/               # Project rules and conventions
│   └── scripts/             # Automation scripts
├── apps/                    # Application projects
├── libs/                    # Shared libraries
├── docs/                    # Project documentation
├── scripts/                 # Build and utility scripts
├── tests/                   # E2E tests (Playwright)
├── node_modules/            # Dependencies
├── dist/                    # Build output
├── coverage/                # Test coverage reports
└── [config files]           # Various configuration files
```

## Applications (`apps/`)

### Infrastructure Applications

**supabase-backend/** (NEW - October 2024)
- Supabase backend infrastructure (migrations, Edge Functions)
- Nx app with Supabase CLI integration
- Technology: Supabase, PostgreSQL
- **Status**: Active (Issue #179 - Extracted from slide-system)
- **Purpose**: Permanent Supabase infrastructure separated from temporary Motia code
- **Structure**:
  - `supabase/config.toml` - Supabase project configuration
  - `supabase/migrations/` - 7 database migrations
  - `supabase/functions/` - Edge Functions (ready for deployment)
  - `MIGRATION_GUIDE.md` - Complete migration workflow
  - `MIGRATION_CHEATSHEET.md` - Quick reference
  - `LOCAL-DEVELOPMENT.md` - Local dev setup
- **Nx Targets**:
  - `db:push` - Push migrations to remote
  - `db:pull` - Pull schema from remote
  - `migration:new` - Create new migration
  - `functions:new/serve/deploy` - Edge Function operations
- **Migrations** (7 files):
  - `20251012_create_active_bots.sql` - Bot tracking table
  - `20251015_baseline_existing_schema.sql` - Schema baseline
  - `20251015_make_all_daily_columns_nullable.sql` - Daily.co nullable fix
  - `20251015_add_livekit_support.sql` - LiveKit integration
  - `20251016_add_screenshare_livekit_bot_type.sql` - Bot type enum
  - `20251022_add_session_metrics.sql` - Session analytics
  - `20251024000000_add_customer_registry.sql` - Customer data (511 lines)

### Production Applications

**bot-spawner/** (DEPLOYED - October 2025)
- Dedicated bot spawning service on Railway
- Node.js screenshare bot with LiveKit video streaming
- Production URL: `https://bot-spawner-production.up.railway.app`
- Technology: Node.js, Express, TypeScript, Playwright, LiveKit, Supabase
- **Status**: Production ready (Epic #164, Tasks #162, #160, #166)
- **Purpose**: Screenshare bot lifecycle management with HTTP API
- **API Endpoints**:
  - `GET /health` - Health check with database connectivity
  - `POST /api/bots/spawn` - Spawn new screenshare bot (LiveKit)
  - `GET /api/bots/:bot_id/status` - Get bot status
  - `POST /api/bots/:bot_id/kill` - Terminate bot
- **Bot Features**:
  - Playwright browser automation for screenshot capture
  - LiveKit Node SDK for real-time video streaming (10 FPS, 640x360)
  - Supabase Realtime for slide control commands (next, prev, goto)
  - Automated cleanup on 1-hour inactivity
  - Full TypeScript type safety
- **Bot Directory Structure**:
  ```
  bot-spawner/src/
  ├── main.ts                    # Express HTTP server
  ├── bot/
  │   ├── screenshare-bot.ts     # Main bot implementation
  │   ├── video-stream.ts        # LiveKit video streaming
  │   ├── slide-controller.ts    # Supabase slide navigation
  │   └── lifecycle.ts           # Spawn/cleanup management
  ├── types/
  │   └── database.ts            # Supabase type definitions
  └── utils/
      └── logger.ts              # Logging utilities
  ```
- **Railway Deployment**:
  - RAILPACK builder with Playwright system dependencies
  - Bundled build with esbuild
  - External Playwright binaries (installed via postinstall)
  - Optimized apt packages (libatk, libnss3, libxcomposite, etc.)

**slide-system/** (DEPLOYED)
- Motia.dev API backend on Railway
- Slidev deck generation and control
- Bot spawning proxy (delegates to bot-spawner via HTTP API)
- Production URL: `https://slide-system-production-5813.up.railway.app`
- Technology: Node.js, Express, Motia, Supabase
- **API Endpoints**:
  - `POST /api/slidev/generate` - Generate Slidev presentation
  - `POST /api/slidev/control` - Control presentation
  - `POST /demo-sessions` - Create demo session
  - `POST /api/bots/screenshare/spawn-livekit` - Proxy to bot-spawner (HTTP)
  - `GET /api/bots/screenshare/status` - Check bot status
  - `POST /api/bots/screenshare/kill/:bot_id` - Terminate bot
  - `GET /health` - Health check
- **Steps (Motia API)**:
  - `slidev-generate.step.ts` - Presentation generation
  - `slidev-control.step.ts` - Presentation control
  - `bot-spawn-livekit.step.ts` - Bot spawning (HTTP proxy to bot-spawner)
  - `bot-status-get.step.ts` - Bot status retrieval
  - `bot-kill.step.ts` - Bot termination
  - `bot-logs-get.step.ts` - Log file retrieval (diagnostic)
- **Note**: Supabase infrastructure moved to `apps/supabase-backend/` (Issue #179)
- **Architecture Change (October 2025)**:
  - **Before**: Direct Python subprocess spawning within slide-system
  - **After**: HTTP API calls to bot-spawner service
  - **Benefits**: Service isolation, better error handling, independent scaling

**proxy-server/**
- Vercel serverless functions
- API proxy and webhook handling
- Technology: Node.js, Express, Vercel

**backup-workflows/**
- Motia backend workflow automation
- Customer data management
- Event-driven processing
- Technology: Motia, Node.js

### Development Applications

**demos/**
- Customer-facing demo interfaces
- Multiple demo configurations (BuzzTrail, SendCloud)
- Technology: React, Vite

**chatbot/**
- Chat interface application
- AI-powered conversation UI
- Technology: React, TypeScript

**extension/**
- Browser extension (WXT framework)
- Chrome/Firefox compatible
- Technology: WXT, React, TypeScript

**demo-experience-ui/**
- Enhanced demo user experience
- Technology: React

**backup-manager/**
- Data backup management interface
- Technology: Node.js

**voice-agent-livekit/** (✅ DEPLOYED - Epic #142 COMPLETE)
- LiveKit Agents voice AI worker
- Real-time voice conversation with slide control
- Python application with LiveKit SDK
- Technology: Python 3.11+, LiveKit Agents, ElevenLabs, Deepgram, GPT-4
- **Application Structure**:
  ```
  voice-agent-livekit/
  ├── src/voice_agent_livekit/
  │   ├── __init__.py           # Package entry point
  │   ├── agent.py              # Main voice agent
  │   ├── conversation.py       # Conversation manager
  │   ├── supabase_client.py    # Realtime broadcast
  │   ├── metrics.py            # Session metrics tracking (NEW - Oct 2025)
  │   └── tools/                # AI tool functions
  │       ├── __init__.py
  │       ├── slide_control.py  # Slide navigation tools
  │       └── slide_generation.py  # Deck generation tools
  ├── docs/
  │   └── MONITORING.md         # Monitoring setup guide (NEW - Oct 2025)
  ├── tests/                    # pytest tests
  ├── pyproject.toml            # uv project config
  ├── railway.json              # Railway deployment
  └── .env.example              # Environment template
  ```

**voice-demo-ui/** (NEW - Epic #142)
- Angular UI for LiveKit voice demos
- Real-time voice conversation interface
- LiveKit client integration
- Technology: Angular, LiveKit Client SDK
- **Features**:
  - Room creation and joining
  - Audio visualization
  - End call functionality
  - Participant display

### Testing Applications

**fake-tavus-server/**
- Mock Tavus API server for testing
- Local development support
- Technology: Node.js, Express

**fake-tavus-server-e2e/**
- E2E tests for fake server
- Technology: Jest, Playwright

## Libraries (`libs/`)

### Shared Libraries

**shared/**
- `utils/` - API clients, logging, common utilities
- `components/` - Reusable React components
- `types/` - TypeScript type definitions
- `config/` - Configuration utilities
- `constants/` - Shared constants
- `icons/` - Icon components
- `styles/` - Styling utilities
- `themes/` - Theme system
- `ui/` - UI component library

### Domain-Specific Libraries

**slidev/**
- Slidev integration utilities
- Presentation generation logic
- Control system components

**tavus/**
- Tavus API client
- Integration utilities
- Type definitions

**accounts-backup/**
- Account backup logic
- Data export/import utilities

**backup-workflows/**
- Workflow orchestration
- Event handling
- State management

**customer-management/**
- Customer data models
- Management utilities

**shared-database/**
- Database schemas
- Migration utilities
- Query helpers

**gating/** - **NEW October 2024**
- Pre-conversation lead capture form
- Package: `@buzztrail-ai/gating`
- **Single source of truth** for gating across all BuzzTrail packages
- **Features**:
  - React components: `<GatingForm>`, `<GatingFormField>`, `<GatingPrivacyConsent>`
  - React hook: `useGatingForm()` for state management
  - Internationalization: 5 languages (en, no, de, es, fr) with i18next
  - Email validation: Format + top 50 free provider blocking
  - Phone validation: International format support
  - Supabase lead submission
  - GDPR-compliant privacy consent UI
  - TypeScript: Full type safety
- **Architecture**: Shared library imported by:
  - `@buzztrail-ai/engage`
  - `@buzztrail-ai/presentation` (future)
  - `@buzztrail-ai/experience` (future)
- **Build**: 326 KB (83 KB gzipped)
- **Technology**: React, TypeScript, i18next, validator, Supabase
- **Issue**: #171 - Completed October 24, 2025

**engage-package/** - **NEW October 2024**
- Universal NPM package for video conversations
- Package: `@buzztrail-ai/engage`
- Epic #167: Universal NPM Package & CDN Distribution (40% complete)
- **Features**:
  - CDN distribution (jsDelivr/unpkg)
  - Wix-first integration approach
  - Browser compatibility checking (ESLint + browserslist)
  - Email validation utilities
- **Technology**: Vite, TypeScript, Tavus SDK
- **Issues**: #172 (Extract Wix Code ✅), #173 (Build System ✅)

**ui/**
- Component library
- Design system components

## Documentation (`docs/`)

### API Documentation
- `api/slidev-api.md` - Complete API reference
- `api/slidev-generate.md` - Generation endpoint
- `api/slidev-control.md` - Control endpoint

### Architecture
- `architecture/slidev-system.md` - System design

### Deployment
- `deployment/railway-deployment.md` - Railway deployment guide

### Operations
- `operations/monitoring.md` - Monitoring guide
- `operations/troubleshooting.md` - Troubleshooting guide
- `operations/production-checklist.md` - Deployment checklist

### Testing
- `testing/test-readiness-report.md` - Test status
- `testing/test-execution-plan.md` - Test plan
- `testing/slidev-e2e-report.md` - E2E test results

### Other
- `database-schema.md` - Database documentation
- `build-system-configuration-inventory.md` - Build configuration

## Testing Structure (`tests/`)

```
tests/
└── e2e/                     # End-to-end tests
    ├── slidev-flow.spec.ts  # Happy path tests
    ├── error-handling.spec.ts # Error scenarios
    └── browser-compatibility.spec.ts # Cross-browser tests
```

## Scripts Directory (`scripts/`)

Utility scripts for development and testing:
- `performance-test.ts` - Performance testing
- `concurrent-test.ts` - Concurrent load testing
- Test execution helpers
- Data management utilities

## Configuration Files

### Build System
- `nx.json` - Nx workspace configuration
- `package.json` - Project dependencies and scripts
- `pnpm-workspace.yaml` - pnpm workspace setup
- `tsconfig.base.json` - Base TypeScript config
- `tsconfig.json` - Root TypeScript config

### Testing
- `jest.config.js` - Jest configuration
- `jest.preset.js` - Jest preset
- `playwright.config.ts` - Playwright E2E config

### Linting & Formatting
- `.eslintrc.js` - ESLint configuration
- `.prettierrc` - Prettier configuration
- `.prettierignore` - Prettier ignore rules

### Environment
- `.env` - Environment variables (gitignored)
- `.env.example` - Environment template
- `.gitignore` - Git ignore rules

### Deployment
- `vercel.json` - Vercel configuration
- `.npmrc` - npm configuration

## File Naming Conventions

### TypeScript Files
- `*.ts` - TypeScript source files
- `*.tsx` - TypeScript React components
- `*.spec.ts` - Test files
- `*.test.ts` - Alternative test naming
- `*.d.ts` - Type declaration files

### Configuration
- `project.json` - Nx project configuration
- `tsconfig.json` - TypeScript configuration
- `jest.config.js` - Jest configuration

### Documentation
- `README.md` - Project/package documentation
- `*.md` - Markdown documentation files

## Module Organization

### Import Path Patterns

**Shared libraries**: `@buzztrail/shared/*`
```typescript
import { logger } from '@buzztrail/shared/utils';
import { Button } from '@buzztrail/shared/components';
```

**Domain libraries**: `@buzztrail/*`
```typescript
import { TavusClient } from '@buzztrail/tavus';
import { SlidevGenerator } from '@buzztrail/slidev';
```

### Dependency Flow

```
apps/ → depends on → libs/
libs/shared/ → depended on by → other libs/
libs/domain-specific/ → may depend on → libs/shared/
```

## Build Output Structure

```
dist/
├── apps/
│   ├── slide-system/        # Production API build
│   ├── proxy-server/        # Vercel functions
│   └── [other-apps]/
└── libs/                    # Compiled libraries
```

## Key Directories by Purpose

### Source Code
- `apps/*/src/` - Application source code
- `libs/*/src/` - Library source code

### Tests
- `apps/*/src/**/*.spec.ts` - Unit tests
- `tests/e2e/` - E2E tests
- `coverage/` - Test coverage reports

### Configuration
- `apps/*/project.json` - App-specific Nx config
- `libs/*/project.json` - Library-specific Nx config

### Build Artifacts
- `dist/` - Production builds
- `.nx/` - Nx cache
- `node_modules/` - Dependencies

## Update History

- **2025-10-22T10:51:22Z**: Major bot-spawner architecture update (Tasks #160, #166) - Replaced Python bot with Node.js TypeScript implementation, updated bot-spawner to use Playwright + LiveKit Node SDK for screenshare video streaming, added complete API endpoint documentation, documented RAILPACK Railway deployment configuration, updated slide-system to proxy bot spawning via HTTP API instead of direct subprocess management, clarified service responsibilities and benefits
- **2025-10-21T13:27:09Z**: Added bot-spawner application (Epic #164, Task #162), new dedicated Railway service for isolated Python bot spawning with Express.js HTTP server and Supabase integration
- **2025-10-17T07:17:43Z**: Added bot-logs-get.step.ts diagnostic endpoint, documented bot logs directory, added API endpoint list to slide-system
- **2025-10-16T08:00:22Z**: Added voice-agent-livekit and voice-demo-ui applications (Epic #142), updated epic progress to 90%
