Contributing to Watch Together
Thank you for your interest in contributing to Watch Together! This document provides guidelines and instructions for contributing.
Table of Contents
Section titled “Table of Contents”- Development Setup
- Project Structure
- Code Style
- Making Changes
- Testing
- GitHub Workflows
- Pull Request Process
- Security
- Code of Conduct
Development Setup
Section titled “Development Setup”Prerequisites
Section titled “Prerequisites”- Docker & Docker Compose - For containerized development
- Node.js 20+ - For frontend development
- Python 3.11+ - For backend development
- Git - Version control
Option 1: Docker Development (Recommended)
Section titled “Option 1: Docker Development (Recommended)”# Clone the repositorygit clone https://github.com/rennerdo30/watch-together.gitcd watch-together
# Copy environment filecp .env.example .env
# Start all services with hot-reloaddocker compose up -d --build
# View logsdocker compose logs -fServices:
- Frontend: http://localhost:3000 (via proxy at :80)
- Backend API: http://localhost:8000
- Nginx Proxy: http://localhost:80
Option 2: Local Development
Section titled “Option 2: Local Development”# Backendcd backendpython -m venv venvsource venv/bin/activate # Windows: venv\Scripts\activatepip install -r requirements.txtuvicorn main:app --reload --port 8000
# Frontend (new terminal)cd frontendnpm install --legacy-peer-depsnpm run devDevelopment Identity
Section titled “Development Identity”For local development without Cloudflare, set DEVELOPMENT_MODE=true and use the ?user= query parameter:
# Backend must have DEVELOPMENT_MODE enabledDEVELOPMENT_MODE=true uvicorn main:app --reload --port 8000http://localhost:3000/room/[email protected]Note: The
?user=query parameter only works whenDEVELOPMENT_MODE=trueis set. This is disabled by default to prevent user impersonation in production.
Project Structure
Section titled “Project Structure”watch-together/├── backend/│ ├── main.py # FastAPI app, endpoints, proxy│ ├── connection_manager.py # WebSocket room management│ ├── services/│ │ ├── resolver.py # yt-dlp video resolution│ │ ├── database.py # SQLite persistence│ │ └── cache.py # Memory/disk caching│ ├── api/routes/ # API route modules│ └── core/ # Config, security├── frontend/│ ├── app/ # Next.js App Router pages│ │ ├── page.tsx # Home page│ │ └── room/[id]/ # Room page│ ├── components/│ │ ├── custom-player.tsx # Main video player│ │ ├── player-controls.tsx│ │ ├── player/hooks/ # useShakaPlayer, useHlsPlayer, etc.│ │ └── sortable-queue-item.tsx│ └── lib/│ ├── api.ts # Backend API client│ ├── abr.ts # Latency-aware bandwidth sampling for Shaka│ └── hooks/ # useRoomSettings, useLocalStorageState├── extension/ # Browser extension├── nginx/ # Nginx configuration└── docker-compose.ymlKey Files
Section titled “Key Files”| File | Purpose |
|---|---|
backend/main.py |
API endpoints, video proxy, app initialization |
backend/connection_manager.py |
WebSocket room state, sync logic |
backend/services/resolver.py |
yt-dlp integration, format selection |
frontend/components/custom-player.tsx |
Video player component |
frontend/components/player/hooks/useDashSync.ts |
A/V sync for DASH streams |
frontend/lib/hooks/useRoomSync.ts |
WebSocket room synchronization |
Code Style
Section titled “Code Style”Frontend (TypeScript/React)
Section titled “Frontend (TypeScript/React)”- TypeScript: Strict mode enabled, use proper types
- React: Functional components with hooks
- Styling: TailwindCSS classes only (no CSS modules)
- Imports: Use absolute imports (
@/components/...)
// Goodconst MyComponent: React.FC<Props> = ({ value }) => { const [state, setState] = useState<string>('');
return ( <div className="flex items-center gap-2"> {/* ... */} </div> );};
// Avoidclass MyComponent extends React.Component { } // Use functionalimport styles from './styles.module.css'; // Use TailwindBackend (Python)
Section titled “Backend (Python)”- Type Hints: Required on all function signatures
- Async: Use
async/awaitfor all I/O operations - Models: Pydantic for request/response validation
- Style: PEP 8 with 100 character line limit
# Goodasync def get_video(url: str, user_email: str | None = None) -> VideoResponse: """Resolve video URL and return stream info.""" result = await resolver.extract(url) return VideoResponse(url=result.url, title=result.title)
# Avoiddef get_video(url, user_email=None): # Missing types result = resolver.extract(url) # Sync callMaking Changes
Section titled “Making Changes”Adding a New API Endpoint
Section titled “Adding a New API Endpoint”- Define Pydantic models in
backend/api/models.py(or relevant file) - Add route in
backend/api/routes/orbackend/main.py - Add corresponding API call in
frontend/lib/api.ts
Adding a New WebSocket Message Type
Section titled “Adding a New WebSocket Message Type”- Add handler in
backend/connection_manager.py:elif msg_type == "my_new_type":await self._handle_my_new_type(room_id, data, websocket) - Update
frontend/lib/hooks/useRoomSync.tsto send/receive
Modifying the Video Player
Section titled “Modifying the Video Player”- Core player logic:
frontend/components/custom-player.tsx - A/V sync (DASH):
frontend/components/player/hooks/useDashSync.ts - HLS playback:
frontend/components/player/hooks/useHlsPlayer.ts - UI controls:
frontend/components/player-controls.tsx
Testing
Section titled “Testing”Frontend
Section titled “Frontend”cd frontendnpm run build # Type checking + buildnpm run lint # ESLintBackend
Section titled “Backend”cd backendpython -m py_compile main.py connection_manager.py services/*.py # Syntax checkpytest # Run tests (if available)Before Committing
Section titled “Before Committing”# Frontend must build without errorscd frontend && npm run build
# Backend must compile without errorscd backend && python -m py_compile main.py connection_manager.pyGitHub Workflows
Section titled “GitHub Workflows”This repository uses GitHub Actions for quality, security, and release automation:
- CI (
.github/workflows/ci.yml): backend tests, frontend lint/build, extension sanity checks - CodeQL (
.github/workflows/codeql.yml): security scanning for Python and TypeScript/JavaScript - Container Publish (
.github/workflows/docker-publish.yml): publish backend/frontend images to GHCR onmain - Chrome Extension Nightly (
.github/workflows/extension-nightly.yml): package the MV3 extension on everymaincommit and refresh the rollingnightlyprerelease - Dependabot (
.github/dependabot.yml): automated dependency update pull requests
Pull Request Process
Section titled “Pull Request Process”- Fork the repository
- Create a branch:
git checkout -b feature/amazing-feature - Make changes following the code style guidelines
- Test your changes locally
- Commit using conventional commits:
feat:New featurefix:Bug fixrefactor:Code refactoringdocs:Documentationchore:Maintenance
- Push:
git push origin feature/amazing-feature - Open a Pull Request with:
- Clear description of changes
- Screenshots for UI changes
- Test steps if applicable
Commit Message Examples
Section titled “Commit Message Examples”feat: add subtitle support for HLS streamsfix: prevent audio desync during seek operationsrefactor: extract video player into separate hooksdocs: update deployment guide for CloudflareReporting Issues
Section titled “Reporting Issues”Use GitHub Issues with:
- Bug reports: Steps to reproduce, expected vs actual behavior, browser/OS info
- Feature requests: Clear description of the feature and use case
- Questions: Check existing issues first, then ask
Security
Section titled “Security”Please report vulnerabilities privately as described in SECURITY.md. Do not open public issues for potential security vulnerabilities.
Security Guidelines for Contributors
Section titled “Security Guidelines for Contributors”When contributing code, keep these security measures in mind:
- SSRF Protection: Any new endpoints that accept URLs must validate them via
validate_proxy_url()to block access to private/internal networks - CORS: Origins are configured via
ALLOWED_ORIGINSenv var. Never hardcodeallow_origins=["*"]withallow_credentials=True - Authentication: The
?user=query param auth is gated behindDEVELOPMENT_MODEenv var. Never add unauthenticated access paths in production code - Input Validation: Room IDs are sanitized to
[a-zA-Z0-9_-]. Validate all user inputs at system boundaries - Cookie Handling: Cookie uploads are limited to 1MB and validated for Netscape format. Apply similar validation to new cookie-accepting endpoints
- WebSocket Limits: Connection limits are enforced per-room (50) and per-user (10). Consider resource implications when adding new WebSocket features
- Docker: Container images are pinned to specific versions. Resource limits are configured. Internal services are not exposed on host ports
Code of Conduct
Section titled “Code of Conduct”By participating in this project, you agree to follow the Code of Conduct.
Questions?
Section titled “Questions?”Feel free to open an issue or discussion if you have questions about contributing!