# Stylunique Headless Stack

Migration base for `stylunique.fr` from WooCommerce to a headless architecture.

## Stack

- Storefront: Next.js 16 + TypeScript + Tailwind + Motion
- Commerce backend: Medusa v2 + Stripe provider
- Content CMS: Sanity Studio
- Migration utility: WooCommerce export script

## Repository layout

- `apps/storefront`: customer-facing React storefront
- `apps/commerce`: Medusa backend and admin
- `apps/cms`: Sanity studio (content pages/hero/SEO)
- `scripts/woo-export.mjs`: WooCommerce API export helper

## Prerequisites

- Node.js 20 or 22 (recommended: use `.nvmrc`)
- npm 10+
- PostgreSQL 15+

## 0) Cmd for build

```bash
cd /var/www/stylunique
set -a
source /etc/stylunique/env/storefront.env
set +a
sudo -E -u stylunique npm run build -w @stylunique/storefront
sudo systemctl restart stylunique-storefront
```

```bash
cd /var/www/stylunique
set -a
source /etc/stylunique/env/cms.env
set +a
sudo -H -E -u stylunique npm run build -w @stylunique/cms
sudo rsync -a --delete apps/cms/dist/ /var/www/cms-staging/
sudo systemctl reload apache2
```
```bash
cd /var/www/stylunique
sudo -H -u stylunique npm install
sudo systemctl restart stylunique-commerce
sudo rsync -a --delete apps/cms/dist/ /var/www/cms/
sudo systemctl reload apache2
```
## 1) Install dependencies

```bash
npm install
```

## 2) Configure environment files

- Copy `apps/commerce/.env.example` to `apps/commerce/.env`
- Copy `apps/storefront/.env.example` to `apps/storefront/.env.local`
- Copy `apps/cms/.env.example` to `apps/cms/.env`

## 3) Start Medusa backend

```bash
npm run dev:commerce
```

In another terminal, run seed once:

```bash
npm run seed -w @stylunique/commerce
```

Then create an admin user (if needed):

```bash
npx medusa user -e admin@stylunique.fr -p password -w apps/commerce
```

## 4) Get publishable API key for storefront

- Open Medusa Admin
- Copy the publishable API key
- Set it in `apps/storefront/.env.local` as `NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY`

## 5) Start storefront and CMS

```bash
npm run dev:storefront
npm run dev:cms
```

Or run all apps in parallel:

```bash
npm run dev
```

## Stripe setup

- Add `STRIPE_API_KEY` and `STRIPE_WEBHOOK_SECRET` in `apps/commerce/.env`
- Configure Stripe webhook endpoint to Medusa backend according to Medusa docs
- Activate Stripe payment provider in Medusa admin

## WooCommerce export

1. Copy `.env.woo.example` to `.env.woo`
2. Fill `WOO_KEY` and `WOO_SECRET`
3. Run:

```bash
$env:WOO_URL="https://stylunique.fr"; $env:WOO_KEY="ck_xxx"; $env:WOO_SECRET="cs_xxx"; npm run woo:export
```

Output: `data/woo-export.json`

Use this export to map products/categories/pages into Medusa + Sanity.

## Current storefront routes

- `/` home (Sanity hero + featured products)
- `/boutique` product listing
- `/produits/[handle]` product page with variant + personalization
- `/panier` cart page (Medusa cart API)

# Todo List

## CRO & Tracking
- [ ] Tracking business complet (GA4 + Meta CAPI): `view_item`, `add_to_cart`, `begin_checkout`, `purchase`, abandon tunnel par etape.
- [ ] Checkout ultra-court + wallets: Apple Pay / Google Pay / Link, suppression des champs non essentiels, auto-remplissage.
- [ ] Emails automatiques a fort ROI: abandon panier, abandon checkout, post-achat, relance 7/30 jours.

## Produit & Conversion
- [ ] Avis clients produit (UGC): note + texte + photo, affichage sur PDP et listing.
- [ ] Blocs de conversion PDP: delai estime, retours, "livraison offerte des X EUR", FAQ produit, preuves de confiance.
- [ ] Upsell/Cross-sell intelligents: "souvent achetes ensemble", "complete ton pack", bundle pricing.

## Catalogue & Merchandising
- [ ] Merchandising recherche/categorie: tri "meilleures ventes", boost produits marge/stock, synonymes de recherche.
- [ ] Google Merchant Center + flux produits: Shopping/PMAX + coherence prix/stock.

## SEO & Performance
- [ ] SEO e-commerce avance: Product/Breadcrumb/FAQ schema sur toutes PDP, descriptions uniques, maillage interne fort.
- [ ] Core Web Vitals en objectif business: budget perf (LCP/INP/CLS) + monitoring continu.

## CRM & Experimentation
- [ ] Personnalisation CRM: segments nouveaux vs recurrents, recommandations et offres par comportement.
- [ ] A/B testing continu: PDP (CTA, prix, reassurance), panier, checkout, tri des categories.



## Notes

- `apps/commerce-storefront` may exist from generator artifacts and is intentionally unused.
- Main workspace apps are `storefront`, `commerce`, `cms`.

