# Architecture WaouW - État des lieux et Refonte
## État actuel (ANALYSE)
### Vue d'ensemble
WaouW est une application web PHP traditionnelle permettant de déployer des hébergements web (WordPress, PrestaShop, Joomla, Nextcloud) sur Raspberry Pi. L'architecture actuelle présente plusieurs défis techniques.
### Architecture technique actuelle
```mermaid
graph TB
subgraph "Interface Web"
UI[Interface PHP/Bootstrap
waouw_int/]
Auth[Authentification]
Dashboard[Dashboard]
end
subgraph "Provisioning"
Scripts[Scripts Bash
configs/]
CMS[cms_install.sh]
VHost[vhost.sh]
Check[check_vhost.sh]
end
subgraph "Applications"
Apache[Apache + VirtualHosts]
MySQL[MySQL/MariaDB]
Apps[WordPress/Joomla/PrestaShop]
PMA[phpMyAdmin]
end
subgraph "Sauvegarde"
ScriptsSauv[Scripts par OS
scpt/]
SauvLinux[Sauvegarde_sur_Linux.sh]
SauvWin[Scripts Windows]
SauvMac[Scripts macOS]
end
subgraph "Modules"
Presence[waouw-presence]
Security[waouw-securite]
Shell[waouw-shell]
end
UI --> Scripts
Scripts --> Apache
Scripts --> MySQL
UI --> ScriptsSauv
Apache --> Apps
MySQL --> Apps
```
### Composants identifiés
#### Frontend (`waouw_int/`)
- **Technologie** : PHP 8+ avec Bootstrap 5, jQuery
- **Structure** : Pages PHP avec inclusion de templates
- **Authentification** : Sessions PHP basiques
- **Interface** : Forms multi-étapes pour création de sites
#### Provisioning (`configs/`)
- **cms_install.sh** : Script principal (719 lignes) - très complexe
- **vhost.sh** : Gestion des VirtualHosts Apache
- **Scripts de vérification** : check_vhost.sh, verif-install.sh
- **Processus** : Création DB → Installation CMS → Configuration Apache → SSL
#### Sauvegarde (`scpt/`)
- **Scripts par OS** : Linux, Windows, macOS
- **Méthode** : mysqldump + rsync + 7zip
- **Destination** : Serveurs distants via SSH/SFTP
- **Rotation** : 7 jours de rétention
#### Applications (`waouw_apps/`)
- **phpMyAdmin** : Gestion bases de données
- **Modules métier** : présence, sécurité, shell
### Points de douleur identifiés
#### 🔴 Sécurité
- Mots de passe en dur dans `cfg.php` (ligne 12, 19)
- Exécution de scripts en root
- Pas d'isolation entre sites
- Secrets versionnés
#### 🔴 Complexité opérationnelle
- Scripts bash monolithiques (719 lignes)
- Gestion d'erreurs fragile
- Pas d'idempotence
- Logs dispersés
#### 🔴 Architecture technique
- Couplage fort entre composants
- Pas d'API REST
- Interface utilisateur vieillissante
- Pas d'agent pour boîtiers distants
#### 🔴 Sauvegarde/Mirroring
- Scripts complexes par OS
- Pas de vérification d'intégrité
- Configuration manuelle lourde
- Pas de dry-run
#### 🔴 Monitoring/Observabilité
- Collecte d'infos boîtiers via "fichier MAC" fragile
- Pas de métriques temps réel
- Logs non structurés
- Pas de healthchecks
## Architecture cible (PROPOSITION)
### Principes directeurs
1. **Isolation** : Conteneurs Docker ou services systemd séparés
2. **Sécurité** : Secrets externalisés, utilisateurs non-root, TLS automatique
3. **Simplicité** : API REST, interface moderne, scripts idempotents
4. **Observabilité** : Métriques, logs structurés, healthchecks
5. **Robustesse** : Tests automatisés, rollbacks, tolérance aux pannes
### Option A : Architecture conteneurisée (RECOMMANDÉE)
```mermaid
graph TB
subgraph "Frontend"
React[React + Tailwind
UI/]
Nginx[Nginx Static]
end
subgraph "API Layer"
FastAPI[FastAPI Backend
BACKEND/]
Auth[JWT Auth]
Jobs[Background Jobs]
end
subgraph "Orchestration"
Traefik[Traefik Proxy
Auto-TLS]
Docker[Docker Compose]
end
subgraph "Data"
Redis[Redis Cache]
PostgreSQL[PostgreSQL Main]
MariaDB[MariaDB per site]
end
subgraph "Applications isolées"
WP[WordPress Container]
PS[PrestaShop Container]
JM[Joomla Container]
NC[Nextcloud Container]
end
subgraph "Device Management"
Agent[Device Agent
DEVICE_AGENT/]
MQTT[Mosquitto MQTT]
end
subgraph "Mirroring"
Lsyncd[lsyncd + rsync]
Rclone[rclone S3/SFTP]
end
React --> FastAPI
FastAPI --> Docker
Traefik --> WP
Traefik --> PS
Traefik --> JM
Traefik --> NC
Agent --> MQTT
Agent --> FastAPI
Lsyncd --> FastAPI
```
### Stack technique cible
#### Frontend - React + Tailwind
- **Framework** : React 18 + TypeScript
- **Styling** : Tailwind CSS + shadcn/ui
- **State** : Zustand pour l'état global
- **Routing** : React Router
- **API** : TanStack Query
#### Backend - FastAPI
- **Framework** : FastAPI + Python 3.11
- **ORM** : SQLAlchemy + Alembic
- **Jobs** : Celery + Redis
- **Auth** : JWT + bcrypt
- **Validation** : Pydantic
#### Proxy/TLS - Traefik
- **Auto-TLS** : Let's Encrypt ACME
- **Service Discovery** : Labels Docker
- **Load Balancing** : Round-robin
- **Monitoring** : Métriques Prometheus
#### Orchestration - Docker Compose
- **Isolation** : Réseaux Docker par site
- **Volumes** : Stockage persistant
- **Secrets** : Docker secrets
- **Healthchecks** : Intégrés
#### Mirroring - lsyncd (par défaut)
- **Monitoring** : inotify
- **Sync** : rsync incrémental
- **Robustesse** : Retry automatique
- **Alternative** : rclone pour cloud
### Flows fonctionnels cible
#### 1. Création d'un site WordPress
```mermaid
sequenceDiagram
participant U as User
participant API as FastAPI
participant D as Docker
participant T as Traefik
participant DB as MariaDB
U->>API: POST /sites {domain, cms: "wordpress"}
API->>API: Validate domain
API->>DB: Create database
API->>D: Deploy WordPress container
API->>T: Configure routing
API->>API: Generate TLS cert
API->>U: Site ready (200)
```
#### 2. Device heartbeat
```mermaid
sequenceDiagram
participant A as Device Agent
participant M as MQTT/API
participant DB as Database
participant UI as Frontend
loop Every 30s
A->>A: Collect metrics
A->>M: Publish heartbeat
M->>DB: Store metrics
DB->>UI: Real-time update
end
```
### Sécurité intégrée
#### Secrets management
```bash
# .env.example
DATABASE_URL=postgresql://user:pass@db:5432/waouw
JWT_SECRET_KEY=generate_with_openssl
TRAEFIK_ACME_EMAIL=admin@domain.com
DEVICE_HMAC_SECRET=shared_secret_for_agents
```
#### Network isolation
```yaml
# docker-compose.yml extract
networks:
traefik:
external: true
backend:
internal: true
site_wordpress_com:
internal: true
```
#### Non-root containers
```dockerfile
# Dockerfile example
RUN adduser --disabled-password --gecos '' appuser
USER appuser
```
### Migration strategy
#### Phase 1 : Coexistence
- Déployer nouvelle stack en parallèle
- Migrer progressivement les sites
- Conserver ancienne interface en backup
#### Phase 2 : Migration données
- Export/import bases de données
- Synchronisation fichiers
- Tests de validation
#### Phase 3 : Cutover
- Redirection DNS
- Arrêt ancienne stack
- Monitoring intensif
## Comparaison architectures
| Critère | Actuel | Cible |
|---------|--------|-------|
| **Langages** | PHP + Bash | Python + TypeScript |
| **Frontend** | jQuery/Bootstrap | React/Tailwind |
| **API** | Aucune | REST FastAPI |
| **Isolation** | Aucune | Docker/systemd |
| **TLS** | Manuel/Let's Encrypt | Auto Traefik |
| **Secrets** | Hard-codés | .env + secrets |
| **Tests** | Aucun | Automatisés |
| **Monitoring** | Logs fichiers | Métriques/healthz |
| **Mirroring** | Scripts complexes | lsyncd/rclone |
| **Device Mgmt** | Fichier MAC | Agent heartbeat |
## Métriques de réussite
- ✅ Déploiement WordPress en < 2 minutes
- ✅ Interface responsive et moderne
- ✅ TLS automatique 100% sites
- ✅ Agent heartbeat < 30s latence
- ✅ Sauvegarde automatique avec retry
- ✅ Logs structurés et searchables
- ✅ Zero-downtime deployments
- ✅ Documentation turn-key complète
## 🎯 Architecture Cible COMPLÈTE (WaouW v2.0)
### Vue d'ensemble des services complets
```mermaid
graph TB
subgraph "Raspberry Pi - WaouW v2.0 PLATFORM COMPLÈTE"
subgraph "Reverse Proxy"
T[Traefik
:80,:443
Auto-HTTPS]
end
subgraph "Core Services"
API[FastAPI Backend
:8000]
UI[React UI
:3000]
DB[(PostgreSQL
:5432)]
CACHE[(Redis
:6379)]
end
subgraph "Web Applications"
WP[WordPress
Container]
PS[PrestaShop
Container]
JM[Joomla
Container]
NC[Nextcloud
Container]
end
subgraph "Email Services"
ROUNDCUBE[Roundcube
Webmail :8080]
POSTFIX[Postfix
SMTP Server]
DOVECOT[Dovecot
IMAP/POP3]
MAILADMIN[Email Admin
:8081]
end
subgraph "System Management"
WEBMIN[Webmin
:10000]
PHPMYADMIN[phpMyAdmin
:8082]
AGENT[Device Agent
Python Service]
end
subgraph "Security & VPN"
VPN[Waouw Présence
OpenVPN Server]
F2B[Fail2Ban
Security Monitor]
FIREWALL[UFW Firewall]
end
subgraph "Backup & Sync"
SYNC[Sync Service
lsyncd/rsync]
BACKUP[Backup Manager
Automated]
RESTORE[Restore Service]
end
subgraph "Monitoring & Logs"
LOGS[Log Manager
Centralized]
METRICS[System Metrics
Collector]
HEALTH[Health Checks]
end
end
subgraph "External"
USER[👤 End User]
CENTRAL[🌐 Central Server
Authentication]
REMOTE[📡 Remote Backup]
MOBILE[📱 Mobile Access
via VPN]
end
USER --> T
T --> UI
T --> API
T --> WP
T --> PS
T --> JM
T --> NC
T --> ROUNDCUBE
T --> WEBMIN
T --> PHPMYADMIN
T --> MAILADMIN
API --> DB
API --> CACHE
API --> AGENT
API --> LOGS
API --> METRICS
AGENT --> CENTRAL
SYNC --> REMOTE
VPN --> MOBILE
F2B --> FIREWALL
BACKUP --> RESTORE
```
### Services détaillés par catégorie
#### 🌐 **Internet (Gestion sites)**
- **Création de site** : Interface pour WordPress, Joomla, PrestaShop, Nextcloud
- **Gestion des sites** : Start/stop, configuration, SSL, domaines
- **Admin BDD** : phpMyAdmin intégré (:8082)
- **Dossiers Logs** : Interface centralisée des logs
#### 🛠️ **Outils (Services intégrés)**
- **Webmin** (:10000) : Administration système complète
- **Waouw-Cloud** : Nextcloud pour stockage personnel
- **Synchronisation** (:7165) : Interface de sync des fichiers
- **Sauvegarde/Restauration** : Interface complète multi-OS
- **Waouw Présence** : VPN/Proxy pour accès distant
- **Waouw Sécurité** : Fail2ban et monitoring sécurité
- **Webmail** : Roundcube (:8080) pour consultation emails
- **Gestion emails** (:8081) : Administration comptes email
#### 💻 **Système**
- **Informations** : Versions, statuts, métriques temps réel
- **Utilisateur** : Gestion comptes et permissions
- **Redémarrer** : Interface sécurisée avec confirmation
#### 📧 **Stack Email complète**
- **Postfix** : Serveur SMTP sortant
- **Dovecot** : Serveurs IMAP/POP3 entrant
- **Roundcube** : Interface webmail moderne
- **Email Admin** : Gestion comptes, aliases, quotas
#### 🔐 **Sécurité intégrée**
- **OpenVPN** : Accès VPN sécurisé
- **Fail2ban** : Protection intrusion automatique
- **UFW Firewall** : Pare-feu simplifié
- **SSL automatique** : Let's Encrypt via Traefik
### Ports et accès
| Service | Port | URL | Description |
|---------|------|-----|-------------|
| **Interface WaouW** | 443 | `https://waouw.local` | Interface principale |
| **Webmin** | 10000 | `https://waouw.local:10000` | Admin système |
| **Roundcube** | 8080 | `https://waouw.local:8080` | Webmail |
| **Email Admin** | 8081 | `https://waouw.local:8081` | Gestion emails |
| **phpMyAdmin** | 8082 | `https://waouw.local:8082` | Admin BDD |
| **Nextcloud** | 443 | `https://waouw.local/nextcloud` | Cloud personnel |
| **Sync Interface** | 7165 | `https://waouw.local:7165` | Synchronisation |
| **VPN** | 1194 | `udp://waouw.local:1194` | OpenVPN |
## Prochaines étapes
1. **ADRs** : Formaliser les décisions d'architecture
2. **Prototyping** : MVP avec 1 site WordPress
3. **Templates** : Docker Compose + systemd
4. **Agent** : Device heartbeat basique
5. **Tests** : Validation end-to-end
6. **Migration** : Plan détaillé avec rollback
---
*Architecture WaouW v2.0 - Raspberry Pi optimized*
*Generated: $(date)*