| app | ||
| migrations | ||
| scripts | ||
| tests | ||
| .env.example | ||
| .env.prod.example | ||
| .gitignore | ||
| app.py | ||
| compose.prod.yml | ||
| compose.yml | ||
| Dockerfile | ||
| LICENSE | ||
| Makefile | ||
| pytest.ini | ||
| README.md | ||
| requirements.txt | ||
Stream Fav Music Sync
A web application that synchronizes music libraries between Spotify and Amazon Music platforms with bidirectional sync capabilities, conflict resolution, and administrative controls.
Core Functionality
- Bidirectional Synchronization: Sync playlists and libraries between Spotify and Amazon Music
- Conflict Resolution: Handle sync conflicts with user-controlled resolution strategies
- OAuth Authentication: Secure authentication with both music platforms
- Web Interface: Functional web interface for managing synchronization operations
- Administrative System: System configuration, user management, and monitoring tools
- Audit Logging: Comprehensive logging of sync operations and system events
Development Setup
This project uses container-first development with Finch (Docker). All Python execution happens within containers to ensure consistent, isolated development environments.
Prerequisites
- Finch installed
- Make (for convenience commands)
- Git (for version control)
Quick Start
-
Clone and setup:
git clone <repository-url> cd spotify-amazon-sync cp .env.example .env -
Configure environment: Edit
.envwith your OAuth credentials from Spotify and Amazon Music developer consoles. -
Build and start:
make build make up make init-db -
Access the application:
- Web interface: http://localhost:5000
- Database: localhost:5432 (PostgreSQL)
Development Commands
Container Management
make build- Build Docker containersmake up- Start all services (app, database)make down- Stop all servicesmake clean- Clean up containers and volumesfinch exec spotifytoamzn-app-1 python scripts/script_name.py- Execute Python scripts in containermake logs- View application logs (recent history)make logs-follow- Follow logs in real-timemake status- Check service statusmake health-check- Verify all services are running
Database Operations
make init-db- Initialize database with schemamake migrate- Create new database migrationmake upgrade- Apply database migrationsmake init-migrate- Initialize Flask-Migrate (run once)
Python Execution
Never run Python directly on the host. Use these container-based patterns:
finch exec spotifytoamzn-app-1 your-python-command- Run any Python commandfinch exec spotifytoamzn-app-1 python path/to/script.py- Run Python scriptsmake pytest ARGS="-k test_name"- Run specific tests
Container Development Standards
This project follows a container-first development approach using Finch (Docker) to ensure consistent, isolated development environments across all team members.
Core Principles
- Container-First Development: All development activities happen inside containers
- Host System Isolation: Host system remains clean and dependency-free
- Consistent Environments: Identical development environment for all developers
- Finch Runtime: Finch is the primary container runtime for this project
Project Structure
├── app/ # Flask application
│ ├── models/ # SQLAlchemy database models
│ ├── services/ # Business logic and service layer
│ ├── routes/ # Flask route handlers and API endpoints
│ ├── templates/ # Jinja2 HTML templates
│ ├── static/ # CSS, JavaScript, fonts, and assets
│ └── utils/ # Utility functions and helpers
├── tests/ # Comprehensive test suite
│ ├── unit/ # Unit tests (fast, isolated)
│ ├── integration/ # Integration tests (database, services)
│ ├── property/ # Property-based tests (Hypothesis)
│ ├── security/ # Security and authentication tests
│ ├── performance/ # Performance and load tests
│ └── fixtures/ # Test data factories and fixtures
├── migrations/ # Database migrations (Alembic)
├── scripts/ # Utility and maintenance scripts
├── reports/ # Test reports and coverage data
├── logs/ # Application logs
├── compose.yml # Docker Compose configuration
├── Dockerfile # Container definition
├── Makefile # Development commands
└── requirements.txt # Python dependencies
Testing Framework
The project uses a comprehensive testing framework with pytest and Hypothesis for property-based testing.
Running Tests
# Run all tests (optimized for parallel execution)
make test
# Run specific test categories
make test-unit # Unit tests (fast, parallel)
make test-integration # Integration tests (serial, database)
make test-property # Property-based tests (Hypothesis)
make test-security # Security and authentication tests
make test-performance # Performance and load tests
# Run with coverage analysis
make test-coverage
# Debug tests (serial execution, verbose output)
make test-debug
# Fast feedback for development
make test-fast
Test Categories
- Unit Tests: Fast, isolated component tests with mocked dependencies
- Integration Tests: Test component interactions with real database connections
- Property-Based Tests: Hypothesis-driven testing with random input generation
- Security Tests: Authentication, authorization, and vulnerability protection
- Performance Tests: Load testing and resource usage validation
Test Configuration
- Minimum coverage threshold: 80%
- Parallel execution with automatic worker detection
- Isolated test databases per worker
- Comprehensive mock services for external APIs
- Property-based tests use Hypothesis with configurable iteration counts
Configuration
Environment Variables
Copy .env.example to .env and configure:
# Database Configuration
DATABASE_URL=postgresql://user:password@db:5432/spotify_sync
# Spotify OAuth Credentials
SPOTIFY_CLIENT_ID=your_spotify_client_id
SPOTIFY_CLIENT_SECRET=your_spotify_client_secret
# Amazon Music OAuth Credentials
AMAZON_CLIENT_ID=your_amazon_client_id
AMAZON_CLIENT_SECRET=your_amazon_client_secret
# Application Settings
SECRET_KEY=your_secret_key
FLASK_ENV=development
OAuth Setup
-
Spotify Developer Console:
- Create an app at https://developer.spotify.com/dashboard
- Add redirect URI:
http://localhost:5000/oauth/spotify/callback - Copy Client ID and Secret to
.env
-
Amazon Music Developer Console:
- Create an app at Amazon Developer Console
- Configure OAuth settings with appropriate scopes
- Copy Client ID and Secret to
.env
Essential Scripts
The scripts/ directory contains utility scripts for maintenance and operations:
Core Scripts
database_utils.py- Database operations, migrations, and testing utilitiesdeploy.sh- Production deployment script (supportslatestandprodtags)startup.sh- Container startup script with initialization and error handling
REMOVED: - check_dependencies.py - Dependency validation and health checks
Development Scripts
test_utilities.py- Test framework utilities and helpersvalidation_utilities.py- Input validation and data integrity checks
Maintenance Scripts
REMOVED: - audit_external_resources.py - External resource and dependency auditing
security_audit_and_fixes.py- Security vulnerability scanning and fixesstartup_initialization.py- Application startup initialization procedures
All scripts are designed to run within containers using the make script command.
API Documentation
Authentication Endpoints
POST /login- User login with credentialsPOST /register- User registrationGET /oauth/spotify- Initiate Spotify OAuth flowGET /oauth/amazon- Initiate Amazon Music OAuth flowGET /logout- User logout and session cleanup
Synchronization Endpoints
GET /api/sync/status- Get current sync status and progressPOST /api/sync/start- Start synchronization processGET /api/sync/history- Retrieve sync operation historyPOST /api/sync/resolve-conflict- Resolve sync conflicts
Administrative Endpoints
GET /admin/dashboard- Administrative dashboard and system overviewGET /admin/users- User management interfaceGET /admin/logs- System logs and audit trailPOST /admin/config- System configuration management
Deployment
Production Deployment
-
Prepare environment:
cp .env.example .env.production # Edit .env.production with production values -
Deploy using script:
./scripts/deploy.sh prod
Container Architecture
- app: Main Flask application with web interface and API
- db: PostgreSQL database with persistent storage
- test: Testing service with isolated environment and test database
Development Guidelines
Container-First Development
- All development happens inside containers
- Host system remains clean and dependency-free
- Use
finch exec spotifytoamzn-app-1 python scripts/script_name.pyfor script execution - Never run
pythonorpipdirectly on host system
Code Organization
- Business logic in
app/services/ - Database models in
app/models/ - API routes in
app/routes/ - Utilities and helpers in
app/utils/ - Templates in
app/templates/ - Static assets in
app/static/
Testing Best Practices
- Write tests for all new functionality
- Use appropriate test categories (unit, integration, property)
- Maintain minimum 80% code coverage
- Use mock services for external API testing
- Property-based tests for universal behavior validation
Security Considerations
- All user inputs are validated and sanitized
- CSRF protection enabled on forms
- Secure session management with encrypted cookies
- OAuth token encryption and secure storage
- SQL injection prevention through parameterized queries
- Input validation at API boundaries
Troubleshooting
Common Issues
Application won't start:
- Check
.envconfiguration is complete - Verify database connection settings
- Check container logs:
make logs - Ensure services are healthy:
make health-check
Tests failing in parallel but passing serially:
- Check for shared state between tests
- Ensure proper database isolation
- Verify thread-safe resource access
- Use
make test-debugfor serial execution
OAuth authentication failing:
- Verify client credentials in
.env - Check redirect URIs in developer consoles
- Ensure proper OAuth scopes are configured
- Check network connectivity to OAuth providers
Database connection issues:
- Run
make init-dbto initialize database - Check database service status:
make status - Verify database credentials in
.env - Ensure database migrations are applied:
make upgrade
Performance issues:
- Use
make test-performanceto identify bottlenecks - Check container resource allocation
- Monitor database query performance
- Review application logs for errors
Getting Help
- Check application logs:
make logsormake logs-follow - Run health checks:
make health-check - Verify service status:
make status - Run tests to verify functionality:
make test - Execute specific scripts:
finch exec spotifytoamzn-app-1 python scripts/debug_script.py - Check database connectivity: Create and run a script to test database connection
Contributing
- Fork the repository
- Create a feature branch from
main - Make changes following development guidelines
- Write tests for new functionality
- Ensure all tests pass:
make test - Verify code coverage:
make test-coverage - Submit a pull request with clear description
Code Standards
- Follow PEP 8 for Python code style
- Use type hints where appropriate
- Write comprehensive docstrings
- Maintain test coverage above 80%
- Use container-based development workflow
Maintenance Guidelines
Regular Maintenance Tasks
Weekly Tasks
- Dependency Updates: Check for security updates in
requirements.txt - Log Review: Review application logs for errors or warnings
- Test Execution: Run full test suite to catch regressions
- Performance Monitoring: Check application performance metrics
Monthly Tasks
- Container Updates: Update base container images for security patches
- Database Maintenance: Review database performance and optimize queries
- Documentation Review: Update documentation for any changes
- Security Audit: Run security scans and address vulnerabilities
Quarterly Tasks
- Dependency Audit: Review all dependencies for updates and security issues
- Performance Analysis: Conduct thorough performance analysis
- Backup Testing: Verify backup and restore procedures
- Disaster Recovery: Test disaster recovery procedures
Code Quality Standards
Python Code Standards
- Follow PEP 8 style guidelines
- Use type hints for function parameters and return values
- Write comprehensive docstrings for all functions and classes
- Maintain minimum 80% test coverage
- Use meaningful variable and function names
Container Standards
- Use multi-stage Dockerfile builds for optimization
- Pin all dependency versions for reproducibility
- Use non-root users in containers for security
- Implement proper health checks for services
- Use .dockerignore to exclude unnecessary files
Testing Standards
- Write tests for all new functionality
- Use appropriate test categories (unit, integration, property)
- Mock external dependencies in unit tests
- Use property-based testing for universal behavior validation
- Maintain test isolation and avoid shared state
Security Maintenance
Regular Security Tasks
- Dependency Scanning: Use tools to scan for vulnerable dependencies
- Container Scanning: Scan container images for security vulnerabilities
- OAuth Token Management: Regularly rotate OAuth client secrets
- Database Security: Review database access patterns and permissions
- Log Analysis: Monitor logs for suspicious activity
Security Best Practices
- Never commit secrets or credentials to version control
- Use environment variables for all configuration
- Implement proper input validation and sanitization
- Use HTTPS for all external communications
- Regularly update base container images
- Implement proper error handling that doesn't leak information
Performance Maintenance
Monitoring
- Monitor application response times
- Track database query performance
- Monitor container resource usage
- Track test execution times
Optimization
- Optimize slow database queries
- Review and optimize container resource allocation
- Implement caching where appropriate
- Optimize test execution for faster feedback
Troubleshooting Guidelines
Common Issues and Solutions
Container Won't Start
- Check
.envconfiguration - Verify port availability
- Check container logs:
make logs - Rebuild containers:
make build
Tests Failing Intermittently
- Check for race conditions in parallel tests
- Verify test isolation
- Run tests serially:
make test-debug - Check for shared state between tests
Database Connection Issues
- Verify database service is running:
make status - Check database credentials in
.env - Restart database service:
make down && make up - Initialize database:
make init-db
Performance Degradation
- Check container resource usage
- Analyze database query performance
- Review application logs for errors
- Run performance tests:
make test-performance
Debugging Process
- Identify the Problem: Gather symptoms and error messages
- Check Logs: Review application and container logs
- Isolate the Issue: Use minimal reproduction steps
- Test Hypothesis: Make targeted changes and test
- Document Solution: Update documentation with solution
Backup and Recovery
Backup Procedures
- Database Backups: Automated daily backups of PostgreSQL database
- Configuration Backups: Version control all configuration files
- Container Images: Tag and store container images for rollback
- Environment Backups: Backup
.envfiles securely
Recovery Procedures
- Database Recovery: Restore from most recent backup
- Application Recovery: Deploy previous container image version
- Configuration Recovery: Restore configuration from version control
- Full System Recovery: Complete environment restoration
License
This project is licensed under the MIT License - see the LICENSE file for details.
MIT License Summary
The MIT License is a permissive open source license that allows for:
- Commercial use
- Modification
- Distribution
- Private use
The only requirement is that the license and copyright notice must be included with any substantial portions of the software.
Third-Party Dependencies
This project uses several open source libraries, each with their own licenses:
- Flask and related extensions (BSD License)
- PostgreSQL driver (BSD License)
- Testing frameworks (MIT/BSD Licenses)
- Other dependencies as listed in requirements.txt
All dependencies are compatible with the MIT License and open source distribution.
Property-Based Testing
This project includes a comprehensive property-based testing framework using Hypothesis. Property-based tests validate universal properties across the application with automatically generated test data.
Framework Components
- Hypothesis Configuration: Configurable test profiles (dev, default, ci)
- Custom Strategies: Domain-specific data generators for music, users, and sync scenarios
- Property Test Generators: High-level generators for complex test scenarios
- Base Classes: Foundation classes with setup/teardown and assertion helpers
Running Property Tests
# Run all property-based tests
make test-property
# Run with specific Hypothesis profile
export HYPOTHESIS_PROFILE=ci
make test-property
# Run with verbose output
make pytest ARGS="-k property -v"
Property-based tests automatically find minimal failing examples and provide comprehensive coverage of edge cases and boundary conditions.
For detailed information about the property-based testing framework, see tests/property/README.md.