Aller au contenu

Architecture Backend ProbatioVault

Ce document décrit l'architecture spécifique au backend. Voir ProbatioVault-infra/docs/architecture/overview.md pour l'architecture globale.

Stack technique

Composant Technologie Version
Framework NestJS 10.x
Language TypeScript 5.x
ORM TypeORM 0.3.x
Database PostgreSQL 15.x
HSM AWS CloudHSM PKCS#11
Queue Bull (Redis) -

Architecture modulaire

src/
├── modules/
│   ├── auth/           # Authentification SRP-6a
│   ├── documents/      # Gestion documents
│   ├── crypto/         # Services cryptographiques
│   ├── storage/        # Stockage S3
│   ├── audit/          # Logs d'audit
│   └── blockchain/     # Ancrage blockchain
├── common/
│   ├── guards/         # Auth guards
│   ├── filters/        # Exception filters
│   ├── interceptors/   # Request interceptors
│   └── decorators/     # Custom decorators
├── database/
│   ├── entities/       # TypeORM entities
│   └── migrations/     # DB migrations
└── config/             # Configuration

Modules principaux

Auth Module

  • OIDC/Keycloak (PD-26) : OAuth2 avec JWT RS256 via JWKS
  • Authentification SRP-6a (Zero-Knowledge) - legacy
  • Autorisation HYBRID (rôles + scopes)
  • Fail-closed JWKS (INV-08)
  • Audit whitelist (INV-04)

Documents Module

  • CRUD documents (métadonnées)
  • Validation hash SHA3-256
  • Gestion propriétaire/accès

Crypto Module

  • Interface PKCS#11 vers HSM
  • Key Wrapping (AES-KWP)
  • Signature RSA-PSS

Storage Module

  • Interface S3
  • Upload/Download documents chiffrés
  • Gestion Object Lock

Audit Module

  • Logging actions utilisateur
  • Trail immutable
  • Export pour audit

Sécurité

Row-Level Security (RLS)

CREATE POLICY documents_isolation ON documents
  USING (owner_id = current_setting('app.current_user_id')::uuid);

Guards

  • OidcJwtAuthGuard : Valide JWT OIDC via JWKS (PD-26)
  • AuthorizationGuard : Vérifie rôles et scopes HYBRID (PD-26)
  • JwtAuthGuard : Vérifie JWT valide (legacy)
  • RolesGuard : Vérifie rôles utilisateur (legacy)
  • ThrottlerGuard : Rate limiting

Base de données

Entités principales

┌─────────────┐     ┌─────────────────┐
│   users     │────<│   documents     │
└─────────────┘     └─────────────────┘
      │                     │
      │             ┌───────┴───────┐
      │             │               │
      ▼             ▼               ▼
┌─────────────┐ ┌─────────┐ ┌─────────────┐
│ key_envelopes│ │ proofs  │ │   shares    │
└─────────────┘ └─────────┘ └─────────────┘

API

Versioning

Toutes les routes préfixées /api/v1/

Endpoints principaux

Méthode Route Description Auth
GET /health Health check OIDC/JWKS Public
POST /auth/register Inscription Public
POST /auth/login Connexion SRP Public
GET /documents Liste documents JWT
POST /documents Créer document JWT
GET /documents/:id Détail document JWT
POST /documents/:id/certify Certifier JWT

Liens

  • Architecture globale : ProbatioVault-infra/docs/architecture/overview.md
  • Data Flows : ProbatioVault-infra/docs/architecture/data-flows.md
  • Crypto Model