# sophanith21/library-book-retrieval-rag-engine architecture

> Architecture diagram of the GitHub repository sophanith21/library-book-retrieval-rag-engine, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sophanith21/library-book-retrieval-rag-engine
- Repository: https://github.com/sophanith21/library-book-retrieval-rag-engine

## Overview

LBRE is documented as a digital library and RAG search system: users enter through a browser, reach backend services through the edge and API gateways, and search results are retrieved and synthesized with citations. Its documented domain capabilities include authentication, book CRUD and object storage, hybrid indexing, fused retrieval, and LLM synthesis. The sampled NestJS controllers and services are mostly hello-world scaffolding, and the frontend is a Vite starter; therefore domain interactions below rely on README statements, not inspected implementations. Dashed edges mark documented or implied-but-unverified messaging and data links.

Main entry points: [`backend/apps/api-gateway/src/api-gateway.controller.ts`](https://github.com/sophanith21/library-book-retrieval-rag-engine/blob/main/backend/apps/api-gateway/src/api-gateway.controller.ts) (API Gateway), [`backend/apps/retrieval/src/retrieval.service.ts`](https://github.com/sophanith21/library-book-retrieval-rag-engine/blob/main/backend/apps/retrieval/src/retrieval.service.ts) (Retrieval Service), [`backend/apps/book/src/book.service.ts`](https://github.com/sophanith21/library-book-retrieval-rag-engine/blob/main/backend/apps/book/src/book.service.ts) (Book Service), [`backend/apps/indexing/src/indexing.service.ts`](https://github.com/sophanith21/library-book-retrieval-rag-engine/blob/main/backend/apps/indexing/src/indexing.service.ts) (Indexing Service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["User Experience"]
  node_frontend["Web Interface<br/>[App.tsx]"]
  node_edge["Edge Gateway<br/>[nginx.conf]"]
end

subgraph group_backend["Backend Services"]
  node_api["API Gateway"]
  node_auth["Authentication<br/>[auth.service.ts]"]
  node_books["Book Service<br/>[book.service.ts]"]
  node_contracts["Service Contracts"]
end

subgraph group_search["Search and Synthesis"]
  node_indexing["Indexing Service"]
  node_retrieval["Retrieval Service"]
  node_llm["LLM Synthesis<br/>[llm.service.ts]"]
  node_ollama["Ollama LLM"]
  node_crawler["Crawler and Ingest<br/>[ingest.py]"]
end

subgraph group_storage["Persistence and Messaging"]
  node_prisma["Database Client<br/>[prisma.service.ts]"]
  node_broker["RabbitMQ"]
  node_postgres[("PostgreSQL PgVector")]
  node_objects[("SeaweedFS S3")]
end

node_browser(("Library User"))

node_browser -.->|"uses"| node_frontend
node_frontend -.->|"routes API requests"| node_edge
node_edge -.->|"proxies API"| node_api
node_api -.->|"routes requests"| node_auth
node_api -.->|"routes requests"| node_books
node_api -.->|"routes requests"| node_indexing
node_api -.->|"routes requests"| node_retrieval
node_api -.->|"routes requests"| node_llm
node_api -.->|"dispatches messages"| node_broker
node_auth -.->|"uses messaging"| node_broker
node_books -.->|"uses messaging"| node_broker
node_indexing -.->|"uses messaging"| node_broker
node_retrieval -.->|"uses messaging"| node_broker
node_llm -.->|"uses messaging"| node_broker
node_books -.->|"stores book files"| node_objects
node_indexing -.->|"stores vectors"| node_postgres
node_retrieval -.->|"searches vectors"| node_postgres
node_retrieval -.->|"provides fused chunks"| node_llm
node_llm -.->|"generates synthesis"| node_ollama
node_crawler -.->|"supplies book content"| node_books
node_crawler -.->|"supplies documents"| node_indexing

click node_frontend "https://github.com/sophanith21/library-book-retrieval-rag-engine/blob/main/frontend/src/App.tsx"
click node_edge "https://github.com/sophanith21/library-book-retrieval-rag-engine/blob/main/infra/edge-gateway/nginx.conf"
click node_api "https://github.com/sophanith21/library-book-retrieval-rag-engine/blob/main/backend/apps/api-gateway/src/api-gateway.controller.ts"
click node_auth "https://github.com/sophanith21/library-book-retrieval-rag-engine/blob/main/backend/apps/auth/src/auth.service.ts"
click node_books "https://github.com/sophanith21/library-book-retrieval-rag-engine/blob/main/backend/apps/book/src/book.service.ts"
click node_indexing "https://github.com/sophanith21/library-book-retrieval-rag-engine/blob/main/backend/apps/indexing/src/indexing.service.ts"
click node_retrieval "https://github.com/sophanith21/library-book-retrieval-rag-engine/blob/main/backend/apps/retrieval/src/retrieval.service.ts"
click node_llm "https://github.com/sophanith21/library-book-retrieval-rag-engine/blob/main/backend/apps/llm/src/llm.service.ts"
click node_contracts "https://github.com/sophanith21/library-book-retrieval-rag-engine/blob/main/backend/libs/contracts/src/contracts.service.ts"
click node_prisma "https://github.com/sophanith21/library-book-retrieval-rag-engine/blob/main/backend/libs/prisma/src/prisma.service.ts"
click node_crawler "https://github.com/sophanith21/library-book-retrieval-rag-engine/blob/main/ingest.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_frontend,node_edge,node_browser toneBlue
class node_api,node_auth,node_books,node_contracts toneAmber
class node_indexing,node_retrieval,node_llm,node_ollama,node_crawler toneMint
class node_prisma,node_broker,node_postgres,node_objects toneRose
```

## Components

### User Experience

- [Web Interface](https://github.com/sophanith21/library-book-retrieval-rag-engine/blob/main/frontend/src/App.tsx): `frontend/src/App.tsx`
- [Edge Gateway](https://github.com/sophanith21/library-book-retrieval-rag-engine/blob/main/infra/edge-gateway/nginx.conf): `infra/edge-gateway/nginx.conf`

### Backend Services

- [API Gateway](https://github.com/sophanith21/library-book-retrieval-rag-engine/blob/main/backend/apps/api-gateway/src/api-gateway.controller.ts): `backend/apps/api-gateway/src/api-gateway.controller.ts`
- [Authentication](https://github.com/sophanith21/library-book-retrieval-rag-engine/blob/main/backend/apps/auth/src/auth.service.ts): `backend/apps/auth/src/auth.service.ts`
- [Book Service](https://github.com/sophanith21/library-book-retrieval-rag-engine/blob/main/backend/apps/book/src/book.service.ts): `backend/apps/book/src/book.service.ts`
- [Service Contracts](https://github.com/sophanith21/library-book-retrieval-rag-engine/blob/main/backend/libs/contracts/src/contracts.service.ts): `backend/libs/contracts/src/contracts.service.ts`

### Search and Synthesis

- [Indexing Service](https://github.com/sophanith21/library-book-retrieval-rag-engine/blob/main/backend/apps/indexing/src/indexing.service.ts): `backend/apps/indexing/src/indexing.service.ts`
- [Retrieval Service](https://github.com/sophanith21/library-book-retrieval-rag-engine/blob/main/backend/apps/retrieval/src/retrieval.service.ts): `backend/apps/retrieval/src/retrieval.service.ts`
- [LLM Synthesis](https://github.com/sophanith21/library-book-retrieval-rag-engine/blob/main/backend/apps/llm/src/llm.service.ts): `backend/apps/llm/src/llm.service.ts`
- **Ollama LLM**
- [Crawler and Ingest](https://github.com/sophanith21/library-book-retrieval-rag-engine/blob/main/ingest.py): `ingest.py`

### Persistence and Messaging

- [Database Client](https://github.com/sophanith21/library-book-retrieval-rag-engine/blob/main/backend/libs/prisma/src/prisma.service.ts): `backend/libs/prisma/src/prisma.service.ts`
- **RabbitMQ**
- **PostgreSQL PgVector**
- **SeaweedFS S3**

### Other components

- **Library User**

## Connections

- Library User → Web Interface: uses (evidence: `README.md`)
- Web Interface → Edge Gateway: routes API requests (evidence: `README.md`)
- Edge Gateway → API Gateway: proxies API (evidence: `README.md`)
- API Gateway → Authentication: routes requests (evidence: `README.md`)
- API Gateway → Book Service: routes requests (evidence: `README.md`)
- API Gateway → Indexing Service: routes requests (evidence: `README.md`)
- API Gateway → Retrieval Service: routes requests (evidence: `README.md`)
- API Gateway → LLM Synthesis: routes requests (evidence: `README.md`)
- API Gateway → RabbitMQ: dispatches messages (evidence: `README.md`)
- Authentication → RabbitMQ: uses messaging (evidence: `README.md`)
- Book Service → RabbitMQ: uses messaging (evidence: `README.md`)
- Indexing Service → RabbitMQ: uses messaging (evidence: `README.md`)
- Retrieval Service → RabbitMQ: uses messaging (evidence: `README.md`)
- LLM Synthesis → RabbitMQ: uses messaging (evidence: `README.md`)
- Book Service → SeaweedFS S3: stores book files (evidence: `README.md`)
- Indexing Service → PostgreSQL PgVector: stores vectors (evidence: `README.md`)
- Retrieval Service → PostgreSQL PgVector: searches vectors (evidence: `README.md`)
- Retrieval Service → LLM Synthesis: provides fused chunks (evidence: `README.md`)
- LLM Synthesis → Ollama LLM: generates synthesis (evidence: `README.md`)
- Crawler and Ingest → Book Service: supplies book content
- Crawler and Ingest → Indexing Service: supplies documents
