Architecture Réseau - Système Notarial 4NK_IA
🌐 Vue d'ensemble du Réseau
Le système notarial 4NK_IA utilise une architecture réseau distribuée avec des services conteneurisés et une communication sécurisée entre composants.
🔗 Topologie du Réseau
┌─────────────────────────────────────────────────────────────────┐
│ RÉSEAU EXTERNE │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Client │ │ Notaire │ │ Admin │ │
│ │ Web │ │ (API) │ │ (Grafana) │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
└─────────────────────┬───────────────────────────────────────────┘
│ HTTPS/WSS
┌─────────────────────▼───────────────────────────────────────────┐
│ TRAEFIK (Port 80/443) │
│ Passerelle et Load Balancer │
└─────────────────────┬───────────────────────────────────────────┘
│
┌─────────────────────▼───────────────────────────────────────────┐
│ RÉSEAU DOCKER INTERNE │
│ │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ API │ │ Worker │ │ Web UI │ │
│ │ (8000) │ │ Celery │ │ (8081) │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
│ │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ PostgreSQL │ │ Redis │ │ MinIO │ │
│ │ (5432) │ │ (6379) │ │ (9000/9001) │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
│ │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Ollama │ │ AnythingLLM │ │ Neo4j │ │
│ │ (11434) │ │ (3001) │ │ (7474) │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
│ │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ OpenSearch │ │ Prometheus │ │ Grafana │ │
│ │ (9200) │ │ (9090) │ │ (3000) │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
└─────────────────────────────────────────────────────────────────┘
🔌 Ports et Services
Services Exposés (Accessibles depuis l'extérieur)
Service |
Port |
Protocole |
Description |
Traefik |
80 |
HTTP |
Passerelle principale |
Traefik |
443 |
HTTPS |
Passerelle sécurisée |
Web UI |
8081 |
HTTP |
Interface utilisateur |
MinIO Console |
9001 |
HTTP |
Interface d'administration MinIO |
Grafana |
3000 |
HTTP |
Dashboards de monitoring |
Neo4j Browser |
7474 |
HTTP |
Interface Neo4j |
Services Internes (Réseau Docker)
Service |
Port |
Protocole |
Description |
API FastAPI |
8000 |
HTTP |
API principale |
PostgreSQL |
5432 |
TCP |
Base de données |
Redis |
6379 |
TCP |
Cache et queue |
MinIO |
9000 |
HTTP |
Stockage objet |
Ollama |
11434 |
HTTP |
LLM local |
AnythingLLM |
3001 |
HTTP |
RAG et chat |
Neo4j |
7687 |
TCP |
Base de données graphe |
OpenSearch |
9200 |
HTTP |
Moteur de recherche |
Prometheus |
9090 |
HTTP |
Métriques |
🌍 Communication Inter-Services
Flux de Données Principal
graph TD
A[Client Web] -->|HTTPS| B[Traefik]
B -->|HTTP| C[API FastAPI]
C -->|TCP| D[PostgreSQL]
C -->|Redis| E[Redis Queue]
E -->|Celery| F[Worker]
F -->|HTTP| G[Ollama]
F -->|HTTP| H[AnythingLLM]
F -->|HTTP| I[MinIO]
F -->|HTTP| J[OpenSearch]
F -->|TCP| K[Neo4j]
L[Prometheus] -->|Scrape| C
L -->|Scrape| F
M[Grafana] -->|Query| L
Patterns de Communication
1. API → Base de Données
# PostgreSQL (Données structurées)
DATABASE_URL = "postgresql+psycopg://notariat:notariat_pwd@postgres:5432/notariat"
# Redis (Cache et Queue)
REDIS_URL = "redis://redis:6379/0"
2. Worker → Services Externes
# Ollama (LLM)
OLLAMA_BASE_URL = "http://ollama:11434"
# AnythingLLM (RAG)
ANYLLM_BASE_URL = "http://anythingsqlite:3001"
# MinIO (Stockage)
MINIO_ENDPOINT = "minio:9000"
3. Monitoring
# Prometheus (Métriques)
- targets: ['api:8000', 'worker:celery', 'postgres:5432']
scrape_interval: 15s
# Grafana (Dashboards)
- datasource: prometheus:9090
- dashboards: ['api', 'worker', 'database']
🔒 Sécurité Réseau
Isolation des Services
# Docker Compose - Réseaux
networks:
frontend:
driver: bridge
ipam:
config:
- subnet: 172.20.0.0/16
backend:
driver: bridge
ipam:
config:
- subnet: 172.21.0.0/16
monitoring:
driver: bridge
ipam:
config:
- subnet: 172.22.0.0/16
Sécurité des Communications
1. Chiffrement TLS
- Traefik : Certificats Let's Encrypt automatiques
- API : HTTPS obligatoire en production
- Base de données : Connexions chiffrées
2. Authentification
# JWT pour l'API
JWT_SECRET_KEY = "your-secret-key"
JWT_ALGORITHM = "HS256"
JWT_EXPIRATION = 3600 # 1 heure
# Authentification base de données
POSTGRES_USER = "notariat"
POSTGRES_PASSWORD = "notariat_pwd"
3. Firewall et Accès
# Règles iptables (exemple)
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --dport 443 -j ACCEPT
iptables -A INPUT -p tcp --dport 8081 -j ACCEPT
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
iptables -A INPUT -j DROP
📡 APIs Externes
Services Gouvernementaux
Configuration des APIs Externes
# Configuration des timeouts et retry
EXTERNAL_API_CONFIG = {
"timeout": 30,
"retry_attempts": 3,
"retry_delay": 1,
"rate_limit": {
"cadastre": 100, # requêtes/heure
"georisques": 50,
"bodacc": 200
}
}
🔄 Load Balancing et Haute Disponibilité
Traefik Configuration
# docker-compose.yml
traefik:
image: traefik:v3.0
command:
- "--api.dashboard=true"
- "--providers.docker=true"
- "--entrypoints.web.address=:80"
- "--entrypoints.websecure.address=:443"
- "--certificatesresolvers.letsencrypt.acme.email=ops@4nkweb.com"
- "--certificatesresolvers.letsencrypt.acme.storage=/letsencrypt/acme.json"
- "--certificatesresolvers.letsencrypt.acme.httpchallenge.entrypoint=web"
Health Checks
# API Health Check
@app.get("/api/health")
async def health_check():
return {
"status": "healthy",
"services": {
"database": check_db_connection(),
"redis": check_redis_connection(),
"minio": check_minio_connection(),
"ollama": check_ollama_connection()
}
}
📊 Monitoring Réseau
Métriques Collectées
- Latence : Temps de réponse des services
- Débit : Requêtes par seconde
- Erreurs : Taux d'erreur par service
- Connexions : Nombre de connexions actives
- Bande passante : Utilisation réseau
Alertes Configurées
# Prometheus Alert Rules
groups:
- name: network_alerts
rules:
- alert: HighLatency
expr: http_request_duration_seconds > 5
for: 2m
labels:
severity: warning
annotations:
summary: "High latency detected"
- alert: ServiceDown
expr: up == 0
for: 1m
labels:
severity: critical
annotations:
summary: "Service is down"
🚀 Optimisations Réseau
1. Mise en Cache
# Redis Cache
@cache(expire=3600) # 1 heure
async def get_document_analysis(doc_id: str):
# Analyse mise en cache
pass
2. Compression
# Gzip compression
app.add_middleware(GZipMiddleware, minimum_size=1000)
3. Connection Pooling
# PostgreSQL
engine = create_engine(
DATABASE_URL,
pool_size=20,
max_overflow=30,
pool_pre_ping=True
)
🔧 Dépannage Réseau
Commandes de Diagnostic
# Test de connectivité
docker exec -it 4nk_ia-api-1 ping postgres
docker exec -it 4nk_ia-api-1 ping redis
# Vérification des ports
netstat -tulpn | grep :8000
netstat -tulpn | grep :5432
# Test des services
curl -f http://localhost:8000/api/health
curl -f http://localhost:8081
# Logs réseau
docker logs 4nk_ia-traefik-1
docker logs 4nk_ia-api-1
Problèmes Courants
- Port déjà utilisé :
lsof -i :8000
- Connexion refusée : Vérifier les services Docker
- Timeout : Augmenter les timeouts dans la config
- DNS : Vérifier la résolution des noms de services
📋 Checklist de Déploiement Réseau