# Architecture des Flux et Services - LeCoffre Node --- ## Tableau des Services - IP/Domaines et Ports ### 🚀 **Scripts de Gestion (Nouveau)** | Script | Fonction | Utilisation | |--------|----------|-------------| | **`start.sh`** | Démarrage séquentiel avec progression | `./scripts/start.sh` | | **`validate-deployment.sh`** | Validation complète du déploiement | `./scripts/validate-deployment.sh` | | **`maintenance.sh`** | Menu interactif de maintenance | `./scripts/maintenance.sh` | | **`backup-data.sh`** | Sauvegarde des volumes Docker | `./scripts/backup-data.sh` | | **`restore-data.sh`** | Restauration depuis sauvegarde | `./scripts/restore-data.sh ` | | **`update-images.sh`** | Mise à jour sécurisée | `./scripts/update-images.sh` | ### 🏠 **Services Locaux (Docker Compose)** | Service | Container | Port Local | Port Interne | Protocole | URL d'accès | |---------|-----------|------------|--------------|-----------|-------------| | **tor** | tor-proxy | - | 9050 | TCP | Réseau interne uniquement | | **bitcoin** | bitcoin-signet | - | 38332 (RPC)
38333 (P2P)
29000 (ZMQ hash)
29001 (ZMQ rawtx) | TCP | Réseau interne uniquement | | **blindbit** | blindbit-oracle | 0.0.0.0:8000 | 8000 | HTTP | http://0.0.0.0:8000 | | **sdk_relay** | sdk_relay | 0.0.0.0:8090
0.0.0.0:8091 | 8090 (WS)
8091 (HTTP) | WebSocket/HTTP | ws://0.0.0.0:8090
http://0.0.0.0:8091 | | **lecoffre-back** | lecoffre-back | 0.0.0.0:8080 | 8080 | HTTP | http://0.0.0.0:8080 | | **lecoffre-front** | lecoffre-front | 127.0.0.2:3004 | 3000 | HTTP | http://127.0.0.2:3004 | | **ihm_client** | ihm_client | 0.0.0.0:3003 | 3003 | HTTP | http://0.0.0.0:3003 | | **sdk_signer** | sdk_signer | 0.0.0.0:3001 | 3001 | HTTP/WebSocket | http://0.0.0.0:3001 | | **sdk_storage** | sdk_storage | 0.0.0.0:8081 | 8080 | HTTP | http://0.0.0.0:8081 | | **grafana** | grafana | 127.0.0.1:3005 | 3000 | HTTP | http://127.0.0.1:3005 | | **loki** | loki | 127.0.0.1:3100 | 3100 | HTTP | http://127.0.0.1:3100 | | **promtail** | promtail | - | - | - | Collecte des logs | ### 🌐 **Services Externes** | Service | Domaine | Port | Protocole | URL d'accès | Statut | |---------|---------|------|-----------|-------------|--------| | **Bootstrap Relay** | dev3.4nkweb.com | 443 | WSS | wss://dev3.4nkweb.com/ws/ | ✅ Actif | | **Signer Externe** | dev3.4nkweb.com | 9090 | WS | ws://dev3.4nkweb.com:9090 | ✅ Actif | | **Signer Base** | dev3.4nkweb.com | 443 | HTTPS | https://dev3.4nkweb.com | ✅ Actif | | **Mempool** | mempool2.4nkweb.com | 443 | HTTPS | https://mempool2.4nkweb.com | ✅ Actif | | **Storage** | dev4.4nkweb.com | 443 | HTTPS | https://dev4.4nkweb.com/storage | ✅ Actif | ### 🔄 **Proxy Nginx (dev4.4nkweb.com)** | Route | Destination | Port | Protocole | Description | |-------|-------------|------|-----------|-------------| | **/** | ihm_client | 3003 | HTTP | Interface principale | | **/lecoffre** | lecoffre-front | 3004 | HTTP | Application LeCoffre | | **/api/** | lecoffre-back | 8080 | HTTP | API Backend | | **/back/** | lecoffre-back | 8080 | HTTP | API Backend (alias) | | **/ws/** | sdk_relay | 8090 | WebSocket | Relay WebSocket | | **/signer/** | sdk_signer | 3001 | HTTP/WebSocket | Service Signer | | **/src/service-workers/** | ihm_client | 3003 | HTTP | Service Workers | | **/grafana/** | grafana | 3005 | HTTP | Interface de monitoring | | **/loki/** | loki | 3100 | HTTP | API de logs | ### 🏠 **Proxy Nginx Local (local.4nkweb.com)** | Route | Destination | Port | Protocole | Description | |-------|-------------|------|-----------|-------------| | **/** | Redirection | 3000 | HTTP | Redirige vers port 3000 | | **/lecoffre/** | lecoffre-front | 3004 | HTTP | Application LeCoffre local | ### 🔧 **Configuration Bitcoin Signet** | Service | Port | Protocole | Description | |---------|------|-----------|-------------| | **RPC** | 38332 | TCP | Interface RPC Bitcoin | | **P2P** | 38333 | TCP | Réseau peer-to-peer | | **ZMQ Hash** | 29000 | TCP | Notifications de blocs | | **ZMQ RawTx** | 29001 | TCP | Notifications de transactions | | **Tor** | 9050 | TCP | Proxy Tor | ### 🌐 **Réseau Docker** | Réseau | Subnet | Driver | Services | |--------|--------|--------|----------| | **btcnet** | 172.20.0.0/16 | bridge | Tous les services | ### 🔗 **Variables d'Environnement Clés (Centralisées - 2024-09-21)** **Configuration centralisée** : Toutes les variables sont dans `lecoffre_node/.env.master` | Variable | Valeur | Service | |----------|--------|---------| | **VITE_BOOTSTRAPURL** | wss://dev4.4nkweb.com/ws/ | ihm_client | | **SIGNER_WS_URL** | ws://dev3.4nkweb.com:9090 | sdk_signer | | **SIGNER_BASE_URL** | https://dev3.4nkweb.com | sdk_signer | | **RELAY_URLS** | wss://dev4.4nkweb.com/ws/,wss://dev3.4nkweb.com/ws/ | sdk_signer | | **bootstrap_url** | wss://dev3.4nkweb.com/ws/ | sdk_relay | | **storage** | https://dev4.4nkweb.com/storage | sdk_relay | | **GRAFANA_ADMIN_PASSWORD** | admin123 | grafana | | **GF_SERVER_ROOT_URL** | https://dev4.4nkweb.com/grafana/ | grafana | **Variables centralisées** : - **SDK_RELAY_*** : Configuration complète du service relay - **SIGNER_*** : Configuration complète du service signer - **VITE_*** : Configuration des applications frontend - **IDNOT_*** : Configuration des APIs notaires - **STRIPE_*** : Configuration des paiements - **MAILCHIMP_*** : Configuration des emails - **OVH_*** : Configuration des SMS --- ## Flux d'Architecture ### 🔄 **Flux Principal** ``` Internet → dev4.4nkweb.com (Nginx) → Services Locaux ``` 1. **Frontend** : `https://dev4.4nkweb.com/lecoffre` → lecoffre-front (127.0.0.2:3004) 2. **API** : `https://dev4.4nkweb.com/api/` → lecoffre-back (0.0.0.0:8080) 3. **IHM** : `https://dev4.4nkweb.com/` → ihm_client (0.0.0.0:3003) 4. **WebSocket** : `https://dev4.4nkweb.com/ws/` → sdk_relay (0.0.0.0:8090) 5. **Monitoring** : `https://dev4.4nkweb.com/grafana/` → grafana (127.0.0.1:3005) 6. **Logs API** : `https://dev4.4nkweb.com/loki/` → loki (127.0.0.1:3100) ### 🔗 **Flux de Redirection** ``` local.4nkdev.com → local.4nkweb.com → https://dev4.4nkweb.com/lecoffre ``` ### 🌐 **Flux Externes** - **Bootstrap** : `wss://dev3.4nkweb.com/ws/` (Relay externe) - **Signer** : `ws://dev3.4nkweb.com:9090` (Actuellement inactif) - **Mempool** : `https://mempool2.4nkweb.com` (Réseau Bitcoin Signet) --- ## 📊 **Architecture du Monitoring** ### 🔄 **Stack de Monitoring** ``` Services → Logs Centralisés → Promtail → Loki → Grafana ↓ ↓ ↓ ↓ ↓ Docker logs/ Collecte Stockage Dashboard ``` ### 📁 **Centralisation des Logs** | Service | Dossier de Logs | Volume Docker | Description | |---------|-----------------|---------------|-------------| | **bitcoin** | `logs/bitcoin/` | `./logs/bitcoin:/var/log/bitcoin` | Logs Bitcoin Signet | | **blindbit** | `logs/blindbit/` | `./logs/blindbit:/var/log/blindbit` | Logs Oracle | | **sdk_relay** | `logs/sdk_relay/` | `./logs/sdk_relay:/var/log/sdk_relay` | Logs Relay | | **sdk_signer** | `logs/sdk_signer/` | `./logs/sdk_signer:/var/log/sdk_signer` | Logs Signer | | **sdk_storage** | `logs/sdk_storage/` | `./logs/sdk_storage:/var/log/sdk_storage` | Logs Storage | | **lecoffre-back** | `logs/lecoffre-back/` | `./logs/lecoffre-back:/var/log/lecoffre-back` | Logs Backend | | **lecoffre-front** | `logs/lecoffre-front/` | `./logs/lecoffre-front:/var/log/lecoffre-front` | Logs Frontend | | **ihm_client** | `logs/ihm_client/` | `./logs/ihm_client:/var/log/ihm_client` | Logs IHM | | **miner** | `logs/miner/` | `./logs/miner:/var/log/miner` | Logs Mineur | | **tor** | `logs/tor/` | `./logs/tor:/var/log/tor` | Logs Tor | ### 📊 **Dashboards Grafana** | Dashboard | ID | Description | Métriques | |-----------|----|--------------|-----------| | **Vue d'ensemble LeCoffre** | `lecoffre-overview` | Monitoring global | Erreurs par service, volume de logs, logs d'erreur temps réel | | **Bitcoin & Miner** | `bitcoin-miner` | Monitoring blockchain | Nouveaux blocs, blocs minés, erreurs blockchain | | **Services Applications** | `services-overview` | Monitoring applicatif | Volume de logs par service, erreurs applications | ### 🔧 **Scripts de Gestion** | Script | Description | Usage | |--------|-------------|-------| | `deploy-grafana.sh` | Déploiement du monitoring | `./scripts/deploy-grafana.sh start` | | `setup-logs.sh` | Configuration des logs | `./scripts/setup-logs.sh` | | `collect-logs.sh` | Collecte des logs | `./scripts/collect-logs.sh` | | `test-monitoring.sh` | Test de connectivité | `./scripts/test-monitoring.sh` | | `sync-monitoring-config.sh` | Synchronisation config | `./scripts/sync-monitoring-config.sh` | --- ## ⚠️ **Points d'Attention** 1. **dev3.4nkweb.com:9090** - Service signer externe actuellement inactif 2. **dev3.4nkweb.com** - Retourne 502 Bad Gateway (services backend indisponibles) 3. **Ports 0.0.0.0** - Services locaux uniquement accessibles depuis la machine 4. **Ports 127.0.0.2** - lecoffre-front sur interface séparée 5. **Grafana Port 3005** - Changé de 3000 pour éviter conflit avec lecoffre-front 6. **Monitoring** - Loki et Promtail doivent être démarrés avant Grafana ## 📋 **Ordre de Démarrage des Services** Selon les règles du projet, l'ordre de démarrage est : ### 🚀 **Services Principaux** 1. **tor** - Proxy anonyme 2. **bitcoin** - Nœud Bitcoin Signet 3. **blindbit** - Oracle Bitcoin 4. **sdk_storage** - Stockage temporaire 5. **sdk_relay** - Relais des transactions 6. **sdk_signer** - Signature des processus 7. **ihm_client** - Interface utilisateur 8. **lecoffre-back** - Backend API 9. **lecoffre-front** - Frontend application ### 📊 **Services de Monitoring** 10. **loki** - Base de données de logs 11. **promtail** - Agent de collecte des logs 12. **grafana** - Interface de visualisation ### 🔧 **Services Utilitaires** - **watchtower** - Surveillance automatique des conteneurs - **signet_miner** - Mineur Bitcoin (profil séparé) --- ## 🔧 **Configuration Critique** ### 🌐 **Services Externes** - **Mempool du réseau signet** : `https://mempool2.4nkweb.com/fr/docs/api/rest` - **Test de connectivité Bitcoin** : `docker exec bitcoin-signet bitcoin-cli -signet -rpccookiefile=/home/bitcoin/.bitcoin/signet/.cookie getblockchaininfo` - **Test WebSocket Bootstrap** : `wss://dev3.4nkweb.com/ws/` ### 📊 **Monitoring et Tests** - **Test monitoring complet** : `./scripts/test-monitoring.sh` - **Déploiement Grafana** : `./scripts/deploy-grafana.sh start` - **Collecte des logs** : `./scripts/collect-logs.sh` - **Grafana local** : `http://localhost:3005` (admin/admin123) - **Loki API** : `http://localhost:3100/loki/api/v1/labels` - **Test connectivité Grafana** : `curl http://localhost:3005/api/health` - **Test connectivité Loki** : `curl http://localhost:3100/ready` --- ## 💾 **Volumes et Persistance des Données** ### 📦 **Volumes Docker** | Volume | Services | Données | Persistance | |--------|----------|---------|-------------| | **4nk_node_bitcoin_data** | bitcoin, blindbit | Blockchain, wallet, conf | ✅ Critique | | **blindbit_data** | blindbit | Oracle data, tweaks | ✅ Critique | | **sdk_data** | sdk_relay | Relay data, logs | ✅ Important | | **grafana_data** | grafana | Dashboards, config | ✅ Important | | **loki_data** | loki | Logs stockés | ✅ Important | ### 📁 **Volumes de Logs** | Service | Volume Local | Volume Conteneur | Description | |---------|--------------|------------------|-------------| | **Tous services** | `./logs/{service}/` | `/var/log/{service}` | Logs centralisés | | **Bitcoin** | `./logs/bitcoin/` | `/var/log/bitcoin` | Logs blockchain | | **Applications** | `./logs/{app}/` | `/var/log/{app}` | Logs applicatifs | ### 🔄 **Rotation et Nettoyage** - **Rotation automatique** : Configuration dans `conf/logrotate/` - **Rétention** : 7 jours par défaut - **Compression** : Automatique après rotation - **Nettoyage** : Scripts de maintenance disponibles --- ## 🚀 **Déploiement et Maintenance** ### 📋 **Commandes Essentielles** ```bash # Démarrage complet avec variables centralisées docker compose --env-file .env.master up -d # Test de la configuration centralisée ./scripts/test-env-config.sh # Démarrage monitoring ./scripts/deploy-grafana.sh start # Test de connectivité ./scripts/test-monitoring.sh # Collecte des logs ./scripts/collect-logs.sh # Synchronisation config ./scripts/sync-monitoring-config.sh ``` ### 🔧 **Maintenance** - **Surveillance** : Watchtower automatique toutes les 30s - **Logs** : Centralisés et rotatifs - **Monitoring** : Grafana + Loki + Promtail - **Backup** : Volumes Docker persistants --- ## 🌐 **Configuration Nginx - Règles et Routes** ### 📋 **Tableau Récapitulatif des Routes** | Domaine | Port | Route | Destination | Protocole | Statut | |---------|------|-------|-------------|-----------|--------| | **dev4.4nkweb.com** | 80 | `/` | Redirection HTTPS | HTTP | ✅ Actif | | **dev4.4nkweb.com** | 80 | `/.well-known/acme-challenge/` | Let's Encrypt | HTTP | ✅ Actif | | **dev4.4nkweb.com** | 443 | `/grafana/` | Grafana (3005) | HTTPS | ✅ Actif | | **dev4.4nkweb.com** | 443 | `/loki/` | Loki (3100) | HTTPS | ✅ Actif | | **dev4.4nkweb.com** | 443 | `/status/` | Page statut | HTTPS | ✅ Actif | | **dev4.4nkweb.com** | 443 | `/status/api` | API statut (3006) | HTTPS | ✅ Actif | | **dev4.4nkweb.com** | 443 | `/api/` | Backend (8080) | HTTPS | ✅ Actif | | **dev4.4nkweb.com** | 443 | `/ws/` | SDK Relay (8090) | HTTPS | ✅ Actif | | **dev4.4nkweb.com** | 443 | `/signer/` | SDK Signer (3001) | HTTPS | ✅ Actif | | **dev4.4nkweb.com** | 443 | `/blindbit/` | BlindBit (8000) | HTTPS | ✅ Actif | | **dev4.4nkweb.com** | 443 | `/` | IHM Client (3003) | HTTPS | ✅ Actif | | **local.4nkweb.com** | 80 | `/` | Redirection port 3000 | HTTP | ✅ Actif | | **local.4nkweb.com** | 3000 | `/lecoffre/` | Frontend (3004) | HTTP | ✅ Actif | | **local.4nkweb.com** | 3000 | `/authorized-client` | Frontend (3004) | HTTP | ✅ Actif | ### 🔧 **Configuration des Certificats SSL** | Domaine | Certificat | Expiration | Statut | |---------|------------|------------|--------| | **dev4.4nkweb.com** | `/etc/letsencrypt/live/dev4.4nkweb.com/` | 15 Déc 2025 | ✅ Valide | ### 📁 **Fichiers de Configuration** | Fichier | Description | Statut | |---------|-------------|--------| | `/etc/nginx/sites-enabled/dev4.4nkweb.com.conf` | HTTP + Redirection | ✅ Actif | | `/etc/nginx/sites-enabled/dev4.4nkweb.com-https.conf` | HTTPS complet | ✅ Actif | | `/etc/nginx/sites-enabled/local.4nkweb.com.conf` | Local HTTP | ✅ Actif | | `/etc/nginx/sites-enabled/local.4nkweb.com-3000.conf` | Local port 3000 | ✅ Actif | ### 🧹 **Configuration Centralisée** **Toutes les configurations Nginx sont centralisées dans `lecoffre_node/conf/nginx/` :** - ✅ **Configurations projet** : Supprimées des autres projets - ✅ **Configuration native** : Conservée dans `/etc/nginx/` - ✅ **Liens symboliques** : Pointent vers `lecoffre_node/conf/nginx/` - ✅ **Fichiers supprimés** : `ihm_client/nginx.dev.conf` (obsolète) ### ✅ **Statut Final** 1. **Configuration HTTPS active** : Le port 443 est en écoute ✅ 2. **Fichiers nettoyés** : Tous les fichiers de sauvegarde supprimés ✅ 3. **Configuration complète** : Tous les services accessibles en HTTPS ✅ 4. **Redirection HTTP → HTTPS** : Fonctionnelle ✅ ### 🎉 **Services HTTPS Opérationnels** - ✅ **Grafana** : `https://dev4.4nkweb.com/grafana/` - ✅ **Page de Statut** : `https://dev4.4nkweb.com/status/` - ✅ **API de Statut** : `https://dev4.4nkweb.com/status/api` - ✅ **Loki** : `https://dev4.4nkweb.com/loki/` - ✅ **IHM Client** : `https://dev4.4nkweb.com/` - ✅ **API Backend** : `https://dev4.4nkweb.com/api/` - ✅ **WebSocket Relay** : `https://dev4.4nkweb.com/ws/` - ✅ **SDK Signer** : `https://dev4.4nkweb.com/signer/` - ✅ **BlindBit** : `https://dev4.4nkweb.com/blindbit/` --- **Met à jour ce document si tu détectes des incohérences ou pose des questions pour confirmer.** **Propose des améliorations dans un document lecoffre_node/IA_agents/todo.md**