# CuraHealthLine - Quick Setup & Reference Guide

## 🚀 Initial Setup

### Prerequisites
- PHP 8.1+
- Composer
- Node.js & npm
- MySQL or PostgreSQL

### Installation Steps

```bash
# 1. Navigate to project directory
cd c:\Users\RichmondBonah\Documents\K&A\Laravel\CURA\cura-app

# 2. Install PHP dependencies
composer install

# 3. Install Node dependencies
npm install

# 4. Copy environment file
cp .env.example .env

# 5. Generate application key
php artisan key:generate

# 6. Configure database in .env
# DB_CONNECTION=mysql
# DB_HOST=127.0.0.1
# DB_PORT=3306
# DB_DATABASE=cura_healthline
# DB_USERNAME=root
# DB_PASSWORD=

# 7. Run migrations and seeders
php artisan migrate:fresh --seed

# 8. Build assets
npm run build
# OR for development with hot reload:
npm run dev

# 9. Start development server
php artisan serve
```

## 🔐 Test User Credentials (from seeder)

### Admin User
- Email: `admin@cura.test`
- Password: `password`
- URL: http://localhost:8000/admin

### Employer User
- Email: `employer@cura.test`
- Password: `password`
- URL: http://localhost:8000/employer

### Nurse Users
- Email: `nurse1@cura.test` or `nurse2@cura.test`
- Password: `password`
- URL: http://localhost:8000/nurse

## 📍 Key Routes

### Public Routes
- Homepage: `/`
- Jobs Listing: `/jobs`
- Job Details: `/jobs/{id}`
- Login: `/login`
- Register: `/register`

### Nurse Routes (require nurse role)
- Dashboard: `/nurse`
- Profile: `/nurse/profile/edit`
- Applications: `/nurse/applications`
- Connections: `/nurse/connections`
- Messages: `/nurse/messages`

### Employer Routes (require employer role)
- Dashboard: `/employer`
- Profile: `/employer/profile/edit`
- Jobs List: `/employer/jobs`
- Create Job: `/employer/jobs/create`
- Edit Job: `/employer/jobs/{id}/edit`
- View Applicants: `/employer/jobs/{id}/applicants`
- Application Details: `/applications/{id}`

### Admin Routes (require admin role)
- Dashboard: `/admin`
- Employers: `/admin/employers`
- Jobs: `/admin/jobs`
- Users: `/admin/users`
- Nurses: `/admin/nurses`

## 🎨 Fixed Issues Summary

### 1. Colors & Styling
✅ All custom colors now work:
- `bg-brand` → #1d5bbf (blue)
- `bg-teal` → #27b1a2 (teal)
- `bg-ink` → #2c3e50 (dark gray)
- `bg-soft` → #f7f9fb (light gray)
- `text-brand`, `text-teal`, `text-ink` also work

**Fix:** Updated `tailwind.config.js` and rebuilt assets with `npm run build`

### 2. Home Page Functionality
✅ "Apply Now" button → now properly links to `/jobs`
✅ Job search form → submits to `/jobs?search=...&location=...`
✅ Search functionality → accepts both 'search' and 'q' parameters

### 3. Employer Profile
✅ Routes added: `/employer/profile/edit` and `/employer/profile`
✅ Validation: website URL, about text max length

### 4. Validation & Security

#### Duplicate Prevention
✅ **Job Applications**: Cannot apply to same job twice
- Shows error: "You have already applied to this job"
- Database has unique constraint: `[job_posting_id, user_id]`

✅ **Connection Requests**: Cannot send duplicate requests
- Shows error: "Connection request already exists"
- Database has unique constraint: `[requester_id, recipient_id]`

✅ **Self-Connection**: Cannot connect to yourself
- Shows error: "You cannot send a connection request to yourself"

#### Input Validation
✅ Cover letter: max 5,000 characters
✅ About text: max 2,000 characters
✅ Website: must be valid URL
✅ Message body: max 10,000 characters
✅ XSS Prevention: HTML stripped from messages

#### Authorization
✅ Role-based access control on all routes
✅ Employers can only view/edit their own jobs
✅ Nurses can only access their own applications
✅ Conversation access restricted to participants

## 🧪 Testing Commands

