Skip to content

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

ComposantRoleFichiers
APIRoutes HTTP, auth, validation schemassrc/api/
Pipeline10 etapes : adapter, cache, rate limit, transform, call, validatesrc/core/pipeline.ts
QueueJobs POST async via BullMQ, retry, idempotencesrc/queue/
CacheRedis, isole par tenant, TTL par endpointsrc/core/cache/
Hub GoRate limiting centralise, token bucket adaptatif, WebSockethub-go/
PollerPolling adaptatif, diff snapshots, dispatch webhookssrc/poller/
SyncBulk sync progressif (discovery + batches)src/sync/
WebhooksHMAC-SHA256, retry 3x, events filtres par souscriptionsrc/webhooks/

Stack technique

CoucheTechnologie
HTTP serverHono
ValidationZod v4
Base de donneesPostgreSQL + Drizzle ORM
Cache / QueueRedis + BullMQ
Hub centraliseGo + gorilla/websocket
ChiffrementAES-256-GCM (crypto Node.js)
Auth hubJWT HS256 (genere par le hub Go)
Loggingpino
TestsVitest (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 tenantHash dans chaque job
  • Tables PostgreSQL : colonne tenant_hash dans audit_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│     │
│  └─────────┘        └─────────┘        └─────────┘      │
└─────────────────────────────────────────────────────────┘