]> git.digitality.be Git - pdw25-26/commitdiff
feat(gateway): ajout gateway + demo kit microservices
authorSteph Ponzo <ponzo.stephane2@gmail.com>
Thu, 26 Feb 2026 13:31:16 +0000 (14:31 +0100)
committerSteph Ponzo <ponzo.stephane2@gmail.com>
Thu, 26 Feb 2026 13:31:16 +0000 (14:31 +0100)
Wallette/.env.example [new file with mode: 0644]
Wallette/README-DEMO.md [new file with mode: 0644]
Wallette/start-all.bat [new file with mode: 0644]
Wallette/start-all.ps1 [new file with mode: 0644]

diff --git a/Wallette/.env.example b/Wallette/.env.example
new file mode 100644 (file)
index 0000000..f7be18a
--- /dev/null
@@ -0,0 +1,55 @@
+# =========================================================
+# CONFIGURATION WALL-E-TTE - MICROSERVICES
+# =========================================================
+# Copie ce fichier en .env dans Wallette/server/ :
+#   cp .env.example Wallette/server/.env
+# =========================================================
+
+# ─────────────────────────────────────────────────────────
+# PORTS DES SERVICES
+# ─────────────────────────────────────────────────────────
+GATEWAY_PORT=3000
+PRICE_PORT=3001
+STRATEGY_PORT=3002
+ALERTS_PORT=3003
+
+# ─────────────────────────────────────────────────────────
+# URLs INTERNES (utilisées par le gateway)
+# ─────────────────────────────────────────────────────────
+PRICE_BASE_URL=http://127.0.0.1:3001
+STRATEGY_BASE_URL=http://127.0.0.1:3002
+ALERTS_BASE_URL=http://127.0.0.1:3003
+
+# ─────────────────────────────────────────────────────────
+# BASE DE DONNÉES
+# ─────────────────────────────────────────────────────────
+DB_HOST=students2.promotion-sociale-marche.be
+DB_PORT=3306
+DB_NAME=wallette
+DB_USER=walletteuser
+DB_PASS=
+
+# ─────────────────────────────────────────────────────────
+# EMAIL (Nodemailer / Mailtrap)
+# ─────────────────────────────────────────────────────────
+MAIL_HOST=sandbox.smtp.mailtrap.io
+MAIL_PORT=2525
+MAIL_USER=
+MAIL_PASS=
+
+# ─────────────────────────────────────────────────────────
+# TELEGRAM (optionnel)
+# ─────────────────────────────────────────────────────────
+TELEGRAM_BOT_TOKEN=
+TELEGRAM_CHAT_ID=
+
+# ─────────────────────────────────────────────────────────
+# DISCORD (optionnel)
+# ─────────────────────────────────────────────────────────
+DISCORD_WEBHOOK_URL=
+
+# ─────────────────────────────────────────────────────────
+# SERVEUR
+# ─────────────────────────────────────────────────────────
+NODE_ENV=development
+PORT=3000
diff --git a/Wallette/README-DEMO.md b/Wallette/README-DEMO.md
new file mode 100644 (file)
index 0000000..3f8c1ec
--- /dev/null
@@ -0,0 +1,172 @@
+# Wall-e-tte — Guide de démo (Architecture Micro-services)
+
+## Architecture
+
+```
+ FRONTEND (navigateur)
+     │
+     │  (toutes les requêtes passent par ici)
+     ▼
+ GATEWAY :3000          ← point d'entrée unique
+ gateway/gateway.js
+     │
+     ├──► PRICE SERVICE :3001
+     │    server/modules/price/server.js
+     │    /api/price/*  /api/pairs
+     │
+     ├──► ALERTS SERVICE :3003
+     │    server/modules/alerts/server.js
+     │    /api/alerts/*
+     │
+     └──► STRATEGY SERVICE :3002  (stub → 502 si absent)
+          server/modules/strategy/server.js
+```
+
+---
+
+## ⚡ Démarrage rapide
+
+### Étape 1 — Copier la configuration
+
+```bash
+# Depuis le dossier Wallette/
+cp .env.example server/.env
+```
+
+Puis ouvrir `server/.env` et remplir les vraies valeurs (DB_PASS, MAIL_USER, etc.)
+
+### Étape 2 — Installer les dépendances
+
+```bash
+# Service principal (alerts + config)
+cd server
+npm install
+
+# Gateway
+cd ../gateway
+npm install
+```
+
+> Le price-service utilise le même `node_modules` que `server/`.
+
+### Étape 3 — Lancer tous les services
+
+**Windows (double-cliquer) :**
+```
+start-all.bat
+```
+
+**PowerShell :**
+```powershell
+.\start-all.ps1
+```
+
+**Manuel (4 terminaux séparés) :**
+```bash
+# Terminal 1 - Price service
+cd server && node modules/price/server.js
+
+# Terminal 2 - Alerts service
+cd server && node modules/alerts/server.js
+
+# Terminal 3 - Gateway
+cd gateway && node gateway.js
+
+# Terminal 4 - (optionnel) Strategy
+cd server && node modules/strategy/server.js
+```
+
+---
+
+## ✅ Vérification
+
+### Gateway health check
+```bash
+curl http://localhost:3000/api/gateway/health
+```
+→ Doit retourner l'état de chaque service.
+
+### Table de routing
+```bash
+curl http://localhost:3000/api/gateway/routes
+```
+
+### Tests prix (via gateway)
+```bash
+curl "http://localhost:3000/api/price/current?pair=BTC/EUR"
+curl "http://localhost:3000/api/price/history?pair=BTC/EUR&limit=10"
+curl "http://localhost:3000/api/pairs"
+```
+
+### Tests alertes (via gateway)
+```bash
+curl "http://localhost:3000/api/alerts?userId=1"
+curl -X POST "http://localhost:3000/api/alerts" \
+  -H "Content-Type: application/json" \
+  -d '{"userId":1,"pair":"BTC/EUR","condition":"ABOVE","threshold":50000}'
+```
+
+### Test strategy (service absent → 502 attendu)
+```bash
+curl http://localhost:3000/api/strategy/signals
+# → {"ok":false,"error":{"code":"UPSTREAM_DOWN","message":"strategy-service unavailable"}}
+```
+
+---
+
+## 🎯 WOW DEMO — Résilience du gateway
+
+### Scénario : couper et relancer le price-service
+
+**1. Tout fonctionne normalement**
+```bash
+curl "http://localhost:3000/api/price/current?pair=BTC/EUR"
+# → { "ok": true, "data": { ... } }
+```
+
+**2. Fermer la fenêtre "price-service :3001"**
+```bash
+curl "http://localhost:3000/api/price/current?pair=BTC/EUR"
+# → HTTP 502
+# → { "ok": false, "error": { "code": "UPSTREAM_DOWN", "message": "price-service unavailable" } }
+```
+
+**3. Les alertes continuent de fonctionner !**
+```bash
+curl "http://localhost:3000/api/alerts?userId=1"
+# → { "ok": true, "data": { ... } }   ← alerts-service toujours up
+```
+
+**4. Relancer le price-service**
+```bash
+# Dans un terminal :
+cd server && node modules/price/server.js
+```
+```bash
+curl "http://localhost:3000/api/price/current?pair=BTC/EUR"
+# → { "ok": true, "data": { ... } }   ← récupération automatique !
+```
+
+---
+
+## 📝 Ports utilisés
+
+| Service           | Port | Fichier de démarrage                          |
+|-------------------|------|-----------------------------------------------|
+| Gateway           | 3000 | `gateway/gateway.js`                          |
+| Price Service     | 3001 | `server/modules/price/server.js`              |
+| Strategy Service  | 3002 | `server/modules/strategy/server.js` (à créer) |
+| Alerts Service    | 3003 | `server/modules/alerts/server.js`             |
+
+---
+
+## 🔧 Variables d'environnement importantes
+
+| Variable           | Défaut                   | Description                    |
+|--------------------|--------------------------|--------------------------------|
+| `GATEWAY_PORT`     | `3000`                   | Port du gateway                |
+| `PRICE_PORT`       | `3001`                   | Port du price-service          |
+| `ALERTS_PORT`      | `3003`                   | Port du alerts-service         |
+| `PRICE_BASE_URL`   | `http://127.0.0.1:3001`  | URL upstream prix (gateway)    |
+| `ALERTS_BASE_URL`  | `http://127.0.0.1:3003`  | URL upstream alertes (gateway) |
+| `STRATEGY_BASE_URL`| `http://127.0.0.1:3002`  | URL upstream strategy (gateway)|
diff --git a/Wallette/start-all.bat b/Wallette/start-all.bat
new file mode 100644 (file)
index 0000000..04f1710
--- /dev/null
@@ -0,0 +1,52 @@
+@echo off
+REM =========================================================
+REM  WALL-E-TTE - Démarrage de tous les micro-services
+REM  NE REQUIERT PAS de droits administrateur
+REM =========================================================
+REM  Ouvre 4 terminaux :
+REM   1) price-service   (port 3001)
+REM   2) alerts-service  (port 3003)
+REM   3) gateway         (port 3000)
+REM  (strategy-service ignoré s'il n'existe pas)
+REM =========================================================
+
+SET ROOT=%~dp0
+
+echo [Wall-e-tte] Demarrage des services...
+
+REM ─── PRICE SERVICE (port 3001) ───────────────────────────
+start "price-service :3001" cmd /k "cd /d %ROOT%server && echo [price-service] Demarrage... && node --experimental-vm-modules modules/price/server.js"
+
+REM Petite pause pour laisser le service démarrer
+timeout /t 2 /nobreak >nul
+
+REM ─── ALERTS SERVICE (port 3003) ──────────────────────────
+start "alerts-service :3003" cmd /k "cd /d %ROOT%server && echo [alerts-service] Demarrage... && node modules/alerts/server.js"
+
+REM Petite pause
+timeout /t 2 /nobreak >nul
+
+REM ─── STRATEGY SERVICE (port 3002) ─ optionnel ────────────
+IF EXIST "%ROOT%server\modules\strategy\server.js" (
+    start "strategy-service :3002" cmd /k "cd /d %ROOT%server && echo [strategy-service] Demarrage... && node modules/strategy/server.js"
+    timeout /t 2 /nobreak >nul
+) ELSE (
+    echo [strategy-service] Non trouve - le gateway retournera 502 pour /api/strategy/*
+)
+
+REM ─── GATEWAY (port 3000) ─────────────────────────────────
+start "gateway :3000" cmd /k "cd /d %ROOT%gateway && echo [gateway] Demarrage... && node gateway.js"
+
+echo.
+echo [Wall-e-tte] Tous les services ont ete lances !
+echo.
+echo  Gateway  : http://localhost:3000
+echo  Price    : http://localhost:3001
+echo  Alerts   : http://localhost:3003
+echo.
+echo  Tests rapides :
+echo    curl http://localhost:3000/api/gateway/health
+echo    curl http://localhost:3000/api/price/current?pair=BTC/EUR
+echo    curl http://localhost:3000/api/alerts?userId=1
+echo.
+pause
diff --git a/Wallette/start-all.ps1 b/Wallette/start-all.ps1
new file mode 100644 (file)
index 0000000..6a978e2
--- /dev/null
@@ -0,0 +1,48 @@
+# =========================================================
+#  WALL-E-TTE - Démarrage de tous les micro-services (PowerShell)
+#  Equivalent de start-all.bat
+# =========================================================
+
+$ROOT = Split-Path -Parent $MyInvocation.MyCommand.Path
+
+Write-Host "[Wall-e-tte] Demarrage des services..." -ForegroundColor Cyan
+
+# ─── PRICE SERVICE (port 3001) ───────────────────────────
+Write-Host "[1/4] Lancement price-service sur :3001" -ForegroundColor Yellow
+Start-Process "cmd.exe" -ArgumentList "/k", "cd /d `"$ROOT\server`" && node modules/price/server.js" -WindowStyle Normal
+
+Start-Sleep -Seconds 2
+
+# ─── ALERTS SERVICE (port 3003) ──────────────────────────
+Write-Host "[2/4] Lancement alerts-service sur :3003" -ForegroundColor Yellow
+Start-Process "cmd.exe" -ArgumentList "/k", "cd /d `"$ROOT\server`" && node modules/alerts/server.js" -WindowStyle Normal
+
+Start-Sleep -Seconds 2
+
+# ─── STRATEGY SERVICE (port 3002) - optionnel ─────────────
+$strategyPath = Join-Path $ROOT "server\modules\strategy\server.js"
+if (Test-Path $strategyPath) {
+    Write-Host "[3/4] Lancement strategy-service sur :3002" -ForegroundColor Yellow
+    Start-Process "cmd.exe" -ArgumentList "/k", "cd /d `"$ROOT\server`" && node modules/strategy/server.js" -WindowStyle Normal
+    Start-Sleep -Seconds 2
+} else {
+    Write-Host "[3/4] strategy-service non trouve - le gateway retournera 502 pour /api/strategy/*" -ForegroundColor DarkYellow
+}
+
+# ─── GATEWAY (port 3000) ─────────────────────────────────
+Write-Host "[4/4] Lancement gateway sur :3000" -ForegroundColor Yellow
+Start-Process "cmd.exe" -ArgumentList "/k", "cd /d `"$ROOT\gateway`" && node gateway.js" -WindowStyle Normal
+
+Write-Host ""
+Write-Host "Tous les services sont lances !" -ForegroundColor Green
+Write-Host ""
+Write-Host "  Gateway  : http://localhost:3000" -ForegroundColor Cyan
+Write-Host "  Price    : http://localhost:3001" -ForegroundColor Cyan
+Write-Host "  Alerts   : http://localhost:3003" -ForegroundColor Cyan
+Write-Host ""
+Write-Host "Tests rapides :"
+Write-Host "  curl http://localhost:3000/api/gateway/health"
+Write-Host "  curl 'http://localhost:3000/api/price/current?pair=BTC/EUR'"
+Write-Host "  curl 'http://localhost:3000/api/alerts?userId=1'"
+Write-Host ""
+Read-Host "Appuyez sur Entree pour fermer cette fenetre"