This document provides context and guidelines for AI assistants (particularly Claude) working on the StreamSource project.
This project runs EXCLUSIVELY in Docker containers. Do NOT use system Ruby, Bundler, or any host machine tools.
Quick start:
# Start everything
docker compose up -d
# Run any command
docker compose exec web [command]
# Examples:
docker compose exec web bin/test
docker compose exec web bin/rails console
docker compose exec web bundle exec rubocopStreamSource is a Rails 8 application providing both a RESTful API and a real-time collaborative admin interface for managing streamers and their streaming sources. Originally migrated from Node.js/Express, it now features modern security practices, comprehensive testing, real-time collaboration with ActionCable, and automated deployment via GitHub Actions.
- Complete deployment automation with GitHub Actions
- DigitalOcean deployment guide with cost optimization
- Comprehensive environment variable documentation
- Real-time collaborative editing with cell-level locking
- Simplified data model (removed Notes and StreamUrl models)
- Rails 8.0.x - Main framework
- Ruby 4.0.1 - Programming language
- PostgreSQL 18 - Primary database
- Redis 8 - Caching, ActionCable, sessions
- Puma - Web server with multi-worker support
- Docker - Containerization (mandatory)
- Hotwire - Turbo + Stimulus for real-time updates
- Tailwind CSS 3.x - Styling framework
- esbuild - JavaScript bundling
- ActionCable - WebSocket support
- GitHub Actions - CI/CD pipeline (free tier)
- DigitalOcean Droplet - Production hosting ($6/month)
- Nginx - Reverse proxy with SSL
- Let's Encrypt - Free SSL certificates
- Automated power management - 67% cost savings
/README.md- Complete project overview/DIGITALOCEAN_DEPLOYMENT_GUIDE.md- Production deployment/docs/ENVIRONMENT_VARIABLES.md- All env vars documented/api-docs- Interactive Swagger documentation/vendor/docs/- Rails, Hotwire, Stimulus references
.env.example- Development environment templatedeploy/.env.production.template- Production template.github/workflows/- GitHub Actions workflowsdeploy/- All deployment scripts and configs
-
User - Authentication and authorization
- Roles: default, editor, admin
- JWT auth for API (24-hour expiration)
- Session auth for admin interface
- Devise + bcrypt for security
-
Streamer - Content creators
- Has many streamer accounts and streams
- Name normalization for consistency
- Full-text search capabilities
-
StreamerAccount - Platform-specific accounts
- Platforms: TikTok, Facebook, Twitch, YouTube, Instagram, Other
- Auto-generates profile URLs
- Links streamers to platforms
-
Stream - Individual streaming sessions
- Smart continuation (30-minute window)
- Status: checking, live, offline, error, archived
- Pin/unpin for highlighting
- Real-time updates via ActionCable
-
Timestamp - Event annotations
- Links to multiple streams via join table
- Priority levels for importance
- Time-based incident tracking
- JWT authentication with Bearer tokens
- RESTful design with consistent patterns
- Comprehensive rate limiting (60 req/min default)
- Pagination with Pagy (25 items default)
- Advanced filtering and search
- Feature flags via Flipper
- Real-time collaboration
- Cell-level locking prevents conflicts
- User presence with color coding
- 5-second edit timeout
- Automatic unlock on disconnect
- Turbo-powered UI
- Instant updates without refresh
- Modal forms with Turbo Frames
- Debounced search
- Responsive design
- SSL/TLS enforced in production
- CORS configuration for API
- CSP headers prevent XSS
- SQL injection protection
- CSRF tokens for web forms
- Secure password requirements
- Rate limiting with Rack::Attack
- Fail2ban for SSH protection
# Clone repository
git clone https://github.com/yourusername/streamsource.git
cd streamsource
# Copy environment file
cp .env.example .env
# Start services
docker compose up -d
# Check logs
docker compose logs -f web# Rails console
docker compose exec web bin/rails console
# Run tests
docker compose exec web bin/test
# Database migrations
docker compose exec web bin/rails db:migrate
# Linting
docker compose exec web bundle exec rubocop -A
# Asset compilation
docker compose exec web yarn build
docker compose exec web yarn build:css- Write tests first (TDD)
- Run full suite before commits
- Maintain high coverage (SimpleCov)
- Test edge cases and errors
- Use factories, not fixtures
- Mock external API calls
# Create feature branch
git checkout -b feature/your-feature
# Make changes and test
docker compose exec web bin/test
# Commit with clear message
git commit -m "Add feature: description"
# Push and create PR
git push origin feature/your-feature- Push to main branch
- Tests run automatically
- If tests pass, deploys to production
- Health check verifies deployment
# Quick deploy after setup
make deploy HOST=your-droplet-ip
# Check status
make status HOST=your-droplet-ip
# View logs
make logs HOST=your-droplet-ip- Droplet powers off at 6 PM daily
- Powers on at 9 AM weekdays
- Saves ~$21/month (67% reduction)
- Configurable via GitHub Actions
Access Flipper UI at /admin/flipper when logged in as admin (opens in new tab from sidebar).
stream_analytics- Advanced analytics for streamsstream_bulk_import- Bulk importing of streams (enabled for editors)stream_export- Data export functionalitystream_tags- Tagging system for streams (enabled for admins)advanced_search- Enhanced search functionality (enabled by default)maintenance_mode- Application maintenance mode (disabled by default)location_validation- Validate stream locations against known cities
# Login
POST /api/v1/users/login
{"email": "user@example.com", "password": "Password123!"}
# Returns JWT token
{"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9..."}
# Use token
GET /api/v1/streams
Authorization: Bearer YOUR_TOKENGET /api/v1/streams- List streamsPOST /api/v1/streams- Create streamPATCH /api/v1/streams/:id- Update streamPUT /api/v1/streams/:id/pin- Pin streamPOST /api/v1/streams/:id/archive- Archive
GET /api/v1/streams?status=live&pinned=true&page=2
GET /api/v1/streamers?search=gaming&per_page=50
Docker container errors
docker compose down
docker compose up -d --buildDatabase connection issues
docker compose exec web bin/rails db:resetAsset compilation problems
docker compose exec web yarn install
docker compose exec web yarn buildTest failures
docker compose exec web bin/rails db:test:prepare
docker compose exec web bin/test- Always use Docker - Never install Ruby/Rails locally
- Environment variables - Check
.env.examplefor all options - Feature flags - Test new features behind flags first
- Real-time updates - ActionCable requires Redis
- Security first - Follow security best practices
- Documentation - Update docs with code changes
- Test coverage - Maintain >90% coverage
- Code style - Follow RuboCop rules
# Start project
docker compose up -d
# Run tests
docker compose exec web bin/test
# Rails console
docker compose exec web bin/rails console
# Deploy to production
make deploy HOST=your-server
# Check deployment
make status HOST=your-server
# View production logs
make logs HOST=your-server
# Database tasks
docker compose exec web bin/rails db:migrate
docker compose exec web bin/rails db:seed
docker compose exec web bin/rails db:reset
# Linting
docker compose exec web bundle exec rubocop -A
# Asset building
docker compose exec web yarn build
docker compose exec web yarn build:css- Check existing documentation in
/docs - Review test files for usage examples
- Use
bin/rails routesto see all routes - Check
/api-docsfor API documentation - Review GitHub Actions logs for deployment issues
Remember: This project prioritizes security, testing, and documentation. When in doubt, write a test!