Skip to main content

Architecture Overview

Retrieva is a DORA-compliance RAG platform. The core flow is: upload vendor documents → AI-generated DORA gap analysis report → conversational Q&A.

Services​

backend/     - Express 5 API server (ES modules, Node.js 20)
frontend/ - Next.js 16 App Router (React 19, TypeScript)

Data Flow​

Gap Analysis Flow​

User → Upload vendor PDF/DOCX/XLSX
→ assessmentController → assessmentQueue (BullMQ)
→ assessmentWorker:
1. fileIndex: parse → embed chunks → Qdrant
2. gapAnalysis: retrieve chunks → LLM generates DORA gap report
→ Assessment results stored in PostgreSQL
→ User downloads report or queries via chat

RAG (Q&A) Flow​

User Question → RAG Service
→ Embed query → Qdrant retrieval (k=15)
→ Cross-encoder re-ranking (top 5)
→ Context expansion (sibling chunks)
→ LLM generates answer with citations
→ Response streamed to frontend

Model Hierarchy​

Organization  (company account — e.g. "HDI Global SE")
└── OrganizationMember (org_admin | analyst | viewer)
└── User (one user belongs to one org)
└── Workspace (vendor isolation boundary — scoped to org)
└── Assessment (per vendor DORA evaluation)
└── DocumentSource (indexed chunks in Qdrant)

Organization-First B2B Model​

All vendor workspaces are scoped to an Organization. When a user belongs to an org, they automatically see every workspace that shares the same organizationId — no per-workspace invitation is required. Org-level roles map to workspace permissions:

Org roleWorkspace access
org_adminowner-level (can invite, configure, query)
analystmember-level (can query, view sources)
viewerviewer-level (read-only)

Legacy users without an organizationId fall back to the previous per-workspace WorkspaceMember access model.

Backend Request Flow​

Routes → Middleware (authenticate, requireWorkspaceAccess, validateBody)
→ Controllers (thin — parse HTTP, call service, send response)
→ Services (business logic) → Repositories (Drizzle) → PostgreSQL
→ BullMQ queues
→ Qdrant (vector store)

Key Components​

Controllers​

ControllerResponsibility
assessmentController.jsUpload files, start gap analysis, retrieve results
ragController.jsConversational Q&A over indexed documents
workspaceMemberController.jsWorkspace CRUD + member management
organizationController.jsOrganization creation, team invitations, member management
authController.jsRegister, login, logout, token refresh
conversationController.jsConversation history management
exportController.jsRoI export (DORA Art. 28 Excel workbook)
healthController.jsService health checks

Workers (BullMQ)​

WorkerQueuePurpose
assessmentWorker.jsassessmentJobsOrchestrates file indexing + DORA gap analysis; idempotency guard skips already-indexed documents on retry
monitoringWorker.jsmonitoringJobs24-hour schedule: compliance threshold alerts

Key Services​

ServicePurpose
services/rag.jsCore RAG pipeline: retrieval, re-ranking, answer generation
services/AssessmentService.jsAssessment business logic: create, list, get, delete, risk decisions, clause sign-offs
services/WorkspaceService.jsWorkspace CRUD, member invitation and revocation
services/alertMonitorService.jsCompliance threshold checks and alert delivery via repositories
services/roiExportService.jsEBA-compliant DORA Art. 28(3) XLSX workbook
services/fileIngestionService.jsParses PDF, DOCX, XLSX; deterministic Qdrant point IDs (SHA-256)
services/emailService.jsTransactional email via Resend HTTP API
services/storageServiceFile storage on S3-compatible object storage (MinIO / Cloudflare R2)

Repository Layer​

RepositoryPurpose
repositories/AssessmentRepository.jsAssessment queries: findByWorkspaces, markDocumentIndexed, completeAnalysis, findLatestByWorkspace
repositories/WorkspaceRepository.jsWorkspace queries: findByOrganization, findWithCertifications, findDueForReview, findByContractEndingSoon
repositories/MessageRepository.jsMessage persistence
repositories/ConversationRepository.jsConversation management

All repositories extend BaseRepository (repositories/BaseRepository.js) which provides common CRUD, pagination, and aggregation operations.

Configuration​

ModulePurpose
config/llmProvider.tsChat LLM client → the AI gateway (LiteLLM, OpenAI-compatible)
config/embeddingProvider.tsOllama bge-m3 embeddings (OpenAI fallback)
config/tracing.tsLangfuse (traces, prompt management, feedback)
config/vectorStore.jsQdrant client + collection management
config/queue.jsBullMQ queue definitions
config/db.tsPostgreSQL (pg Pool) connection + migrations on boot
config/redis.jsRedis connection (BullMQ + RAG cache)

Infrastructure​

                 ┌─────────────┐
HTTPS ─────→ │ Nginx │
└──────┬──────┘
┌─────────┴──────────┐
↓ ↓
┌──────────┐ ┌──────────┐
│ Frontend │ │ Backend │
│ :3000 │ │ :3007 │
└──────────┘ └────┬─────┘
┌─────┼──────┐
↓ ↓ ↓
PostgreSQL Redis Qdrant

Production (self-hosted minicloud k3s, GitOps via ArgoCD + Kargo):

  • ingress-nginx + cert-manager TLS (Cloudflare tunnel for public access)
  • PostgreSQL (CNPG on k8s; Drizzle migrations on boot)
  • Qdrant (vector store) · Redis 7 (cache + BullMQ)
  • Object storage: MinIO / Cloudflare R2
  • LLM via the minicloud LiteLLM AI gateway (routing, PII masking, budgets, EU governance) · embeddings on self-hosted Ollama bge-m3

Multi-Tenancy​

Workspace/organization isolation. Every Qdrant query filters by workspaceId; relational queries compose entityScopeCondition (Drizzle) and run entity-scoped under ENTITY_ISOLATION_MODE=enforce (defense-in-depth at both the DB and vector-store layers).

LLM Provider Abstraction​

config/llmProvider.ts is a thin OpenAI-compatible client over the platform AI gateway (LiteLLM) — the single provider. The gateway owns provider routing (Ollama Cloud, Azure, Bedrock…), key rotation, retries/fallbacks, PII masking, budgets and EU governance. Callers pick a model name / intent alias (e.g. tier-premium, tier-standard) via purpose / LLM_MODEL; the gateway resolves it. Config: LITELLM_BASE_URL + LITELLM_API_KEY.