# Stile Energy LPG App

A complete **LPG Gas Delivery** platform with a **PHP + MySQL** backend and **React Native** mobile app.

---

## Project Structure

```
lpg-app-2/
├── backend/                   ← PHP REST API
│   ├── index.php              ← Entry point / router
│   ├── .htaccess              ← Apache URL rewriting
│   ├── config/
│   │   └── database.php       ← MySQL connection (PDO)
│   ├── middleware/
│   │   └── auth.php           ← JWT auth + helpers
│   └── api/
│       ├── auth/
│       │   ├── login.php      ← POST /api/auth/login
│       │   └── register.php   ← POST /api/auth/register
│       ├── customer/
│       │   ├── products/
│       │   │   └── list.php   ← GET /api/customer/products
│       │   ├── orders/
│       │   │   ├── place-order.php  ← POST /api/customer/orders/place
│       │   │   └── my-orders.php    ← GET  /api/customer/orders
│       │   └── profile.php    ← GET/PATCH /api/customer/profile
│       ├── admin/
│       │   ├── products/index.php ← GET/POST/PATCH/DELETE /api/admin/products
│       │   ├── orders/index.php   ← GET/PATCH /api/admin/orders
│       │   ├── users/index.php    ← GET /api/admin/users
│       │   ├── gallery/index.php  ← GET/POST/PATCH/DELETE /api/admin/gallery
│       │   ├── messages/index.php ← GET/PATCH /api/admin/messages
│       │   └── stats/index.php    ← GET /api/admin/stats
│       └── public/
│           ├── gallery.php    ← GET /api/gallery (public)
│           └── contact.php    ← POST /api/contact (public)
├── database/
│   └── schema.sql             ← MySQL schema + seed admin user
└── mobile/                    ← React Native app
    ├── src/
    │   ├── App.tsx
    │   ├── types/index.ts
    │   ├── services/api.ts    ← All API calls (axios)
    │   ├── navigation/AppNavigator.tsx
    │   ├── components/
    │   │   ├── ProductCard.tsx
    │   │   └── OrderCard.tsx
    │   └── screens/
    │       ├── auth/
    │       │   ├── Login.tsx
    │       │   └── Register.tsx
    │       ├── customer/
    │       │   ├── Home.tsx
    │       │   ├── ProductList.tsx
    │       │   ├── Cart.tsx
    │       │   ├── MyOrders.tsx
    │       │   └── Profile.tsx
    │       └── admin/
    │           ├── AdminDashboard.tsx
    │           ├── AddProduct.tsx    (includes edit + delete)
    │           ├── ManageOrders.tsx
    │           └── ManageUsers.tsx
    ├── package.json
    └── tsconfig.json
```

---

## Backend Setup (PHP + MySQL)

### Requirements
- PHP 8.0+
- MySQL 8.0+
- Apache with `mod_rewrite` enabled

### Steps

1. **Import the database:**
   ```bash
   mysql -u root -p < database/schema.sql
   ```

2. **Configure database credentials** in `backend/config/database.php`:
   ```php
   define('DB_HOST', 'localhost');
   define('DB_NAME', 'stile_lpg');
   define('DB_USER', 'your_user');
   define('DB_PASS', 'your_password');
   ```

3. **Change JWT secret** in `backend/middleware/auth.php`:
   ```php
   define('JWT_SECRET', 'your_very_long_random_secret_here');
   ```

4. **Point Apache virtual host** to `backend/` folder.

5. **Default admin login:**
   - Email: `admin@stilenergy.com`
   - Password: `admin123`

---

## Mobile App Setup (React Native)

```bash
cd mobile
npm install
npx expo start
```

Update the backend URL in `src/services/api.ts`:
```typescript
export const BASE_URL = 'http://YOUR_SERVER_IP/stile-lpg/backend';
```

---

## API Endpoints

| Method | Endpoint | Auth | Description |
|--------|----------|------|-------------|
| POST | `/api/auth/login` | None | Login, returns JWT token |
| POST | `/api/auth/register` | None | Register new customer |
| GET | `/api/customer/products` | Customer | List active products |
| POST | `/api/customer/orders/place` | Customer | Place COD order |
| GET | `/api/customer/orders` | Customer | My orders |
| GET/PATCH | `/api/customer/profile` | Customer | Get/update profile |
| GET | `/api/admin/stats` | Admin | Dashboard stats |
| GET/POST/PATCH/DELETE | `/api/admin/products` | Admin | Manage products |
| GET/PATCH | `/api/admin/orders` | Admin | Manage orders |
| GET | `/api/admin/users` | Admin | View customers |
| GET/POST/PATCH/DELETE | `/api/admin/gallery` | Admin | Manage gallery |
| GET/PATCH | `/api/admin/messages` | Admin | View/read messages |
| GET | `/api/gallery` | None | Public gallery |
| POST | `/api/contact` | None | Send contact message |

---

## Payment

**Cash on Delivery only** — Stripe and Flutterwave have been completely removed.
All orders are placed with `payment_method = 'cod'`.
