# 🚨 Incohérences Tiers - Web Sentinel

**Date:** 7 novembre 2025  
**Problème:** Les limites des tiers sont **différentes** entre la documentation, le backend admin et le CLI/GUI

---

## 📊 Comparaison des valeurs

### FREE

| Source | max_domains | max_users | allow_source_scan | max_source_files |
|--------|-------------|-----------|-------------------|------------------|
| **Documentation (tier-limits.html)** | 5 | 0 (anonyme) | ❌ | 0 |
| **Backend Admin (sast_defaults.py)** | ✅ 5 | ✅ 0 | ✅ False | ✅ 0 |
| **CLI (subscription/models.py)** | ❌ **3** | ❌ **1** | ✅ False | ✅ 0 |
| **Payment API (api_routes.py)** | - | - | - | - |

**🔴 INCOHÉRENCE CLI:** 
- `domain_limit=3` au lieu de **5**
- `max_users=1` au lieu de **0**
- Tier FREE manquant dans `payment/api_routes.py`

---

### STARTER

| Source | max_domains | max_users | allow_source_scan | max_source_files | max_source_size_mb |
|--------|-------------|-----------|-------------------|------------------|--------------------|
| **Documentation (tier-limits.html)** | ∞ | 1 | ✅ | 10 | 10 MB |
| **Backend Admin (sast_defaults.py)** | ✅ -1 (∞) | ✅ 1 | ✅ True | ✅ 10 | ❌ **5 MB** |
| **CLI (subscription/models.py)** | ❌ **MANQUANT** | - | - | - | - |
| **Payment API (api_routes.py)** | ❌ **10** | ✅ 1 | - | - | - |

**🔴 INCOHÉRENCES:**
- **CLI n'a pas de tier STARTER** (seulement FREE, PRO, ENTERPRISE, SYSOP)
- Backend: `max_source_size_mb=5` au lieu de **10 MB** documenté
- Payment API: `max_domains=10` au lieu de **illimité (-1)**

---

### PRO

| Source | max_domains | max_users | allow_source_scan | max_source_files | max_source_size_mb | allow_api_access |
|--------|-------------|-----------|-------------------|------------------|--------------------|------------------|
| **Documentation (tier-limits.html)** | ∞ | 1 | ✅ | 100 | 50 MB | ✅ |
| **Backend Admin (sast_defaults.py)** | ✅ -1 (∞) | ✅ 1 | ✅ True | ✅ 100 | ✅ 50 | ✅ True |
| **CLI (subscription/models.py)** | ✅ -1 (∞) | ❌ **5** | ✅ True | ✅ 100 | ❌ **20** | ❌ **False** |
| **Payment API (api_routes.py)** | ❌ **50** | ✅ 1 | - | - | - | - |

**🔴 INCOHÉRENCES CLI:**
- `max_users=5` au lieu de **1**
- `max_source_size_mb=20` au lieu de **50**
- `allow_api_access=False` au lieu de **True**

**🔴 INCOHÉRENCE Payment API:**
- `max_domains=50` au lieu de **illimité (-1)**

---

### ENTERPRISE

| Source | max_domains | max_users | allow_source_scan | max_source_files | max_source_size_mb | allow_multi_user |
|--------|-------------|-----------|-------------------|------------------|--------------------|------------------|
| **Documentation (tier-limits.html)** | ∞ | 10 | ✅ | 500 | 200 MB | ✅ |
| **Backend Admin (sast_defaults.py)** | ✅ -1 (∞) | ✅ 10 | ✅ True | ✅ 500 | ✅ 200 | ✅ True |
| **CLI (subscription/models.py)** | ✅ -1 (∞) | ❌ **50** | ✅ True | ✅ 500 | ❌ **100** | ✅ True |
| **Payment API (api_routes.py)** | ✅ 999999 (∞) | ✅ 10 | - | - | - | - |

**🔴 INCOHÉRENCES CLI:**
- `max_users=50` au lieu de **10**
- `max_source_size_mb=100` au lieu de **200**

---

## 📝 Résumé des corrections à faire

