How mardotquis/spotify-laravel works
Project type and purpose
• This is a full-stack Laravel web application whose purpose is to sync a user’s Spotify “Liked Songs” into a local database and display them via a clean Blade-powered web UI. It also supports manual or scheduled syncs via a CLI command.
Main components
A. Client / Presentation Layer
• Web Browser (or any HTTP client)
• Static assets served from public/ (CSS, JS, images)
B. Web Server & Entry Point
• Nginx/Apache or built-in PHP server (public/index.php → bootstrap/app.php → HTTP Kernel)
C. Laravel Application Layers
1. Routes (routes/web.php)
2. Controllers (app/Http/Controllers/SpotifyController.php)
3. Services (app/Services/SpotifyService.php) – contains business logic and orchestrates API calls and DB writes
4. Models (app/Models/SpotifyTrack.php, SyncHistory.php, User.php) – Eloquent ORM mapping
5. Views (resources/views/*.blade.php) – Blade templates to render HTML
D. Database & Storage
• Relational database (MySQL, Postgres, etc.) with three key tables: users, spotify_tracks, sync_histories
• Optional: file cache/queue tables (jobs, cache) if using queue or file cache drivers
• Storage for user-uploaded or service-generated files (storage/app/public, storage/*)
E. Background / Scheduled Tasks
• artisan command SyncSpotifyLikedTracks (app/Console/Commands)
• Laravel scheduler (Kernel.php → schedule the command)
• Optional: queue workers (config/queue.php, jobs table)
F. External Services
• Spotify Web API (OAuth authentication, data fetch)
• Optional: Email service, third-party logging or analytics (config/mail, config/logging)
G. Deployment & Infrastructure (optional, but useful)
• Docker Compose (PHP-FPM, Nginx, MySQL)
• Serverless stack (AWS Lambda + API Gateway + Aurora Serverless + EventBridge)
Relationships and data flows
• User clicks “Connect to Spotify” → Browser → Web Server → Routes → SpotifyController → SpotifyService → External Spotify API → callback → Controller → View → Browser
• User clicks “Sync Now” → same flow as above for manual sync
• Scheduled cron → artisan command → SpotifyService → External API → Database → logs / SyncHistory
• Database reads for page load (Controller → Model → DB → Controller → View)
• If using queues: Controller/Command dispatches a job → Queue Worker pulls job → SpotifyService → DB
Architectural patterns & principles
• MVC: clear separation of concerns between Models, Views, Controllers
• Service Layer: business logic extracted into app/Services
• Dependency Injection (in controllers, commands)
• Single Responsibility: each class has one purpose (Controller handles HTTP, Service handles API logic, Model handles DB)
• Scheduler/CLI: reusable commands for both manual and automated tasks
• Config-driven: environment variables, config/*.php for service credentials, queue, cache