Architecture Opcovia
Opcovia est un proxy intelligent entre les logiciels CFA et les APIs OPCO (API Convergence). Il normalise, rate-limite, cache, queue et surveille toutes les interactions.
Diagramme systeme
Composants principaux
| Composant | Role | Fichiers |
|---|---|---|
| API | Routes HTTP, auth, validation schemas | src/api/ |
| Pipeline | 10 etapes : adapter, cache, rate limit, transform, call, validate | src/core/pipeline.ts |
| Queue | Jobs POST async via BullMQ, retry, idempotence | src/queue/ |
| Cache | Redis, isole par tenant, TTL par endpoint | src/core/cache/ |
| Hub Go | Rate limiting centralise, token bucket adaptatif, WebSocket | hub-go/ |
| Poller | Polling adaptatif, diff snapshots, dispatch webhooks | src/poller/ |
| Sync | Bulk sync progressif (discovery + batches) | src/sync/ |
| Webhooks | HMAC-SHA256, retry 3x, events filtres par souscription | src/webhooks/ |
Stack technique
| Couche | Technologie |
|---|---|
| HTTP server | Hono |
| Validation | Zod v4 |
| Base de donnees | PostgreSQL + Drizzle ORM |
| Cache / Queue | Redis + BullMQ |
| Hub centralise | Go + gorilla/websocket |
| Chiffrement | AES-256-GCM (crypto Node.js) |
| Auth hub | JWT HS256 (genere par le hub Go) |
| Logging | pino |
| Tests | Vitest (293 unit + 69 integration) |
Isolation multi-tenant
Chaque CFA est identifie par son X-API-KEY. L'isolation repose sur un tenantHash :
tenantHash = sha256(X-API-KEY)Ce hash est utilise comme cle de partitionnement dans :
- Cache Redis : cle =
opcovia:cache:{opcoId}:{tenantHash}:{method}:{path}:{queryHash} - Jobs BullMQ : champ
tenantHashdans chaque job - Tables PostgreSQL : colonne
tenant_hashdansaudit_logs,job_results,webhooks,snapshots,sync_jobs - Webhooks : un CFA ne recoit que ses propres events
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ CFA #1 │ │ CFA #2 │ │ CFA #3 │
│ X-API-KEY: A │ │ X-API-KEY: B │ │ X-API-KEY: C │
└──────┬───────┘ └──────┬───────┘ └──────┬───────┘
│ │ │
▼ ▼ ▼
┌─────────────────────────────────────────────────────────┐
│ Opcovia Proxy │
│ │
│ tenantHash(A) tenantHash(B) tenantHash(C) │
│ ┌─────────┐ ┌─────────┐ ┌─────────┐ │
│ │ cache │ │ cache │ │ cache │ │
│ │ jobs │ │ jobs │ │ jobs │ │
│ │ webhooks │ │ webhooks │ │ webhooks │ │
│ │ snapshots│ │ snapshots│ │ snapshots│ │
│ └─────────┘ └─────────┘ └─────────┘ │
└─────────────────────────────────────────────────────────┘