# akilanpl/enterprise-rag-platform architecture

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

- Interactive diagram: https://gitdiagram.com/akilanpl/enterprise-rag-platform
- Repository: https://github.com/akilanpl/enterprise-rag-platform

## Overview

This is an enterprise-oriented, multi-tenant RAG API. A chat request binds its tenant, embeds the query, retrieves and reranks documents, then generates an answer from sanitized context; generation records estimated token cost. The repository also has a separate orchestration function, ingestion and evaluation modules, and security and observability components. The README describes these capabilities but gives little implementation detail; links for unsampled subsystems are therefore omitted rather than inferred.

Main entry points: [`app/api/chat.py`](https://github.com/akilanpl/enterprise-rag-platform/blob/main/app/api/chat.py) (Chat endpoint), [`app/generation/generator.py`](https://github.com/akilanpl/enterprise-rag-platform/blob/main/app/generation/generator.py) (Answer generator), [`app/retrieval/retriever.py`](https://github.com/akilanpl/enterprise-rag-platform/blob/main/app/retrieval/retriever.py) (Vector retrieval), [`app/orchestration/rag_pipeline.py`](https://github.com/akilanpl/enterprise-rag-platform/blob/main/app/orchestration/rag_pipeline.py) (RAG pipeline)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and orchestration"]
  node_main["FastAPI application<br/>[main.py]"]
  node_chat["Chat endpoint<br/>[chat.py]"]
  node_pipeline["RAG pipeline<br/>[rag_pipeline.py]"]
end

subgraph group_knowledge["Knowledge pipeline"]
  node_ingestion["Document ingestion"]
  node_loader["Document loader<br/>[loader.py]"]
  node_chunker["Document chunker<br/>[chunker.py]"]
  node_indexer["Vector indexer<br/>[indexer.py]"]
  node_retriever["Vector retrieval<br/>[retriever.py]"]
  node_reranker["Result reranker<br/>[reranker.py]"]
end

subgraph group_generation["Answer generation"]
  node_generator["Answer generator<br/>[generator.py]"]
end

subgraph group_controls["Tenant and security"]
  node_firewall["Context sanitizer<br/>[prompt_firewall.py]"]
  node_tenant["Tenant context<br/>[tenant.py]"]
  node_security["Access controls<br/>[auth.py]"]
  node_cache["Redis cache<br/>[cache.py]"]
end

subgraph group_operations["Evaluation and observability"]
  node_cost["Cost tracking<br/>[cost.py]"]
  node_latency["Latency tracking<br/>[latency.py]"]
  node_metrics["Runtime metrics<br/>[metrics.py]"]
  node_tracing["Request tracing<br/>[tracing.py]"]
  node_feedback["User feedback<br/>[feedback.py]"]
  node_evaluation["RAG evaluation<br/>[ragas_eval.py]"]
end

node_user(("API client"))
node_qdrant[("Qdrant")]
node_embeddings["Embedding model"]
node_openai["OpenAI API"]
node_redis[("Redis")]

node_user -->|"submits query"| node_chat
node_main -->|"mounts router"| node_chat
node_chat -->|"sets tenant"| node_tenant
node_chat -->|"embeds query"| node_embeddings
node_chat -->|"retrieves documents"| node_retriever
node_chat -->|"reranks documents"| node_reranker
node_chat -->|"requests answer"| node_generator
node_retriever -->|"reads tenant"| node_tenant
node_retriever -->|"searches vectors"| node_qdrant
node_indexer -->|"embeds documents"| node_embeddings
node_indexer -->|"writes vectors"| node_qdrant
node_generator -->|"sanitizes context"| node_firewall
node_generator -->|"requests completion"| node_openai
node_generator -->|"records usage"| node_cost
node_cost -->|"reads tenant"| node_tenant
node_pipeline -->|"retrieves documents"| node_retriever
node_pipeline -->|"generates answer"| node_generator
node_pipeline -->|"tracks duration"| node_latency
node_cache -.->|"reads and writes"| node_redis

click node_main "https://github.com/akilanpl/enterprise-rag-platform/blob/main/app/main.py"
click node_chat "https://github.com/akilanpl/enterprise-rag-platform/blob/main/app/api/chat.py"
click node_pipeline "https://github.com/akilanpl/enterprise-rag-platform/blob/main/app/orchestration/rag_pipeline.py"
click node_ingestion "https://github.com/akilanpl/enterprise-rag-platform/tree/main/app/ingestion"
click node_loader "https://github.com/akilanpl/enterprise-rag-platform/blob/main/app/ingestion/loader.py"
click node_chunker "https://github.com/akilanpl/enterprise-rag-platform/blob/main/app/ingestion/chunker.py"
click node_indexer "https://github.com/akilanpl/enterprise-rag-platform/blob/main/app/ingestion/indexer.py"
click node_retriever "https://github.com/akilanpl/enterprise-rag-platform/blob/main/app/retrieval/retriever.py"
click node_reranker "https://github.com/akilanpl/enterprise-rag-platform/blob/main/app/retrieval/reranker.py"
click node_generator "https://github.com/akilanpl/enterprise-rag-platform/blob/main/app/generation/generator.py"
click node_firewall "https://github.com/akilanpl/enterprise-rag-platform/blob/main/app/core/prompt_firewall.py"
click node_tenant "https://github.com/akilanpl/enterprise-rag-platform/blob/main/app/core/tenant.py"
click node_security "https://github.com/akilanpl/enterprise-rag-platform/blob/main/app/core/auth.py"
click node_cost "https://github.com/akilanpl/enterprise-rag-platform/blob/main/app/observability/cost.py"
click node_latency "https://github.com/akilanpl/enterprise-rag-platform/blob/main/app/observability/latency.py"
click node_metrics "https://github.com/akilanpl/enterprise-rag-platform/blob/main/app/observability/metrics.py"
click node_tracing "https://github.com/akilanpl/enterprise-rag-platform/blob/main/app/observability/tracing.py"
click node_feedback "https://github.com/akilanpl/enterprise-rag-platform/blob/main/app/observability/feedback.py"
click node_evaluation "https://github.com/akilanpl/enterprise-rag-platform/blob/main/app/evaluation/ragas_eval.py"
click node_cache "https://github.com/akilanpl/enterprise-rag-platform/blob/main/app/core/cache.py"

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_main,node_chat,node_pipeline,node_user toneBlue
class node_ingestion,node_loader,node_chunker,node_indexer,node_retriever,node_reranker,node_qdrant,node_redis toneAmber
class node_generator,node_openai toneMint
class node_firewall,node_tenant,node_security,node_cache toneRose
class node_cost,node_latency,node_metrics,node_tracing,node_feedback,node_evaluation,node_embeddings toneIndigo
```

## Components

### API and orchestration

- [FastAPI application](https://github.com/akilanpl/enterprise-rag-platform/blob/main/app/main.py): `app/main.py`
- [Chat endpoint](https://github.com/akilanpl/enterprise-rag-platform/blob/main/app/api/chat.py): `app/api/chat.py`
- [RAG pipeline](https://github.com/akilanpl/enterprise-rag-platform/blob/main/app/orchestration/rag_pipeline.py): `app/orchestration/rag_pipeline.py`

### Knowledge pipeline

- [Document ingestion](https://github.com/akilanpl/enterprise-rag-platform/tree/main/app/ingestion): `app/ingestion`
- [Document loader](https://github.com/akilanpl/enterprise-rag-platform/blob/main/app/ingestion/loader.py): `app/ingestion/loader.py`
- [Document chunker](https://github.com/akilanpl/enterprise-rag-platform/blob/main/app/ingestion/chunker.py): `app/ingestion/chunker.py`
- [Vector indexer](https://github.com/akilanpl/enterprise-rag-platform/blob/main/app/ingestion/indexer.py): `app/ingestion/indexer.py`
- [Vector retrieval](https://github.com/akilanpl/enterprise-rag-platform/blob/main/app/retrieval/retriever.py): `app/retrieval/retriever.py`
- [Result reranker](https://github.com/akilanpl/enterprise-rag-platform/blob/main/app/retrieval/reranker.py): `app/retrieval/reranker.py`

### Answer generation

- [Answer generator](https://github.com/akilanpl/enterprise-rag-platform/blob/main/app/generation/generator.py): `app/generation/generator.py`

### Tenant and security

- [Context sanitizer](https://github.com/akilanpl/enterprise-rag-platform/blob/main/app/core/prompt_firewall.py): `app/core/prompt_firewall.py`
- [Tenant context](https://github.com/akilanpl/enterprise-rag-platform/blob/main/app/core/tenant.py): `app/core/tenant.py`
- [Access controls](https://github.com/akilanpl/enterprise-rag-platform/blob/main/app/core/auth.py): `app/core/auth.py`
- [Redis cache](https://github.com/akilanpl/enterprise-rag-platform/blob/main/app/core/cache.py): `app/core/cache.py`

### Evaluation and observability

- [Cost tracking](https://github.com/akilanpl/enterprise-rag-platform/blob/main/app/observability/cost.py): `app/observability/cost.py`
- [Latency tracking](https://github.com/akilanpl/enterprise-rag-platform/blob/main/app/observability/latency.py): `app/observability/latency.py`
- [Runtime metrics](https://github.com/akilanpl/enterprise-rag-platform/blob/main/app/observability/metrics.py): `app/observability/metrics.py`
- [Request tracing](https://github.com/akilanpl/enterprise-rag-platform/blob/main/app/observability/tracing.py): `app/observability/tracing.py`
- [User feedback](https://github.com/akilanpl/enterprise-rag-platform/blob/main/app/observability/feedback.py): `app/observability/feedback.py`
- [RAG evaluation](https://github.com/akilanpl/enterprise-rag-platform/blob/main/app/evaluation/ragas_eval.py): `app/evaluation/ragas_eval.py`

### Other components

- **API client**
- **Qdrant**
- **Embedding model**
- **OpenAI API**
- **Redis**

## Connections

- API client → Chat endpoint: submits query
- FastAPI application → Chat endpoint: mounts router
- Chat endpoint → Tenant context: sets tenant
- Chat endpoint → Embedding model: embeds query
- Chat endpoint → Vector retrieval: retrieves documents
- Chat endpoint → Result reranker: reranks documents
- Chat endpoint → Answer generator: requests answer
- Vector retrieval → Tenant context: reads tenant
- Vector retrieval → Qdrant: searches vectors
- Vector indexer → Embedding model: embeds documents
- Vector indexer → Qdrant: writes vectors
- Answer generator → Context sanitizer: sanitizes context
- Answer generator → OpenAI API: requests completion
- Answer generator → Cost tracking: records usage
- Cost tracking → Tenant context: reads tenant
- RAG pipeline → Vector retrieval: retrieves documents
- RAG pipeline → Answer generator: generates answer
- RAG pipeline → Latency tracking: tracks duration
- Redis cache → Redis: reads and writes
