# AffiliateHub — Project Structure

Standard Laravel 12 layout. Everything under `database/migrations/` is fully
built in this step; the rest of the tree is scaffolded (folders created) and
gets populated in the following steps, noted inline.

```
affiliatehub/
├── app/
│   ├── Console/                     # Artisan commands (Step 6: payout batch jobs, sitemap gen)
│   ├── Exceptions/                  # Custom exception handling
│   ├── Http/
│   │   ├── Controllers/
│   │   │   ├── Admin/               # Step 4 — Admin CRUD controllers (Users, Products, Withdrawals...)
│   │   │   ├── Affiliate/           # Step 4 — Dashboard, Links, Reports, Withdraw
│   │   │   ├── Auth/                # Step 4 — Breeze/Jetstream auth controllers
│   │   │   └── Api/                 # Step 4 — Sanctum REST API (click tracking, stats)
│   │   ├── Middleware/              # Step 4 — RoleMiddleware, TrackReferral, etc.
│   │   └── Requests/                # Step 4 — Form Request validation, by domain
│   │       ├── Admin/
│   │       ├── Affiliate/
│   │       └── Auth/
│   ├── Models/                      # Step 2 — Eloquent models, one per migration table
│   ├── Providers/                   # Service providers
│   ├── Policies/                    # Step 4 — Authorization policies (ProductPolicy, etc.)
│   ├── Services/                    # Step 4 — Business logic: LinkGenerator, CommissionCalculator
│   ├── Observers/                   # Step 2/4 — Model observers (cached balance sync)
│   └── Notifications/               # Step 5 — Email/DB notifications (withdrawal updates, etc.)
│
├── bootstrap/
│   └── cache/
│
├── config/                          # Step 2 — app.php, database.php, sanctum.php, services.php
│
├── database/
│   ├── migrations/                  # ✅ DONE — 32 migrations, see below
│   ├── seeders/                     # Step 3 — DatabaseSeeder + per-table seeders
│   └── factories/                   # Step 3 — Model factories for realistic fake data
│
├── public/
│   ├── css/                         # Step 7 — compiled/custom CSS
│   ├── js/                          # Step 7 — custom JS (AJAX, counters, filters)
│   ├── images/                      # Static brand/theme assets
│   └── uploads/
│       ├── products/
│       ├── avatars/
│       ├── banners/
│       └── blog/
│
├── resources/
│   ├── views/
│   │   ├── layouts/                 # Step 7 — app.blade.php, guest.blade.php, admin.blade.php
│   │   ├── partials/                # Step 7 — navbar, footer, sidebar
│   │   ├── components/              # Step 7 — Blade components (product-card, stat-card...)
│   │   ├── frontend/
│   │   │   ├── home/  products/  blog/  pages/  auth/
│   │   ├── affiliate/               # Step 7 — dashboard, links, withdraw, reports
│   │   ├── admin/                   # Step 7 — admin panel views
│   │   └── emails/                  # Step 5 — Markdown mail templates
│   ├── css/
│   ├── js/
│   └── lang/en/
│
├── routes/                          # Step 4 — web.php, api.php, admin.php, affiliate.php
│
├── storage/                         # framework/app/logs — Laravel defaults, untouched
│
├── tests/
│   ├── Feature/                     # Step 8 — link tracking, checkout, withdrawal flow tests
│   └── Unit/                        # Step 8 — commission calculation, referral logic
│
└── docs/
    ├── ER-DIAGRAM.md                # ✅ DONE — full schema explanation
    └── FOLDER-STRUCTURE.md          # ✅ this file
```

## Migrations delivered in this step (32 files, run in this order)

| # | File | Table |
|---|------|-------|
| 1 | `..._000001_create_roles_table.php` | roles |
| 2 | `..._000002_create_permissions_table.php` | permissions |
| 3 | `..._000003_create_permission_role_table.php` | permission_role (pivot) |
| 4 | `..._000004_create_users_table.php` | users |
| 5 | `..._000005_create_standard_laravel_tables.php` | password_reset_tokens, sessions, cache, cache_locks, jobs, failed_jobs, personal_access_tokens, notifications |
| 6 | `..._000006_create_categories_table.php` | categories |
| 7 | `..._000007_create_brands_table.php` | brands |
| 8 | `..._000008_create_tags_table.php` | tags |
| 9 | `..._000009_create_products_table.php` | products |
| 10 | `..._000010_create_product_images_table.php` | product_images |
| 11 | `..._000011_create_product_tag_table.php` | product_tag (pivot) |
| 12 | `..._000012_create_product_reviews_table.php` | product_reviews |
| 13 | `..._000013_create_affiliate_links_table.php` | affiliate_links |
| 14 | `..._000014_create_clicks_table.php` | clicks |
| 15 | `..._000015_create_orders_table.php` | orders |
| 16 | `..._000016_create_conversions_table.php` | conversions |
| 17 | `..._000017_create_commissions_table.php` | commissions |
| 18 | `..._000018_create_payment_methods_table.php` | payment_methods |
| 19 | `..._000019_create_withdrawals_table.php` | withdrawals |
| 20 | `..._000020_create_coupons_table.php` | coupons |
| 21 | `..._000021_add_coupon_foreign_key_to_orders_table.php` | (alters orders) |
| 22 | `..._000022_create_banners_table.php` | banners |
| 23 | `..._000023_create_sliders_table.php` | sliders |
| 24 | `..._000024_create_pages_table.php` | pages |
| 25 | `..._000025_create_blog_categories_table.php` | blog_categories |
| 26 | `..._000026_create_blog_posts_table.php` | blog_posts |
| 27 | `..._000027_create_support_tickets_table.php` | support_tickets |
| 28 | `..._000028_create_support_ticket_replies_table.php` | support_ticket_replies |
| 29 | `..._000029_create_newsletter_subscribers_table.php` | newsletter_subscribers |
| 30 | `..._000030_create_settings_table.php` | settings |
| 31 | `..._000031_create_wishlists_table.php` | wishlists |
| 32 | `..._000032_create_activity_logs_table.php` | activity_logs |

## How to use this locally

```bash
composer create-project laravel/laravel affiliatehub
cd affiliatehub
# copy database/migrations/*.php from this delivery into your project's
# database/migrations/, replacing the defaults
php artisan migrate
```

No `composer.json`/vendor files are included — this sandbox has no internet
access, so Laravel itself needs to be installed on your machine where
Composer can reach packagist.org. Everything delivered here is plain PHP you
drop into a real Laravel install.
