---
issue: 165
title: Implement Node.js Screenshare Bot
analyzed: 2025-10-21T14:03:07Z
estimated_hours: 20-30
parallelization_factor: 2.5
---

# Parallel Work Analysis: Issue #165

## Overview

Implement a Node.js/TypeScript screenshare bot using Playwright for browser automation and LiveKit SDK for WebRTC streaming. This involves creating the bot core logic, API integration, and testing infrastructure.

## Parallel Streams

### Stream A: Bot Core Implementation
**Scope**: Playwright browser automation, screenshot capture loop, LiveKit streaming
**Files**:
- `apps/bot-spawner/src/bots/ScreenshareBot.ts` (new)
- `apps/bot-spawner/src/bots/types.ts` (new)
- `apps/bot-spawner/src/bots/BotRegistry.ts` (new)
**Agent Type**: backend-specialist
**Can Start**: immediately
**Estimated Hours**: 12-15
**Dependencies**: none

**Tasks**:
- Implement `ScreenshareBot` class with Playwright integration
- Create screenshot capture loop (30fps target)
- Integrate LiveKit Node SDK for screenshare track
- Implement graceful shutdown and cleanup
- Add TypeScript interfaces and types

### Stream B: API Routes & Integration
**Scope**: Express API endpoints, LiveKit token generation, Supabase integration
**Files**:
- `apps/bot-spawner/src/routes/bots.ts` (new)
- `apps/bot-spawner/src/services/livekit.ts` (new)
- `apps/bot-spawner/src/main.ts` (modify - route registration)
**Agent Type**: backend-specialist
**Can Start**: immediately (can mock bot implementation)
**Estimated Hours**: 6-8
**Dependencies**: none (can develop with mocked bot)

**Tasks**:
- Implement POST `/api/bots/screenshare/spawn-livekit` endpoint
- Implement POST `/api/bots/:id/kill` endpoint
- Implement GET `/api/bots/:id/status` endpoint
- Create LiveKit token generation service
- Add Supabase `active_bots` table integration
- Register routes in main.ts

### Stream C: Supabase Realtime Integration
**Scope**: Slide control listener, keyboard navigation commands
**Files**:
- `apps/bot-spawner/src/bots/ScreenshareBot.ts` (extend from Stream A)
- `apps/bot-spawner/src/services/supabase.ts` (new)
**Agent Type**: backend-specialist
**Can Start**: after Stream A core is functional
**Estimated Hours**: 3-4
**Dependencies**: Stream A (needs bot instance with Playwright page)

**Tasks**:
- Subscribe to Supabase Realtime slide_control channel
- Implement slide command handler (next/prev)
- Add Playwright keyboard navigation (ArrowLeft/Right)
- Handle connection errors and reconnection

### Stream D: Testing & Deployment
**Scope**: Local testing, Railway deployment, end-to-end validation
**Files**:
- `apps/bot-spawner/package.json` (modify - add postinstall)
- Railway configuration (modify)
- Test scripts (new)
**Agent Type**: backend-specialist
**Can Start**: after Streams A & B are integrated
**Estimated Hours**: 4-6
**Dependencies**: Stream A (bot core), Stream B (API routes)

**Tasks**:
- Add Playwright postinstall script for Chromium
- Test bot spawning locally
- Test LiveKit room joining
- Test screenshot streaming
- Deploy to Railway staging
- End-to-end test with voice-demo-ui

## Coordination Points

### Shared Files
- `apps/bot-spawner/src/bots/ScreenshareBot.ts` - Streams A & C (A creates core, C adds Realtime)
- `apps/bot-spawner/src/main.ts` - Stream B modifies for route registration
- `apps/bot-spawner/package.json` - Stream D adds postinstall, all streams may add dependencies

### Sequential Requirements
1. **Stream A must complete core bot** before Stream C adds Realtime (needs Playwright page instance)
2. **Streams A & B must integrate** before Stream D testing (needs functional bot + API)
3. **Stream C can run parallel** with Stream B (independent features)

## Conflict Risk Assessment
- **Low Risk**: Streams A & B work on completely different files initially
- **Medium Risk**: ScreenshareBot.ts shared between A & C (sequential by design)
- **Low Risk**: Stream D only modifies config files, minimal overlap

## Parallelization Strategy

**Recommended Approach**: hybrid

**Phase 1 (Parallel):**
- Launch Stream A (bot core) and Stream B (API routes) simultaneously
- Both can develop independently with mocked interfaces
- Estimated wall time: 12-15 hours (max of both streams)

**Phase 2 (Integration):**
- Integrate A & B (bot spawning works end-to-end)
- Add Stream C (Supabase Realtime) to Stream A's bot
- Estimated wall time: 3-4 hours

**Phase 3 (Testing):**
- Stream D (testing & deployment)
- Estimated wall time: 4-6 hours

**Total wall time: 19-25 hours** (vs 25-33 hours sequential)

## Expected Timeline

With parallel execution:
- Wall time: 19-25 hours
- Total work: 25-33 hours
- Efficiency gain: 24-32% time savings

Without parallel execution:
- Wall time: 25-33 hours

## Notes

**Critical Path:**
Stream A (bot core) is the longest task and on the critical path. Stream B can run fully in parallel.

**Integration Points:**
- After Phase 1: Integrate Stream A's `ScreenshareBot` class with Stream B's API routes
- After Phase 2: Stream C extends `ScreenshareBot` with Realtime listener

**Dependency Management:**
- Stream B should define the `BotConfig` interface that Stream A implements
- Agree on bot spawn/kill/status interfaces early
- Use TypeScript types to enforce contracts

**Testing Strategy:**
- Stream A can unit test bot logic independently
- Stream B can test API routes with mocked bot
- Stream D does integration testing after merge

**Deployment Considerations:**
- Playwright installation via postinstall may take time on Railway
- Test Chromium download works correctly in build
- Monitor Railway build time (may be longer with Playwright)
