# ranjith-fullstack/enterprise-rag-ai-assistance architecture

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

- Interactive diagram: https://gitdiagram.com/ranjith-fullstack/enterprise-rag-ai-assistance
- Repository: https://github.com/ranjith-fullstack/enterprise-rag-ai-assistance

## Overview

This is a local-first, permission-aware enterprise document assistant. Users authenticate, upload organizational documents, then search or ask questions and receive cited answers; administrators also manage organizations, audit activity, and run evaluations. The README documents ingestion, retrieval, local inference, and database enforcement, while the sampled source confirms application routing, authentication context, and frontend API behavior. Some backend service-to-service calls are not excerpted, so those links are omitted rather than inferred.

Main entry points: [`backend/app/main.py`](https://github.com/ranjith-fullstack/enterprise-rag-ai-assistance/blob/main/backend/app/main.py) (FastAPI app), [`frontend/src/App.jsx`](https://github.com/ranjith-fullstack/enterprise-rag-ai-assistance/blob/main/frontend/src/App.jsx) (React app routes), [`frontend/src/lib/api.js`](https://github.com/ranjith-fullstack/enterprise-rag-ai-assistance/blob/main/frontend/src/lib/api.js) (API client), [`backend/app/services/rag.py`](https://github.com/ranjith-fullstack/enterprise-rag-ai-assistance/blob/main/backend/app/services/rag.py) (Grounded answer orchestration)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["User application"]
  node_app["React app routes<br/>[App.jsx]"]
  node_auth_ui["Auth context<br/>[AuthContext.jsx]"]
  node_chat_ui["Chat page<br/>[ChatPage.jsx]"]
  node_documents_ui["Document screens"]
  node_admin_ui["Admin and org screens"]
  node_evaluation_ui["Evaluation page<br/>[EvaluationPage.jsx]"]
  node_api_client["API client<br/>[api.js]"]
end

subgraph group_api["API and access"]
  node_api_entry["FastAPI app<br/>[main.py]"]
  node_auth_router["Auth endpoints<br/>[auth.py]"]
  node_chat_router["Chat endpoints<br/>[chat.py]"]
  node_documents_router["Document endpoints<br/>[documents.py]"]
  node_org_router["Organization endpoints<br/>[organizations.py]"]
  node_search_router["Search endpoints<br/>[search.py]"]
  node_evaluation_router["Evaluation endpoints<br/>[evaluation.py]"]
  node_auth_service["Identity service<br/>[auth.py]"]
  node_auth_context["Access dependencies<br/>[auth.py]"]
end

subgraph group_ingestion["Document ingestion"]
  node_ingestion_service["Document extraction<br/>[ingestion.py]"]
  node_storage_service["Safe file storage<br/>[storage.py]"]
  node_embedding_pipeline["Chunk embedding persistence"]
end

subgraph group_retrieval["Search and answers"]
  node_embeddings["Local embeddings<br/>[embeddings.py]"]
  node_search_service["Semantic search<br/>[search.py]"]
  node_rag_service["Grounded answer orchestration<br/>[rag.py]"]
  node_llm_service["Local LLM generation<br/>[llm.py]"]
end

subgraph group_platform["State and operations"]
  node_database[("PostgreSQL and pgvector")]
  node_db_context["RLS transaction context<br/>[context.py]"]
  node_config["Runtime configuration<br/>[config.py]"]
  node_ollama["Ollama"]
  node_local_model["Embedding model"]
end

node_user(("User"))

node_user -->|"uses"| node_app
node_app -->|"provides context"| node_auth_ui
node_app -->|"routes to"| node_chat_ui
node_app -->|"routes to"| node_documents_ui
node_app -->|"routes to"| node_admin_ui
node_app -->|"routes to"| node_evaluation_ui
node_auth_ui -->|"calls"| node_api_client
node_chat_ui -->|"calls"| node_api_client
node_documents_ui -.->|"calls"| node_api_client
node_admin_ui -.->|"calls"| node_api_client
node_evaluation_ui -->|"calls"| node_api_client
node_api_client -->|"sends requests"| node_api_entry
node_api_entry -->|"registers"| node_auth_router
node_api_entry -->|"registers"| node_chat_router
node_api_entry -->|"registers"| node_documents_router
node_api_entry -->|"registers"| node_org_router
node_api_entry -->|"registers"| node_search_router
node_api_entry -->|"registers"| node_evaluation_router
node_auth_router -->|"delegates"| node_auth_service
node_auth_context -->|"verifies access"| node_database
node_auth_context -->|"sets tenant context"| node_db_context
node_documents_router -.->|"handles uploads"| node_ingestion_service
node_ingestion_service -->|"stores files"| node_storage_service
node_ingestion_service -->|"requests embeddings"| node_embedding_pipeline
node_embedding_pipeline -->|"embeds chunks"| node_embeddings
node_embedding_pipeline -->|"persists vectors"| node_database
node_embeddings -->|"runs locally"| node_local_model
node_search_router -->|"delegates search"| node_search_service
node_chat_router -.->|"answers questions"| node_rag_service
node_rag_service -->|"retrieves passages"| node_search_service
node_rag_service -->|"generates answer"| node_llm_service
node_search_service -->|"embeds query"| node_embeddings
node_search_service -->|"queries chunks"| node_database
node_llm_service -->|"requests generation"| node_ollama
node_rag_service -->|"persists history"| node_database
node_database -->|"enforces RLS"| node_db_context
node_config -->|"configures host"| node_ollama

click node_app "https://github.com/ranjith-fullstack/enterprise-rag-ai-assistance/blob/main/frontend/src/App.jsx"
click node_auth_ui "https://github.com/ranjith-fullstack/enterprise-rag-ai-assistance/blob/main/frontend/src/features/auth/AuthContext.jsx"
click node_chat_ui "https://github.com/ranjith-fullstack/enterprise-rag-ai-assistance/blob/main/frontend/src/features/chat/ChatPage.jsx"
click node_documents_ui "https://github.com/ranjith-fullstack/enterprise-rag-ai-assistance/tree/main/frontend/src/features/documents"
click node_admin_ui "https://github.com/ranjith-fullstack/enterprise-rag-ai-assistance/tree/main/frontend/src/features/admin"
click node_evaluation_ui "https://github.com/ranjith-fullstack/enterprise-rag-ai-assistance/blob/main/frontend/src/features/evaluation/EvaluationPage.jsx"
click node_api_client "https://github.com/ranjith-fullstack/enterprise-rag-ai-assistance/blob/main/frontend/src/lib/api.js"
click node_api_entry "https://github.com/ranjith-fullstack/enterprise-rag-ai-assistance/blob/main/backend/app/main.py"
click node_auth_router "https://github.com/ranjith-fullstack/enterprise-rag-ai-assistance/blob/main/backend/app/routers/auth.py"
click node_chat_router "https://github.com/ranjith-fullstack/enterprise-rag-ai-assistance/blob/main/backend/app/routers/chat.py"
click node_documents_router "https://github.com/ranjith-fullstack/enterprise-rag-ai-assistance/blob/main/backend/app/routers/documents.py"
click node_org_router "https://github.com/ranjith-fullstack/enterprise-rag-ai-assistance/blob/main/backend/app/routers/organizations.py"
click node_search_router "https://github.com/ranjith-fullstack/enterprise-rag-ai-assistance/blob/main/backend/app/routers/search.py"
click node_evaluation_router "https://github.com/ranjith-fullstack/enterprise-rag-ai-assistance/blob/main/backend/app/routers/evaluation.py"
click node_auth_service "https://github.com/ranjith-fullstack/enterprise-rag-ai-assistance/blob/main/backend/app/services/auth.py"
click node_auth_context "https://github.com/ranjith-fullstack/enterprise-rag-ai-assistance/blob/main/backend/app/dependencies/auth.py"
click node_ingestion_service "https://github.com/ranjith-fullstack/enterprise-rag-ai-assistance/blob/main/backend/app/services/ingestion.py"
click node_storage_service "https://github.com/ranjith-fullstack/enterprise-rag-ai-assistance/blob/main/backend/app/services/storage.py"
click node_embedding_pipeline "https://github.com/ranjith-fullstack/enterprise-rag-ai-assistance/blob/main/backend/app/services/embedding_pipeline.py"
click node_embeddings "https://github.com/ranjith-fullstack/enterprise-rag-ai-assistance/blob/main/backend/app/services/embeddings.py"
click node_search_service "https://github.com/ranjith-fullstack/enterprise-rag-ai-assistance/blob/main/backend/app/services/search.py"
click node_rag_service "https://github.com/ranjith-fullstack/enterprise-rag-ai-assistance/blob/main/backend/app/services/rag.py"
click node_llm_service "https://github.com/ranjith-fullstack/enterprise-rag-ai-assistance/blob/main/backend/app/services/llm.py"
click node_db_context "https://github.com/ranjith-fullstack/enterprise-rag-ai-assistance/blob/main/backend/app/database/context.py"
click node_config "https://github.com/ranjith-fullstack/enterprise-rag-ai-assistance/blob/main/backend/app/core/config.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_app,node_auth_ui,node_chat_ui,node_documents_ui,node_admin_ui,node_evaluation_ui,node_api_client,node_user toneBlue
class node_api_entry,node_auth_router,node_chat_router,node_documents_router,node_org_router,node_search_router,node_evaluation_router,node_auth_service,node_auth_context toneAmber
class node_ingestion_service,node_storage_service,node_embedding_pipeline toneMint
class node_embeddings,node_search_service,node_rag_service,node_llm_service toneRose
class node_database,node_db_context,node_config,node_ollama,node_local_model toneIndigo
```

## Components

### User application

- [React app routes](https://github.com/ranjith-fullstack/enterprise-rag-ai-assistance/blob/main/frontend/src/App.jsx): `frontend/src/App.jsx`
- [Auth context](https://github.com/ranjith-fullstack/enterprise-rag-ai-assistance/blob/main/frontend/src/features/auth/AuthContext.jsx): `frontend/src/features/auth/AuthContext.jsx`
- [Chat page](https://github.com/ranjith-fullstack/enterprise-rag-ai-assistance/blob/main/frontend/src/features/chat/ChatPage.jsx): `frontend/src/features/chat/ChatPage.jsx`
- [Document screens](https://github.com/ranjith-fullstack/enterprise-rag-ai-assistance/tree/main/frontend/src/features/documents): `frontend/src/features/documents`
- [Admin and org screens](https://github.com/ranjith-fullstack/enterprise-rag-ai-assistance/tree/main/frontend/src/features/admin): `frontend/src/features/admin`
- [Evaluation page](https://github.com/ranjith-fullstack/enterprise-rag-ai-assistance/blob/main/frontend/src/features/evaluation/EvaluationPage.jsx): `frontend/src/features/evaluation/EvaluationPage.jsx`
- [API client](https://github.com/ranjith-fullstack/enterprise-rag-ai-assistance/blob/main/frontend/src/lib/api.js): `frontend/src/lib/api.js`

### API and access

- [FastAPI app](https://github.com/ranjith-fullstack/enterprise-rag-ai-assistance/blob/main/backend/app/main.py): `backend/app/main.py`
- [Auth endpoints](https://github.com/ranjith-fullstack/enterprise-rag-ai-assistance/blob/main/backend/app/routers/auth.py): `backend/app/routers/auth.py`
- [Chat endpoints](https://github.com/ranjith-fullstack/enterprise-rag-ai-assistance/blob/main/backend/app/routers/chat.py): `backend/app/routers/chat.py`
- [Document endpoints](https://github.com/ranjith-fullstack/enterprise-rag-ai-assistance/blob/main/backend/app/routers/documents.py): `backend/app/routers/documents.py`
- [Organization endpoints](https://github.com/ranjith-fullstack/enterprise-rag-ai-assistance/blob/main/backend/app/routers/organizations.py): `backend/app/routers/organizations.py`
- [Search endpoints](https://github.com/ranjith-fullstack/enterprise-rag-ai-assistance/blob/main/backend/app/routers/search.py): `backend/app/routers/search.py`
- [Evaluation endpoints](https://github.com/ranjith-fullstack/enterprise-rag-ai-assistance/blob/main/backend/app/routers/evaluation.py): `backend/app/routers/evaluation.py`
- [Identity service](https://github.com/ranjith-fullstack/enterprise-rag-ai-assistance/blob/main/backend/app/services/auth.py): `backend/app/services/auth.py`
- [Access dependencies](https://github.com/ranjith-fullstack/enterprise-rag-ai-assistance/blob/main/backend/app/dependencies/auth.py): `backend/app/dependencies/auth.py`

### Document ingestion

- [Document extraction](https://github.com/ranjith-fullstack/enterprise-rag-ai-assistance/blob/main/backend/app/services/ingestion.py): `backend/app/services/ingestion.py`
- [Safe file storage](https://github.com/ranjith-fullstack/enterprise-rag-ai-assistance/blob/main/backend/app/services/storage.py): `backend/app/services/storage.py`
- [Chunk embedding persistence](https://github.com/ranjith-fullstack/enterprise-rag-ai-assistance/blob/main/backend/app/services/embedding_pipeline.py): `backend/app/services/embedding_pipeline.py`

### Search and answers

- [Local embeddings](https://github.com/ranjith-fullstack/enterprise-rag-ai-assistance/blob/main/backend/app/services/embeddings.py): `backend/app/services/embeddings.py`
- [Semantic search](https://github.com/ranjith-fullstack/enterprise-rag-ai-assistance/blob/main/backend/app/services/search.py): `backend/app/services/search.py`
- [Grounded answer orchestration](https://github.com/ranjith-fullstack/enterprise-rag-ai-assistance/blob/main/backend/app/services/rag.py): `backend/app/services/rag.py`
- [Local LLM generation](https://github.com/ranjith-fullstack/enterprise-rag-ai-assistance/blob/main/backend/app/services/llm.py): `backend/app/services/llm.py`

### State and operations

- **PostgreSQL and pgvector**
- [RLS transaction context](https://github.com/ranjith-fullstack/enterprise-rag-ai-assistance/blob/main/backend/app/database/context.py): `backend/app/database/context.py`
- [Runtime configuration](https://github.com/ranjith-fullstack/enterprise-rag-ai-assistance/blob/main/backend/app/core/config.py): `backend/app/core/config.py`
- **Ollama**
- **Embedding model**

### Other components

- **User**

## Connections

- User → React app routes: uses (evidence: `README.md`)
- React app routes → Auth context: provides context (evidence: `frontend/src/App.jsx`)
- React app routes → Chat page: routes to (evidence: `frontend/src/App.jsx`)
- React app routes → Document screens: routes to (evidence: `frontend/src/App.jsx`)
- React app routes → Admin and org screens: routes to (evidence: `frontend/src/App.jsx`)
- React app routes → Evaluation page: routes to (evidence: `frontend/src/App.jsx`)
- Auth context → API client: calls (evidence: `frontend/src/features/auth/AuthContext.jsx`)
- Chat page → API client: calls (evidence: `frontend/src/features/chat/ChatPage.jsx`)
- Document screens → API client: calls (evidence: `frontend/src/features/documents/DocumentDetailsPage.jsx`)
- Admin and org screens → API client: calls (evidence: `frontend/src/features/admin/AdminUsersPage.jsx`)
- Evaluation page → API client: calls (evidence: `frontend/src/features/evaluation/EvaluationPage.jsx`)
- API client → FastAPI app: sends requests (evidence: `README.md`)
- FastAPI app → Auth endpoints: registers (evidence: `backend/app/main.py`)
- FastAPI app → Chat endpoints: registers (evidence: `backend/app/main.py`)
- FastAPI app → Document endpoints: registers (evidence: `backend/app/main.py`)
- FastAPI app → Organization endpoints: registers (evidence: `backend/app/main.py`)
- FastAPI app → Search endpoints: registers (evidence: `backend/app/main.py`)
- FastAPI app → Evaluation endpoints: registers (evidence: `backend/app/main.py`)
- Auth endpoints → Identity service: delegates (evidence: `backend/app/routers/auth.py`)
- Access dependencies → PostgreSQL and pgvector: verifies access (evidence: `backend/app/dependencies/auth.py`)
- Access dependencies → RLS transaction context: sets tenant context (evidence: `backend/app/dependencies/auth.py`)
- Document endpoints → Document extraction: handles uploads
- Document extraction → Safe file storage: stores files (evidence: `backend/app/services/ingestion.py`)
- Document extraction → Chunk embedding persistence: requests embeddings (evidence: `backend/app/services/ingestion.py`)
- Chunk embedding persistence → Local embeddings: embeds chunks (evidence: `backend/app/services/embedding_pipeline.py`)
- Chunk embedding persistence → PostgreSQL and pgvector: persists vectors (evidence: `README.md`)
- Local embeddings → Embedding model: runs locally (evidence: `README.md`)
- Search endpoints → Semantic search: delegates search (evidence: `backend/app/routers/search.py`)
- Chat endpoints → Grounded answer orchestration: answers questions
- Grounded answer orchestration → Semantic search: retrieves passages (evidence: `backend/app/services/rag.py`)
- Grounded answer orchestration → Local LLM generation: generates answer (evidence: `backend/app/services/rag.py`)
- Semantic search → Local embeddings: embeds query (evidence: `backend/app/services/search.py`)
- Semantic search → PostgreSQL and pgvector: queries chunks (evidence: `README.md`)
- Local LLM generation → Ollama: requests generation (evidence: `README.md`)
- Grounded answer orchestration → PostgreSQL and pgvector: persists history (evidence: `README.md`)
- PostgreSQL and pgvector → RLS transaction context: enforces RLS (evidence: `README.md`)
- Runtime configuration → Ollama: configures host (evidence: `backend/app/core/config.py`)
