# 🚀 Toasty — Initialisation complète

## Structure générée

Cette initialisation crée la structure complète du projet Toasty selon `CLAUDE.md`.

### ✅ Dossiers créés (28)

**Backend PHP**
```
app/
├── Auth/
├── Controllers/
│   ├── Admin/
│   ├── Api/
│   └── Shopify/
├── Helpers/
├── Jobs/
├── Middleware/
├── Models/
└── Services/

config/
public/api/
├── auth/
├── admin/
├── shopify/
└── push/
```

**Frontend React**
```
src/
├── admin/
│   ├── layout/
│   ├── pages/
│   ├── partials/
│   ├── snippets/
│   └── styles/
├── shopify-app/
│   ├── components/
│   ├── pages/
│   └── styles/
└── shared/
    ├── components/
    ├── hooks/
    └── styles/
```

**Infrastructure**
```
storage/
├── logs/
├── cache/
└── queue/

scripts/migrations/
tests/
```

### ✅ Fichiers générés (45+)

#### Configuration (4)
- `.env.example` → Toutes les variables d'environnement
- `composer.json` → Dépendances PHP
- `package.json` → Dépendances Node.js
- `vite.config.js` → Config Vite (double entrée)

#### Helpers PHP (4)
- `app/Helpers/response.php` → `json_response()`
- `app/Helpers/db.php` → Singleton PDO
- `app/Helpers/jwt.php` → JWT encode/decode
- `app/Helpers/env.php` → Lecture `.env`

#### Middlewares (2)
- `app/Middleware/auth.php` → Vérification JWT
- `app/Middleware/shopify_hmac.php` → Vérification HMAC Shopify

#### Services (3)
- `app/Services/TwoFactorService.php` → 2FA (code 6 chiffres, TTL 10 min)
- `app/Services/PushService.php` → Queue push + VAPID/FCM stubs
- `app/Services/ShopifyService.php` → API Shopify (shop, webhooks, customers)

#### API Router (6)
- `public/api/index.php` → Router principal (dispatch auth/admin/shopify/push)
- `public/api/auth/index.php` → Login + 2FA verification
- `public/api/admin/index.php` → Dashboard + Profile (protégé JWT)
- `public/api/shopify/index.php` → Install + Webhooks (HMAC)
- `public/api/push/index.php` → Subscribe + Unsubscribe
- `public/index.php` → Autoloader PSR-4

#### Frontend React (15+)
- `src/admin/main.jsx` → Point d'entrée admin
- `src/admin/App.jsx` → Composant root admin
- `src/admin/layout/Header.jsx` → Header navigation
- `src/admin/pages/Dashboard.jsx` → Dashboard page
- `src/admin/partials/PageHeader.jsx` → Partial en-tête page
- `src/admin/snippets/StatCard.jsx` → Snippet card statistique
- `src/admin/styles/index.css` → Styles admin
- `src/shopify-app/main.jsx` → Point d'entrée Shopify app
- `src/shopify-app/App.jsx` → Composant root Shopify
- `src/shopify-app/pages/Campaigns.jsx` → Page campagnes (Polaris)
- `src/shopify-app/components/SubscriberList.jsx` → Composant subscribers
- `src/shopify-app/styles/index.css` → Styles Shopify app
- `src/shared/hooks/useFetch.js` → Hook API générique
- `src/shared/components/styles.css` → Styles partagés
- HTML entry points (`public/admin/index.html` + `public/app/index.html`)

#### Push & Utils (3)
- `public/sw.js` → Service Worker (push notifications)
- `tests/ExampleTest.php` → Placeholder tests
- `scripts/migrations/001_initial_schema.sql` → Placeholder migrations

### ✅ Architecture API

```
/api/auth
  POST /login              → Envoie code 2FA par email
  POST /verify-2fa         → Valide code → JWT token
  GET  /logout             → Client-side

/api/admin (protégé JWT)
  GET  /dashboard          → Stats (shops, campaigns, subscribers)
  GET  /profile            → Profil admin
  PUT  /profile            → Mise à jour profil

/api/shopify (protégé HMAC)
  POST /install            → Installer l'app Shopify
  POST /webhooks/*         → Webhooks Shopify (orders, customers)

/api/push
  POST /subscribe          → S'abonner aux notifications
  POST /unsubscribe        → Se désabonner
```

### ✅ Stack confirmée

| Couche | Technologie |
|--------|-------------|
| Backend | PHP 8.1+ (routing custom, PDO natif) |
| Admin Frontend | React 18 + Vite |
| Shopify App | React 18 + Polaris + App Bridge |
| DB | MySQL (requêtes préparées) |
| Auth | JWT + 2FA email (6 chiffres, TTL 10 min) |
| Push | VAPID (web) + FCM (mobile) |
| Queue | Redis |

### 📋 Prochaines étapes

1. **Schéma MySQL complet**
   - Tables: shops, admins, subscribers, campaigns, notifications, push_queue, admin_2fa, billing
   - Indexes, contraintes, relations

2. **Services PHP avancés**
   - Implémentation VAPID signature JWT
   - Firebase Cloud Messaging (FCM)
   - Email 2FA (Mailtrap)
   - Redis workers

3. **Flow OAuth Shopify**
   - Installation app
   - Webhooks setup
   - Permissions

4. **Panel Admin complet**
   - Dashboard avec stats
   - Gestion campagnes
   - Gestion abonnés

5. **App Shopify Polaris**
   - Settings
   - Campaign creation
   - Analytics

---

**État** : ✅ Structure prête
**Prochaine étape** : Schéma MySQL (voir MEMORY.md)
