How faisalq05/llm-rag-web-parser works
1. This repository is a TypeScript/Express backend for a RAG pipeline: it crawls websites, extracts text, embeds chunks, stores them in Qdrant, and answers questions over that indexed content with an LLM.
2. The runtime entry path is src/app/server.ts → src/app/app.ts → src/app/container.ts. That split suggests a clean separation between process startup, Express app assembly, and dependency wiring.
3. Configuration is centralized under src/config (env.ts, cors.ts, logger.ts, index.ts). Environment variables drive ports and external service endpoints, while logging and CORS are treated as app-level concerns rather than per-route logic.
4. The HTTP edge is handled by shared middleware in src/common/middlewares: request validation, rate limiting, mTLS enforcement, 404 handling, and a global error middleware. This means requests are normalized and rejected at the boundary before they reach business logic.
5. Domain HTTP handling lives in src/modules/url, with a controller, routes, and service layer. The exposed API is centered on URL indexing and retrieval operations such as parse/index, chat, list indexed URLs, and delete.
6. The indexing path is implemented in src/modules/ai/services/scraper.service.ts. The crawler uses a BFS-style crawl over internal links, strips non-content DOM elements, and produces cleaned text chunks with overlap for downstream embedding.
7. Embedding and vector storage are split into dedicated AI services: embedding.service.ts for Gemini embeddings and qdrant.service.ts for vector persistence/search. This is the core ingestion boundary: text chunks become vectors, then are written to Qdrant for semantic retrieval.
8. The chat path is a retrieval-then-generation flow. A user query is embedded, Qdrant returns top matching chunks, and the LLM service (openai.service.ts in the tree, but described in the README as Groq/Llama) generates an answer from those retrieved sources and optional conversation history.
9. Persistent relational storage is present via src/common/database/connect.ts, with Prisma-specific error handling in src/common/utils/prisma-error.ts. That indicates PostgreSQL is used for app metadata such as indexed URL records and possibly user-related state, separate from Qdrant’s vector store.
10. Shared utilities and exception classes in src/common provide consistent API responses, async handler wrapping, and typed error mapping (bad-request, unauthorized, forbidden, not-found). This keeps controllers thin and pushes cross-cutting concerns into reusable primitives.
11. src/seeder contains seed scripts, which suggests the repository supports bootstrapping database state during development or deployment. That fits with the dockerized workflow described in the README.
12. Infrastructure-wise, the repo is designed to run both locally and in containers via Docker/Docker Compose. The external dependencies that materially shape the architecture are PostgreSQL, Qdrant, Google Gemini for embeddings, and Groq-hosted Llama for generation.
Main entry points: app.ts App · url.service.ts URL Service · index.ts Config Index · connect.ts Database
Components 28
Runtime
Process startup and application assembly
HTTP Edge
Middleware and request handling boundaries
- Validate · Request validation boundary
src/common/middlewares/validate.middleware.ts - Rate Limit · Request throttling boundary
src/common/middlewares/rate-limit.middleware.ts - mTLS · Client certificate enforcement
src/common/middlewares/mtls.middleware.ts - 404 Handler · Fallback for unmatched routes
src/common/middlewares/notFound.middleware.ts - Error MW · Global error translation and response
src/common/middlewares/error.middleware.ts
Config
Environment and app-wide settings
- Env · Environment variable loading and validation
src/config/env.ts - CORS · Cross-origin policy settings
src/config/cors.ts - Logger · Application logging configuration
src/config/logger.ts - Config Index · Central config aggregation
src/config/index.ts
Domain
URL indexing and chat API
- URL Controller · API orchestration for indexing and chat
src/modules/url/controller/url.controller.ts - URL Routes · HTTP route definitions for URL workflows
src/modules/url/routes/url.routes.ts - URL Service · Domain operations over indexed URLs
src/modules/url/services/url.service.ts
AI Pipeline
Crawl, embed, store, and generate answers
- Scraper · BFS crawl, clean pages, and chunk text
src/modules/ai/services/scraper.service.ts - Embeddings · Creates vector embeddings for chunks
src/modules/ai/services/embedding.service.ts - Qdrant · Stores and searches embedded chunks
src/modules/ai/services/qdrant.service.ts - LLM · Generates answers from retrieved context
src/modules/ai/services/openai.service.ts
Shared Core
Database, errors, and response utilities
- Database · Relational persistence connection
src/common/database/connect.ts - Prisma Errors · Maps Prisma failures to app errors
src/common/utils/prisma-error.ts - Response Utils · Standard API response helpers
src/common/utils/response.ts - Exceptions · Typed application error hierarchy
src/common/exceptions/app.exception.ts
Seeding
Bootstrapping data scripts
- Seeder · Database seeding entrypoint
src/seeder/seed.ts - User Seeder · Seeds baseline user records
src/seeder/user.seeder.ts
External
Infrastructure and model dependencies
- PostgreSQL · Relational metadata storage
- Gemini · Hosted embedding model endpoint
- Groq Llama · Hosted chat generation endpoint
Connections 27
- Server → App: starts · Bootstraps the Express app
- App → Container: loads · Resolves app dependencies and services
- Container → Config Index: uses · Pulls centralized configuration
- Config Index → Env: includes · Environment-driven runtime settings
- Config Index → CORS: includes · CORS policy settings
- Config Index → Logger: includes · Logging configuration
- App → Rate Limit: applies · Protects incoming requests
- App → mTLS: applies · Enforces client identity
- App → Validate: applies · Validates request payloads
- App → URL Routes: mounts · Registers URL API routes
- URL Routes → URL Controller: delegates · Routes forward to controller handlers
- URL Controller → URL Service: calls · Controller delegates domain logic
- URL Service → Scraper: crawls · Fetches and chunks web content
- Scraper → Embeddings: embeds · Prepares chunks for vectorization
- Embeddings → Gemini: requests · Uses hosted embedding model
- URL Service → Qdrant: stores/searches · Persists vectors and retrieves matches
- Qdrant → LLM: retrieves context for · Provides top chunks for answer generation
- LLM → Groq Llama: requests · Uses hosted generation model
- URL Service → Database: reads/writes · Persists URL metadata and app state
- Database → PostgreSQL: connects to · Relational backend
- Database → Prisma Errors: maps errors with · Converts database failures into app errors
- URL Service → Response Utils: formats · Builds consistent API responses
- URL Service → Exceptions: throws · Uses typed domain and HTTP errors
- App → 404 Handler: finalizes with · Handles unmatched routes
- App → Error MW: finalizes with · Handles uncaught application errors
- Seeder → User Seeder: runs · Seeder entrypoint orchestrates seed modules
- Seeder → Database: initializes · Seeds the relational database