# Music Monitor API Documentation

Backend Laravel API-only for **Music Monitor**, optimized for PostgreSQL (`pgvector`), Redis queue/cache/session, Laravel Sanctum, and Ollama local AI (`nomic-embed-text` & `phi3:mini`).

---

## Base URL & Configuration
- **Backend URL (LAN)**: `http://192.168.178.100:8000`
- **Frontend URL (Next.js)**: `http://localhost:3000` or `http://192.168.178.100:3000`
- **Frontend API Base**: `const API_URL = process.env.NEXT_PUBLIC_API_URL;`

---

## Endpoints

### 1. Health Check
- **URL**: `GET /api/health`
- **Auth**: None
- **Description**: Returns the health status of Database, Redis, and Ollama.
- **Response (200 OK / 503 Service Unavailable)**:
```json
{
  "status": "ok",
  "timestamp": "2026-10-20T12:00:00+00:00",
  "services": {
    "database": "up",
    "redis": "up",
    "ollama": "up"
  }
}
```

### 2. User Authentication (Sanctum)
- **URL**: `GET /api/user`
- **Auth**: `Bearer Token` (Sanctum)
- **Description**: Returns authenticated user object.

### 3. Vector Search Contacts
- **URL**: `POST /api/search`
- **Auth**: `Bearer Token` (Sanctum)
- **Request Body**:
```json
{
  "query": "Techno DJ in Berlin",
  "limit": 10,
  "threshold": 0.5,
  "ruolo": "DJ",
  "citta": "Berlin",
  "nazione": "Germany"
}
```
- **Response (200 OK)**:
```json
{
  "query": "Techno DJ in Berlin",
  "count": 1,
  "data": [
    {
      "id": 1,
      "nome": "Max Smith",
      "email": "max@example.com",
      "telefono": "+49123456789",
      "citta": "Berlin",
      "nazione": "Germany",
      "ruolo": "DJ",
      "generi_musicali": ["Techno", "House"],
      "note": "Resident DJ at Tresor",
      "metadata": {},
      "similarity": 0.8942,
      "created_at": "2026-10-20T12:00:00+00:00",
      "updated_at": "2026-10-20T12:00:00+00:00"
    }
  ]
}
```

---

## Artisan Commands
- **Import Contacts**:
  ```bash
  php artisan contacts:import path/to/contacts.csv
  php artisan contacts:import path/to/contacts.json --async
  ```
