# anulsasidharan/unified-rag-studio architecture

> Architecture diagram of the GitHub repository anulsasidharan/unified-rag-studio, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-06-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/anulsasidharan/unified-rag-studio
- Repository: https://github.com/anulsasidharan/unified-rag-studio

## Overview

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: [`apps/web/src/app`](https://github.com/anulsasidharan/unified-rag-studio/tree/main/apps/web/src/app) (Web app), [`apps/api/app/services`](https://github.com/anulsasidharan/unified-rag-studio/tree/main/apps/api/app/services) (Domain services), [`apps/api/app/core`](https://github.com/anulsasidharan/unified-rag-studio/tree/main/apps/api/app/core) (RAG core), [`docker/docker-compose.yml`](https://github.com/anulsasidharan/unified-rag-studio/blob/main/docker/docker-compose.yml) (Compose stack)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_frontend["Frontend"]
  node_web_app["Web app<br/>Next.js 14 UI"]
  node_web_components["UI components<br/>React views"]
  node_web_state["UI state<br/>Stores & hooks"]
  node_web_lib["UI catalogs<br/>Client lib"]
  node_web_types["UI types<br/>Type models"]
end

subgraph group_group_backend["Backend"]
  node_api_main["API app<br/>FastAPI entry<br/>[main.py]"]
  node_api_routers["HTTP routers<br/>API endpoints"]
  node_api_services["Domain services<br/>App services"]
  node_api_core_rag["RAG core<br/>Pipeline core"]
  node_api_guardrails{{"Guardrails<br/>Policy layer"}}
  node_api_vectorstore[("Vector stores<br/>Adapters")]
  node_api_worker["Worker<br/>Celery jobs"]
  node_api_models[("Data models<br/>SQLAlchemy models")]
  node_api_migrations["Migrations<br/>Alembic"]
  node_api_observability["Observability<br/>Metrics & logging"]
end

subgraph group_group_shared["Shared catalogs"]
  node_shared_data["Data catalogs<br/>JSON catalogs"]
end

subgraph group_group_deploy["Deployment"]
  node_deploy_stack["Compose stack<br/>Docker stack<br/>[docker-compose.yml]"]
  node_k8s_prod["K8s deploy<br/>Production manifests"]
end

node_web_app -->|"renders"| node_web_components
node_web_app -->|"uses"| node_web_state
node_web_app -->|"calls"| node_web_lib
node_web_app -->|"types"| node_web_types
node_web_lib -->|"loads"| node_shared_data
node_api_main -->|"mounts"| node_api_routers
node_api_routers -->|"delegates"| node_api_services
node_api_services -->|"orchestrates"| node_api_core_rag
node_api_services -->|"enqueues"| node_api_worker
node_api_core_rag -->|"wraps"| node_api_guardrails
node_api_core_rag -->|"reads/writes"| node_api_vectorstore
node_api_worker -->|"uses"| node_api_vectorstore
node_api_core_rag -->|"emits"| node_api_observability
node_api_services -->|"persists"| node_api_models
node_api_models -->|"evolves"| node_api_migrations
node_api_routers -.->|"serves"| node_web_app
node_api_services -.->|"references"| node_shared_data
node_deploy_stack -->|"runs"| node_web_app
node_deploy_stack -->|"runs"| node_api_main
node_deploy_stack -->|"runs"| node_api_worker
node_k8s_prod -.->|"deploys"| node_api_main
node_k8s_prod -.->|"deploys"| node_web_app
node_web_lib -.->|"previews"| node_api_services

click node_web_app "https://github.com/anulsasidharan/unified-rag-studio/tree/main/apps/web/src/app"
click node_web_components "https://github.com/anulsasidharan/unified-rag-studio/tree/main/apps/web/src/components"
click node_web_state "https://github.com/anulsasidharan/unified-rag-studio/tree/main/apps/web/src/stores"
click node_web_lib "https://github.com/anulsasidharan/unified-rag-studio/tree/main/apps/web/src/lib"
click node_web_types "https://github.com/anulsasidharan/unified-rag-studio/tree/main/apps/web/src/types"
click node_api_main "https://github.com/anulsasidharan/unified-rag-studio/blob/main/apps/api/app/main.py"
click node_api_routers "https://github.com/anulsasidharan/unified-rag-studio/tree/main/apps/api/app/routers"
click node_api_services "https://github.com/anulsasidharan/unified-rag-studio/tree/main/apps/api/app/services"
click node_api_core_rag "https://github.com/anulsasidharan/unified-rag-studio/tree/main/apps/api/app/core"
click node_api_guardrails "https://github.com/anulsasidharan/unified-rag-studio/tree/main/apps/api/app/core/guardrails"
click node_api_vectorstore "https://github.com/anulsasidharan/unified-rag-studio/tree/main/apps/api/app/core/vectorstore"
click node_api_worker "https://github.com/anulsasidharan/unified-rag-studio/tree/main/apps/api/app/worker"
click node_api_models "https://github.com/anulsasidharan/unified-rag-studio/tree/main/apps/api/app/models"
click node_api_migrations "https://github.com/anulsasidharan/unified-rag-studio/tree/main/apps/api/alembic"
click node_api_observability "https://github.com/anulsasidharan/unified-rag-studio/tree/main/apps/api/app/observability"
click node_shared_data "https://github.com/anulsasidharan/unified-rag-studio/tree/main/data"
click node_deploy_stack "https://github.com/anulsasidharan/unified-rag-studio/blob/main/docker/docker-compose.yml"
click node_k8s_prod "https://github.com/anulsasidharan/unified-rag-studio/tree/main/k8s/production"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_web_app,node_web_components,node_web_state,node_web_lib,node_web_types toneBlue
class node_api_main,node_api_routers,node_api_services,node_api_core_rag,node_api_guardrails,node_api_vectorstore,node_api_worker,node_api_models,node_api_migrations,node_api_observability toneAmber
class node_shared_data toneMint
class node_deploy_stack,node_k8s_prod toneRose
```

## Components

### Frontend

Next.js control plane for designer, autopilot, auth, and admin UX.

- [Web app](https://github.com/anulsasidharan/unified-rag-studio/tree/main/apps/web/src/app): Next.js 14 UI · Interactive product surface for login, designer, autopilot, projects, and admin flows. · `apps/web/src/app`
- [UI components](https://github.com/anulsasidharan/unified-rag-studio/tree/main/apps/web/src/components): React views · Reusable designer, autopilot, auth, landing, profile, and shared interface components. · `apps/web/src/components`
- [UI state](https://github.com/anulsasidharan/unified-rag-studio/tree/main/apps/web/src/stores): Stores & hooks · Client-side auth, project, designer, and autopilot state plus subscriptions and visibility hooks. · `apps/web/src/stores`
- [UI catalogs](https://github.com/anulsasidharan/unified-rag-studio/tree/main/apps/web/src/lib): Client lib · Frontend API client, validators, catalogs, route helpers, generators, and preview utilities. · `apps/web/src/lib`
- [UI types](https://github.com/anulsasidharan/unified-rag-studio/tree/main/apps/web/src/types): Type models · 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](https://github.com/anulsasidharan/unified-rag-studio/blob/main/apps/api/app/main.py): FastAPI entry · Application bootstrap, dependency wiring, and route registration for the backend. · `apps/api/app/main.py`
- [HTTP routers](https://github.com/anulsasidharan/unified-rag-studio/tree/main/apps/api/app/routers): API endpoints · Product-facing endpoints for auth, designer, autopilot, projects, deployments, jobs, analytics, and admin. · `apps/api/app/routers`
- [Domain services](https://github.com/anulsasidharan/unified-rag-studio/tree/main/apps/api/app/services): App services · Workflow orchestration for designer, autopilot builds, exports, deployments, evaluation, analytics, and templates. · `apps/api/app/services`
- [RAG core](https://github.com/anulsasidharan/unified-rag-studio/tree/main/apps/api/app/core): Pipeline core · Composable ingestion, chunking, embedding, retrieval, generation, routing, compression, and evaluation machinery. · `apps/api/app/core`
- [Guardrails](https://github.com/anulsasidharan/unified-rag-studio/tree/main/apps/api/app/core/guardrails): Policy layer · Input, retrieval, and output policy enforcement around the RAG flow. · `apps/api/app/core/guardrails`
- [Vector stores](https://github.com/anulsasidharan/unified-rag-studio/tree/main/apps/api/app/core/vectorstore): Adapters · Provider adapters and factory for Qdrant, Pinecone, and Weaviate backends. · `apps/api/app/core/vectorstore`
- [Worker](https://github.com/anulsasidharan/unified-rag-studio/tree/main/apps/api/app/worker): Celery jobs · Asynchronous execution for long-running autopilot, sync, and background tasks. · `apps/api/app/worker`
- [Data models](https://github.com/anulsasidharan/unified-rag-studio/tree/main/apps/api/app/models): SQLAlchemy models · Persistence models for projects, users, builds, deployments, evaluations, subscriptions, tokens, and logs. · `apps/api/app/models`
- [Migrations](https://github.com/anulsasidharan/unified-rag-studio/tree/main/apps/api/alembic): Alembic · Schema evolution and initial database setup. · `apps/api/alembic`
- [Observability](https://github.com/anulsasidharan/unified-rag-studio/tree/main/apps/api/app/observability): Metrics & logging · 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](https://github.com/anulsasidharan/unified-rag-studio/tree/main/data): JSON catalogs · Repo-wide pricing, providers, models, retrieval, chunking, vector store, and template catalogs. · `data`

### Deployment

Container, observability, and Kubernetes packaging.

- [Compose stack](https://github.com/anulsasidharan/unified-rag-studio/blob/main/docker/docker-compose.yml): Docker stack · Web, API, worker, db, redis, vector DB, MLflow, MinIO, and nginx runtime topology. · `docker/docker-compose.yml`
- [K8s deploy](https://github.com/anulsasidharan/unified-rag-studio/tree/main/k8s/production): Production manifests · Kubernetes production manifests for web, API, ingress, config, and secrets. · `k8s/production`

## Connections

- 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.
