# Elohome E-Commerce Platform

A modern, full-stack ecommerce application built with Laravel 11, MySQL, Vue.js/Blade templating, Bootstrap 5/Tailwind CSS, and RESTful architecture. Specially designed for Elohome, an electronics and technology store in Rwanda.

## Features

### Frontend Features
- ✅ Modern, responsive UI with dark/light mode
- ✅ Hero banners and featured products
- ✅ Advanced product search and filtering
- ✅ Product details with image gallery
- ✅ Product reviews and ratings system
- ✅ Wishlist functionality
- ✅ Shopping cart with real-time updates
- ✅ Secure checkout process
- ✅ Multiple payment methods (MTN MoMo, Airtel Money, Card)
- ✅ Order tracking
- ✅ Mobile money payment integration
- ✅ Blog/news section
- ✅ Contact page with WhatsApp integration
- ✅ SEO optimized pages

### Product Categories
- Smartphones
- Laptops
- Tablets
- Accessories
- Smart Watches
- Gaming Products
- Audio Devices
- Repairs & Services

### Admin Panel
- 📊 Analytics dashboard with sales statistics
- 📦 Product management (CRUD operations)
- 🏷️ Category and brand management
- 📊 Inventory/stock management
- 👥 Customer management
- 📋 Order management with status tracking
- 💰 Payment management
- 🎟️ Discount & coupon management
- 🖼️ Banner management
- 📝 Blog management
- 👤 User roles & permissions
- 📋 Activity logs and audit trail
- 🔔 Notifications system

### User Features
- User registration and login
- Social login (Google/Facebook - optional)
- Email verification
- Password reset functionality
- Order history and tracking
- Saved addresses
- Wishlist management
- Product reviews
- Notifications

### Technical Features
- MVC architecture with Laravel best practices
- Laravel authentication with Spatie permissions
- API-ready RESTful structure
- Secure validation and CSRF protection
- Optimized database relationships
- Pagination and filtering
- AJAX capabilities
- Image upload and storage management
- Multi-language support (English/French/Kinyarwanda)
- Currency support (RWF)
- PDF invoice generation
- Email notifications
- SMS notifications (Twilio)
- Activity logging (Spatie)

## Technology Stack

### Backend
- **Laravel 11** - PHP web application framework
- **MySQL 8+** - Database
- **Laravel Sanctum** - API authentication
- **Spatie Permission** - Role-based access control
- **Spatie Activity Log** - Audit logging
- **Barryvdh DomPDF** - PDF generation
- **Intervention Image** - Image processing
- **Maatwebsite Excel** - Excel export

### Frontend
- **Blade Templating** - Server-side rendering
- **Vue.js 3** - Interactive components (optional)
- **Bootstrap 5** - CSS framework
- **Tailwind CSS** - Utility-first CSS
- **Alpine.js** - Lightweight interactivity
- **JavaScript ES6+** - Modern JavaScript

### Additional Services
- **Stripe** - Card payment processing
- **MTN MoMo API** - Mobile money integration
- **Airtel Money API** - Mobile money integration
- **Twilio** - SMS notifications
- **Google & Facebook OAuth** - Social login
- **Laravel Mail** - Email service
- **Redis** - Caching (optional)

## Installation & Setup

### Prerequisites
- PHP 8.2 or higher
- Composer
- MySQL 8.0 or higher
- Node.js 16+ (for frontend tools)
- Git

### Step 1: Clone Repository
```bash
git clone https://github.com/yourusername/elohome-ecommerce.git
cd elohome-ecommerce
```

### Step 2: Install Dependencies
```bash
composer install
npm install
```

### Step 3: Environment Setup
```bash
cp .env.example .env
php artisan key:generate
```

### Step 4: Configure Database
Edit `.env`:
```
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=elohome_ecommerce
DB_USERNAME=root
DB_PASSWORD=
```

Create database:
```bash
mysql -u root -p -e "CREATE DATABASE elohome_ecommerce;"
```

### Step 5: Run Migrations & Seeders
```bash
php artisan migrate
php artisan db:seed
```

This will create all tables and seed with sample data:
- Admin user: `admin@elohome.rw` / `password123`
- Manager user: `manager@elohome.rw` / `password123`
- Sample customers and products

### Step 6: Storage Configuration
```bash
php artisan storage:link
```

### Step 7: Payment Gateway Setup
Add your credentials to `.env`:
```
# Stripe
STRIPE_PUBLIC_KEY=your_public_key
STRIPE_SECRET_KEY=your_secret_key

# MTN MoMo
MTN_MOMO_API_KEY=your_api_key
MTN_MOMO_SUBSCRIPTION_KEY=your_subscription_key

# Airtel Money
AIRTEL_API_KEY=your_api_key
AIRTEL_API_SECRET=your_secret

# Twilio (for SMS)
TWILIO_ACCOUNT_SID=your_account_sid
TWILIO_AUTH_TOKEN=your_auth_token
TWILIO_PHONE_NUMBER=your_phone_number
```

### Step 8: Compile Frontend Assets
```bash
npm run dev    # Development
npm run build  # Production
```

### Step 9: Start Development Server
```bash
php artisan serve
```

Access the application at: `http://localhost:8000`

## Initial Access

### Admin Panel
- URL: `http://localhost:8000/admin/dashboard`
- Email: `admin@elohome.rw`
- Password: `password123`

