---
issue: 162
title: Create Bot-Spawner NX App & Railway Service
analyzed: 2025-10-21T08:45:32Z
estimated_hours: 10
parallelization_factor: 1.8
---

# Parallel Work Analysis: Issue #162

## Overview

Create the foundational infrastructure for the bot-spawner service. This involves creating an NX app with Express HTTP server, a Dockerfile with dual runtime (Node.js 20 + Python 3.11), and deploying to Railway with environment configuration. The service will serve as the container for bot spawning logic (which will be added in Task #156).

**Prerequisites**: Phase 0 validation complete (Tasks #155, #157) - both PASSED ✅

## Parallel Streams

### Stream A: NX App & Express Server
**Scope**: Create NX application structure, Express HTTP server with health endpoint, TypeScript configuration
**Files**:
- `apps/bot-spawner/src/main.ts` (Express server)
- `apps/bot-spawner/project.json` (NX config)
- `apps/bot-spawner/tsconfig.json`
- `apps/bot-spawner/package.json`
- `apps/bot-spawner/.eslintrc.json`
**Agent Type**: backend-specialist (Node.js/TypeScript)
**Can Start**: immediately
**Estimated Hours**: 3 hours
**Dependencies**: none

**Deliverables**:
- NX app created via `pnpm nx generate @nx/node:application bot-spawner`
- Express server with `/health` endpoint
- Health check includes:
  - Supabase connection test (query `active_bots` count)
  - Python version verification
  - Timestamp and status reporting
- TypeScript types for health response
- Local testing with `pnpm nx serve bot-spawner`

### Stream B: Dockerfile & Build Configuration
**Scope**: Create multi-runtime Dockerfile (Node.js 20 + Python 3.11), optimize build layers, validate local builds
**Files**:
- `apps/bot-spawner/Dockerfile`
- `apps/bot-spawner/.dockerignore`
- `apps/bot-spawner/README.md` (build instructions)
**Agent Type**: devops-specialist (Docker, build optimization)
**Can Start**: immediately (parallel with Stream A)
**Estimated Hours**: 4 hours
**Dependencies**: none (can reference Phase 0 diagnostic Dockerfile)

**Deliverables**:
- Dockerfile with Ubuntu 24.04 base
- Node.js 20 installation (via nodesource)
- Python 3.11 installation (via deadsnakes PPA)
- pnpm installation and dependency caching
- Layer optimization for <10 minute builds
- `.dockerignore` for build efficiency
- Local Docker build validation: `docker build -t bot-spawner .`
- Python version verification in container: `docker run bot-spawner python3.11 --version`

### Stream C: Railway Deployment & Configuration
**Scope**: Create Railway project, configure environment variables, deploy service, validate internal networking
**Files**:
- `apps/bot-spawner/railway.json` (Railway config)
- Documentation updates for deployment
**Agent Type**: general-purpose (deployment, infrastructure)
**Can Start**: after Stream A completes (needs Express server code)
**Estimated Hours**: 3 hours
**Dependencies**: Stream A (needs working Express server), Stream B (needs Dockerfile)

**Deliverables**:
- Railway project created: `bot-spawner`
- Environment variables configured:
  - `SUPABASE_URL`
  - `SUPABASE_SERVICE_KEY`
  - `LIVEKIT_URL`, `LIVEKIT_API_KEY`, `LIVEKIT_API_SECRET`
  - `DAILY_PIPECAT_API_KEY` (for tool-forwarder)
  - `PORT=3001`
- Service deployed successfully
- Health endpoint accessible:
  - Public: `https://bot-spawner-<id>.up.railway.app/health`
  - Internal: `http://bot-spawner.railway.internal:3001/health`
- Internal networking validated from slide-system service
- Railway logs confirm successful startup
- Build time verified <10 minutes

## Coordination Points

### Shared Files
**Minimal overlap** - streams work on different aspects:
- `apps/bot-spawner/package.json` - Stream A creates, Stream B references for Docker build
- `apps/bot-spawner/README.md` - Stream B creates build docs, Stream C adds deployment docs

### Sequential Requirements
1. **Stream A must complete** before Stream C can deploy (needs working Express server)
2. **Stream B must complete** before Stream C can deploy (needs Dockerfile)
3. **Stream C validates both** Stream A (server works) and Stream B (Docker builds)

### Integration Point
**Stream C (Deployment)** requires:
- Working Express server from Stream A (`main.ts` compiled to `dist/`)
- Valid Dockerfile from Stream B
- Railway CLI authenticated and ready
- Environment variables defined

## Conflict Risk Assessment

**Risk Level: LOW**

- Stream A: Works on `src/` directory (TypeScript code)
- Stream B: Works on root-level config files (Dockerfile, .dockerignore)
- Stream C: Works on Railway platform (external to codebase)
- No file overlap between A & B
- Stream C only reads files, doesn't modify during deployment

**Potential Issues**:
- If Stream A adds dependencies to `package.json`, Stream B's Dockerfile may need update
  - **Mitigation**: Stream B uses standard pnpm install pattern that works for any deps

## Parallelization Strategy

**Recommended Approach**: Hybrid (A & B parallel, C sequential)

**Execution Plan**:
1. **Phase 1** (parallel, ~4 hours):
   - Stream A: Create NX app + Express server (3h)
   - Stream B: Create Dockerfile + build config (4h)
2. **Phase 2** (sequential, ~3 hours):
   - Stream C: Deploy to Railway + validate (3h)

**Why This Approach**:
- Streams A & B have no dependencies and work on separate files
- Stream C naturally depends on both A & B completing
- Total wall time reduced from 10h (sequential) to ~7h (hybrid)

## Expected Timeline

**With parallel execution:**
- Phase 1 wall time: 4 hours (max of Stream A and B)
- Phase 2 wall time: 3 hours (Stream C)
- **Total wall time: 7 hours**
- **Total work: 10 hours**
- **Efficiency gain: 30%**

**Without parallel execution (sequential):**
- Stream A: 3 hours
- Stream B: 4 hours
- Stream C: 3 hours
- **Total wall time: 10 hours**

**Parallelization factor: 1.8x** (moderate speedup due to sequential dependency in Stream C)

## Agent Assignments

**Stream A Agent**: Backend specialist (Node.js/TypeScript)
- Expert in NX monorepo tooling
- Familiar with Express.js and REST APIs
- Understands Supabase client integration
- Creates production-ready TypeScript code

**Stream B Agent**: DevOps specialist (Docker)
- Expert in Dockerfile optimization
- Familiar with multi-runtime containers
- Understands layer caching and build efficiency
- Can validate Python installation in containers

**Stream C Agent**: General-purpose (deployment)
- Familiar with Railway CLI and platform
- Can configure environment variables
- Understands internal networking validation
- Documents deployment procedures

## Notes

**Critical Success Factors**:
1. **Dual Runtime**: Dockerfile must successfully install both Node.js 20 and Python 3.11
2. **Python Validation**: Must verify Python 3.11 from Phase 0 diagnostic works in bot-spawner container
3. **Internal Networking**: Must validate `.railway.internal` DNS from slide-system to bot-spawner
4. **Build Time**: Must achieve <10 minute builds for fast iteration

**Reference Materials**:
- Phase 0 diagnostic Dockerfile: `.claude/epics/bot-spawner-extraction/diagnostic/Dockerfile`
- Test service examples: `.claude/epics/bot-spawner-extraction/test-services/`
- Voice-agent Dockerfile (proven Python 3.11 setup): `apps/voice-agent-livekit/Dockerfile`

**Environment Parity**:
- Use **exact same** Ubuntu 24.04 + Python 3.11 setup as Phase 0 diagnostic (validated working)
- Copy environment variables from slide-system Railway service
- Match voice-agent's proven configuration

**Testing Strategy**:
- **Local first**: Validate Express server and Docker build locally before Railway
- **Incremental deployment**: Deploy basic health endpoint first, add complexity later
- **Validation sequence**:
  1. Local: `pnpm nx serve bot-spawner` → health endpoint works
  2. Local: `docker build` → image builds successfully
  3. Local: `docker run` → Python 3.11 accessible
  4. Railway: Deploy → service starts
  5. Railway: Public health endpoint works
  6. Railway: Internal networking from slide-system works

**Rollback Plan**:
- If deployment fails, Railway allows easy rollback to previous version
- If Dockerfile build issues, reference Phase 0 diagnostic (known working)
- No impact on slide-system (bot-spawner not yet integrated)

**Follow-up Actions**:
- After successful deployment, Task #156 (Port Bot Spawning Logic) will add bot spawn endpoints
- Bot spawner becomes the isolated environment for testing asyncio hang hypothesis
