HEX
Server: Apache
System: Linux 136-243-153-58.cprapid.com 4.18.0-553.81.1.el8_10.x86_64 #1 SMP Mon Oct 27 11:29:19 EDT 2025 x86_64
User: mytest (1001)
PHP: 8.2.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: /home/mytest/.trash/CRITICAL_INFO_FOR_FUTURE_AI.md.21
# CRITICAL INFO FOR FUTURE AI ASSISTANTS

**Last Updated:** 2025-11-18  
**Repository:** georgemargiolos/yolo-clone  
**Branch:** allHands  
**User:** George Margiolos

---

## ⚠️ IMPORTANT RULES

### 1. File Access
- ❌ **NEVER** say "I can't give you a download link"
- ❌ **NEVER** reference `/workspace/project/` to the user
- ✅ **ALWAYS** direct to GitHub: https://github.com/georgemargiolos/yolo-clone/archive/refs/heads/allHands.zip
- ✅ **User cannot access your workspace** - only GitHub!

### 2. Workflow
```
Your Workspace  →  GitHub  →  User's Server
(temporary)     (permanent) (/home/mytest/public_html/)
```

### 3. When User Says "Give me the file"
Answer: "Download from GitHub: [ZIP link]"  
**NOT:** "The file is in my workspace at /workspace/project/..."

---

## 🏗️ Architecture

### Production Server
- **Location:** `/home/mytest/public_html/`
- **Database:** SQLite at `data/yolo_charters.db`
- **Live Site:** https://mytestserver.gr/
- **Company ID:** 7850 (YOLO Boats)

### Database Setup
- **Type:** SQLite3
- **Location:** `/home/mytest/public_html/data/yolo_charters.db`
- **Connection:** Use `Database::getInstance()` class
- **Migration Tracking:** `schema_version` table

### Important Classes
- `Database` - Singleton pattern for DB connection
- `BookingManagerService` - API calls to Booking Manager
- All services use `Database::getInstance()` (never PDO directly)

---

## 🎯 System Features

### 1. Weekly Availability Caching (IMPLEMENTED)
- **Why:** Avoid 52 API calls per page load
- **How:** Cron job updates database hourly
- **Table:** `yacht_weekly_availability`
- **Cron:** `/home/mytest/public_html/cron-update-availability.php`
- **Setup:** See `AVAILABILITY_CACHE_SETUP.md`

### 2. Search System
- **Flexibility:** Default = 14 days (not 6!)
- **Duplicates:** Use `DISTINCT yacht_id` in queries
- **Friend's Boats:** Only show if available for searched dates

### 3. Reviews System
- **Admin Auth:** Goes through `api/index.php` → `admin.php` → `reviews.php`
- **Public:** Direct routing to `reviews.php`
- **Auth Function:** `authenticateRequest()` (not `verifyToken()`)

---

## 🐛 Common Mistakes to Avoid

### Database Mistakes
❌ Never use `$pdo = new PDO(...)` directly  
✅ Always use `Database::getInstance()`

❌ Never use `getConnection()` on existing instances  
✅ Use `Database::getInstance()` which returns the connection

### API Mistakes
❌ Don't request 6-month ranges in one call  
✅ Use caching system with hourly updates

❌ Don't use flexibility=6 for searches  
✅ Use flexibility=14 minimum

### Routing Mistakes
❌ Don't bypass authentication checks  
✅ Admin routes must go through `api/index.php` auth

---

## 📁 Key Files

### Backend
- `api/index.php` - Main API router with authentication
- `api/routes/admin.php` - Admin endpoints router
- `api/routes/reviews.php` - Reviews CRUD operations
- `api/services/BookingManagerService.php` - Booking Manager API wrapper
- `database/Database.php` - Singleton DB connection class
- `cron-update-availability.php` - Hourly availability updater

### Frontend
- `public/pages/yacht-detail.php` - Yacht detail page with availability calendar
- `public/pages/search-results.php` - Search results with deduplication