### Customer Account
- URL: `http://localhost:8000`
- Sample customer email: `john@example.com`
- Password: `password123`

## Project Structure

```
├── app/
│   ├── Http/
│   │   ├── Controllers/
│   │   │   ├── Auth/
│   │   │   ├── Admin/
│   │   │   └── ...
│   │   ├── Middleware/
│   │   └── Requests/
│   ├── Models/
│   ├── Services/
│   └── Providers/
├── database/
│   ├── migrations/
│   ├── seeders/
│   └── factories/
├── routes/
│   ├── web.php
│   ├── api.php
│   └── console.php
├── resources/
│   ├── views/
│   │   ├── components/
│   │   ├── layouts/
│   │   ├── admin/
│   │   └── ...
│   ├── css/
│   └── js/
├── public/
├── storage/
└── config/
```

## Database Schema

### Core Tables
- **users** - User accounts
- **roles & permissions** - Access control (Spatie)
- **products** - Product catalog
- **categories** - Product categories
- **brands** - Product brands
- **product_images** - Product image gallery
- **orders** - Customer orders
- **order_items** - Order line items
- **payments** - Payment records
- **carts** - Shopping carts
- **wishlist_items** - User wishlists
- **reviews** - Product reviews and ratings
- **addresses** - Shipping/billing addresses
- **coupons** - Discount coupons
- **banners** - Promotional banners
- **blogs** - Blog/news posts
- **notifications** - User notifications
- **activity_log** - Audit trail (Spatie)

## API Endpoints

### Public Endpoints
- `GET /api/products` - List products
- `GET /api/products/{product}` - Get product details
- `GET /api/products/{product}/images` - Get product images
- `GET /api/products/{product}/related` - Get related products
- `GET /api/products/{product}/reviews` - Get product reviews

### Protected Endpoints (Requires Auth Token)
- `POST /api/cart` - Add to cart
- `GET /api/cart` - Get cart items
- `PUT /api/cart/{item}` - Update cart item
- `DELETE /api/cart/{item}` - Remove from cart
- `POST /api/orders` - Create order
- `GET /api/orders` - List user orders
- `GET /api/orders/{order}` - Get order details
- `DELETE /api/orders/{order}` - Cancel order

## Admin Routes

```
GET  /admin/dashboard              - Admin dashboard
GET  /admin/products               - List products
POST /admin/products               - Create product
GET  /admin/products/{id}/edit     - Edit product
PUT  /admin/products/{id}          - Update product
DELETE /admin/products/{id}        - Delete product
```

## User Roles & Permissions

### Admin
- Full access to all features
- Can manage all users and content
- Access to analytics and reports

### Manager
- Product management
- Order management
- User management
- View analytics
- Category and brand management

### Support
- View and manage orders
- Manage customer support tickets
- View user information

### Customer
- Browse products
- Create orders
- Leave reviews
- Manage account and addresses

## Configuration Files

Key configuration files to check:

### app/config/
- `app.php` - Application settings
- `database.php` - Database connections
- `mail.php` - Email configuration
- `filesystems.php` - Storage configuration
- `services.php` - Third-party APIs

## Deployment

### Production Deployment Checklist
1. Set `APP_ENV=production` in `.env`
2. Set `APP_DEBUG=false` in `.env`
3. Run `php artisan config:cache`
4. Run `php artisan route:cache`
5. Run `php artisan view:cache`
6. Set up proper database backups
7. Configure HTTPS/SSL certificate
8. Set up proper file permissions
9. Configure email service
10. Set up error logging (Sentry, etc.)

### Database Backup
```bash
mysqldump -u root -p elohome_ecommerce > backup.sql
```

## Customization Guide

### Adding New Payment Gateway
1. Create service class in `app/Services/Payments/`
2. Implement `PaymentInterface`
3. Add to payment controller logic
4. Update migrations if needed

### Adding New Product Category
1. Add category via admin panel
2. Update category seeder if needed
3. Products automatically categorized

### Custom Email Templates
- Located in `resources/views/emails/`
- Customize newsletter, order confirmation, etc.

## Troubleshooting

### Common Issues

**Migration Errors**
```bash
php artisan migrate:rollback
php artisan migrate
```

**Permission Errors**
```bash
sudo chown -R www-data:www-data storage bootstrap/cache
chmod -R 775 storage bootstrap/cache
```

**Storage Link Issues**
```bash
php artisan storage:link
```

**Cache Issues**
```bash
php artisan cache:clear
php artisan config:clear
```

**Database Connection Failed**
- Verify MySQL is running
- Check `.env` database credentials
- Ensure database exists

## Support & Contributing

For support, contact: support@elohome.rw

To contribute:
1. Fork the repository
2. Create your feature branch
3. Commit your changes
4. Push to the branch
5. Create a Pull Request

## License

This project is licensed under the MIT License - see LICENSE file for details.

## Author

Developed by Elohome Development Team
- Website: www.elohome.rw
- Email: support@elohome.rw
- WhatsApp: +250 788 123 456

## Version History

### v1.0.0 (Current)
- Initial release
- Core ecommerce functionality
- Admin panel
- Payment integration
- Product management
- Order management
- User accounts and profiles

---

**Last Updated:** May 2026
**Status:** Production Ready
