# pd241008/intellidoc-query architecture

> Architecture diagram of the GitHub repository pd241008/intellidoc-query, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/pd241008/intellidoc-query
- Repository: https://github.com/pd241008/intellidoc-query

## Overview

IntelliDoc is a full-stack document-intelligence platform. Users upload documents for asynchronous processing and indexing, then query an owned document for semantic retrieval and streamed, document-grounded answers; the frontend also exposes authentication, status, and admin workflows. The graph preserves the separate auth service, ingestion and RAG stages, and storage/health concerns. Some frontend-to-service links and README-described capabilities are documented rather than visible in source excerpts; unsampled implementation details are not inferred.

Main entry points: [`backend/app/services/rag_service.py`](https://github.com/pd241008/intellidoc-query/blob/main/backend/app/services/rag_service.py) (RAG orchestrator), [`backend/main.py`](https://github.com/pd241008/intellidoc-query/blob/main/backend/main.py) (FastAPI gateway), [`backend/app/middleware/workers/ingestion_pipeline/tasks/ingestion_tasks.py`](https://github.com/pd241008/intellidoc-query/blob/main/backend/app/middleware/workers/ingestion_pipeline/tasks/ingestion_tasks.py) (Clean, chunk, embed), [`auth/src/routes/otp/route.ts`](https://github.com/pd241008/intellidoc-query/blob/main/auth/src/routes/otp/route.ts) (Auth and OTP routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["User interface"]
  node_web["Next.js application"]
  node_web_api["Frontend API routes"]
end

subgraph group_auth["Authentication and documents"]
  node_auth_service["Auth service<br/>[app.ts]"]
  node_auth_routes["Auth and OTP routes<br/>[route.ts]"]
  node_user_sync["User sync controller<br/>[user_controller.ts]"]
  node_auth_users[("User records<br/>[users.ts]")]
  node_documents[("Document metadata<br/>[documents.ts]")]
end

subgraph group_api["Backend API"]
  node_backend["FastAPI gateway<br/>[main.py]"]
  node_api_router["API router<br/>[api_router.py]"]
  node_upload_api["Upload API<br/>[upload.py]"]
  node_query_api["Query API<br/>[query.py]"]
end

subgraph group_ingest["Ingestion pipeline"]
  node_ingest_service["Ingestion trigger"]
  node_ingest_orchestrator["Ingestion orchestrator"]
  node_ingest_tasks["Clean, chunk, embed<br/>[ingestion_tasks.py]"]
end

subgraph group_rag["Retrieval and answers"]
  node_rag_service["RAG orchestrator<br/>[rag_service.py]"]
  node_search["Semantic search<br/>[search_service.py]"]
  node_llm_chain["Query rewrite and answer"]
  node_context["Context builder<br/>[context_builder.py]"]
  node_llm["LLM generation<br/>[llm.py]"]
end

subgraph group_infra["Storage and operations"]
  node_mongo[("MongoDB repositories<br/>[document_repo.py]")]
  node_chroma[("Chroma vector store")]
  node_redis[("Redis status and cache<br/>[redis_repo.py]")]
  node_health["Health and pipeline status<br/>[health.py]"]
  node_queue["Celery task queue<br/>[celery_app.py]"]
end

node_browser(("User"))

node_browser -->|"uses"| node_web
node_web -->|"calls"| node_web_api
node_web_api -->|"requests"| node_backend
node_backend -->|"registers"| node_api_router
node_browser -->|"authenticates"| node_auth_service
node_auth_service -.->|"serves"| node_auth_routes
node_auth_routes -.->|"syncs users"| node_auth_users
node_auth_routes -->|"reads and writes"| node_documents
node_browser -->|"uploads"| node_upload_api
node_upload_api -.->|"triggers"| node_ingest_service
node_ingest_service -->|"starts"| node_ingest_orchestrator
node_ingest_orchestrator -->|"chains tasks"| node_ingest_tasks
node_ingest_orchestrator -->|"marks status"| node_health
node_ingest_tasks -->|"runs on"| node_queue
node_ingest_tasks -->|"stores embeddings"| node_chroma
node_ingest_tasks -.->|"stores pipeline data"| node_redis
node_browser -->|"submits query"| node_query_api
node_query_api -.->|"runs RAG"| node_rag_service
node_rag_service -->|"checks ownership"| node_mongo
node_rag_service -->|"retrieves passages"| node_search
node_rag_service -->|"rewrites and streams"| node_llm_chain
node_llm_chain -->|"builds context"| node_context
node_llm_chain -->|"generates answer"| node_llm
node_rag_service -->|"marks status"| node_health
node_backend -->|"checks connection"| node_redis
node_backend -->|"checks connection"| node_chroma
node_health -->|"reads and writes status"| node_redis

click node_web "https://github.com/pd241008/intellidoc-query/tree/main/frontend/src/app"
click node_web_api "https://github.com/pd241008/intellidoc-query/tree/main/frontend/src/app/api"
click node_auth_service "https://github.com/pd241008/intellidoc-query/blob/main/auth/src/app.ts"
click node_auth_routes "https://github.com/pd241008/intellidoc-query/blob/main/auth/src/routes/otp/route.ts"
click node_user_sync "https://github.com/pd241008/intellidoc-query/blob/main/auth/src/controllers/user_controller.ts"
click node_auth_users "https://github.com/pd241008/intellidoc-query/blob/main/auth/src/models/users.ts"
click node_documents "https://github.com/pd241008/intellidoc-query/blob/main/auth/src/models/documents.ts"
click node_backend "https://github.com/pd241008/intellidoc-query/blob/main/backend/main.py"
click node_api_router "https://github.com/pd241008/intellidoc-query/blob/main/backend/app/api/api_router.py"
click node_upload_api "https://github.com/pd241008/intellidoc-query/blob/main/backend/app/api/upload/upload.py"
click node_query_api "https://github.com/pd241008/intellidoc-query/blob/main/backend/app/api/query/query.py"
click node_ingest_service "https://github.com/pd241008/intellidoc-query/blob/main/backend/app/services/ingestion_service.py"
click node_ingest_orchestrator "https://github.com/pd241008/intellidoc-query/blob/main/backend/app/middleware/workers/ingestion_pipeline/ingestion_pipeline.py"
click node_ingest_tasks "https://github.com/pd241008/intellidoc-query/blob/main/backend/app/middleware/workers/ingestion_pipeline/tasks/ingestion_tasks.py"
click node_rag_service "https://github.com/pd241008/intellidoc-query/blob/main/backend/app/services/rag_service.py"
click node_search "https://github.com/pd241008/intellidoc-query/blob/main/backend/app/services/search_service.py"
click node_llm_chain "https://github.com/pd241008/intellidoc-query/blob/main/backend/app/services/llm_chain_service.py"
click node_context "https://github.com/pd241008/intellidoc-query/blob/main/backend/app/rag/context_builder.py"
click node_llm "https://github.com/pd241008/intellidoc-query/blob/main/backend/app/rag/llm.py"
click node_mongo "https://github.com/pd241008/intellidoc-query/blob/main/backend/app/data_access/mongodb/document_repo.py"
click node_chroma "https://github.com/pd241008/intellidoc-query/blob/main/backend/app/database/chromadb/chromaconnection.py"
click node_redis "https://github.com/pd241008/intellidoc-query/blob/main/backend/app/data_access/redis/redis_repo.py"
click node_health "https://github.com/pd241008/intellidoc-query/blob/main/backend/app/core/config/health.py"
click node_queue "https://github.com/pd241008/intellidoc-query/blob/main/backend/app/middleware/workers/ingestion_pipeline/celery_app.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_web,node_web_api,node_browser toneBlue
class node_auth_service,node_auth_routes,node_user_sync,node_auth_users,node_documents toneAmber
class node_backend,node_api_router,node_upload_api,node_query_api toneMint
class node_ingest_service,node_ingest_orchestrator,node_ingest_tasks toneRose
class node_rag_service,node_search,node_llm_chain,node_context,node_llm toneIndigo
class node_mongo,node_chroma,node_redis,node_health,node_queue toneTeal
```

## Components

### User interface

- [Next.js application](https://github.com/pd241008/intellidoc-query/tree/main/frontend/src/app): `frontend/src/app`
- [Frontend API routes](https://github.com/pd241008/intellidoc-query/tree/main/frontend/src/app/api): `frontend/src/app/api`

### Authentication and documents

- [Auth service](https://github.com/pd241008/intellidoc-query/blob/main/auth/src/app.ts): `auth/src/app.ts`
- [Auth and OTP routes](https://github.com/pd241008/intellidoc-query/blob/main/auth/src/routes/otp/route.ts): `auth/src/routes/otp/route.ts`
- [User sync controller](https://github.com/pd241008/intellidoc-query/blob/main/auth/src/controllers/user_controller.ts): `auth/src/controllers/user_controller.ts`
- [User records](https://github.com/pd241008/intellidoc-query/blob/main/auth/src/models/users.ts): `auth/src/models/users.ts`
- [Document metadata](https://github.com/pd241008/intellidoc-query/blob/main/auth/src/models/documents.ts): `auth/src/models/documents.ts`

### Backend API

- [FastAPI gateway](https://github.com/pd241008/intellidoc-query/blob/main/backend/main.py): `backend/main.py`
- [API router](https://github.com/pd241008/intellidoc-query/blob/main/backend/app/api/api_router.py): `backend/app/api/api_router.py`
- [Upload API](https://github.com/pd241008/intellidoc-query/blob/main/backend/app/api/upload/upload.py): `backend/app/api/upload/upload.py`
- [Query API](https://github.com/pd241008/intellidoc-query/blob/main/backend/app/api/query/query.py): `backend/app/api/query/query.py`

### Ingestion pipeline

- [Ingestion trigger](https://github.com/pd241008/intellidoc-query/blob/main/backend/app/services/ingestion_service.py): `backend/app/services/ingestion_service.py`
- [Ingestion orchestrator](https://github.com/pd241008/intellidoc-query/blob/main/backend/app/middleware/workers/ingestion_pipeline/ingestion_pipeline.py): `backend/app/middleware/workers/ingestion_pipeline/ingestion_pipeline.py`
- [Clean, chunk, embed](https://github.com/pd241008/intellidoc-query/blob/main/backend/app/middleware/workers/ingestion_pipeline/tasks/ingestion_tasks.py): `backend/app/middleware/workers/ingestion_pipeline/tasks/ingestion_tasks.py`

### Retrieval and answers

- [RAG orchestrator](https://github.com/pd241008/intellidoc-query/blob/main/backend/app/services/rag_service.py): `backend/app/services/rag_service.py`
- [Semantic search](https://github.com/pd241008/intellidoc-query/blob/main/backend/app/services/search_service.py): `backend/app/services/search_service.py`
- [Query rewrite and answer](https://github.com/pd241008/intellidoc-query/blob/main/backend/app/services/llm_chain_service.py): `backend/app/services/llm_chain_service.py`
- [Context builder](https://github.com/pd241008/intellidoc-query/blob/main/backend/app/rag/context_builder.py): `backend/app/rag/context_builder.py`
- [LLM generation](https://github.com/pd241008/intellidoc-query/blob/main/backend/app/rag/llm.py): `backend/app/rag/llm.py`

### Storage and operations

- [MongoDB repositories](https://github.com/pd241008/intellidoc-query/blob/main/backend/app/data_access/mongodb/document_repo.py): `backend/app/data_access/mongodb/document_repo.py`
- [Chroma vector store](https://github.com/pd241008/intellidoc-query/blob/main/backend/app/database/chromadb/chromaconnection.py): `backend/app/database/chromadb/chromaconnection.py`
- [Redis status and cache](https://github.com/pd241008/intellidoc-query/blob/main/backend/app/data_access/redis/redis_repo.py): `backend/app/data_access/redis/redis_repo.py`
- [Health and pipeline status](https://github.com/pd241008/intellidoc-query/blob/main/backend/app/core/config/health.py): `backend/app/core/config/health.py`
- [Celery task queue](https://github.com/pd241008/intellidoc-query/blob/main/backend/app/middleware/workers/ingestion_pipeline/celery_app.py): `backend/app/middleware/workers/ingestion_pipeline/celery_app.py`

### Other components

- **User**

## Connections

- User → Next.js application: uses (evidence: `README.md`)
- Next.js application → Frontend API routes: calls (evidence: `README.md`)
- Frontend API routes → FastAPI gateway: requests (evidence: `README.md`)
- FastAPI gateway → API router: registers (evidence: `backend/main.py`)
- User → Auth service: authenticates (evidence: `README.md`)
- Auth service → Auth and OTP routes: serves
- Auth and OTP routes → User records: syncs users
- Auth and OTP routes → Document metadata: reads and writes
- User → Upload API: uploads (evidence: `README.md`)
- Upload API → Ingestion trigger: triggers
- Ingestion trigger → Ingestion orchestrator: starts (evidence: `backend/app/services/ingestion_service.py`)
- Ingestion orchestrator → Clean, chunk, embed: chains tasks (evidence: `backend/app/middleware/workers/ingestion_pipeline/ingestion_pipeline.py`)
- Ingestion orchestrator → Health and pipeline status: marks status (evidence: `backend/app/middleware/workers/ingestion_pipeline/ingestion_pipeline.py`)
- Clean, chunk, embed → Celery task queue: runs on (evidence: `backend/app/middleware/workers/ingestion_pipeline/tasks/ingestion_tasks.py`)
- Clean, chunk, embed → Chroma vector store: stores embeddings (evidence: `backend/app/middleware/workers/ingestion_pipeline/tasks/ingestion_tasks.py`)
- Clean, chunk, embed → Redis status and cache: stores pipeline data
- User → Query API: submits query (evidence: `README.md`)
- Query API → RAG orchestrator: runs RAG
- RAG orchestrator → MongoDB repositories: checks ownership (evidence: `backend/app/services/rag_service.py`)
- RAG orchestrator → Semantic search: retrieves passages (evidence: `backend/app/services/rag_service.py`)
- RAG orchestrator → Query rewrite and answer: rewrites and streams (evidence: `backend/app/services/rag_service.py`)
- Query rewrite and answer → Context builder: builds context (evidence: `backend/app/services/llm_chain_service.py`)
- Query rewrite and answer → LLM generation: generates answer (evidence: `backend/app/services/llm_chain_service.py`)
- RAG orchestrator → Health and pipeline status: marks status (evidence: `backend/app/services/rag_service.py`)
- FastAPI gateway → Redis status and cache: checks connection (evidence: `backend/main.py`)
- FastAPI gateway → Chroma vector store: checks connection (evidence: `backend/main.py`)
- Health and pipeline status → Redis status and cache: reads and writes status (evidence: `backend/app/core/config/health.py`)
