Complete Next.js application for managing OBS Source Switcher - Stream management with multiple screen layouts - Team management CRUD operations - SQLite database integration - OBS WebSocket API integration - Updated to latest versions (Next.js 15.4.1, React 19.1.0, Tailwind CSS 4.0.0) - Enhanced .gitignore for privacy and development
3.4 KiB
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Project Overview
This is a Next.js web application that controls multiple OBS Source Switchers. It provides a UI for managing stream sources across different screen layouts (large, left, right, topLeft, topRight, bottomLeft, bottomRight) and communicates with OBS WebSocket API to control streaming sources.
Key Commands
Development
npm run dev
- Start the development servernpm run build
- Build the production applicationnpm start
- Start the production servernpm run lint
- Run ESLint to check code qualitynpm run type-check
- Run TypeScript type checking without emitting files
Architecture Overview
Technology Stack
- Frontend: Next.js 15.1.6 with React 19, TypeScript, and Tailwind CSS
- Backend: Next.js API routes
- Database: SQLite with sqlite3 driver
- OBS Integration: obs-websocket-js for WebSocket communication with OBS Studio
- Styling: Tailwind CSS with @tailwindcss/forms plugin
Project Structure
/app
- Next.js App Router pages and API routes/api
- Backend API endpoints for stream management/add
- Page for adding new stream clients
/components
- Reusable React components (e.g., Dropdown)/lib
- Core utilities and database connectiondatabase.ts
- SQLite database initialization and connection managementobsClient.js
- OBS WebSocket client for communicating with OBS Studioconstants.ts
- Shared constants (table names, etc.)
/types
- TypeScript type definitions/files
- Default directory for SQLite database and text files (configurable via .env.local)
Key Concepts
-
Stream Management: The app manages stream sources that can be assigned to different screen positions. Each stream has:
- name: Display name
- obs_source_name: Name of the source in OBS
- url: Stream URL
- team_id: Associated team identifier
-
Screen Types: Seven different screen positions are supported: large, left, right, topLeft, topRight, bottomLeft, bottomRight
-
Text File Integration: The app writes the active source name to text files that OBS Source Switcher reads to switch sources automatically
-
Environment Configuration:
FILE_DIRECTORY
: Directory for database and text files (default: ./files)OBS_WEBSOCKET_HOST
: OBS WebSocket host (default: 127.0.0.1)OBS_WEBSOCKET_PORT
: OBS WebSocket port (default: 4455)OBS_WEBSOCKET_PASSWORD
: OBS WebSocket password (optional)
API Endpoints
POST /api/addStream
- Add new stream to database and OBSGET /api/streams
- Get all available streamsGET /api/teams
- Get all teamsGET /api/getActive
- Get currently active sources for all screensPOST /api/setActive
- Set active stream for a specific screenGET /api/getTeamName
- Get team name by ID
Database Schema
Two main tables:
streams
: id, name, obs_source_name, url, team_idteams
: team_id, team_name
OBS Integration Pattern
The app communicates with OBS through:
- WebSocket connection using obs-websocket-js
- Text files that OBS Source Switcher monitors for source changes
- Direct source management through OBS WebSocket API
When setting an active source:
- User selects stream in UI
- API writes source name to corresponding text file (e.g., largeScreen.txt)
- OBS Source Switcher detects file change and switches to that source