# 🍳 ChefsHub Backend

**ProzTec – ChefsHub**

A comprehensive Laravel-based platform providing a backend API, public website, and administrative panels for Chefs and Suppliers, with a Nuxt-powered Admin Panel for staging and production environments.

---

## 📋 Table of Contents

- [Overview](#overview)
- [Technology Stack](#technology-stack)
- [Prerequisites](#prerequisites)
- [Local Development Setup](#local-development-setup)
- [Project Structure](#project-structure)
- [Artisan Helper Commands](#artisan-helper-commands)
- [Nuxt Admin Configuration](#nuxt-admin-configuration)
- [Building for Production](#building-for-production)
- [Deployment](#deployment)
- [Troubleshooting](#troubleshooting)

---

## 🎯 Overview

ChefsHub is a full-stack platform that connects chefs with suppliers, providing:

- **Backend API**: RESTful API for mobile and web clients
- **Public Website**: Laravel-powered frontend for public access
- **Supplier Panel**: Laravel-based admin interface for suppliers
- **Admin Panel**: Nuxt.js-powered admin panel for staging and production

---

## 🛠 Technology Stack

### Backend
- **Framework**: Laravel 11.x
- **PHP**: 8.1+
- **Database**: MySQL 8.0+
- **Authentication**: Laravel Sanctum
- **File Storage**: AWS S3
- **Payment Processing**: Stripe
- **Push Notifications**: Firebase Cloud Messaging
- **Video Processing**: FFmpeg (via Laravel FFmpeg)

### Frontend
- **Build Tool**: Vite 4.x
- **JavaScript Framework**: Vue.js 3
- **CSS Framework**: Tailwind CSS 3.x
- **Admin Panel**: Nuxt.js
- **State Management**: Pinia

### Key Dependencies
- AWS SDK for S3 integration
- Intervention Image for image processing
- Laravel Socialite for OAuth
- Spatie Activity Log for audit trails

---

## 📦 Prerequisites

Make sure the following are installed on your system:

| Software | Version | Notes |
|----------|---------|-------|
| **PHP** | 8.1 or higher | Required for Laravel 11 |
| **Composer** | Latest | PHP dependency manager |
| **Node.js** | 18 or 19 (LTS) | Recommended: 18.x or 19.x LTS |
| **NPM** | Latest | Comes with Node.js |
| **MySQL** | 8.0 or higher | Database server |
| **Local Server** | - | Laravel Valet, Laragon, XAMPP, or `php artisan serve` |

---

## 🚀 Local Development Setup

### 1. Clone the Repository & Install Dependencies

```bash
# Clone the repository
git clone <repository-url>
cd chefshub-backend

# Install PHP dependencies
composer install

# Install JavaScript dependencies
npm install
```

### 2. Environment Configuration

Copy the example environment file and generate the application key:

```bash
cp .env.example .env
php artisan key:generate
```

Update `.env` with your local database credentials:

```env
DB_DATABASE=chefshub
DB_USERNAME=root
DB_PASSWORD=your_password
```

**OR** import the provided database dump:

```bash
# Import the SQL dump
mysql -u root -p chefshub < chefshub.sql
```

### 3. Database Setup

If using migrations and seeders:

```bash
php artisan migrate --seed
```

### 4. Running the Application

Start the Laravel backend server:

```bash
php artisan serve
```

In a separate terminal, start Vite for frontend hot reload:

```bash
npm run dev
```

**Access URLs:**
- **Backend / Website**: http://localhost:8000
- **Vite Dev Server**: http://localhost:5173

---

## 📁 Project Structure

### Frontend Entry Points

The project uses Vite with multiple entry points:

#### Website
- **JavaScript**: `resources/js/site_app.js`
- **Styles**: `resources/css/site_app.scss`

#### Supplier / Admin Panel (Laravel-based)
- **JavaScript**: `resources/js/supplier_app.js`
- **Styles**: `resources/css/supplier_app.scss`

#### Nuxt Admin Panel (Staging & Production)

The Admin Panel is built using Nuxt.js, located at:

```
public/nuxt_admin/
```

This repository provides custom Artisan helpers to automate Nuxt builds and deployment.

### Key Directories

```
chefshub-backend/
├── app/                    # Application logic
│   ├── Http/              # Controllers, Middleware, Requests
│   ├── Models/            # Eloquent models
│   ├── Services/          # Business logic services
│   └── Mail/              # Email templates
├── routes/                 # Route definitions
│   ├── api.php            # API routes
│   ├── AdminApi.php       # Admin API routes
│   └── ChefMobileApi.php  # Chef mobile API routes
├── resources/              # Frontend resources
│   ├── js/                # JavaScript/Vue components
│   ├── css/               # Stylesheets
│   └── views/             # Blade templates
├── public/                 # Public assets
│   ├── nuxt_admin/        # Nuxt admin source
│   ├── staging-admin/     # Staging build output
│   └── production-admin/  # Production build output
└── database/               # Migrations and seeders
```

---

## 🔧 Artisan Helper Commands

From the project root, run:

### Staging Build

```bash
php artisan admin-staging
```

This command:
- Runs `npm run staging` inside `public/nuxt_admin`
- Copies build output from `public/nuxt_admin/.output/public` to `public/staging-admin`

### Production Build

```bash
php artisan admin-production
```

This command:
- Runs `npm run production` inside `public/nuxt_admin`
- Copies build output into `public/production-admin`

### Manual Nuxt Build (Optional)

If you prefer manual steps:

1. **Update Nuxt configuration**:
   ```bash
   cd public/nuxt_admin
   # Edit config.js
   ```

2. **Run build**:
   ```bash
   npm run staging
   # or
   npm run production
   ```

3. **Copy output manually**:
   ```bash
   # From public/nuxt_admin/.output/public
   # To public/staging-admin or public/production-admin
   ```

---

## ⚙️ Nuxt Admin Configuration

The Nuxt admin configuration is located at `public/nuxt_admin/config.js`:

```javascript
export default {
    app_name: 'chefshub',

    development: {
        nuxtBaseURL: "",
        apiBaseURL: "http://127.0.0.1:8000/AdminApi"
    },

    staging: {
        nuxtBaseURL: "/staging-admin",
        apiBaseURL: "/AdminApi"
    },

    production: {
        nuxtBaseURL: "/production-admin",
        apiBaseURL: "/AdminApi"
    }
}
```

### ⚠️ Important Notes

- `nuxtBaseURL` must match the deployed folder name
- Relative `apiBaseURL` is recommended for staging & production
- Avoid duplicating keys inside the same environment block

---

## 🏗 Building for Production

### 1. Compile Assets

```bash
npm run build
```

### 2. Optimize Laravel

```bash
php artisan config:cache
php artisan route:cache
php artisan view:cache
```

### 3. Install Production Dependencies

```bash
composer install --optimize-autoloader --no-dev
```

### 4. Build Nuxt Admin

```bash
php artisan admin-production
```

---

## 🚢 Deployment

### Deployment Checklist

Before deploying to staging or production:

- [ ] **Verify `.env` configuration**
  - Database credentials
  - `APP_URL` matches your domain
  - AWS S3 credentials (if using)
  - Mail configuration
  - Stripe keys
  - Firebase credentials

- [ ] **Run migrations**
  ```bash
  php artisan migrate --force
  ```

- [ ] **Ensure writable permissions**
  ```bash
  chmod -R 775 storage/
  chmod -R 775 bootstrap/cache/
  ```

- [ ] **Build and deploy Nuxt Admin**
  ```bash
  php artisan admin-production
  ```

- [ ] **Configure web server** (Nginx / Apache)
  - Set document root to `public/`
  - Configure URL rewriting
  - Set up SSL certificates
  - Configure proper headers for API

### Web Server Configuration

#### Nginx Example

```nginx
server {
    listen 80;
    server_name your-domain.com;
    root /path/to/chefshub-backend/public;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-Content-Type-Options "nosniff";

    index index.php;

    charset utf-8;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    error_page 404 /index.php;

    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
}
```

---

## 🔍 Troubleshooting

### Common Issues

#### Database Connection Error

```bash
# Verify database credentials in .env
# Test connection
php artisan tinker
>>> DB::connection()->getPdo();
```

#### Permission Errors

```bash
# Fix storage and cache permissions
chmod -R 775 storage bootstrap/cache
chown -R www-data:www-data storage bootstrap/cache
```

#### Vite Build Errors

```bash
# Clear node_modules and reinstall
rm -rf node_modules package-lock.json
npm install
```

#### Nuxt Admin Build Fails

```bash
# Navigate to Nuxt admin directory
cd public/nuxt_admin
npm install
npm run production
```

#### Cache Issues

```bash
# Clear all Laravel caches
php artisan cache:clear
php artisan config:clear
php artisan route:clear
php artisan view:clear
```

---

## 📝 Notes

- **Laravel** handles the API and Website
- **Nuxt.js** is used only for Admin Panel
- **Artisan helpers** are the recommended way to deploy Nuxt Admin builds
- The project includes Postman collections for API testing:
  - `ChefHub.postman_collection.json`
  - `ChefHub Mobile.postman_collection.json`
  - `chef mobile.postman_collection.json`

---

## 📄 License

This project is proprietary software developed by ProzTec.

---

## 👥 Support

For issues, questions, or contributions, please contact the development team.

---

**Last Updated**: 2024
