# Database Schema

## Identity and Authorization

- `users`: customers and staff accounts.
- `roles`, `permissions`, `role_user`, `permission_role`: Super Admin, Administrator, Order Manager, Picker/Packer and Inventory Manager access.
- `customer_addresses`: saved customer delivery addresses.

## Catalogue

- `categories`: parent/child grocery categories with homepage visibility.
- `brands`: supplier-facing brands with featured flags.
- `products`: primary catalogue records with SKU, barcode, price, special price windows, stock, VAT, SEO and product flags.
- `product_variants`: optional variant-level SKU, barcode, price, special price, stock and image.
- `product_images`: gallery images.

## Cart and Wishlist

- `carts`, `cart_items`: user or session cart data.
- `wishlists`, `wishlist_items`: saved grocery items.

## Checkout, Delivery and Promotions

- `delivery_zones`, `delivery_zone_areas`: admin-managed delivery fees, free delivery thresholds, suburbs and postcodes.
- `delivery_slots`: delivery windows, available days, blocked dates and max order capacity.
- `coupons`, `coupon_product`, `coupon_category`, `coupon_usages`: promotional code rules and usage tracking.

## Orders and Payments

- `orders`: customer details, statuses, delivery selections, substitution preferences and calculated totals.
- `order_items`: permanent product snapshots, prices, VAT, discounts and line totals.
- `order_addresses`: permanent delivery address snapshot.
- `order_status_history`: customer-visible and internal status timeline.
- `payments`: payment attempts and transaction IDs.
- `payment_events`: idempotency ledger for PayFast ITN/webhook events.

## Inventory

- `stock_reservations`: temporary stock holds while payment is pending.
- `inventory_transactions`: stock ledger for reservations, releases, sales, returns, damage and manual corrections.

## CMS and Operations

- `banners`: scheduled homepage hero banners.
- `settings`: editable grouped store settings.
- `pages`: manageable static content pages.
- `contact_enquiries`: saved contact form messages.
- `audit_logs`: important admin actions with before/after payloads.
