# Claude Development Context

## Environment Information

**⚠️ IMPORTANT: Local vs Production Environment**

This Claude Code session is running in a **LOCAL ENVIRONMENT** that does not match the production server configuration.

### Path Differences
- **Production Server Path**: `/var/www/html/proviska-ai` ⚠️ NO extra /proviska directory
- **Local Development Path**: `/var/www/html/proviska/proviska-ai` 
- **Database Configuration**: Local MySQL differs from production setup

**CRITICAL**: Deployment scripts must use `/var/www/html/proviska-ai` for server deployment!

### Testing Limitations

**❌ Cannot Test in Local Environment:**
- Database connections (different credentials/setup)
- Apache configuration changes
- PHP module availability (APCu, OpCache)
- File permissions and ownership
- Server-specific optimizations

**✅ What Can Be Done Locally:**
- Code development and syntax validation
- File creation and modification
- Configuration file generation
- Script development

### Deployment Requirements

**🚀 To Test Performance Optimizations:**

1. **Deploy to Production First**
   ```bash
   # On production server:
   sudo /var/www/html/proviska-ai/scripts/apply-performance-optimizations.sh
   ```

2. **Test Production Endpoints**
   ```bash
   # Test simple performance endpoint:
   curl http://your-domain/proviska-ai/api/performance-test-simple.php
   
   # Run load test:
   php /var/www/html/proviska-ai/scripts/production-load-test.php
   ```

3. **Monitor Performance**
   ```bash
   # Check admin dashboard performance metrics
   # Access: http://your-domain/proviska-ai/api/admin-dashboard-v2.html
   ```

### Performance Optimization Files Created

**Core Optimizations:**
- `lib/DatabasePoolV2.php` - Production database connection pooling
- `lib/QueryCache.php` - APCu-based result caching
- `lib/OptimizedEndpoints.php` - High-performance API wrappers
- `config/apache-optimization.conf` - Apache performance tuning
- `config/php-optimization.ini` - PHP production settings

**Monitoring & Testing:**
- `api/performance-test-simple.php` - Basic performance validation
- `api/performance-monitor-v2.php` - Comprehensive performance monitoring
- `scripts/production-load-test.php` - Load testing suite
- `scripts/apply-performance-optimizations.sh` - Deployment script

### Expected Performance Improvements

**Target**: 4.98 req/sec → 100+ req/sec (2000% improvement)

**Key Optimizations Applied:**
- ✅ MySQL 8.0+ compatibility fixes
- ✅ Production-grade connection pooling
- ✅ APCu result caching
- ✅ Apache/PHP production tuning
- ✅ Memory and query optimizations

### Production Deployment Steps

**Step 1: Apply All Optimizations**
```bash
# On production server (/var/www/html/proviska-ai):
cd /var/www/html/proviska-ai
sudo ./scripts/apply-performance-optimizations-v2.sh
```

**Step 2: Validate Deployment**
```bash
# Comprehensive validation (run as root or www-data):
./scripts/validate-production-deployment.sh
```

**Step 3: Performance Testing**
```bash
# Quick performance check:
curl http://your-domain/proviska-ai/api/performance-test-simple.php

# Full load test:
php scripts/production-load-test.php
```

**Step 4: Monitor Results**
```bash
# Check admin dashboard performance metrics
# Access: http://your-domain/proviska-ai/api/admin-dashboard-v2.html

# Monitor error logs:
tail -f /var/log/apache2/error.log
tail -f /var/log/php/error.log
```

### Troubleshooting Common Issues

**Database Connection Issues:**
- Verify credentials in `api/config.php`
- Ensure MySQL is running: `systemctl status mysql`
- Check MySQL user permissions

**APCu Not Working:**
- Install: `apt-get install php8.2-apcu`
- Enable in PHP config: `apc.enabled=1`
- Restart Apache: `systemctl restart apache2`

**Permission Issues:**
```bash
chown -R www-data:www-data /var/www/html/proviska-ai
chmod -R 755 /var/www/html/proviska-ai
```

### Expected Results After Deployment

**Performance Targets:**
- ✅ 4.98 req/sec → 100+ req/sec (2000% improvement)
- ✅ Database queries reduced by 60-80%
- ✅ Response times improved by 50-70%
- ✅ Memory usage optimized by 30-40%

**Validation Success Criteria:**
- 90%+ tests passing in validation script
- Performance grade: A or A+
- Database pool utilization: 10-80%
- APCu hit rate: 60%+

---

**Note**: All database connection testing and performance validation must be performed on the production server where the actual database and web server configurations exist.