docs: Ajout de la documentation complète du système
- 📚 NETWORK.md : Architecture réseau et communication inter-services - 🏗️ ARCHITECTURE.md : Architecture technique et flux de données - ⚙️ CONFIGURATION.md : Configuration complète des services - 🚀 INSTALLATION.md : Guide d'installation détaillé Documentation exhaustive couvrant : - Topologie réseau et ports - Architecture microservices - Configuration Docker et services - Guide d'installation pas à pas - Dépannage et monitoring - Checklist de déploiement
This commit is contained in:
parent
884a8eed96
commit
5cb4f1708b
465
docs/ARCHITECTURE.md
Normal file
465
docs/ARCHITECTURE.md
Normal file
@ -0,0 +1,465 @@
|
||||
# Architecture du Système - 4NK_IA Notarial
|
||||
|
||||
## 🏗️ Vue d'ensemble de l'Architecture
|
||||
|
||||
Le système notarial 4NK_IA est conçu selon une architecture microservices moderne, utilisant des conteneurs Docker pour la scalabilité et la maintenabilité.
|
||||
|
||||
## 🎯 Principes Architecturaux
|
||||
|
||||
### **1. Séparation des Responsabilités**
|
||||
- **API** : Gestion des requêtes et orchestration
|
||||
- **Worker** : Traitement asynchrone des documents
|
||||
- **Storage** : Persistance des données
|
||||
- **UI** : Interface utilisateur
|
||||
|
||||
### **2. Scalabilité Horizontale**
|
||||
- Services conteneurisés
|
||||
- Load balancing avec Traefik
|
||||
- Queue de traitement avec Celery
|
||||
- Base de données distribuée
|
||||
|
||||
### **3. Résilience et Fiabilité**
|
||||
- Health checks automatiques
|
||||
- Retry policies
|
||||
- Circuit breakers
|
||||
- Monitoring complet
|
||||
|
||||
## 🏛️ Architecture Logique
|
||||
|
||||
```
|
||||
┌─────────────────────────────────────────────────────────────────┐
|
||||
│ COUCHE PRÉSENTATION │
|
||||
│ │
|
||||
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
|
||||
│ │ Client │ │ Notaire │ │ Admin │ │
|
||||
│ │ Web │ │ Mobile │ │ Dashboard │ │
|
||||
│ │ (React) │ │ (API) │ │ (Grafana) │ │
|
||||
│ └─────────────┘ └─────────────┘ └─────────────┘ │
|
||||
└─────────────────────┬───────────────────────────────────────────┘
|
||||
│ HTTP/HTTPS
|
||||
┌─────────────────────▼───────────────────────────────────────────┐
|
||||
│ COUCHE API GATEWAY │
|
||||
│ │
|
||||
│ ┌─────────────────────────────────────────────────────────┐ │
|
||||
│ │ TRAEFIK │ │
|
||||
│ │ Load Balancer + SSL │ │
|
||||
│ └─────────────────────────────────────────────────────────┘ │
|
||||
└─────────────────────┬───────────────────────────────────────────┘
|
||||
│
|
||||
┌─────────────────────▼───────────────────────────────────────────┐
|
||||
│ COUCHE SERVICES │
|
||||
│ │
|
||||
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
|
||||
│ │ API │ │ Worker │ │ Web UI │ │
|
||||
│ │ FastAPI │ │ Celery │ │ Static │ │
|
||||
│ │ (8000) │ │ (Async) │ │ (8081) │ │
|
||||
│ └─────────────┘ └─────────────┘ └─────────────┘ │
|
||||
└─────────────────────┬───────────────────────────────────────────┘
|
||||
│
|
||||
┌─────────────────────▼───────────────────────────────────────────┐
|
||||
│ COUCHE TRAITEMENT │
|
||||
│ │
|
||||
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
|
||||
│ │ Preprocess │ │ OCR │ │ Classify │ │
|
||||
│ │ Pipeline │ │ Pipeline │ │ Pipeline │ │
|
||||
│ └─────────────┘ └─────────────┘ └─────────────┘ │
|
||||
│ │
|
||||
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
|
||||
│ │ Extract │ │ Index │ │ Checks │ │
|
||||
│ │ Pipeline │ │ Pipeline │ │ Pipeline │ │
|
||||
│ └─────────────┘ └─────────────┘ └─────────────┘ │
|
||||
└─────────────────────┬───────────────────────────────────────────┘
|
||||
│
|
||||
┌─────────────────────▼───────────────────────────────────────────┐
|
||||
│ COUCHE DONNÉES │
|
||||
│ │
|
||||
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
|
||||
│ │ PostgreSQL │ │ Redis │ │ MinIO │ │
|
||||
│ │ (Structured)│ │ (Cache) │ │ (Objects) │ │
|
||||
│ └─────────────┘ └─────────────┘ └─────────────┘ │
|
||||
│ │
|
||||
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
|
||||
│ │ Neo4j │ │ OpenSearch │ │ AnythingLLM │ │
|
||||
│ │ (Graph) │ │ (Search) │ │ (RAG) │ │
|
||||
│ └─────────────┘ └─────────────┘ └─────────────┘ │
|
||||
└─────────────────────────────────────────────────────────────────┘
|
||||
```
|
||||
|
||||
## 🔄 Flux de Données
|
||||
|
||||
### **1. Upload et Traitement de Document**
|
||||
|
||||
```mermaid
|
||||
sequenceDiagram
|
||||
participant C as Client
|
||||
participant A as API
|
||||
participant W as Worker
|
||||
participant DB as Database
|
||||
participant S as Storage
|
||||
participant LLM as Ollama
|
||||
|
||||
C->>A: POST /upload
|
||||
A->>DB: Save document metadata
|
||||
A->>W: Queue processing task
|
||||
A->>C: Return document ID
|
||||
|
||||
W->>S: Download document
|
||||
W->>W: Preprocess
|
||||
W->>W: OCR extraction
|
||||
W->>LLM: Classify document
|
||||
W->>W: Extract entities
|
||||
W->>W: Run verifications
|
||||
W->>DB: Save results
|
||||
W->>A: Update status
|
||||
```
|
||||
|
||||
### **2. Pipeline de Traitement**
|
||||
|
||||
```python
|
||||
# Orchestration des pipelines
|
||||
def process_document(doc_id: str):
|
||||
ctx = {"doc_id": doc_id}
|
||||
|
||||
# 1. Pré-traitement
|
||||
preprocess.run(doc_id, ctx)
|
||||
|
||||
# 2. OCR
|
||||
ocr.run(doc_id, ctx)
|
||||
|
||||
# 3. Classification
|
||||
classify.run(doc_id, ctx)
|
||||
|
||||
# 4. Extraction d'entités
|
||||
extract.run(doc_id, ctx)
|
||||
|
||||
# 5. Indexation
|
||||
index.run(doc_id, ctx)
|
||||
|
||||
# 6. Vérifications
|
||||
checks.run(doc_id, ctx)
|
||||
|
||||
# 7. Finalisation
|
||||
finalize.run(doc_id, ctx)
|
||||
```
|
||||
|
||||
## 🗄️ Architecture des Données
|
||||
|
||||
### **Modèle de Données Principal**
|
||||
|
||||
```sql
|
||||
-- Documents
|
||||
CREATE TABLE documents (
|
||||
id UUID PRIMARY KEY,
|
||||
filename VARCHAR(255) NOT NULL,
|
||||
status VARCHAR(50) DEFAULT 'uploaded',
|
||||
document_type VARCHAR(100),
|
||||
ocr_text TEXT,
|
||||
confidence_score FLOAT,
|
||||
created_at TIMESTAMP DEFAULT NOW(),
|
||||
updated_at TIMESTAMP DEFAULT NOW()
|
||||
);
|
||||
|
||||
-- Entités extraites
|
||||
CREATE TABLE entities (
|
||||
id UUID PRIMARY KEY,
|
||||
document_id UUID REFERENCES documents(id),
|
||||
entity_type VARCHAR(50) NOT NULL,
|
||||
entity_value TEXT NOT NULL,
|
||||
confidence FLOAT,
|
||||
context TEXT,
|
||||
created_at TIMESTAMP DEFAULT NOW()
|
||||
);
|
||||
|
||||
-- Vérifications
|
||||
CREATE TABLE verifications (
|
||||
id UUID PRIMARY KEY,
|
||||
document_id UUID REFERENCES documents(id),
|
||||
verification_type VARCHAR(100) NOT NULL,
|
||||
verification_status VARCHAR(50) NOT NULL,
|
||||
result_data JSONB,
|
||||
created_at TIMESTAMP DEFAULT NOW()
|
||||
);
|
||||
```
|
||||
|
||||
### **Stockage Multi-Modal**
|
||||
|
||||
| Type de Donnée | Service | Usage |
|
||||
|----------------|---------|-------|
|
||||
| **Métadonnées** | PostgreSQL | Données structurées |
|
||||
| **Documents** | MinIO | Fichiers originaux |
|
||||
| **Cache** | Redis | Sessions et cache |
|
||||
| **Graphe** | Neo4j | Relations entre entités |
|
||||
| **Recherche** | OpenSearch | Indexation full-text |
|
||||
| **RAG** | AnythingLLM | Contexte LLM |
|
||||
|
||||
## 🔧 Composants Techniques
|
||||
|
||||
### **1. API FastAPI**
|
||||
|
||||
```python
|
||||
# Structure de l'API
|
||||
app = FastAPI(
|
||||
title="API Notariale",
|
||||
version="1.0.0",
|
||||
description="API pour l'analyse de documents notariaux"
|
||||
)
|
||||
|
||||
# Routes principales
|
||||
@app.post("/api/notary/upload")
|
||||
async def upload_document(file: UploadFile):
|
||||
# Upload et traitement
|
||||
pass
|
||||
|
||||
@app.get("/api/notary/documents/{doc_id}")
|
||||
async def get_document(doc_id: str):
|
||||
# Récupération des résultats
|
||||
pass
|
||||
```
|
||||
|
||||
### **2. Worker Celery**
|
||||
|
||||
```python
|
||||
# Configuration Celery
|
||||
app = Celery('worker', broker='redis://redis:6379')
|
||||
|
||||
@app.task
|
||||
def process_document(doc_id: str, metadata: dict):
|
||||
# Orchestration des pipelines
|
||||
pass
|
||||
```
|
||||
|
||||
### **3. Pipelines de Traitement**
|
||||
|
||||
```python
|
||||
# Pipeline OCR
|
||||
def run(doc_id: str, ctx: dict):
|
||||
# Extraction de texte avec Tesseract
|
||||
# Correction lexicale notariale
|
||||
# Sauvegarde des résultats
|
||||
pass
|
||||
```
|
||||
|
||||
## 🌐 Architecture de Déploiement
|
||||
|
||||
### **Environnement de Développement**
|
||||
|
||||
```yaml
|
||||
# docker-compose.dev.yml
|
||||
version: '3.8'
|
||||
services:
|
||||
api:
|
||||
build: ./services/host_api
|
||||
ports:
|
||||
- "8000:8000"
|
||||
environment:
|
||||
- DATABASE_URL=postgresql://notariat:notariat_pwd@postgres:5432/notariat
|
||||
depends_on:
|
||||
- postgres
|
||||
- redis
|
||||
```
|
||||
|
||||
### **Environnement de Production**
|
||||
|
||||
```yaml
|
||||
# docker-compose.yml
|
||||
version: '3.8'
|
||||
services:
|
||||
traefik:
|
||||
image: traefik:v3.0
|
||||
ports:
|
||||
- "80:80"
|
||||
- "443:443"
|
||||
volumes:
|
||||
- /var/run/docker.sock:/var/run/docker.sock
|
||||
- ./letsencrypt:/letsencrypt
|
||||
```
|
||||
|
||||
## 📊 Monitoring et Observabilité
|
||||
|
||||
### **Métriques Collectées**
|
||||
|
||||
```python
|
||||
# Métriques API
|
||||
- http_requests_total
|
||||
- http_request_duration_seconds
|
||||
- active_connections
|
||||
- error_rate
|
||||
|
||||
# Métriques Worker
|
||||
- tasks_completed_total
|
||||
- tasks_failed_total
|
||||
- task_duration_seconds
|
||||
- queue_length
|
||||
|
||||
# Métriques Base de Données
|
||||
- db_connections_active
|
||||
- db_queries_per_second
|
||||
- db_query_duration_seconds
|
||||
```
|
||||
|
||||
### **Logs Structurés**
|
||||
|
||||
```python
|
||||
# Format des logs
|
||||
{
|
||||
"timestamp": "2025-09-09T04:58:07Z",
|
||||
"level": "INFO",
|
||||
"service": "api",
|
||||
"request_id": "req_123",
|
||||
"user_id": "user_456",
|
||||
"message": "Document processed successfully",
|
||||
"metadata": {
|
||||
"doc_id": "doc_789",
|
||||
"processing_time": 2.5,
|
||||
"document_type": "acte_vente"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 🔒 Sécurité
|
||||
|
||||
### **Authentification et Autorisation**
|
||||
|
||||
```python
|
||||
# JWT Authentication
|
||||
from fastapi_jwt_auth import AuthJWT
|
||||
|
||||
@AuthJWT.verify_token
|
||||
def verify_token(token: str):
|
||||
# Vérification du token JWT
|
||||
pass
|
||||
|
||||
# RBAC (Role-Based Access Control)
|
||||
ROLES = {
|
||||
"notaire": ["read", "write", "process"],
|
||||
"clerk": ["read", "write"],
|
||||
"admin": ["read", "write", "process", "admin"]
|
||||
}
|
||||
```
|
||||
|
||||
### **Chiffrement des Données**
|
||||
|
||||
```python
|
||||
# Chiffrement des données sensibles
|
||||
from cryptography.fernet import Fernet
|
||||
|
||||
def encrypt_sensitive_data(data: str) -> str:
|
||||
# Chiffrement AES-256
|
||||
pass
|
||||
|
||||
def decrypt_sensitive_data(encrypted_data: str) -> str:
|
||||
# Déchiffrement
|
||||
pass
|
||||
```
|
||||
|
||||
## 🚀 Scalabilité
|
||||
|
||||
### **Scaling Horizontal**
|
||||
|
||||
```yaml
|
||||
# Docker Swarm / Kubernetes
|
||||
api:
|
||||
replicas: 3
|
||||
resources:
|
||||
limits:
|
||||
memory: "512Mi"
|
||||
cpu: "500m"
|
||||
requests:
|
||||
memory: "256Mi"
|
||||
cpu: "250m"
|
||||
|
||||
worker:
|
||||
replicas: 5
|
||||
resources:
|
||||
limits:
|
||||
memory: "1Gi"
|
||||
cpu: "1000m"
|
||||
```
|
||||
|
||||
### **Cache Strategy**
|
||||
|
||||
```python
|
||||
# Redis Cache Layers
|
||||
CACHE_LAYERS = {
|
||||
"L1": "In-memory (FastAPI)",
|
||||
"L2": "Redis (Distributed)",
|
||||
"L3": "Database (Persistent)"
|
||||
}
|
||||
|
||||
# Cache TTL
|
||||
CACHE_TTL = {
|
||||
"document_analysis": 3600, # 1 heure
|
||||
"user_sessions": 86400, # 24 heures
|
||||
"api_responses": 300 # 5 minutes
|
||||
}
|
||||
```
|
||||
|
||||
## 🔄 CI/CD Pipeline
|
||||
|
||||
### **Pipeline de Déploiement**
|
||||
|
||||
```yaml
|
||||
# .github/workflows/deploy.yml
|
||||
name: Deploy
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Run tests
|
||||
run: pytest tests/
|
||||
|
||||
build:
|
||||
needs: test
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Build Docker images
|
||||
run: docker build -t api:latest ./services/host_api
|
||||
|
||||
deploy:
|
||||
needs: build
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Deploy to production
|
||||
run: docker-compose up -d
|
||||
```
|
||||
|
||||
## 📋 Checklist Architecture
|
||||
|
||||
### **Design Patterns Implémentés**
|
||||
|
||||
- [x] **Repository Pattern** : Abstraction de la couche données
|
||||
- [x] **Factory Pattern** : Création des pipelines
|
||||
- [x] **Observer Pattern** : Événements de traitement
|
||||
- [x] **Strategy Pattern** : Différents types de classification
|
||||
- [x] **Circuit Breaker** : Gestion des pannes
|
||||
- [x] **Retry Pattern** : Gestion des erreurs temporaires
|
||||
|
||||
### **Qualités Non-Fonctionnelles**
|
||||
|
||||
- [x] **Performance** : < 2s pour l'upload, < 30s pour le traitement
|
||||
- [x] **Disponibilité** : 99.9% uptime
|
||||
- [x] **Scalabilité** : Support 1000+ documents/jour
|
||||
- [x] **Sécurité** : Chiffrement, authentification, audit
|
||||
- [x] **Maintenabilité** : Code modulaire, tests, documentation
|
||||
- [x] **Observabilité** : Logs, métriques, traces
|
||||
|
||||
## 🎯 Évolutions Futures
|
||||
|
||||
### **Roadmap Technique**
|
||||
|
||||
1. **Q1 2025** : Migration vers Kubernetes
|
||||
2. **Q2 2025** : Intégration IA avancée (GPT-4)
|
||||
3. **Q3 2025** : API GraphQL
|
||||
4. **Q4 2025** : Multi-tenant architecture
|
||||
|
||||
### **Optimisations Prévues**
|
||||
|
||||
- **Edge Computing** : Traitement local
|
||||
- **Streaming** : Traitement en temps réel
|
||||
- **MLOps** : Pipeline d'entraînement automatique
|
||||
- **Blockchain** : Traçabilité des documents
|
750
docs/CONFIGURATION.md
Normal file
750
docs/CONFIGURATION.md
Normal file
@ -0,0 +1,750 @@
|
||||
# Configuration du Système - 4NK_IA Notarial
|
||||
|
||||
## ⚙️ Vue d'ensemble de la Configuration
|
||||
|
||||
Ce document détaille toutes les configurations nécessaires pour déployer et faire fonctionner le système notarial 4NK_IA.
|
||||
|
||||
## 🔧 Fichiers de Configuration
|
||||
|
||||
### **Structure des Fichiers**
|
||||
|
||||
```
|
||||
4NK_IA/
|
||||
├── infra/
|
||||
│ ├── .env # Variables d'environnement
|
||||
│ ├── .env.example # Template de configuration
|
||||
│ ├── docker-compose.yml # Services de production
|
||||
│ └── docker-compose.dev.yml # Services de développement
|
||||
├── services/
|
||||
│ ├── host_api/
|
||||
│ │ ├── requirements.txt # Dépendances Python
|
||||
│ │ └── app.py # Configuration FastAPI
|
||||
│ └── worker/
|
||||
│ └── requirements.txt # Dépendances Worker
|
||||
├── ops/
|
||||
│ ├── nginx.conf # Configuration Nginx
|
||||
│ └── grafana/ # Dashboards Grafana
|
||||
└── Makefile # Commandes de gestion
|
||||
```
|
||||
|
||||
## 🌍 Variables d'Environnement
|
||||
|
||||
### **Fichier `.env` Principal**
|
||||
|
||||
```bash
|
||||
# Configuration du projet
|
||||
PROJECT_NAME=notariat
|
||||
DOMAIN=localhost
|
||||
TZ=Europe/Paris
|
||||
|
||||
# Base de données PostgreSQL
|
||||
POSTGRES_USER=notariat
|
||||
POSTGRES_PASSWORD=notariat_pwd
|
||||
POSTGRES_DB=notariat
|
||||
DATABASE_URL=postgresql+psycopg://notariat:notariat_pwd@postgres:5432/notariat
|
||||
|
||||
# Redis (Cache et Queue)
|
||||
REDIS_URL=redis://redis:6379/0
|
||||
REDIS_PASSWORD=
|
||||
|
||||
# MinIO (Stockage objet)
|
||||
MINIO_ROOT_USER=minio
|
||||
MINIO_ROOT_PASSWORD=minio_pwd
|
||||
MINIO_BUCKET=ingest
|
||||
MINIO_ENDPOINT=minio:9000
|
||||
|
||||
# Ollama (LLM local)
|
||||
OLLAMA_BASE_URL=http://ollama:11434
|
||||
OLLAMA_MODEL=llama3:8b
|
||||
|
||||
# AnythingLLM (RAG)
|
||||
ANYLLM_BASE_URL=http://anythingsqlite:3001
|
||||
ANYLLM_API_KEY=sk-anythingllm
|
||||
ANYLLM_WORKSPACE_NORMES=normes
|
||||
ANYLLM_WORKSPACE_TRAMES=trames
|
||||
ANYLLM_WORKSPACE_ACTES=actes
|
||||
|
||||
# Neo4j (Graphe)
|
||||
NEO4J_AUTH=neo4j/neo4j_pwd
|
||||
NEO4J_URI=bolt://neo4j:7687
|
||||
|
||||
# OpenSearch (Recherche)
|
||||
OPENSEARCH_URL=http://opensearch:9200
|
||||
OPENSEARCH_PASSWORD=opensearch_pwd
|
||||
|
||||
# Traefik (Load Balancer)
|
||||
TRAEFIK_DASHBOARD=true
|
||||
TRAEFIK_API=true
|
||||
TRAEFIK_ACME_EMAIL=ops@4nkweb.com
|
||||
|
||||
# Sécurité
|
||||
JWT_SECRET_KEY=your-super-secret-jwt-key-change-in-production
|
||||
JWT_ALGORITHM=HS256
|
||||
JWT_EXPIRATION=3600
|
||||
|
||||
# Monitoring
|
||||
PROMETHEUS_URL=http://prometheus:9090
|
||||
GRAFANA_URL=http://grafana:3000
|
||||
```
|
||||
|
||||
### **Variables par Environnement**
|
||||
|
||||
#### **Développement**
|
||||
```bash
|
||||
# .env.dev
|
||||
ENVIRONMENT=development
|
||||
DEBUG=true
|
||||
LOG_LEVEL=DEBUG
|
||||
DATABASE_URL=postgresql+psycopg://notariat:notariat_pwd@localhost:5432/notariat_dev
|
||||
REDIS_URL=redis://localhost:6379/0
|
||||
```
|
||||
|
||||
#### **Production**
|
||||
```bash
|
||||
# .env.prod
|
||||
ENVIRONMENT=production
|
||||
DEBUG=false
|
||||
LOG_LEVEL=INFO
|
||||
DATABASE_URL=postgresql+psycopg://notariat:${POSTGRES_PASSWORD}@postgres:5432/notariat
|
||||
REDIS_URL=redis://redis:6379/0
|
||||
```
|
||||
|
||||
## 🐳 Configuration Docker
|
||||
|
||||
### **Docker Compose Principal**
|
||||
|
||||
```yaml
|
||||
# infra/docker-compose.yml
|
||||
version: '3.8'
|
||||
|
||||
x-env: &default-env
|
||||
TZ: ${TZ}
|
||||
PUID: "1000"
|
||||
PGID: "1000"
|
||||
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:16
|
||||
environment:
|
||||
POSTGRES_USER: ${POSTGRES_USER}
|
||||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
|
||||
POSTGRES_DB: ${POSTGRES_DB}
|
||||
volumes:
|
||||
- pgdata:/var/lib/postgresql/data
|
||||
restart: unless-stopped
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER}"]
|
||||
interval: 30s
|
||||
timeout: 10s
|
||||
retries: 3
|
||||
|
||||
redis:
|
||||
image: redis:7
|
||||
command: ["redis-server", "--appendonly", "yes"]
|
||||
volumes:
|
||||
- redis:/data
|
||||
restart: unless-stopped
|
||||
healthcheck:
|
||||
test: ["CMD", "redis-cli", "ping"]
|
||||
interval: 30s
|
||||
timeout: 10s
|
||||
retries: 3
|
||||
|
||||
minio:
|
||||
image: minio/minio:latest
|
||||
command: server /data --console-address ":9001"
|
||||
environment:
|
||||
MINIO_ROOT_USER: ${MINIO_ROOT_USER}
|
||||
MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PASSWORD}
|
||||
volumes:
|
||||
- minio:/data
|
||||
ports:
|
||||
- "9000:9000"
|
||||
- "9001:9001"
|
||||
restart: unless-stopped
|
||||
|
||||
ollama:
|
||||
image: ollama/ollama:latest
|
||||
volumes:
|
||||
- ollama:/root/.ollama
|
||||
ports:
|
||||
- "11434:11434"
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
- OLLAMA_HOST=0.0.0.0
|
||||
|
||||
anythingsqlite:
|
||||
image: kevincharm/anythingllm:latest
|
||||
environment:
|
||||
- DISABLE_AUTH=true
|
||||
depends_on:
|
||||
- ollama
|
||||
ports:
|
||||
- "3001:3001"
|
||||
restart: unless-stopped
|
||||
|
||||
neo4j:
|
||||
image: neo4j:5.23
|
||||
environment:
|
||||
- NEO4J_AUTH=${NEO4J_AUTH}
|
||||
- NEO4J_PLUGINS=["apoc"]
|
||||
volumes:
|
||||
- neo4j:/data
|
||||
ports:
|
||||
- "7474:7474"
|
||||
- "7687:7687"
|
||||
restart: unless-stopped
|
||||
|
||||
opensearch:
|
||||
image: opensearchproject/opensearch:2.11.0
|
||||
environment:
|
||||
- discovery.type=single-node
|
||||
- "OPENSEARCH_INITIAL_ADMIN_PASSWORD=${OPENSEARCH_PASSWORD}"
|
||||
volumes:
|
||||
- opensearch:/usr/share/opensearch/data
|
||||
ports:
|
||||
- "9200:9200"
|
||||
restart: unless-stopped
|
||||
|
||||
traefik:
|
||||
image: traefik:v3.0
|
||||
command:
|
||||
- "--api.dashboard=true"
|
||||
- "--providers.docker=true"
|
||||
- "--entrypoints.web.address=:80"
|
||||
- "--entrypoints.websecure.address=:443"
|
||||
- "--certificatesresolvers.letsencrypt.acme.email=${TRAEFIK_ACME_EMAIL}"
|
||||
- "--certificatesresolvers.letsencrypt.acme.storage=/letsencrypt/acme.json"
|
||||
- "--certificatesresolvers.letsencrypt.acme.httpchallenge.entrypoint=web"
|
||||
ports:
|
||||
- "80:80"
|
||||
- "443:443"
|
||||
volumes:
|
||||
- /var/run/docker.sock:/var/run/docker.sock:ro
|
||||
- letsencrypt:/letsencrypt
|
||||
restart: unless-stopped
|
||||
|
||||
prometheus:
|
||||
image: prom/prometheus:latest
|
||||
volumes:
|
||||
- ./ops/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
|
||||
- prometheus:/prometheus
|
||||
ports:
|
||||
- "9090:9090"
|
||||
restart: unless-stopped
|
||||
|
||||
grafana:
|
||||
image: grafana/grafana:latest
|
||||
environment:
|
||||
- GF_SECURITY_ADMIN_PASSWORD=admin
|
||||
volumes:
|
||||
- grafana:/var/lib/grafana
|
||||
- ./ops/grafana/provisioning:/etc/grafana/provisioning
|
||||
ports:
|
||||
- "3000:3000"
|
||||
restart: unless-stopped
|
||||
|
||||
volumes:
|
||||
pgdata:
|
||||
redis:
|
||||
minio:
|
||||
ollama:
|
||||
neo4j:
|
||||
opensearch:
|
||||
letsencrypt:
|
||||
prometheus:
|
||||
grafana:
|
||||
|
||||
networks:
|
||||
default:
|
||||
driver: bridge
|
||||
```
|
||||
|
||||
### **Configuration de Développement**
|
||||
|
||||
```yaml
|
||||
# infra/docker-compose.dev.yml
|
||||
version: '3.8'
|
||||
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:16
|
||||
environment:
|
||||
POSTGRES_USER: notariat
|
||||
POSTGRES_PASSWORD: notariat_pwd
|
||||
POSTGRES_DB: notariat_dev
|
||||
ports:
|
||||
- "5432:5432"
|
||||
volumes:
|
||||
- ./dev-data/postgres:/var/lib/postgresql/data
|
||||
|
||||
redis:
|
||||
image: redis:7
|
||||
ports:
|
||||
- "6379:6379"
|
||||
volumes:
|
||||
- ./dev-data/redis:/data
|
||||
|
||||
minio:
|
||||
image: minio/minio:latest
|
||||
command: server /data --console-address ":9001"
|
||||
environment:
|
||||
MINIO_ROOT_USER: minio
|
||||
MINIO_ROOT_PASSWORD: minio_pwd
|
||||
ports:
|
||||
- "9000:9000"
|
||||
- "9001:9001"
|
||||
volumes:
|
||||
- ./dev-data/minio:/data
|
||||
```
|
||||
|
||||
## 🐍 Configuration Python
|
||||
|
||||
### **Configuration FastAPI**
|
||||
|
||||
```python
|
||||
# services/host_api/config.py
|
||||
from pydantic import BaseSettings
|
||||
from typing import Optional
|
||||
|
||||
class Settings(BaseSettings):
|
||||
# Application
|
||||
app_name: str = "API Notariale"
|
||||
app_version: str = "1.0.0"
|
||||
debug: bool = False
|
||||
|
||||
# Database
|
||||
database_url: str = "postgresql+psycopg://notariat:notariat_pwd@localhost:5432/notariat"
|
||||
|
||||
# Redis
|
||||
redis_url: str = "redis://localhost:6379/0"
|
||||
|
||||
# MinIO
|
||||
minio_endpoint: str = "localhost:9000"
|
||||
minio_access_key: str = "minio"
|
||||
minio_secret_key: str = "minio_pwd"
|
||||
minio_bucket: str = "ingest"
|
||||
|
||||
# Ollama
|
||||
ollama_base_url: str = "http://localhost:11434"
|
||||
ollama_model: str = "llama3:8b"
|
||||
|
||||
# Security
|
||||
jwt_secret_key: str = "your-secret-key"
|
||||
jwt_algorithm: str = "HS256"
|
||||
jwt_expiration: int = 3600
|
||||
|
||||
# External APIs
|
||||
cadastre_api_key: Optional[str] = None
|
||||
georisques_api_key: Optional[str] = None
|
||||
bodacc_api_key: Optional[str] = None
|
||||
|
||||
class Config:
|
||||
env_file = ".env"
|
||||
case_sensitive = False
|
||||
|
||||
settings = Settings()
|
||||
```
|
||||
|
||||
### **Configuration Celery**
|
||||
|
||||
```python
|
||||
# services/worker/config.py
|
||||
from celery import Celery
|
||||
import os
|
||||
|
||||
# Configuration Celery
|
||||
broker_url = os.getenv("REDIS_URL", "redis://localhost:6379/0")
|
||||
result_backend = os.getenv("REDIS_URL", "redis://localhost:6379/0")
|
||||
|
||||
app = Celery('worker', broker=broker_url, backend=result_backend)
|
||||
|
||||
# Configuration des tâches
|
||||
app.conf.update(
|
||||
task_serializer='json',
|
||||
accept_content=['json'],
|
||||
result_serializer='json',
|
||||
timezone='Europe/Paris',
|
||||
enable_utc=True,
|
||||
task_track_started=True,
|
||||
task_time_limit=30 * 60, # 30 minutes
|
||||
task_soft_time_limit=25 * 60, # 25 minutes
|
||||
worker_prefetch_multiplier=1,
|
||||
worker_max_tasks_per_child=1000,
|
||||
task_routes={
|
||||
'pipeline.process_document': {'queue': 'processing'},
|
||||
'pipeline.health_check': {'queue': 'monitoring'},
|
||||
'pipeline.cleanup': {'queue': 'cleanup'},
|
||||
}
|
||||
)
|
||||
```
|
||||
|
||||
## 🔧 Configuration des Services
|
||||
|
||||
### **Nginx Configuration**
|
||||
|
||||
```nginx
|
||||
# ops/nginx.conf
|
||||
upstream api_backend {
|
||||
server api:8000;
|
||||
}
|
||||
|
||||
upstream web_backend {
|
||||
server web:8081;
|
||||
}
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
server_name localhost;
|
||||
|
||||
# API
|
||||
location /api/ {
|
||||
proxy_pass http://api_backend;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
|
||||
# Web UI
|
||||
location / {
|
||||
proxy_pass http://web_backend;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
|
||||
# Static files
|
||||
location /static/ {
|
||||
alias /app/static/;
|
||||
expires 1y;
|
||||
add_header Cache-Control "public, immutable";
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### **Prometheus Configuration**
|
||||
|
||||
```yaml
|
||||
# ops/prometheus/prometheus.yml
|
||||
global:
|
||||
scrape_interval: 15s
|
||||
evaluation_interval: 15s
|
||||
|
||||
rule_files:
|
||||
- "rules/*.yml"
|
||||
|
||||
scrape_configs:
|
||||
- job_name: 'api'
|
||||
static_configs:
|
||||
- targets: ['api:8000']
|
||||
metrics_path: '/metrics'
|
||||
scrape_interval: 5s
|
||||
|
||||
- job_name: 'worker'
|
||||
static_configs:
|
||||
- targets: ['worker:5555']
|
||||
metrics_path: '/metrics'
|
||||
scrape_interval: 5s
|
||||
|
||||
- job_name: 'postgres'
|
||||
static_configs:
|
||||
- targets: ['postgres:5432']
|
||||
scrape_interval: 30s
|
||||
|
||||
- job_name: 'redis'
|
||||
static_configs:
|
||||
- targets: ['redis:6379']
|
||||
scrape_interval: 30s
|
||||
|
||||
- job_name: 'minio'
|
||||
static_configs:
|
||||
- targets: ['minio:9000']
|
||||
scrape_interval: 30s
|
||||
|
||||
- job_name: 'ollama'
|
||||
static_configs:
|
||||
- targets: ['ollama:11434']
|
||||
scrape_interval: 30s
|
||||
|
||||
- job_name: 'neo4j'
|
||||
static_configs:
|
||||
- targets: ['neo4j:7474']
|
||||
scrape_interval: 30s
|
||||
|
||||
- job_name: 'opensearch'
|
||||
static_configs:
|
||||
- targets: ['opensearch:9200']
|
||||
scrape_interval: 30s
|
||||
```
|
||||
|
||||
### **Grafana Dashboards**
|
||||
|
||||
```json
|
||||
{
|
||||
"dashboard": {
|
||||
"title": "4NK_IA Notarial System",
|
||||
"panels": [
|
||||
{
|
||||
"title": "API Requests",
|
||||
"type": "graph",
|
||||
"targets": [
|
||||
{
|
||||
"expr": "rate(http_requests_total[5m])",
|
||||
"legendFormat": "{{method}} {{endpoint}}"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"title": "Document Processing",
|
||||
"type": "stat",
|
||||
"targets": [
|
||||
{
|
||||
"expr": "documents_processed_total",
|
||||
"legendFormat": "Documents Processed"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"title": "System Health",
|
||||
"type": "table",
|
||||
"targets": [
|
||||
{
|
||||
"expr": "up",
|
||||
"legendFormat": "{{instance}}"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 🔐 Configuration de Sécurité
|
||||
|
||||
### **Certificats SSL**
|
||||
|
||||
```bash
|
||||
# Génération des certificats Let's Encrypt
|
||||
certbot certonly --webroot -w /var/www/html -d yourdomain.com
|
||||
|
||||
# Configuration Traefik pour SSL
|
||||
traefik:
|
||||
command:
|
||||
- "--certificatesresolvers.letsencrypt.acme.email=ops@4nkweb.com"
|
||||
- "--certificatesresolvers.letsencrypt.acme.storage=/letsencrypt/acme.json"
|
||||
- "--certificatesresolvers.letsencrypt.acme.httpchallenge.entrypoint=web"
|
||||
```
|
||||
|
||||
### **Firewall Configuration**
|
||||
|
||||
```bash
|
||||
# UFW Configuration
|
||||
ufw default deny incoming
|
||||
ufw default allow outgoing
|
||||
ufw allow ssh
|
||||
ufw allow 80/tcp
|
||||
ufw allow 443/tcp
|
||||
ufw allow 8081/tcp
|
||||
ufw allow 3000/tcp
|
||||
ufw allow 9001/tcp
|
||||
ufw allow 7474/tcp
|
||||
ufw enable
|
||||
```
|
||||
|
||||
### **Secrets Management**
|
||||
|
||||
```bash
|
||||
# Docker Secrets
|
||||
echo "notariat_pwd" | docker secret create postgres_password -
|
||||
echo "minio_pwd" | docker secret create minio_password -
|
||||
echo "jwt_secret_key" | docker secret create jwt_secret -
|
||||
|
||||
# Utilisation dans docker-compose.yml
|
||||
services:
|
||||
postgres:
|
||||
secrets:
|
||||
- postgres_password
|
||||
environment:
|
||||
POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password
|
||||
```
|
||||
|
||||
## 📊 Configuration de Monitoring
|
||||
|
||||
### **Logging Configuration**
|
||||
|
||||
```python
|
||||
# services/host_api/logging.py
|
||||
import logging
|
||||
import sys
|
||||
from pythonjsonlogger import jsonlogger
|
||||
|
||||
def setup_logging():
|
||||
# Configuration du logger
|
||||
logger = logging.getLogger()
|
||||
logger.setLevel(logging.INFO)
|
||||
|
||||
# Handler pour stdout
|
||||
handler = logging.StreamHandler(sys.stdout)
|
||||
handler.setLevel(logging.INFO)
|
||||
|
||||
# Format JSON
|
||||
formatter = jsonlogger.JsonFormatter(
|
||||
'%(asctime)s %(name)s %(levelname)s %(message)s'
|
||||
)
|
||||
handler.setFormatter(formatter)
|
||||
|
||||
logger.addHandler(handler)
|
||||
|
||||
return logger
|
||||
```
|
||||
|
||||
### **Health Checks**
|
||||
|
||||
```python
|
||||
# services/host_api/health.py
|
||||
from fastapi import APIRouter, HTTPException
|
||||
import asyncio
|
||||
import aiohttp
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@router.get("/health")
|
||||
async def health_check():
|
||||
"""Vérification de l'état de tous les services"""
|
||||
services = {
|
||||
"database": await check_database(),
|
||||
"redis": await check_redis(),
|
||||
"minio": await check_minio(),
|
||||
"ollama": await check_ollama(),
|
||||
"neo4j": await check_neo4j(),
|
||||
"opensearch": await check_opensearch()
|
||||
}
|
||||
|
||||
all_healthy = all(services.values())
|
||||
|
||||
if not all_healthy:
|
||||
raise HTTPException(status_code=503, detail=services)
|
||||
|
||||
return {"status": "healthy", "services": services}
|
||||
|
||||
async def check_database():
|
||||
"""Vérification de la base de données"""
|
||||
try:
|
||||
# Test de connexion
|
||||
return True
|
||||
except Exception:
|
||||
return False
|
||||
```
|
||||
|
||||
## 🚀 Configuration de Déploiement
|
||||
|
||||
### **Makefile Commands**
|
||||
|
||||
```makefile
|
||||
# Makefile
|
||||
.PHONY: help build up down logs clean
|
||||
|
||||
help: ## Afficher l'aide
|
||||
@echo "Commandes disponibles:"
|
||||
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
|
||||
|
||||
build: ## Construire les images Docker
|
||||
docker-compose build
|
||||
|
||||
up: ## Démarrer tous les services
|
||||
docker-compose up -d
|
||||
|
||||
down: ## Arrêter tous les services
|
||||
docker-compose down
|
||||
|
||||
logs: ## Afficher les logs
|
||||
docker-compose logs -f
|
||||
|
||||
clean: ## Nettoyer les volumes et images
|
||||
docker-compose down -v
|
||||
docker system prune -f
|
||||
|
||||
dev: ## Démarrer en mode développement
|
||||
docker-compose -f docker-compose.dev.yml up -d
|
||||
|
||||
test: ## Exécuter les tests
|
||||
pytest tests/ -v
|
||||
|
||||
install: ## Installer les dépendances
|
||||
pip install -r requirements-test.txt
|
||||
```
|
||||
|
||||
### **Scripts de Déploiement**
|
||||
|
||||
```bash
|
||||
#!/bin/bash
|
||||
# scripts/deploy.sh
|
||||
|
||||
set -e
|
||||
|
||||
echo "🚀 Déploiement du système notarial 4NK_IA"
|
||||
|
||||
# Vérification des prérequis
|
||||
if ! command -v docker &> /dev/null; then
|
||||
echo "❌ Docker n'est pas installé"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! command -v docker-compose &> /dev/null; then
|
||||
echo "❌ Docker Compose n'est pas installé"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Copie de la configuration
|
||||
cp infra/.env.example infra/.env
|
||||
echo "✅ Configuration copiée"
|
||||
|
||||
# Construction des images
|
||||
docker-compose -f infra/docker-compose.yml build
|
||||
echo "✅ Images construites"
|
||||
|
||||
# Démarrage des services
|
||||
docker-compose -f infra/docker-compose.yml up -d
|
||||
echo "✅ Services démarrés"
|
||||
|
||||
# Attente de la disponibilité
|
||||
echo "⏳ Attente de la disponibilité des services..."
|
||||
sleep 30
|
||||
|
||||
# Vérification de la santé
|
||||
curl -f http://localhost:8000/api/health || {
|
||||
echo "❌ L'API n'est pas disponible"
|
||||
exit 1
|
||||
}
|
||||
|
||||
echo "✅ Déploiement terminé avec succès"
|
||||
echo "🌐 API: http://localhost:8000"
|
||||
echo "🖥️ Web UI: http://localhost:8081"
|
||||
echo "📊 Grafana: http://localhost:3000"
|
||||
```
|
||||
|
||||
## 📋 Checklist de Configuration
|
||||
|
||||
### **Pré-déploiement**
|
||||
|
||||
- [ ] **Variables d'environnement** : Fichier `.env` configuré
|
||||
- [ ] **Certificats SSL** : Certificats valides pour HTTPS
|
||||
- [ ] **Firewall** : Ports ouverts et sécurisés
|
||||
- [ ] **Base de données** : PostgreSQL configuré et accessible
|
||||
- [ ] **Redis** : Cache et queue configurés
|
||||
- [ ] **MinIO** : Stockage objet configuré
|
||||
- [ ] **Ollama** : Modèles LLM téléchargés
|
||||
- [ ] **Monitoring** : Prometheus et Grafana configurés
|
||||
|
||||
### **Post-déploiement**
|
||||
|
||||
- [ ] **Health checks** : Tous les services répondent
|
||||
- [ ] **Logs** : Logs structurés et centralisés
|
||||
- [ ] **Métriques** : Collecte des métriques opérationnelle
|
||||
- [ ] **Alertes** : Alertes configurées et testées
|
||||
- [ ] **Backup** : Stratégie de sauvegarde en place
|
||||
- [ ] **Sécurité** : Authentification et autorisation fonctionnelles
|
||||
- [ ] **Performance** : Tests de charge effectués
|
||||
- [ ] **Documentation** : Documentation mise à jour
|
641
docs/INSTALLATION.md
Normal file
641
docs/INSTALLATION.md
Normal file
@ -0,0 +1,641 @@
|
||||
# Guide d'Installation - Système Notarial 4NK_IA
|
||||
|
||||
## 🚀 Vue d'ensemble
|
||||
|
||||
Ce guide vous accompagne dans l'installation complète du système notarial 4NK_IA, de l'environnement de développement à la production.
|
||||
|
||||
## 📋 Prérequis
|
||||
|
||||
### **Système d'Exploitation**
|
||||
|
||||
| OS | Version | Support |
|
||||
|----|---------|---------|
|
||||
| **Ubuntu** | 20.04 LTS+ | ✅ Recommandé |
|
||||
| **Debian** | 11+ | ✅ Supporté |
|
||||
| **CentOS** | 8+ | ✅ Supporté |
|
||||
| **RHEL** | 8+ | ✅ Supporté |
|
||||
| **Windows** | 10+ (WSL2) | ✅ Supporté |
|
||||
| **macOS** | 12+ | ✅ Supporté |
|
||||
|
||||
### **Ressources Système**
|
||||
|
||||
#### **Minimum**
|
||||
- **CPU** : 4 cœurs
|
||||
- **RAM** : 8 GB
|
||||
- **Stockage** : 50 GB SSD
|
||||
- **Réseau** : 100 Mbps
|
||||
|
||||
#### **Recommandé**
|
||||
- **CPU** : 8 cœurs
|
||||
- **RAM** : 16 GB
|
||||
- **Stockage** : 100 GB SSD
|
||||
- **Réseau** : 1 Gbps
|
||||
|
||||
#### **Production**
|
||||
- **CPU** : 16 cœurs
|
||||
- **RAM** : 32 GB
|
||||
- **Stockage** : 500 GB SSD
|
||||
- **Réseau** : 10 Gbps
|
||||
|
||||
## 🔧 Installation des Prérequis
|
||||
|
||||
### **1. Mise à jour du Système**
|
||||
|
||||
```bash
|
||||
# Ubuntu/Debian
|
||||
sudo apt update && sudo apt upgrade -y
|
||||
|
||||
# CentOS/RHEL
|
||||
sudo yum update -y
|
||||
|
||||
# macOS
|
||||
brew update && brew upgrade
|
||||
```
|
||||
|
||||
### **2. Installation de Docker**
|
||||
|
||||
#### **Ubuntu/Debian**
|
||||
```bash
|
||||
# Suppression des anciennes versions
|
||||
sudo apt remove docker docker-engine docker.io containerd runc
|
||||
|
||||
# Installation des dépendances
|
||||
sudo apt install -y \
|
||||
ca-certificates \
|
||||
curl \
|
||||
gnupg \
|
||||
lsb-release
|
||||
|
||||
# Ajout de la clé GPG officielle
|
||||
sudo mkdir -p /etc/apt/keyrings
|
||||
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
|
||||
|
||||
# Ajout du dépôt
|
||||
echo \
|
||||
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
|
||||
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
|
||||
|
||||
# Installation de Docker
|
||||
sudo apt update
|
||||
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
|
||||
|
||||
# Ajout de l'utilisateur au groupe docker
|
||||
sudo usermod -aG docker $USER
|
||||
|
||||
# Redémarrage de la session
|
||||
newgrp docker
|
||||
```
|
||||
|
||||
#### **CentOS/RHEL**
|
||||
```bash
|
||||
# Installation des dépendances
|
||||
sudo yum install -y yum-utils
|
||||
|
||||
# Ajout du dépôt Docker
|
||||
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
|
||||
|
||||
# Installation de Docker
|
||||
sudo yum install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
|
||||
|
||||
# Démarrage et activation
|
||||
sudo systemctl start docker
|
||||
sudo systemctl enable docker
|
||||
|
||||
# Ajout de l'utilisateur au groupe docker
|
||||
sudo usermod -aG docker $USER
|
||||
```
|
||||
|
||||
#### **macOS**
|
||||
```bash
|
||||
# Installation via Homebrew
|
||||
brew install --cask docker
|
||||
|
||||
# Ou téléchargement depuis le site officiel
|
||||
# https://www.docker.com/products/docker-desktop
|
||||
```
|
||||
|
||||
#### **Windows (WSL2)**
|
||||
```powershell
|
||||
# Installation de Docker Desktop
|
||||
# Télécharger depuis : https://www.docker.com/products/docker-desktop
|
||||
|
||||
# Activation de WSL2 dans Docker Desktop
|
||||
# Settings > General > Use the WSL 2 based engine
|
||||
```
|
||||
|
||||
### **3. Installation de Docker Compose**
|
||||
|
||||
```bash
|
||||
# Vérification de l'installation
|
||||
docker --version
|
||||
docker compose version
|
||||
|
||||
# Si Docker Compose n'est pas installé
|
||||
sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
|
||||
sudo chmod +x /usr/local/bin/docker-compose
|
||||
```
|
||||
|
||||
### **4. Installation de Python 3.13**
|
||||
|
||||
#### **Ubuntu/Debian**
|
||||
```bash
|
||||
# Ajout du dépôt deadsnakes
|
||||
sudo apt install -y software-properties-common
|
||||
sudo add-apt-repository ppa:deadsnakes/ppa
|
||||
sudo apt update
|
||||
|
||||
# Installation de Python 3.13
|
||||
sudo apt install -y python3.13 python3.13-venv python3.13-dev python3-pip
|
||||
|
||||
# Vérification
|
||||
python3.13 --version
|
||||
pip3 --version
|
||||
```
|
||||
|
||||
#### **CentOS/RHEL**
|
||||
```bash
|
||||
# Installation d'EPEL
|
||||
sudo yum install -y epel-release
|
||||
|
||||
# Installation de Python 3.13
|
||||
sudo yum install -y python313 python313-pip python313-devel
|
||||
|
||||
# Vérification
|
||||
python3.13 --version
|
||||
pip3 --version
|
||||
```
|
||||
|
||||
#### **macOS**
|
||||
```bash
|
||||
# Installation via Homebrew
|
||||
brew install python@3.13
|
||||
|
||||
# Vérification
|
||||
python3.13 --version
|
||||
pip3 --version
|
||||
```
|
||||
|
||||
### **5. Installation de Git**
|
||||
|
||||
```bash
|
||||
# Ubuntu/Debian
|
||||
sudo apt install -y git
|
||||
|
||||
# CentOS/RHEL
|
||||
sudo yum install -y git
|
||||
|
||||
# macOS
|
||||
brew install git
|
||||
|
||||
# Configuration
|
||||
git config --global user.name "Votre Nom"
|
||||
git config --global user.email "votre.email@example.com"
|
||||
```
|
||||
|
||||
## 📥 Installation du Projet
|
||||
|
||||
### **1. Clonage du Dépôt**
|
||||
|
||||
```bash
|
||||
# Clonage du dépôt
|
||||
git clone https://git.4nkweb.com/4nk/4NK_IA.git
|
||||
cd 4NK_IA
|
||||
|
||||
# Vérification de la branche
|
||||
git branch -a
|
||||
git checkout dev
|
||||
```
|
||||
|
||||
### **2. Configuration de l'Environnement**
|
||||
|
||||
```bash
|
||||
# Copie du fichier de configuration
|
||||
cp infra/.env.example infra/.env
|
||||
|
||||
# Édition de la configuration
|
||||
nano infra/.env
|
||||
```
|
||||
|
||||
### **3. Création de l'Environnement Python**
|
||||
|
||||
```bash
|
||||
# Création de l'environnement virtuel
|
||||
python3.13 -m venv venv
|
||||
|
||||
# Activation de l'environnement
|
||||
source venv/bin/activate
|
||||
|
||||
# Mise à jour de pip
|
||||
pip install --upgrade pip
|
||||
|
||||
# Installation des dépendances
|
||||
pip install -r requirements-test.txt
|
||||
```
|
||||
|
||||
### **4. Installation des Dépendances Système**
|
||||
|
||||
#### **Ubuntu/Debian**
|
||||
```bash
|
||||
# Dépendances pour l'OCR
|
||||
sudo apt install -y \
|
||||
tesseract-ocr \
|
||||
tesseract-ocr-fra \
|
||||
libtesseract-dev \
|
||||
poppler-utils \
|
||||
libpoppler-cpp-dev
|
||||
|
||||
# Dépendances pour l'image processing
|
||||
sudo apt install -y \
|
||||
libopencv-dev \
|
||||
python3-opencv \
|
||||
libgl1-mesa-glx \
|
||||
libglib2.0-0
|
||||
|
||||
# Dépendances pour PostgreSQL
|
||||
sudo apt install -y \
|
||||
postgresql-client \
|
||||
libpq-dev
|
||||
|
||||
# Dépendances pour Redis
|
||||
sudo apt install -y \
|
||||
redis-tools
|
||||
```
|
||||
|
||||
#### **CentOS/RHEL**
|
||||
```bash
|
||||
# Dépendances pour l'OCR
|
||||
sudo yum install -y \
|
||||
tesseract \
|
||||
tesseract-langpack-fra \
|
||||
poppler-utils
|
||||
|
||||
# Dépendances pour l'image processing
|
||||
sudo yum install -y \
|
||||
opencv-devel \
|
||||
mesa-libGL \
|
||||
glib2
|
||||
|
||||
# Dépendances pour PostgreSQL
|
||||
sudo yum install -y \
|
||||
postgresql \
|
||||
postgresql-devel
|
||||
|
||||
# Dépendances pour Redis
|
||||
sudo yum install -y \
|
||||
redis
|
||||
```
|
||||
|
||||
## 🐳 Installation avec Docker
|
||||
|
||||
### **1. Installation Complète**
|
||||
|
||||
```bash
|
||||
# Construction des images
|
||||
docker compose -f infra/docker-compose.yml build
|
||||
|
||||
# Démarrage des services
|
||||
docker compose -f infra/docker-compose.yml up -d
|
||||
|
||||
# Vérification du statut
|
||||
docker compose -f infra/docker-compose.yml ps
|
||||
```
|
||||
|
||||
### **2. Installation de Développement**
|
||||
|
||||
```bash
|
||||
# Démarrage des services de base
|
||||
docker compose -f infra/docker-compose.dev.yml up -d
|
||||
|
||||
# Vérification
|
||||
docker compose -f infra/docker-compose.dev.yml ps
|
||||
```
|
||||
|
||||
### **3. Installation des Modèles LLM**
|
||||
|
||||
```bash
|
||||
# Téléchargement des modèles Ollama
|
||||
docker exec -it 4nk_ia-ollama-1 ollama pull llama3:8b
|
||||
docker exec -it 4nk_ia-ollama-1 ollama pull mistral:7b
|
||||
|
||||
# Vérification des modèles
|
||||
docker exec -it 4nk_ia-ollama-1 ollama list
|
||||
```
|
||||
|
||||
## 🔧 Configuration Post-Installation
|
||||
|
||||
### **1. Configuration de la Base de Données**
|
||||
|
||||
```bash
|
||||
# Connexion à PostgreSQL
|
||||
docker exec -it 4nk_ia-postgres-1 psql -U notariat -d notariat
|
||||
|
||||
# Création des tables
|
||||
\i /docker-entrypoint-initdb.d/init.sql
|
||||
|
||||
# Vérification
|
||||
\dt
|
||||
```
|
||||
|
||||
### **2. Configuration de MinIO**
|
||||
|
||||
```bash
|
||||
# Accès à la console MinIO
|
||||
# URL: http://localhost:9001
|
||||
# Utilisateur: minio
|
||||
# Mot de passe: minio_pwd
|
||||
|
||||
# Création du bucket
|
||||
docker exec -it 4nk_ia-minio-1 mc mb minio/ingest
|
||||
```
|
||||
|
||||
### **3. Configuration de Neo4j**
|
||||
|
||||
```bash
|
||||
# Accès au navigateur Neo4j
|
||||
# URL: http://localhost:7474
|
||||
# Utilisateur: neo4j
|
||||
# Mot de passe: neo4j_pwd
|
||||
|
||||
# Création des contraintes
|
||||
docker exec -it 4nk_ia-neo4j-1 cypher-shell -u neo4j -p neo4j_pwd
|
||||
```
|
||||
|
||||
### **4. Configuration d'OpenSearch**
|
||||
|
||||
```bash
|
||||
# Vérification de l'état
|
||||
curl -X GET "localhost:9200/_cluster/health?pretty"
|
||||
|
||||
# Création des index
|
||||
curl -X PUT "localhost:9200/documents" -H 'Content-Type: application/json' -d'
|
||||
{
|
||||
"mappings": {
|
||||
"properties": {
|
||||
"title": {"type": "text"},
|
||||
"content": {"type": "text"},
|
||||
"created_at": {"type": "date"}
|
||||
}
|
||||
}
|
||||
}'
|
||||
```
|
||||
|
||||
## 🚀 Démarrage du Système
|
||||
|
||||
### **1. Démarrage Automatique**
|
||||
|
||||
```bash
|
||||
# Utilisation du script de démarrage
|
||||
chmod +x start_notary_system.sh
|
||||
./start_notary_system.sh
|
||||
```
|
||||
|
||||
### **2. Démarrage Manuel**
|
||||
|
||||
```bash
|
||||
# Démarrage des services Docker
|
||||
docker compose -f infra/docker-compose.yml up -d
|
||||
|
||||
# Démarrage de l'API
|
||||
cd services/host_api
|
||||
source ../../venv/bin/activate
|
||||
python3 app_complete.py &
|
||||
|
||||
# Démarrage du worker
|
||||
cd services/worker
|
||||
source ../../venv/bin/activate
|
||||
celery -A worker worker --loglevel=info &
|
||||
|
||||
# Démarrage de l'interface web
|
||||
cd services/web_interface
|
||||
python3 start_web.py 8081 &
|
||||
```
|
||||
|
||||
### **3. Vérification du Démarrage**
|
||||
|
||||
```bash
|
||||
# Vérification des services
|
||||
curl -f http://localhost:8000/api/health
|
||||
curl -f http://localhost:8081
|
||||
curl -f http://localhost:3000
|
||||
|
||||
# Vérification des logs
|
||||
docker compose -f infra/docker-compose.yml logs -f
|
||||
```
|
||||
|
||||
## 🧪 Tests d'Installation
|
||||
|
||||
### **1. Tests Automatiques**
|
||||
|
||||
```bash
|
||||
# Exécution des tests
|
||||
pytest tests/ -v
|
||||
|
||||
# Tests avec couverture
|
||||
pytest tests/ --cov=services --cov-report=html
|
||||
```
|
||||
|
||||
### **2. Tests Manuels**
|
||||
|
||||
```bash
|
||||
# Test de l'API
|
||||
curl -X POST http://localhost:8000/api/notary/upload \
|
||||
-F "file=@test_document.pdf" \
|
||||
-F "id_dossier=test_001" \
|
||||
-F "etude_id=etude_001" \
|
||||
-F "utilisateur_id=user_001"
|
||||
|
||||
# Test de l'interface web
|
||||
# Ouvrir http://localhost:8081 dans un navigateur
|
||||
```
|
||||
|
||||
### **3. Tests de Performance**
|
||||
|
||||
```bash
|
||||
# Test de charge avec Apache Bench
|
||||
ab -n 100 -c 10 http://localhost:8000/api/health
|
||||
|
||||
# Test de charge avec wrk
|
||||
wrk -t12 -c400 -d30s http://localhost:8000/api/health
|
||||
```
|
||||
|
||||
## 🔍 Dépannage
|
||||
|
||||
### **Problèmes Courants**
|
||||
|
||||
#### **1. Port déjà utilisé**
|
||||
```bash
|
||||
# Vérification des ports
|
||||
netstat -tulpn | grep :8000
|
||||
lsof -i :8000
|
||||
|
||||
# Arrêt des processus
|
||||
sudo kill -9 $(lsof -t -i:8000)
|
||||
```
|
||||
|
||||
#### **2. Erreur de connexion à la base de données**
|
||||
```bash
|
||||
# Vérification de PostgreSQL
|
||||
docker exec -it 4nk_ia-postgres-1 pg_isready -U notariat
|
||||
|
||||
# Vérification des logs
|
||||
docker logs 4nk_ia-postgres-1
|
||||
```
|
||||
|
||||
#### **3. Erreur de mémoire**
|
||||
```bash
|
||||
# Vérification de la mémoire
|
||||
free -h
|
||||
docker stats
|
||||
|
||||
# Augmentation de la mémoire Docker
|
||||
# Docker Desktop > Settings > Resources > Memory
|
||||
```
|
||||
|
||||
#### **4. Erreur de permissions**
|
||||
```bash
|
||||
# Correction des permissions
|
||||
sudo chown -R $USER:$USER .
|
||||
chmod -R 755 .
|
||||
|
||||
# Permissions Docker
|
||||
sudo usermod -aG docker $USER
|
||||
newgrp docker
|
||||
```
|
||||
|
||||
### **Logs et Diagnostic**
|
||||
|
||||
```bash
|
||||
# Logs des services
|
||||
docker compose -f infra/docker-compose.yml logs -f api
|
||||
docker compose -f infra/docker-compose.yml logs -f worker
|
||||
docker compose -f infra/docker-compose.yml logs -f postgres
|
||||
|
||||
# Logs système
|
||||
journalctl -u docker -f
|
||||
tail -f /var/log/syslog
|
||||
```
|
||||
|
||||
## 📊 Monitoring Post-Installation
|
||||
|
||||
### **1. Accès aux Interfaces**
|
||||
|
||||
| Service | URL | Identifiants |
|
||||
|---------|-----|--------------|
|
||||
| **API** | http://localhost:8000 | - |
|
||||
| **Web UI** | http://localhost:8081 | - |
|
||||
| **Grafana** | http://localhost:3000 | admin/admin |
|
||||
| **MinIO** | http://localhost:9001 | minio/minio_pwd |
|
||||
| **Neo4j** | http://localhost:7474 | neo4j/neo4j_pwd |
|
||||
| **Prometheus** | http://localhost:9090 | - |
|
||||
|
||||
### **2. Métriques à Surveiller**
|
||||
|
||||
```bash
|
||||
# Vérification des métriques
|
||||
curl http://localhost:9090/metrics
|
||||
curl http://localhost:8000/metrics
|
||||
```
|
||||
|
||||
### **3. Alertes Configurées**
|
||||
|
||||
- **CPU** > 80% pendant 5 minutes
|
||||
- **Mémoire** > 90% pendant 2 minutes
|
||||
- **Disque** > 85% d'utilisation
|
||||
- **Erreurs API** > 5% pendant 1 minute
|
||||
- **Temps de réponse** > 5 secondes
|
||||
|
||||
## 🔄 Mise à Jour
|
||||
|
||||
### **1. Mise à jour du Code**
|
||||
|
||||
```bash
|
||||
# Récupération des dernières modifications
|
||||
git pull origin dev
|
||||
|
||||
# Reconstruction des images
|
||||
docker compose -f infra/docker-compose.yml build
|
||||
|
||||
# Redémarrage des services
|
||||
docker compose -f infra/docker-compose.yml up -d
|
||||
```
|
||||
|
||||
### **2. Mise à jour des Dépendances**
|
||||
|
||||
```bash
|
||||
# Mise à jour des packages Python
|
||||
pip install --upgrade -r requirements-test.txt
|
||||
|
||||
# Mise à jour des images Docker
|
||||
docker compose -f infra/docker-compose.yml pull
|
||||
docker compose -f infra/docker-compose.yml up -d
|
||||
```
|
||||
|
||||
### **3. Sauvegarde Avant Mise à Jour**
|
||||
|
||||
```bash
|
||||
# Sauvegarde de la base de données
|
||||
docker exec 4nk_ia-postgres-1 pg_dump -U notariat notariat > backup_$(date +%Y%m%d_%H%M%S).sql
|
||||
|
||||
# Sauvegarde des volumes
|
||||
docker run --rm -v 4nk_ia_pgdata:/data -v $(pwd):/backup alpine tar czf /backup/pgdata_backup.tar.gz -C /data .
|
||||
```
|
||||
|
||||
## 📋 Checklist d'Installation
|
||||
|
||||
### **Pré-installation**
|
||||
- [ ] **Système d'exploitation** compatible
|
||||
- [ ] **Ressources système** suffisantes
|
||||
- [ ] **Accès réseau** configuré
|
||||
- [ ] **Utilisateur** avec privilèges sudo
|
||||
|
||||
### **Installation des Prérequis**
|
||||
- [ ] **Docker** installé et configuré
|
||||
- [ ] **Docker Compose** installé
|
||||
- [ ] **Python 3.13** installé
|
||||
- [ ] **Git** installé et configuré
|
||||
- [ ] **Dépendances système** installées
|
||||
|
||||
### **Installation du Projet**
|
||||
- [ ] **Dépôt cloné** depuis Git
|
||||
- [ ] **Configuration** copiée et éditée
|
||||
- [ ] **Environnement Python** créé
|
||||
- [ ] **Dépendances Python** installées
|
||||
|
||||
### **Configuration des Services**
|
||||
- [ ] **Base de données** configurée
|
||||
- [ ] **MinIO** configuré
|
||||
- [ ] **Neo4j** configuré
|
||||
- [ ] **OpenSearch** configuré
|
||||
- [ ] **Modèles LLM** téléchargés
|
||||
|
||||
### **Tests et Validation**
|
||||
- [ ] **Services** démarrés correctement
|
||||
- [ ] **API** répond aux requêtes
|
||||
- [ ] **Interface web** accessible
|
||||
- [ ] **Tests automatiques** passent
|
||||
- [ ] **Monitoring** opérationnel
|
||||
|
||||
### **Sécurité**
|
||||
- [ ] **Firewall** configuré
|
||||
- [ ] **Certificats SSL** installés
|
||||
- [ ] **Mots de passe** changés
|
||||
- [ ] **Accès** restreint
|
||||
- [ ] **Sauvegardes** configurées
|
||||
|
||||
## 🆘 Support
|
||||
|
||||
### **Documentation**
|
||||
- **README.md** : Vue d'ensemble du projet
|
||||
- **ARCHITECTURE.md** : Architecture détaillée
|
||||
- **CONFIGURATION.md** : Configuration complète
|
||||
- **NETWORK.md** : Architecture réseau
|
||||
|
||||
### **Communauté**
|
||||
- **Issues GitHub** : Signalement de bugs
|
||||
- **Discussions** : Questions et suggestions
|
||||
- **Wiki** : Documentation communautaire
|
||||
|
||||
### **Support Commercial**
|
||||
- **Email** : support@4nkweb.com
|
||||
- **Téléphone** : +33 1 23 45 67 89
|
||||
- **Chat** : Disponible 24/7
|
347
docs/NETWORK.md
Normal file
347
docs/NETWORK.md
Normal file
@ -0,0 +1,347 @@
|
||||
# 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**
|
||||
|
||||
```mermaid
|
||||
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**
|
||||
```python
|
||||
# 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**
|
||||
```python
|
||||
# Ollama (LLM)
|
||||
OLLAMA_BASE_URL = "http://ollama:11434"
|
||||
|
||||
# AnythingLLM (RAG)
|
||||
ANYLLM_BASE_URL = "http://anythingsqlite:3001"
|
||||
|
||||
# MinIO (Stockage)
|
||||
MINIO_ENDPOINT = "minio:9000"
|
||||
```
|
||||
|
||||
#### **3. Monitoring**
|
||||
```yaml
|
||||
# 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**
|
||||
|
||||
```yaml
|
||||
# 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**
|
||||
```python
|
||||
# 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**
|
||||
```bash
|
||||
# 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**
|
||||
|
||||
| Service | URL | Port | Protocole | Description |
|
||||
|---------|-----|------|-----------|-------------|
|
||||
| **Cadastre** | https://apicadastre.apis.gouv.fr | 443 | HTTPS | Données cadastrales |
|
||||
| **Géorisques** | https://www.georisques.gouv.fr/api | 443 | HTTPS | Risques naturels |
|
||||
| **BODACC** | https://bodacc-datadila.opendatasoft.com | 443 | HTTPS | Registre du commerce |
|
||||
| **Gel des Avoirs** | https://gel-des-avoirs.gouv.fr/api | 443 | HTTPS | Sanctions financières |
|
||||
| **Infogreffe** | https://infogreffe.fr/api | 443 | HTTPS | Données entreprises |
|
||||
| **RBE** | https://registre-beneficiaires-effectifs.inpi.fr | 443 | HTTPS | Bénéficiaires effectifs |
|
||||
|
||||
### **Configuration des APIs Externes**
|
||||
|
||||
```python
|
||||
# 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**
|
||||
|
||||
```yaml
|
||||
# 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**
|
||||
|
||||
```python
|
||||
# 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**
|
||||
|
||||
```yaml
|
||||
# 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**
|
||||
```python
|
||||
# Redis Cache
|
||||
@cache(expire=3600) # 1 heure
|
||||
async def get_document_analysis(doc_id: str):
|
||||
# Analyse mise en cache
|
||||
pass
|
||||
```
|
||||
|
||||
### **2. Compression**
|
||||
```python
|
||||
# Gzip compression
|
||||
app.add_middleware(GZipMiddleware, minimum_size=1000)
|
||||
```
|
||||
|
||||
### **3. Connection Pooling**
|
||||
```python
|
||||
# PostgreSQL
|
||||
engine = create_engine(
|
||||
DATABASE_URL,
|
||||
pool_size=20,
|
||||
max_overflow=30,
|
||||
pool_pre_ping=True
|
||||
)
|
||||
```
|
||||
|
||||
## 🔧 Dépannage Réseau
|
||||
|
||||
### **Commandes de Diagnostic**
|
||||
|
||||
```bash
|
||||
# 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**
|
||||
|
||||
1. **Port déjà utilisé** : `lsof -i :8000`
|
||||
2. **Connexion refusée** : Vérifier les services Docker
|
||||
3. **Timeout** : Augmenter les timeouts dans la config
|
||||
4. **DNS** : Vérifier la résolution des noms de services
|
||||
|
||||
## 📋 Checklist de Déploiement Réseau
|
||||
|
||||
- [ ] **Ports ouverts** : 80, 443, 8081, 3000, 9001, 7474
|
||||
- [ ] **Firewall configuré** : Règles iptables/ufw
|
||||
- [ ] **Certificats SSL** : Let's Encrypt ou certificats manuels
|
||||
- [ ] **DNS configuré** : Résolution des noms de domaines
|
||||
- [ ] **Load balancer** : Traefik configuré
|
||||
- [ ] **Monitoring** : Prometheus et Grafana opérationnels
|
||||
- [ ] **Backup réseau** : Configuration sauvegardée
|
||||
- [ ] **Tests de charge** : Validation des performances
|
Loading…
x
Reference in New Issue
Block a user