### 1. CLI (`web_sentinel/subscription/models.py`) - **PRIORITÉ CRITIQUE**

```python
# AVANT (INCORRECT)
_FEATURE_MATRIX: Dict[SubscriptionTier, SubscriptionFeatures] = {
    SubscriptionTier.FREE: SubscriptionFeatures(
        tier=SubscriptionTier.FREE,
        domain_limit=3,  # ❌ Doit être 5
        max_users=1,     # ❌ Doit être 0
        # ...
    ),
    # ❌ STARTER manquant !
    SubscriptionTier.PRO: SubscriptionFeatures(
        tier=SubscriptionTier.PRO,
        domain_limit=-1,
        max_users=5,              # ❌ Doit être 1
        allow_api_access=False,   # ❌ Doit être True
        max_source_size_mb=20,    # ❌ Doit être 50
        # ...
    ),
    SubscriptionTier.ENTERPRISE: SubscriptionFeatures(
        tier=SubscriptionTier.ENTERPRISE,
        max_users=50,             # ❌ Doit être 10
        max_source_size_mb=100,   # ❌ Doit être 200
        # ...
    ),
}
```

**APRÈS (CORRECT):**
```python
_FEATURE_MATRIX: Dict[SubscriptionTier, SubscriptionFeatures] = {
    SubscriptionTier.FREE: SubscriptionFeatures(
        tier=SubscriptionTier.FREE,
        domain_limit=5,  # ✅ 5 domaines
        max_users=0,     # ✅ Anonyme
        allow_invasive_tests=False,
        allow_html_export=False,
        allow_multi_user=False,
        allow_api_access=False,
        allow_source_scan=False,
        max_source_files=0,
        max_source_size_mb=0,
        advanced_rules=False,
    ),
    SubscriptionTier.STARTER: SubscriptionFeatures(  # ✅ AJOUTER STARTER
        tier=SubscriptionTier.STARTER,
        domain_limit=-1,  # ✅ Illimité
        max_users=1,      # ✅ 1 utilisateur
        allow_invasive_tests=False,
        allow_html_export=True,   # ✅ Export HTML activé
        allow_multi_user=False,
        allow_api_access=False,
        allow_source_scan=True,   # ✅ SAST activé
        max_source_files=10,      # ✅ 10 fichiers/mois
        max_source_size_mb=10,    # ✅ 10 MB max
        advanced_rules=False,
    ),
    SubscriptionTier.PRO: SubscriptionFeatures(
        tier=SubscriptionTier.PRO,
        domain_limit=-1,
        max_users=1,              # ✅ 1 utilisateur (mono-user)
        allow_invasive_tests=True,
        allow_html_export=True,
        allow_multi_user=False,   # ✅ Pas de multi-user
        allow_api_access=True,    # ✅ API activé
        allow_source_scan=True,
        max_source_files=100,
        max_source_size_mb=50,    # ✅ 50 MB
        advanced_rules=False,
    ),
    SubscriptionTier.ENTERPRISE: SubscriptionFeatures(
        tier=SubscriptionTier.ENTERPRISE,
        domain_limit=-1,
        max_users=10,             # ✅ 10 utilisateurs
        allow_invasive_tests=True,
        allow_html_export=True,
        allow_multi_user=True,
        allow_api_access=True,
        allow_source_scan=True,
        max_source_files=500,
        max_source_size_mb=200,   # ✅ 200 MB
        advanced_rules=True,
    ),
    # SYSOP reste inchangé
}
```

### 2. Payment API (`web_sentinel/payment/api_routes.py`) - **PRIORITÉ HAUTE**

```python
# AVANT (ligne 419-423)
limits = {
    'STARTER': {'max_domains': 10, 'max_users': 1},        # ❌ max_domains doit être -1
    'PRO': {'max_domains': 50, 'max_users': 1},            # ❌ max_domains doit être -1
    'ENTERPRISE': {'max_domains': 999999, 'max_users': 10} # ✅ OK
}

# APRÈS
limits = {
    'FREE': {'max_domains': 5, 'max_users': 0},            # ✅ Ajouter FREE
    'STARTER': {'max_domains': -1, 'max_users': 1},        # ✅ Illimité
    'PRO': {'max_domains': -1, 'max_users': 1},            # ✅ Illimité
    'ENTERPRISE': {'max_domains': -1, 'max_users': 10}     # ✅ Illimité (au lieu de 999999)
}
```

