How anulsasidharan/unified-rag-studio works
1. Top-level shape
- This is a monorepo with two primary runtimes: a Next.js 14 frontend in apps/web and a FastAPI backend in apps/api.
- The system is designed as a product for building RAG pipelines, with two user-facing modes: Designer and Autopilot.
2. Frontend boundary
- apps/web owns the interactive product UI: authentication screens, project views, the multi-step designer, autopilot setup/history, admin pages, and analytics.
- It uses local stores and catalogs in src/stores and src/lib to keep pipeline configuration state, validate inputs, and render strategy/provider selections.
- The web app is also responsible for artifact presentation and export previews; it does not implement the RAG logic itself.
3. Backend API boundary
- apps/api/app is the system-of-record for projects, builds, evaluations, deployments, API keys, users, subscriptions, and jobs.
- The backend is organized in a fairly standard layered way:
- routers/ for HTTP endpoints
- services/ for domain operations
- core/ for RAG, retrieval, embeddings, guardrails, chunking, evaluation, and vector store logic
- models/, schemas/, and alembic/ for persistence and migrations
- This separation is important: the routers expose product workflows, while the core/ package contains the actual pipeline machinery.
4. Designer workflow
- The Designer is a guided, stage-based pipeline builder spanning cloud/provider choice, ingestion, chunking, embeddings, vector store, query processing, retrieval, context compression, reranking, generation, routing, memory, evaluation, observability, guardrails, HITL, and review.
- The frontend collects stage configuration, and the backend turns that into persisted project/pipeline state and exportable artifacts.
- This mode is optimized for human-directed design plus cost estimation and deployment export.
5. Autopilot workflow
- Autopilot is the document-driven optimization path: documents are uploaded, processed, and used to run optimization/evaluation passes.
- The backend has dedicated core agents and services for chunking optimization, retrieval optimization, embedding testing, evaluation, deployment, and progress tracking.
- Long-running work is pushed into apps/api/app/worker/ via Celery, with Redis used as the job broker/backplane.
- Results feed back into the UI as build status, metrics, and recommendations.
6. RAG pipeline internals
- The core/ package contains the actual RAG stack:
- Ingestion: loaders, preprocessors, extractors
- Chunking: fixed, recursive, sentence, semantic, code-aware, document-based strategies
- Embeddings: adapters for OpenAI, Cohere, Google, Hugging Face, Nomic, plus caching/benchmarking
- Retrieval: BM25, fusion, rerankers, retrieval service/strategies
- Generation: prompt/service/strategy layers
- Query processing: query expansion
- Routing: route resolution
- Context compression and evaluation: bridges to scoring/measurement pipelines
- These modules are built as interchangeable strategy layers, so the same pipeline can be reconfigured without changing the product surface.
7. Guardrails and policy enforcement
- Guardrails are treated as a first-class subsystem, not a UI-only feature.
- There are input policies for PII, injection, toxicity, output policies for citation, factuality, hallucination, context references, and retrieval policies for bias, content filtering, source validation.
- The orchestration layer can run guardrails around the RAG flow, which creates a clear boundary between raw model interaction and policy-enforced execution.
8. Data, persistence, and migrations
- Primary persistence is PostgreSQL, with SQLAlchemy-style models and Alembic migrations.
- Domain tables include projects, deployments, evaluation runs, pipeline configs, users, subscriptions, API tokens, build history, and activity logs.
- The repo also ships shared JSON catalogs under data/ for pricing, cloud providers, models, retrieval strategies, chunking strategies, vector stores, and templates; the frontend relies on these catalogs for configuration UX, and the deployment stack mounts them in containerized environments.
9. External service adapters
- The backend contains explicit adapters for external vector stores: Qdrant, Pinecone, and Weaviate.
- Embedding adapters are likewise vendor-specific, which makes the system portable across LLM/embedding providers.
- Optional MLflow integration is used for experiment tracking and build telemetry during Autopilot runs.
- MinIO appears in the Docker stack as object storage for artifacts and documents.
10. Export and deployment path
- The product can export a designed pipeline into multiple target formats: Python, YAML, Terraform, Docker Compose, and Kubernetes YAML.
- Export logic lives in backend services and is surfaced through the Designer UI.
- There is a deployment-oriented service layer plus hints/metadata support, which suggests the system is not only generating code but also packaging deployment-ready outputs.
11. Security and auth boundary
- The API enforces JWT bearer authentication for most /api/* routes, with auth-specific endpoints excluded.
- The backend includes dedicated auth models and security helpers, while the frontend has login/register/password reset/verify-email flows and stores for auth state.
- API keys and subscriptions are modeled separately, indicating support for both user auth and product-level access control.
12. Observability and operational control
- The repo has explicit observability support: Prometheus scraping, Grafana dashboards, and backend observability modules for logging, RAG metrics, and request context.
- There are monitoring and health routers, plus analytics services and metrics dashboards in both backend and UI.
- This makes runtime behavior, build quality, and pipeline performance visible across both manual design and automated autopilot runs.
13. Deployment topology
- The default containerized stack includes web, api, worker, db, redis, vector-db, mlflow, minio, and nginx.
- The nginx container acts as the edge entrypoint, while Compose overlays add dev hot-reload and optional observability services.
- Kubernetes manifests exist under k8s/production, so the repo supports both Compose-based local operations and K8s deployment.
14. How the pieces connect
- The typical flow is: user interacts with the web app → the frontend calls the FastAPI API → the API persists state and dispatches long-running work to the Celery worker → the worker consults vector stores, model providers, guardrails, and evaluation services → results are stored in PostgreSQL/object storage and streamed back to the UI as status/metrics/export artifacts.
- The architecture is therefore centered on a configuration-first RAG platform, with the frontend as the control plane and the backend/worker stack as the execution plane.
Main entry points: app Web app · services Domain services · core RAG core · docker-compose.yml Compose stack
Components 18
Frontend
Next.js control plane for designer, autopilot, auth, and admin UX.
- Web app · Interactive product surface for login, designer, autopilot, projects, and admin flows.
apps/web/src/app - UI components · Reusable designer, autopilot, auth, landing, profile, and shared interface components.
apps/web/src/components - UI state · Client-side auth, project, designer, and autopilot state plus subscriptions and visibility hooks.
apps/web/src/stores - UI catalogs · Frontend API client, validators, catalogs, route helpers, generators, and preview utilities.
apps/web/src/lib - UI types · Shared TypeScript shapes for auth, projects, pipelines, cloud providers, and autopilot state.
apps/web/src/types
Backend
FastAPI execution plane, domain services, and RAG pipeline internals.
- API app · Application bootstrap, dependency wiring, and route registration for the backend.
apps/api/app/main.py - HTTP routers · Product-facing endpoints for auth, designer, autopilot, projects, deployments, jobs, analytics, and admin.
apps/api/app/routers - Domain services · Workflow orchestration for designer, autopilot builds, exports, deployments, evaluation, analytics, and templates.
apps/api/app/services - RAG core · Composable ingestion, chunking, embedding, retrieval, generation, routing, compression, and evaluation machinery.
apps/api/app/core - Guardrails · Input, retrieval, and output policy enforcement around the RAG flow.
apps/api/app/core/guardrails - Vector stores · Provider adapters and factory for Qdrant, Pinecone, and Weaviate backends.
apps/api/app/core/vectorstore - Worker · Asynchronous execution for long-running autopilot, sync, and background tasks.
apps/api/app/worker - Data models · Persistence models for projects, users, builds, deployments, evaluations, subscriptions, tokens, and logs.
apps/api/app/models - Migrations · Schema evolution and initial database setup.
apps/api/alembic - Observability · Request context, logging setup, and RAG metrics instrumentation.
apps/api/app/observability
Shared catalogs
Repo-wide configuration catalogs and generated metadata used by both runtimes.
- Data catalogs · Repo-wide pricing, providers, models, retrieval, chunking, vector store, and template catalogs.
data
Deployment
Container, observability, and Kubernetes packaging.
- Compose stack · Web, API, worker, db, redis, vector DB, MLflow, MinIO, and nginx runtime topology.
docker/docker-compose.yml - K8s deploy · Kubernetes production manifests for web, API, ingress, config, and secrets.
k8s/production
Connections 23
- Web app → UI components: renders · Pages compose reusable designer, autopilot, auth, and shared views.
- Web app → UI state: uses · Routes and views consume local stores and hooks for interactive state.
- Web app → UI catalogs: calls · Frontend consults catalogs, validators, generators, and API client helpers.
- Web app → UI types: types · UI components and stores share product and pipeline types.
- UI catalogs → Data catalogs: loads · Catalog helpers are backed by repo-shipped JSON reference data.
- API app → HTTP routers: mounts · Application entrypoint registers the public API surface.
- HTTP routers → Domain services: delegates · HTTP endpoints hand off product workflows to domain services.
- Domain services → RAG core: orchestrates · Services coordinate the underlying RAG stack and workflow primitives.
- Domain services → Worker: enqueues · Autopilot and other long-running tasks are pushed to background jobs.
- RAG core → Guardrails: wraps · Guardrails run around query, retrieval, and generation execution.
- RAG core → Vector stores: reads/writes · Retrieval and indexing stages use vector store adapters.
- Worker → Vector stores: uses · Background tasks may consult external vector stores during processing.
- RAG core → Observability: emits · RAG flow is instrumented with metrics and contextual logging.
- Domain services → Data models: persists · Domain workflows store projects, builds, deployments, and evaluation state.
- Data models → Migrations: evolves · Schema changes are tracked through Alembic migrations.
- HTTP routers → Web app: serves · Backend endpoints power the frontend product flows.
- Domain services → Data catalogs: references · Pricing, catalog, and template data inform backend exports and validation.
- Compose stack → Web app: runs · Compose stack includes the web service.
- Compose stack → API app: runs · Compose stack includes the API service.
- Compose stack → Worker: runs · Compose stack includes the Celery worker.
- K8s deploy → API app: deploys · Kubernetes manifests package the API service for production.
- K8s deploy → Web app: deploys · Kubernetes manifests package the web service for production.
- UI catalogs → Domain services: previews · Designer export previews and build status UI reflect backend-generated artifacts.