Add Caddyfile for server configuration and API routing; implement player and tasks manager specifications in PROMPT.txt
This commit is contained in:
49
CLAUDE.md
49
CLAUDE.md
@@ -29,7 +29,8 @@ This is a soundboard application with a FastAPI backend and React frontend.
|
|||||||
- **Authentication**: JWT tokens with OAuth2 support (Google, GitHub)
|
- **Authentication**: JWT tokens with OAuth2 support (Google, GitHub)
|
||||||
- **Dependencies**: FastAPI, SQLModel, aiosqlite, bcrypt, PyJWT, pydantic-settings, uvicorn, ffmpeg-python, yt-dlp, python-vlc
|
- **Dependencies**: FastAPI, SQLModel, aiosqlite, bcrypt, PyJWT, pydantic-settings, uvicorn, ffmpeg-python, yt-dlp, python-vlc
|
||||||
- **Structure**:
|
- **Structure**:
|
||||||
- `app/api/v1/`: API endpoints for v1 (auth.py, main.py, sounds.py, socket.py, player.py)
|
- `app/api/v1/`: API endpoints for v1 (auth.py, main.py, sounds.py, extractions.py, socket.py, player.py, playlists.py)
|
||||||
|
- `app/api/v1/admin/`: Admin-only API endpoints (sounds.py, extractions.py)
|
||||||
- `app/models/`: Database models (User, Sound, Playlist, Extraction, Plan, UserOAuth, CreditTransaction, SoundPlayed, etc.)
|
- `app/models/`: Database models (User, Sound, Playlist, Extraction, Plan, UserOAuth, CreditTransaction, SoundPlayed, etc.)
|
||||||
- `app/services/`: Business logic layer (auth.py, oauth.py, socket.py, player.py, sound_scanner.py, sound_normalizer.py, extraction.py, extraction_processor.py, credit.py)
|
- `app/services/`: Business logic layer (auth.py, oauth.py, socket.py, player.py, sound_scanner.py, sound_normalizer.py, extraction.py, extraction_processor.py, credit.py)
|
||||||
- `app/repositories/`: Data access layer (base.py, user.py, user_oauth.py, sound.py, extraction.py, credit_transaction.py, playlist.py)
|
- `app/repositories/`: Data access layer (base.py, user.py, user_oauth.py, sound.py, extraction.py, credit_transaction.py, playlist.py)
|
||||||
@@ -145,11 +146,28 @@ Enhanced sound management with comprehensive duplicate prevention and integrity
|
|||||||
- **Data Integrity**: Proper foreign key relationships and nullable field handling
|
- **Data Integrity**: Proper foreign key relationships and nullable field handling
|
||||||
- **Indexed Fields**: Optimized queries for common operations (filename, hash, type)
|
- **Indexed Fields**: Optimized queries for common operations (filename, hash, type)
|
||||||
|
|
||||||
|
### API Endpoints
|
||||||
|
- `GET /api/v1/sounds/`: Get all sounds with optional type filtering (authenticated users only)
|
||||||
|
- Query parameters: `types` (can be specified multiple times for filtering by multiple types)
|
||||||
|
- Examples:
|
||||||
|
- `GET /api/v1/sounds/` - Returns all sounds
|
||||||
|
- `GET /api/v1/sounds/?types=SDB` - Returns only SDB type sounds
|
||||||
|
- `GET /api/v1/sounds/?types=SDB&types=EXT` - Returns SDB and EXT type sounds
|
||||||
|
- `POST /api/v1/sounds/play/{sound_id}`: Play sound with VLC (requires 1 credit)
|
||||||
|
- `POST /api/v1/sounds/stop`: Stop all VLC instances
|
||||||
|
|
||||||
|
### Sound Type Filtering Features
|
||||||
|
- **Authentication Required**: All sound endpoints require valid user authentication
|
||||||
|
- **Type-based Filtering**: Filter sounds by one or more types (SDB, TTS, EXT)
|
||||||
|
- **Flexible Query Parameters**: Multiple `types` parameters supported for complex filtering
|
||||||
|
- **Empty Results**: Invalid types return empty list without error
|
||||||
|
- **Performance Optimized**: Uses SQLAlchemy `IN` clause for efficient multi-type queries
|
||||||
|
|
||||||
### Technical Implementation
|
### Technical Implementation
|
||||||
- **Repository**: `app/repositories/sound.py` - Complete CRUD operations with specialized queries
|
- **Repository**: `app/repositories/sound.py` - Complete CRUD operations with specialized queries including `get_by_types()` for type filtering
|
||||||
- **Models**: Enhanced `Sound` model with unique constraints and relationship management
|
- **Models**: Enhanced `Sound` model with unique constraints and relationship management
|
||||||
- **API Integration**: Sound creation, update, deletion with duplicate prevention
|
- **API Integration**: Sound creation, update, deletion with duplicate prevention, authenticated sound retrieval
|
||||||
- **Testing**: 15 comprehensive tests covering all sound operations including constraint validation
|
- **Testing**: 15+ comprehensive tests covering all sound operations including constraint validation and API endpoint testing
|
||||||
|
|
||||||
## Player System
|
## Player System
|
||||||
|
|
||||||
@@ -230,14 +248,14 @@ Comprehensive repository pattern implementation with full test coverage for data
|
|||||||
|
|
||||||
### Repository Coverage
|
### Repository Coverage
|
||||||
- **User Repository**: User management, authentication, role-based operations
|
- **User Repository**: User management, authentication, role-based operations
|
||||||
- **Sound Repository**: Audio file management with specialized queries
|
- **Sound Repository**: Audio file management with specialized queries including type-based filtering (`get_by_types()`, `get_by_type()`, `get_by_hash()`, `search_by_name()`, etc.)
|
||||||
- **Credit Transaction Repository**: Credit system transaction management
|
- **Credit Transaction Repository**: Credit system transaction management
|
||||||
- **User OAuth Repository**: OAuth provider management and authentication
|
- **User OAuth Repository**: OAuth provider management and authentication
|
||||||
- **Playlist Repository**: Playlist management and sound associations
|
- **Playlist Repository**: Playlist management and sound associations
|
||||||
- **Extraction Repository**: Audio extraction job management
|
- **Extraction Repository**: Audio extraction job management
|
||||||
|
|
||||||
### Testing Infrastructure
|
### Testing Infrastructure
|
||||||
- **76+ Repository Tests**: Comprehensive test coverage across all repositories
|
- **80+ Repository Tests**: Comprehensive test coverage across all repositories
|
||||||
- **Async Test Support**: Proper async/await testing with pytest-asyncio
|
- **Async Test Support**: Proper async/await testing with pytest-asyncio
|
||||||
- **SQLAlchemy Integration**: Proper session management and lazy loading handling
|
- **SQLAlchemy Integration**: Proper session management and lazy loading handling
|
||||||
- **Type Safety**: Complete mypy type checking compliance
|
- **Type Safety**: Complete mypy type checking compliance
|
||||||
@@ -432,16 +450,16 @@ backend/sounds/originals/extracted/thumbnails/ # Extracted thumbnails
|
|||||||
- `EXTRACTION_MAX_CONCURRENT`: Maximum concurrent extractions (default: 2)
|
- `EXTRACTION_MAX_CONCURRENT`: Maximum concurrent extractions (default: 2)
|
||||||
|
|
||||||
### API Endpoints
|
### API Endpoints
|
||||||
- `POST /api/v1/sounds/extract?url={url}`: Create extraction job (immediate response)
|
- `POST /api/v1/extractions/`: Create extraction job (immediate response)
|
||||||
- `GET /api/v1/sounds/extract/status`: Get extraction processor status
|
- `GET /api/v1/admin/extractions/status`: Get extraction processor status (admin only)
|
||||||
- `GET /api/v1/sounds/extract/{extraction_id}`: Get specific extraction info
|
- `GET /api/v1/extractions/{extraction_id}`: Get specific extraction info
|
||||||
- `GET /api/v1/sounds/extract`: Get user's extraction history
|
- `GET /api/v1/extractions/`: Get user's extraction history
|
||||||
|
|
||||||
### Technical Implementation
|
### Technical Implementation
|
||||||
- **Service**: `app/services/extraction.py` - Core extraction logic with async yt-dlp operations
|
- **Service**: `app/services/extraction.py` - Core extraction logic with async yt-dlp operations
|
||||||
- **Processor**: `app/services/extraction_processor.py` - Background queue manager with concurrency control
|
- **Processor**: `app/services/extraction_processor.py` - Background queue manager with concurrency control
|
||||||
- **Repository**: `app/repositories/extraction.py` - Database operations for extraction records
|
- **Repository**: `app/repositories/extraction.py` - Database operations for extraction records
|
||||||
- **API**: `app/api/v1/sounds.py` - REST endpoints integrated with sound management
|
- **API**: `app/api/v1/extractions.py` - Dedicated extraction API endpoints, `app/api/v1/admin/extractions.py` - Admin extraction endpoints
|
||||||
- **Dependencies**: Requires yt-dlp for media extraction, FFmpeg for audio processing
|
- **Dependencies**: Requires yt-dlp for media extraction, FFmpeg for audio processing
|
||||||
- **Async Operations**: All blocking I/O operations wrapped in `asyncio.to_thread()` for non-blocking execution
|
- **Async Operations**: All blocking I/O operations wrapped in `asyncio.to_thread()` for non-blocking execution
|
||||||
|
|
||||||
@@ -470,12 +488,19 @@ backend/sounds/originals/extracted/thumbnails/ # Extracted thumbnails
|
|||||||
- **Duplicate Prevention**: Service-level duplicate detection during processing
|
- **Duplicate Prevention**: Service-level duplicate detection during processing
|
||||||
- **Comprehensive Logging**: Detailed error messages and extraction status tracking
|
- **Comprehensive Logging**: Detailed error messages and extraction status tracking
|
||||||
|
|
||||||
|
### API Organization
|
||||||
|
- **Dedicated Extraction Endpoints**: Extraction functionality separated into `/api/v1/extractions/` for better organization
|
||||||
|
- **Admin Separation**: Admin-only endpoints moved to `/api/v1/admin/extractions/` for proper access control
|
||||||
|
- **Consistent URL Structure**: RESTful endpoint design following FastAPI best practices
|
||||||
|
- **Router Registration**: Proper router mounting and tag organization for API documentation
|
||||||
|
|
||||||
### Testing
|
### Testing
|
||||||
- **16 comprehensive service tests** covering all extraction scenarios including async operations
|
- **16 comprehensive service tests** covering all extraction scenarios including async operations
|
||||||
- **API endpoint tests** with authentication and background processing validation
|
- **API endpoint tests** with authentication and background processing validation
|
||||||
- **Error handling tests** for various failure scenarios
|
- **Error handling tests** for various failure scenarios
|
||||||
- **Mock yt-dlp operations** for reliable testing without network dependencies
|
- **Mock yt-dlp operations** for reliable testing without network dependencies
|
||||||
- **Concurrency tests** validating non-blocking behavior and thread pool execution
|
- **Concurrency tests** validating non-blocking behavior and thread pool execution
|
||||||
|
- **Endpoint migration tests** ensuring proper URL routing and authentication
|
||||||
|
|
||||||
## Data Integrity & Performance
|
## Data Integrity & Performance
|
||||||
|
|
||||||
@@ -489,7 +514,7 @@ backend/sounds/originals/extracted/thumbnails/ # Extracted thumbnails
|
|||||||
- **Full mypy Compliance**: Complete type checking across all Python code
|
- **Full mypy Compliance**: Complete type checking across all Python code
|
||||||
- **Async/Await Patterns**: Proper async programming throughout the stack
|
- **Async/Await Patterns**: Proper async programming throughout the stack
|
||||||
- **Error Handling**: Comprehensive exception handling with detailed logging
|
- **Error Handling**: Comprehensive exception handling with detailed logging
|
||||||
- **Test Coverage**: 90+ comprehensive tests with 100% critical path coverage including repository, service, and integration tests
|
- **Test Coverage**: 95+ comprehensive tests with 100% critical path coverage including repository, service, and integration tests
|
||||||
|
|
||||||
### Performance Optimizations
|
### Performance Optimizations
|
||||||
- **Lazy Loading Management**: Proper SQLAlchemy relationship loading
|
- **Lazy Loading Management**: Proper SQLAlchemy relationship loading
|
||||||
|
|||||||
69
Caddyfile
Normal file
69
Caddyfile
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
# Caddyfile for Soundboard Application
|
||||||
|
# Replace yourdomain.com with your actual domain
|
||||||
|
|
||||||
|
:80 {
|
||||||
|
# Enable compression
|
||||||
|
encode gzip
|
||||||
|
|
||||||
|
# Security headers
|
||||||
|
header {
|
||||||
|
# Security headers
|
||||||
|
Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
|
||||||
|
X-Content-Type-Options "nosniff"
|
||||||
|
X-Frame-Options "DENY"
|
||||||
|
X-XSS-Protection "1; mode=block"
|
||||||
|
Referrer-Policy "strict-origin-when-cross-origin"
|
||||||
|
|
||||||
|
# Remove server information
|
||||||
|
-Server
|
||||||
|
}
|
||||||
|
|
||||||
|
# API routes - proxy to FastAPI backend
|
||||||
|
handle /api/* {
|
||||||
|
reverse_proxy localhost:8000 {
|
||||||
|
# Headers for proper proxying
|
||||||
|
header_up Host {upstream_hostport}
|
||||||
|
header_up X-Real-IP {remote_host}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# WebSocket connections for real-time features
|
||||||
|
handle /socket.io/* {
|
||||||
|
reverse_proxy localhost:8000 {
|
||||||
|
# WebSocket support
|
||||||
|
header_up Connection {>Connection}
|
||||||
|
header_up Upgrade {>Upgrade}
|
||||||
|
header_up Host {upstream_hostport}
|
||||||
|
header_up X-Real-IP {remote_host}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Static assets (built frontend) - serve from dist directory
|
||||||
|
handle {
|
||||||
|
# Serve static files from the built frontend
|
||||||
|
root * /var/www/sdb
|
||||||
|
|
||||||
|
# Cache static assets for better performance
|
||||||
|
@static {
|
||||||
|
path *.js *.css *.woff *.woff2 *.ttf *.eot *.ico *.png *.jpg *.jpeg *.gif *.svg *.webp
|
||||||
|
}
|
||||||
|
header @static {
|
||||||
|
Cache-Control "public, max-age=31536000, immutable"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Try files, fallback to index.html for SPA routing
|
||||||
|
try_files {path} /index.html
|
||||||
|
file_server
|
||||||
|
}
|
||||||
|
|
||||||
|
# Logging
|
||||||
|
log {
|
||||||
|
output file /var/log/caddy/soundboard-access.log {
|
||||||
|
roll_size 100mb
|
||||||
|
roll_keep 5
|
||||||
|
roll_keep_for 720h
|
||||||
|
}
|
||||||
|
format json
|
||||||
|
level INFO
|
||||||
|
}
|
||||||
|
}
|
||||||
29
PROMPT.txt
Normal file
29
PROMPT.txt
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
PLAYER :
|
||||||
|
|
||||||
|
I need a player service and endpoints.
|
||||||
|
|
||||||
|
The service should start when the application starts and stop when the app stops. At initialisation it should load the current playlist (is_current). It should manage all the features of a player, play/pause, stop, next, previous, play modes (continuous, loop, loop 1, random, single), seek, volume. Since the current playlist can change we also need a way to reload the playlist. At anytime when the state of the player changes (current progress while playing, track changed, stopped, volume change, new playlist loaded ...) it should emit the state the socket to all users. It should also take into account that if a users connects at anytime even if the player is not running the user needs the current state. Finally to count a track as played (play_count in sound and sound_played that already exists) at least 20% of the track has to be played and i mean real time playing even if not consecutive (if at the start of a track we jump to the end for example it shouldn't count). The player should use python-vlc to play the sounds but manage events locally since VLC events are not reliable.
|
||||||
|
|
||||||
|
The player state should include the status (stopped, playing, paused), mode (continuous, loop ...), volume, current_sound_id, current_sound_index, current_sound_position, current_sound_duration, the current_sound (id, name, filename, duration, size, type, thumbnail, play_count), the playlist_id, the playlist_name, the playlist_length, the playlist duration (sum of all the sounds duration) and the playlist_sounds. The duration and position should be in ms.
|
||||||
|
|
||||||
|
Among the other endpoints you will generate, the play endpoint should play the current sound if not already playing, or start playing a specific sound if an index is passed (maybe 2 endpoints needed i don't know ?).
|
||||||
|
|
||||||
|
|
||||||
|
=======
|
||||||
|
|
||||||
|
SOUNDBOARD :
|
||||||
|
|
||||||
|
For my soundboard, I need a vlc service that can play sounds using individual instances of vlc with subprocess. The service also needs a way to stop all instances of vlc (no need to track all the processes of the vlc instances created, just kill all vlc)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
I need a VLC service that can play sounds by launching separate VLC instances using subprocess. Additionally, the service should provide a mechanism to stop all running VLC instances at once — there's no need to keep track of each individual process; a general kill-all approach is sufficient.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
========
|
||||||
|
|
||||||
|
TASKS MANAGER :
|
||||||
|
|
||||||
|
I would like to put in place a centralized tasks manager, especially for long tasks that should run in the background (scan sounds, normalize all sounds or extract). The tasks manager should emit events to the socket. It should be able to manager conflict between tasks for example a sounds scan and a normalization can't run at the same time. Also some tasks like extract can simultaneously (for now 2 at a time for extract). I want the manager to track the step the task is in (real step corresponding to the task process for example for extract steps would be extract sound, add sound to sound table, normalization ...)
|
||||||
Reference in New Issue
Block a user