Architecture Technique Complète
Plateforme IA avec microservices Node.js/Next.js
Vue d'ensemble de l'architecture
Backend Microservices
NestJS avec architecture modulaire, TypeScript, et patterns CQRS
IA & Embeddings
Hugging Face integration avec sentence-transformers/all-mpnet-base-v2
Sécurité
JWT OAuth2.0 + AES-256 encryption pour les données sensibles
Architecture Microservices
Structure des Services
# docker-compose.yml
version: '3.8'
services:
user-service:
build: ./services/user
ports:
- "3001:3000"
environment:
- POSTGRES_URL=postgresql://...
- REDIS_URL=redis://redis:6379
contribution-service:
build: ./services/contribution
ports:
- "3002:3000"
depends_on:
- rabbitmq
- postgres
ai-service:
build: ./services/ai
ports:
- "3003:3000"
environment:
- HUGGING_FACE_API_KEY=${HF_API_KEY}
volumes:
- ./models:/app/models
Configuration NestJS
// app.module.ts
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { RedisModule } from './redis/redis.module';
import { RabbitMQModule } from '@golevelup/nestjs-rabbitmq';
@Module({
imports: [
TypeOrmModule.forRoot({
type: 'postgres',
url: process.env.DATABASE_URL,
entities: [__dirname + '/**/*.entity{.ts,.js}'],
synchronize: true,
}),
RedisModule.forRoot({
host: process.env.REDIS_HOST,
port: process.env.REDIS_PORT,
}),
RabbitMQModule.forRoot(RabbitMQModule, {
exchanges: [
{
name: 'contributions',
type: 'topic',
},
],
}),
],
})
export class AppModule {}
Déploiement Kubernetes
Configuration Kubernetes avec Auto-scaling
HPA Configuration
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: ai-service-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: ai-service
minReplicas: 2
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 70
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: 80
Deployment avec pgvector
apiVersion: apps/v1
kind: Deployment
metadata:
name: postgres-pgvector
spec:
replicas: 1
selector:
matchLabels:
app: postgres
template:
spec:
containers:
- name: postgres
image: ankane/pgvector:v0.5.0
env:
- name: POSTGRES_DB
value: "ai_platform"
- name: POSTGRES_USER
valueFrom:
secretKeyRef:
name: postgres-secret
key: username
volumeMounts:
- name: postgres-storage
mountPath: /var/lib/postgresql/data
volumes:
- name: postgres-storage
persistentVolumeClaim:
claimName: postgres-pvc
Spécifications API RESTful
POST /submit-data
{
"openapi": "3.0.0",
"paths": {
"/submit-data": {
"post": {
"summary": "Soumettre des données pour traitement IA",
"security": [{"bearerAuth": []}],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"required": ["type", "content"],
"properties": {
"type": {
"type": "string",
"enum": ["text", "image", "document"]
},
"content": {
"type": "string"
},
"metadata": {
"type": "object",
"additionalProperties": true
}
}
}
}
}
},
"responses": {
"202": {
"description": "Données acceptées pour traitement",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"jobId": {
"type": "string",
"format": "uuid"
},
"status": {
"type": "string",
"enum": ["queued", "processing"]
}
}
}
}
}
}
}
}
}
}
}
GET /fetch-results
{
"openapi": "3.0.0",
"paths": {
"/fetch-results": {
"get": {
"summary": "Récupérer les résultats du traitement IA",
"security": [{"bearerAuth": []}],
"parameters": [
{
"name": "jobId",
"in": "query",
"required": true,
"schema": {
"type": "string",
"format": "uuid"
}
}
],
"responses": {
"200": {
"description": "Résultats du traitement",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"jobId": {
"type": "string",
"format": "uuid"
},
"status": {
"type": "string",
"enum": ["pending", "completed", "failed"]
},
"result": {
"type": "object",
"properties": {
"embeddings": {
"type": "array",
"items": {
"type": "number"
}
},
"classification": {
"type": "string"
},
"confidence": {
"type": "number",
"minimum": 0,
"maximum": 1
}
}
}
}
}
}
}
}
}
}
}
}
}
Exemple d'utilisation
// Client JavaScript
const submitData = async (content) => {
const response = await fetch('https://api.ai-platform.com/submit-data', {
method: 'POST',
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
type: 'text',
content: content,
metadata: { source: 'web' }
})
});
const { jobId } = await response.json();
// Poll for results
const checkResults = setInterval(async () => {
const result = await fetch(`/fetch-results?jobId=${jobId}`, {
headers: { 'Authorization': `Bearer ${token}` }
});
const data = await result.json();
if (data.status === 'completed') {
clearInterval(checkResults);
console.log('Résultats:', data.result);
}
}, 1000);
};