### 3. Backend Admin (`admin/backend/app/sast_defaults.py`) - **PRIORITÉ BASSE**

```python
# Ligne 34
"max_source_size_mb": 5,  # ❌ Documentation dit 10 MB

# CORRIGER EN:
"max_source_size_mb": 10,  # ✅ 10 MB (STARTER)
```

---

## 🔧 Enum SubscriptionTier

**Ajouter STARTER dans l'enum:**

```python
# web_sentinel/subscription/models.py (ligne 10-15)
class SubscriptionTier(str, Enum):
    """Supported subscription tiers."""

    FREE = "free"
    STARTER = "starter"  # ✅ AJOUTER
    PRO = "pro"
    ENTERPRISE = "enterprise"
    SYSOP = "sysop"
```

---

## ⚠️ Impact sur l'exécutable Windows (.exe)

**OUI, recompilation nécessaire !**

Les fichiers modifiés (`web_sentinel/subscription/models.py`, `web_sentinel/payment/api_routes.py`) sont **inclus dans l'exécutable**.

**Fichiers à recompiler:**
- `web-sentinel.exe` (CLI principal)
- `web-sentinel-gui.exe` (Interface graphique)

**Commande de recompilation:**
```bash
# CLI
pyinstaller web-sentinel.spec --clean

# GUI
pyinstaller web-sentinel-gui.spec --clean
```

---

## ✅ Checklist de vérification

### Phase 1: Corrections code
- [ ] Modifier `web_sentinel/subscription/models.py`
  - [ ] FREE: domain_limit 3→5, max_users 1→0
  - [ ] Ajouter STARTER (domain_limit=-1, max_users=1, SAST 10 fichiers)
  - [ ] PRO: max_users 5→1, max_source_size_mb 20→50, allow_api_access True
  - [ ] ENTERPRISE: max_users 50→10, max_source_size_mb 100→200
- [ ] Modifier `web_sentinel/payment/api_routes.py`
  - [ ] Ajouter FREE: max_domains=5, max_users=0
  - [ ] STARTER: max_domains 10→-1
  - [ ] PRO: max_domains 50→-1
  - [ ] ENTERPRISE: max_domains 999999→-1
- [ ] Modifier `admin/backend/app/sast_defaults.py`
  - [ ] STARTER: max_source_size_mb 5→10

### Phase 2: Tests
- [ ] Tester FREE anonyme (5 domaines max)
- [ ] Tester STARTER (DNS illimité, SAST 10 fichiers)
- [ ] Tester PRO (1 user, API access, SAST 100 fichiers)
- [ ] Tester ENTERPRISE (10 users, SAST 500 fichiers)

### Phase 3: Recompilation
- [ ] Recompiler `web-sentinel.exe` (CLI)
- [ ] Recompiler `web-sentinel-gui.exe` (GUI)
- [ ] Tester exécutables Windows
- [ ] Déployer nouveaux exécutables sur site web

### Phase 4: Déploiement
- [ ] Commit changements GitHub
- [ ] Redéployer backend admin OVH
- [ ] Redéployer API payment (si hébergée séparément)
- [ ] Upload nouveaux .exe sur site de distribution

---

## 🎯 Priorités

1. **CRITIQUE:** Modifier CLI (`subscription/models.py`) - Utilisateurs utilisent anciennes limites
2. **HAUTE:** Modifier Payment API (`api_routes.py`) - Paiements créent licences incorrectes
3. **BASSE:** Modifier Backend Admin (`sast_defaults.py`) - Différence mineure (5 vs 10 MB)
4. **CRITIQUE:** Recompiler .exe Windows - Tous les utilisateurs Windows affectés

---

**Status:** ⏳ Corrections à appliquer  
**Temps estimé:** 2-3 heures (modifications + tests + recompilation)
