# RoutexShipping - Global Logistics Platform

A complete, production-ready logistics and parcel tracking platform built with HTML5, Tailwind CSS, Vanilla JavaScript, PHP, and MySQL.

## Features
 
### Frontend
- **Modern, Responsive Design** - Mobile-first approach with Tailwind CSS
- **Professional Homepage** - Hero section, services, testimonials, and CTA
- **Speedaf-Style Tracking Page** - Real-time parcel tracking with timeline and status updates
- **About & Services Pages** - Comprehensive company information
- **Contact Form** - With CSRF protection and email notifications
- **Live Chat Widget** - Floating chat button on all pages

### Backend
- **Admin Panel** - Secure login and dashboard
- **Parcel Management** - Create, edit, delete parcels with full tracking
- **Review Management** - Manage customer testimonials
- **Email Notifications** - Automated emails on parcel creation/updates
- **Email Logs** - Track all sent emails
- **System Settings** - Configure company info and SMTP settings

### Database
- **MySQL Database** - Fully normalized schema with proper relationships
- **PDO Prepared Statements** - SQL injection protection
- **Automatic Tracking Codes** - Unique, non-editable codes (ROU132AD456TEX format)
- **Timeline History** - Complete update history for each parcel

### Security
- **CSRF Protection** - Token-based CSRF prevention
- **Password Hashing** - Bcrypt password hashing
- **Input Sanitization** - All user inputs sanitized
- **Secure File Uploads** - Type and size validation
- **Session Security** - HTTPOnly and secure session cookies

## Installation

### Prerequisites
- PHP 7.4+
- MySQL 5.7+
- Apache with mod_rewrite enabled
- Composer (optional, for future enhancements)

### Setup Steps

1. **Clone/Extract the project** to your web root:
   ```bash
   cd c:\xampp\htdocs\routex
   ```

2. **Create MySQL Database**:
   ```sql
   CREATE DATABASE routex_shipping CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
   ```

3. **Initialize Database Schema**:
   - Open your browser and navigate to: `http://localhost/routex/config/init_db.php`
   - This will create all tables and insert default admin user

4. **Create Uploads Directory**:
   ```bash
   mkdir uploads
   chmod 755 uploads
   ```

5. **Configure Database** (if needed):
   - Edit `config/database.php`
   - Update DB_HOST, DB_USER, DB_PASS, DB_NAME if different

6. **Access the Application**:
   - **Frontend**: `http://localhost/routex/`
   - **Admin Panel**: `http://localhost/routex/admin/login`
   - **Default Credentials**: 
     - Username: `admin`
     - Password: `admin123`

## Project Structure

```
routex/
├── config/
│   ├── database.php          # Database configuration
│   └── init_db.php           # Database initialization script
├── app/
│   ├── Utils.php             # Utility functions
│   ├── Models/
│   │   ├── Admin.php         # Admin model
│   │   ├── Parcel.php        # Parcel model
│   │   └── Review.php        # Review model
│   └── Services/
│       └── EmailService.php  # Email service
├── pages/
│   ├── home.php              # Homepage
│   ├── track.php             # Tracking page
│   ├── about.php             # About page
│   ├── services.php          # Services page
│   ├── contact.php           # Contact page
│   ├── 404.php               # 404 page
│   └── admin/
│       ├── login.php         # Admin login
│       ├── dashboard.php     # Admin dashboard
│       ├── parcels.php       # Parcel management
│       ├── parcel-create.php # Create parcel
│       ├── parcel-edit.php   # Edit parcel
│       ├── reviews.php       # Review management
│       ├── review-create.php # Create review
│       ├── review-edit.php   # Edit review
│       ├── email-logs.php    # Email logs
│       ├── settings.php      # System settings
│       └── logout.php        # Logout
├── includes/
│   ├── header.php            # Header component
│   └── footer.php            # Footer component
├── uploads/                  # User uploads directory
├── index.php                 # Main router
├── .htaccess                 # Apache rewrite rules
└── README.md                 # This file
```

## Database Schema

### Tables
- **admins** - Admin users
- **parcels** - Parcel information
- **parcel_updates** - Parcel status timeline
- **reviews** - Customer testimonials
- **email_logs** - Email sending logs
- **settings** - System configuration

## Usage

### Creating a Parcel
1. Login to admin panel
2. Click "Create Parcel"
3. Fill in sender and receiver details
4. Set package information and service type
5. Submit - tracking code is auto-generated
6. Notification email sent to receiver

### Tracking a Parcel
1. Go to homepage or `/track` page
2. Enter tracking code
3. View real-time status, timeline, and location
4. See all updates and delivery history

### Managing Reviews
1. Login to admin panel
2. Go to "Manage Reviews"
3. Create, edit, or delete reviews
4. Mark reviews as "Featured" to show on homepage

### Email Configuration
1. Go to Admin > Settings
2. Configure SMTP settings
3. Enter your email provider credentials
4. Test by creating a parcel

## Features in Detail

### Tracking Code Generation
- Format: `ROU` + 11 random alphanumeric characters
- Example: `ROU132AD456TEX`
- Unique and non-editable
- Stored securely in database

### Email Notifications
- Sent when parcel is created
- Sent when parcel status is updated
- HTML formatted with company branding
- Includes tracking link
- Logged in email_logs table

### Admin Dashboard
- Real-time statistics
- Quick action buttons
- Parcel management
- Review management
- Email logs
- System settings

### Security Features
- PDO prepared statements prevent SQL injection
- CSRF tokens on all forms
- Password hashing with bcrypt
- Input sanitization
- File upload validation
- Session security

## Customization

### Branding
- Edit company name in `config/database.php`
- Update colors in `includes/header.php` (CSS variables)
- Replace logo in header/footer

### Email Templates
- Edit email template in `app/Services/EmailService.php`
- Customize subject lines
- Add company branding

### Database
- Add new fields to parcels table
- Create custom reports
- Add new admin features

## Troubleshooting

### Database Connection Error
- Check MySQL is running
- Verify credentials in `config/database.php`
- Ensure database exists

### Email Not Sending
- Check SMTP settings in admin panel
- Verify email provider credentials
- Check email_logs for errors
- Ensure PHP mail() is enabled

### File Upload Issues
- Check uploads directory permissions (755)
- Verify file size limits
- Check allowed file types

### 404 Errors
- Ensure mod_rewrite is enabled
- Check .htaccess file exists
- Verify Apache configuration

## Performance Tips

1. **Database Optimization**
   - Add indexes on frequently queried columns
   - Archive old email logs regularly
   - Optimize parcel_updates queries

2. **Caching**
   - Implement Redis for session storage
   - Cache featured reviews
   - Cache static assets

3. **File Uploads**
   - Compress images on upload
   - Implement CDN for uploads
   - Clean up old uploads regularly

## Future Enhancements

- [ ] Payment gateway integration
- [ ] SMS notifications
- [ ] Real Google Maps integration
- [ ] Advanced reporting
- [ ] API for third-party integrations
- [ ] Mobile app
- [ ] Multi-language support
- [ ] Advanced analytics

## Support

For issues or questions:
1. Check the troubleshooting section
2. Review database schema
3. Check error logs
4. Verify configuration

## License

This project is provided as-is for educational and commercial use.

## Credits

Built with:
- Tailwind CSS
- Font Awesome Icons
- PHP PDO
- MySQL

---

**Version**: 1.0.0  
**Last Updated**: 2024  
**Status**: Production Ready
