# AGENTS.md - Development Guidelines This file contains essential information for AI agents working on this codebase. ## Project Overview PHP website for "Harmonie de Montpellier-Jacou" (music band) with a Vue.js 2 frontend for score management. - **Backend**: PHP with MySQL (legacy codebase) - **Frontend**: Vue.js 2 + Bootstrap Vue (in `frontend/score/`) - **API**: RESTful PHP API in `api/` directory ## Build Commands ### Frontend (Vue.js) ```bash cd frontend/score npm install npm run serve # Development server npm run build # Production build npm run lint # ESLint check ``` ### PHP No build step required. Deploy to PHP-enabled web server. ## Testing ### PHP API Tests Run functional tests for the PHP API: ```bash cd api php tests.php ``` The tests cover: - **Auth**: Login, bad credentials, missing token, invalid token - **Scores**: CRUD operations, error handling for non-existent resources - **Create Score with Pieces**: Functional tests with pieces verification - **Files**: Get files tree, delete file error handling ### Vue/Svelte No test framework configured for frontend. Run single test (when configured): ```bash # Example for Jest (not yet configured) npm test -- --testNamePattern="test name" ``` ## Code Style Guidelines ### PHP - Use ` ``` - **Token format**: JWT (HS256) - see `api/lib/Auth.php` - **Frontend**: Token stored in localStorage, auto-attached to API requests via axios interceptor - **Test**: http://localhost:5173 - login with admin/password - **API base URL**: http://localhost:8000/api/ ## Current Tech Stack (2024) - **Frontend**: SvelteKit (NOT Vue.js 2) in `/partitions/` - **Backend**: PHP API in `/api/` - **Scores storage**: `/legacy/Scores/` (directory-based, not MySQL) ## Security Audit Commands When modifying backend or frontend code, run these security audits: ### Backend Security Audit ```bash # 1. Start the PHP server cd api php -S localhost:8000 router.php & # 2. Clear rate limiting files (important!) rm -f /tmp/rate_* 2>/dev/null # 3. Run all security tests php tests.php # Expected: 50/50 tests passed (100%) ``` ### Frontend Security Check ```bash cd partitions # 1. Check for security issues in dependencies npm audit # 2. Build and check for CSP violations npm run build # 3. Check that environment variables are configured cp .env.example .env # Edit .env and set VITE_API_URL to your backend URL ``` ### Manual Security Verification ```bash # Test JWT authentication curl -s http://localhost:8000/login \ -X POST \ -H "Content-Type: application/json" \ -d '{"username":"admin","password":"password"}' # Test CORS headers curl -s -I http://localhost:8000/scores \ -H "Origin: https://evil.com" # Test directory traversal protection curl -s http://localhost:8000/download/../../../etc/passwd \ -H "Authorization: Bearer " # Expected: 403 or 404 (not 200) # Test security headers curl -s -I http://localhost:8000/login \ -X POST \ -H "Content-Type: application/json" \ -d '{"username":"admin","password":"password"}' # Check for: X-Content-Type-Options, X-Frame-Options, X-XSS-Protection, HSTS ``` ### Environment Setup for Security **Backend (api/.env):** ```bash JWT_SECRET=your_very_long_random_secret_key_here ``` **Frontend (partitions/.env):** ```bash # Development VITE_API_URL=http://localhost:8000 # Production (use HTTPS!) VITE_API_URL=https://api.yourdomain.com ``` ### Security Checklist Before Deployment - [ ] JWT_SECRET is set and strong (use: `openssl rand -base64 32`) - [ ] CORS origins are restricted to your domain only - [ ] HTTPS is enforced in production - [ ] Rate limiting is active - [ ] All 50 tests pass - [ ] npm audit shows no critical vulnerabilities - [ ] CSP headers are configured - [ ] No secrets in code or git history