### Configuration
- `config.php` - Database path and settings
- `api/config.php` - API credentials (Booking Manager)

---

## 🔧 Active Issues & Solutions

### Issue: Weekly Availability Wrong
**Solution:** Use caching system (see `AVAILABILITY_CACHE_SETUP.md`)  
**Status:** ✅ IMPLEMENTED

### Issue: Duplicate Yachts in Search
**Solution:** Use `DISTINCT yacht_id` in queries  
**Status:** ✅ FIXED

### Issue: Reviews Menu 401 Unauthorized
**Solution:** Route through proper admin flow  
**Status:** ✅ FIXED

---

## 🚀 Deployment Process

1. **User makes changes** (or you make changes)
2. **You commit & push** to GitHub `allHands` branch
3. **User downloads** ZIP from GitHub
4. **User uploads** to `/home/mytest/public_html/`
5. **Test on live site**

### Quick Deploy Commands (for user's server)
```bash
# Backup database first!
cp data/yolo_charters.db data/yolo_charters.db.backup

# Run migrations if needed
sqlite3 data/yolo_charters.db < database/migrations/XXX_migration_name.sql

# Set up cron (first time only)
crontab -e
# Add: 0 * * * * /usr/bin/php /home/mytest/public_html/cron-update-availability.php >> /home/mytest/logs/availability-cron.log 2>&1

# Test cron manually
php cron-update-availability.php
```

---

## 📊 Database Schema Highlights

### Important Tables
- `yachts` - Yacht data with `booking_manager_id` and `company_id`
- `yacht_weekly_availability` - **NEW** Cached availability (52 weeks per yacht)
- `reviews` - Guest reviews with approval workflow
- `schema_version` - Migration tracking

### Key Relationships
- `yachts.booking_manager_id` → Booking Manager API yacht ID
- `yachts.company_id` → Usually '7850' for YOLO Boats
- `yacht_weekly_availability.yacht_id` → `yachts.booking_manager_id`

---

## 💡 User Insights

### User Preferences
- ⚡ **Speed is critical** - User wants fast page loads
- 🎯 **Practical solutions** - User prefers caching over real-time API calls
- 📊 **Live site testing** - User tests on production (mytestserver.gr)
- 🔧 **Direct communication** - User appreciates "just give me the file" approach

### User's Brilliant Ideas
- **Availability caching** - Store in DB, update hourly (IMPLEMENTED!)
- **Week-by-week fetching** - More accurate than bulk requests

---

## 📝 Documentation Files (Read These!)

1. `README_FOR_AI.md` - Original AI instructions
2. `DEVINS_MISTAKES.md` - What NOT to do (from Cursor)
3. `AVAILABILITY_CACHE_SETUP.md` - Caching system setup
4. `COMPLETE_TECHNICAL_FIXES.md` - All technical issues and solutions
5. `ALL_FIXES_SUMMARY_2025-11-18.md` - Session summary

---

## 🎓 Lessons Learned

1. **Never assume** user can access your workspace
2. **Always direct** to GitHub for file downloads
3. **Cache expensive operations** (like 52 API calls)
4. **Use Database::getInstance()** everywhere
5. **Test on live site** (mytestserver.gr) to verify fixes
6. **User knows best** - listen to their suggestions (like caching!)

---

## ⚡ Quick Reference

**GitHub Repo:** https://github.com/georgemargiolos/yolo-clone  
**Branch:** allHands  
**Download ZIP:** https://github.com/georgemargiolos/yolo-clone/archive/refs/heads/allHands.zip  
**Production:** https://mytestserver.gr/  
**Server Path:** /home/mytest/public_html/  

**For Next AI:**
1. Read this file first
2. Clone the repo: `git clone -b allHands https://github.com/georgemargiolos/yolo-clone.git`
3. Read all markdown files in root
4. Ask user what needs to be fixed
5. Never reference /workspace/project/ to user!

---

**This file persists across all sessions. Update it when you learn something new!**