```bash
# Run all tests (if implemented)
php artisan test

# Run specific test file
php artisan test tests/Feature/NurseApplicationTest.php

# Run with coverage
php artisan test --coverage

# Clear cache before testing
php artisan config:clear
php artisan cache:clear
php artisan view:clear
```

## 🔧 Common Issues & Solutions

### Issue: Colors not showing
**Solution:** Rebuild assets
```bash
npm run build
# OR
& ".\node_modules\.bin\vite.ps1" build
```

### Issue: Route not found
**Solution:** Clear route cache
```bash
php artisan route:clear
php artisan route:cache
```

### Issue: View not updating
**Solution:** Clear view cache
```bash
php artisan view:clear
```

### Issue: Database errors
**Solution:** Re-run migrations
```bash
php artisan migrate:fresh --seed
```

### Issue: Permission errors (documents upload)
**Solution:** Ensure storage is linked and writable
```bash
php artisan storage:link
chmod -R 775 storage
chmod -R 775 bootstrap/cache
```

## 📊 Database Structure

### Core Tables
- `users` - All user accounts (nurse, employer, admin)
- `nurse_profiles` - Nurse professional information
- `employers` - Employer/organization information
- `job_postings` - Job listings
- `job_applications` - Nurse applications to jobs
- `nurse_connections` - Connection requests between nurses
- `conversations` - Chat conversations
- `messages` - Individual messages
- `nurse_documents` - Uploaded documents (CV, licenses, etc.)

### Key Relationships
- User → Nurse Profile (1:1)
- User → Employer (1:1)
- Employer → Job Postings (1:many)
- Job Posting → Applications (1:many)
- Nurse → Applications (1:many)
- Nurse ↔ Nurse Connections (many:many)
- Conversation → Messages (1:many)

## 🎯 Key Features Status

### ✅ Implemented & Working
- User registration (nurse, employer, admin roles)
- Login & authentication
- Nurse profile management
- Employer profile management
- Job posting CRUD
- Job search & filters
- Job applications
- Application status management
- Nurse connections (request/accept/reject)
- Nurse-to-nurse messaging
- Role-based dashboards
- Admin management (employers, jobs, users)
- Validation & error handling
- XSS prevention
- Duplicate prevention

### ⏳ Not Implemented (Phase II+)
- Real-time messaging (WebSockets)
- Email notifications
- Payment processing
- Advanced search filters
- File compression
- Video interviews
- Background jobs

## 📝 Development Workflow

### Making Changes

1. **Controllers**: `app/Http/Controllers/`
2. **Models**: `app/Models/`
3. **Views**: `resources/views/`
4. **Routes**: `routes/web.php`
5. **Migrations**: `database/migrations/`
6. **Seeders**: `database/seeders/`

### After Making Changes

```bash
# If you changed routes
php artisan route:clear

# If you changed config
php artisan config:clear

# If you changed views
php artisan view:clear

# If you changed CSS/JS
npm run build
# OR for development
npm run dev

# If you changed migrations
php artisan migrate:fresh --seed
```

## 🐛 Debugging

### Enable Debug Mode
In `.env`:
```
APP_DEBUG=true
APP_ENV=local
```

### Check Logs
```bash
# View latest log entries
tail -f storage/logs/laravel.log

# On Windows (PowerShell)
Get-Content storage\logs\laravel.log -Wait -Tail 50
```

### Database Queries
Add to any controller method:
```php
\DB::enableQueryLog();
// ... your code ...
dd(\DB::getQueryLog());
```

## 📚 Additional Resources

- Laravel Documentation: https://laravel.com/docs
- Tailwind CSS: https://tailwindcss.com/docs
- Alpine.js: https://alpinejs.dev

## ✅ Pre-Launch Checklist

Before deploying to production:
- [ ] Set `APP_DEBUG=false` in `.env`
- [ ] Set `APP_ENV=production` in `.env`
- [ ] Run `php artisan config:cache`
- [ ] Run `php artisan route:cache`
- [ ] Run `php artisan view:cache`
- [ ] Run `npm run build`
- [ ] Set strong `APP_KEY`
- [ ] Configure proper database credentials
- [ ] Set up SSL certificate
- [ ] Configure email sending
- [ ] Set up backups
- [ ] Configure queue workers (if using jobs)
- [ ] Test all critical flows
- [ ] Review error logs
