# Laravel Jukebox API - Documentation Index Welcome! This directory contains comprehensive documentation for the Laravel Jukebox API. ## ๐Ÿ“š Documentation Files ### 1. **API_QUICK_REFERENCE.md** โญ START HERE **Best for:** Quick lookups, endpoint overview, getting oriented - Database relationship diagram - Complete endpoint summary (40+ routes) - Authentication methods - Validation rules - Known limitations - Quick start examples with curl **Read time:** ~5 minutes --- ### 2. **API_EXAMPLES.md** **Best for:** Understanding request/response formats, testing endpoints - Real request/response examples for every operation - All CRUD operations demonstrated - Error response samples - HTTP status codes reference - Headers and authentication examples - cURL command examples **Read time:** ~10 minutes --- ### 3. **API_DOCUMENTATION.md** **Best for:** Complete technical reference, deep understanding - All API routes with descriptions - All 8 controllers and 31 methods detailed - All 7 models with relationships - Database schema (11 tables) with column details - Authentication & authorization explained - Configuration details - Seeders & factories documentation - CORS configuration status - Key observations & recommendations **Read time:** ~20 minutes --- ## ๐Ÿš€ Quick Start ### Step 1: Register a user ```bash curl -X POST http://localhost/api/register \ -H "Content-Type: application/json" \ -d '{ "name": "Your Name", "email": "user@example.com", "password": "password123", "password_confirmation": "password123" }' ``` ### Step 2: Get your token The response contains a `token` field. Copy it. ### Step 3: Use the token ```bash curl -X GET http://localhost/api/me \ -H "Authorization: Bearer YOUR_TOKEN_HERE" ``` ### Step 4: Explore Browse the API_EXAMPLES.md for more operations. --- ## ๐Ÿ“Š API Structure ``` PUBLIC ENDPOINTS (2) โ”œโ”€โ”€ POST /register โ””โ”€โ”€ POST /login AUTHENTICATED ENDPOINTS (37+) โ”œโ”€โ”€ Account Management โ”‚ โ”œโ”€โ”€ POST /logout โ”‚ โ””โ”€โ”€ GET /me โ”œโ”€โ”€ User Likes โ”‚ โ”œโ”€โ”€ GET /me/likes โ”‚ โ”œโ”€โ”€ POST /tracks/{id}/like โ”‚ โ””โ”€โ”€ DELETE /tracks/{id}/like โ””โ”€โ”€ Browse (Read-only) โ”œโ”€โ”€ Labels (GET /labels, /labels/{id}) โ”œโ”€โ”€ Genres (GET /genres, /genres/{id}) โ”œโ”€โ”€ Artists (GET /artists, /artists/{id}) โ”œโ”€โ”€ Albums (GET /albums, /albums/{id}) โ””โ”€โ”€ Tracks (GET /tracks, /tracks/{id}) ADMIN-ONLY ENDPOINTS (24) โ”œโ”€โ”€ Create/Update/Delete: Labels, Genres, Artists, Albums, Tracks โ””โ”€โ”€ User Management: List, View, Update, Delete Users ``` --- ## ๐Ÿ” Authentication This API uses **Laravel Sanctum Bearer Tokens**. 1. Register or login to get a token 2. Include token in all requests: `Authorization: Bearer {token}` 3. Tokens stored in `personal_access_tokens` table 4. No automatic expiration (infinite lifetime) --- ## ๐Ÿ‘ฅ Authorization Two roles exist: - **user** (default) - Can browse content and manage likes - **admin** - Can create/update/delete content and manage users Checked via custom `EnsureAdmin` middleware. --- ## ๐Ÿ“ Directory Map ``` /app /Http/Controllers - 8 controllers with 31 methods /Http/Middleware - EnsureAdmin (role checking) /Models - 7 Eloquent models with relationships /routes /api.php - All 40+ API routes defined here /web.php - Minimal web routes /database /migrations - 11 migration files (ordered) /seeders - DatabaseSeeder (creates test user) /factories - UserFactory (only one) /config /sanctum.php - Token auth configuration /auth.php - Authentication guards setup ``` --- ## ๐Ÿ“‹ Database Schema Overview ### Core Tables - **roles** - User roles (admin, user) - **users** - User accounts - **labels** - Record labels - **genres** - Music genres ### Music Catalog - **artists** - Musicians/bands - **albums** - Albums/EPs/singles - **tracks** - Individual songs ### Relationships - **artist_track** - Many-to-many (artists can have many tracks) - **track_genre** - Many-to-many (tracks can have many genres) - **likes** - Many-to-many (users can like many tracks) ### Authentication - **personal_access_tokens** - Sanctum tokens for API authentication --- ## ๐Ÿ”„ Data Relationships ``` User โ”œโ”€โ”€ role (1-to-many) โ””โ”€โ”€ likes (many-to-many: Track) Artist โ”œโ”€โ”€ label (1-to-many) โ””โ”€โ”€ tracks (many-to-many) Album โ”œโ”€โ”€ label (1-to-many) โ””โ”€โ”€ tracks (1-to-many) Track โ”œโ”€โ”€ album (1-to-many) โ”œโ”€โ”€ artists (many-to-many) โ”œโ”€โ”€ genres (many-to-many) โ””โ”€โ”€ likedBy users (many-to-many) Genre โ””โ”€โ”€ tracks (many-to-many) Label โ”œโ”€โ”€ artists (1-to-many) โ””โ”€โ”€ albums (1-to-many) ``` --- ## โš ๏ธ Current Limitations - โŒ No pagination on list endpoints - โŒ No search/filtering capability - โŒ No rate limiting - โŒ No API documentation tool (Swagger/OpenAPI) - โŒ No automatic response wrapping - โŒ No audit logging - โŒ Limited test coverage See API_DOCUMENTATION.md ยง11 for detailed observations. --- ## ๐Ÿ”ง Key Technologies - **Framework:** Laravel 13.0 - **PHP:** 8.3+ - **Database:** MySQL (Docker at 172.17.0.1:3306) - **Authentication:** Laravel Sanctum 4.0 - **ORM:** Eloquent - **Testing:** PHPUnit (12.5.12) --- ## ๐Ÿ“ Response Format All responses are JSON. **Success (single resource):** ```json { "id": 1, "name": "Example", "created_at": "2026-05-07T...", "updated_at": "2026-05-07T..." } ``` **Success (list):** ```json [ { "id": 1, "name": "Item 1" }, { "id": 2, "name": "Item 2" } ] ``` **Error:** ```json { "message": "Error description", "errors": { "field": ["Validation error message"] } } ``` --- ## ๐Ÿงช Testing Accounts **Test User (from DatabaseSeeder):** - Email: `test@example.com` - Password: `password` - Role: user Use these credentials to login and get a token. --- ## ๐Ÿ“ž Common Tasks ### Browse Music ``` GET /api/artists GET /api/albums GET /api/tracks ``` ### Like/Favorite ``` POST /api/tracks/{id}/like GET /api/me/likes DELETE /api/tracks/{id}/like ``` ### Create Content (Admin) ``` POST /api/artists POST /api/albums POST /api/tracks ``` ### Manage Users (Admin) ``` GET /api/users POST /api/users/{id} DELETE /api/users/{id} ``` --- ## ๐Ÿ“– Reading Order Recommendation 1. **This file** (2 min) - Get oriented 2. **API_QUICK_REFERENCE.md** (5 min) - See all endpoints 3. **API_EXAMPLES.md** (10 min) - See request/response examples 4. **routes/api.php** (5 min) - Read actual route definitions 5. **app/Http/Controllers/** (10 min) - Read controller implementations 6. **app/Models/** (5 min) - Understand data models 7. **API_DOCUMENTATION.md** (20 min) - Deep dive on everything Total time: ~60 minutes for complete understanding --- ## ๐Ÿ” Need More Info? - **Routes:** See `/routes/api.php` - single file with all endpoints - **Controllers:** See `/app/Http/Controllers/` - one per resource - **Models:** See `/app/Models/` - Eloquent models with relationships - **Database:** See `/database/migrations/` - migration files - **Auth:** See `/config/sanctum.php` and `/config/auth.php` --- ## ๐Ÿ“‹ Endpoint Summary | Category | Public | Authenticated | Admin-Only | |----------|--------|---------------|-----------| | Auth | 2 | 2 | 0 | | Browse | 0 | 10 | 0 | | Likes | 0 | 3 | 0 | | Labels | 0 | 1 | 3 | | Genres | 0 | 1 | 3 | | Artists | 0 | 1 | 3 | | Albums | 0 | 1 | 3 | | Tracks | 0 | 1 | 3 | | Users | 0 | 0 | 4 | | **TOTAL** | **2** | **19** | **19** | **Total Endpoints: 40+** --- ## โœ… Checklist for Understanding the API After reading the documentation, you should understand: - [ ] What are the 2 public endpoints? - [ ] How to authenticate (register โ†’ login โ†’ token)? - [ ] How to use the token in requests? - [ ] The 3 endpoint categories (public, authenticated, admin)? - [ ] All 7 data models and their relationships? - [ ] The database schema and table structure? - [ ] How admin access control works? - [ ] Response format (success and error)? - [ ] HTTP status codes (200, 201, 204, 403, 404, 422)? - [ ] How to like a track and get favorites? --- ## ๐ŸŽฏ Next Steps 1. **For Frontend Integration:** Read API_QUICK_REFERENCE.md + API_EXAMPLES.md 2. **For Backend Development:** Read API_DOCUMENTATION.md thoroughly 3. **For Testing:** Use test user credentials in API_EXAMPLES.md 4. **For Production:** Address limitations in API_DOCUMENTATION.md ยง11 --- **Last Updated:** May 7, 2026 **Documentation Version:** 1.0 **API Version:** Laravel 13 + Sanctum 4 --- ## Questions? Refer to the appropriate documentation file: - Quick question? โ†’ API_QUICK_REFERENCE.md - How do I do X? โ†’ API_EXAMPLES.md - Why is it built this way? โ†’ API_DOCUMENTATION.md