How nosportugal/librechat works
Project type and purpose
• This is a full-stack, open-source AI chat platform (“LibreChat”) comprising:
• A React/Vite single-page application (client/)
• A Node.js/Express-style REST & SSE backend (api/)
• Supporting packages (data-provider, data-schemas, mcp)
• Infrastructure definitions (Docker, Helm charts, CI/CD workflows)
• Purpose: Provide a ChatGPT-inspired UI, multiple AI endpoints (OpenAI, Anthropic, Google, Bedrock, custom OpenAI-compatible), file upload & processing, agents/tool integrations, RAG (vector search) API, multi-user auth, caching, and vector DB retrieval.
File structure
• Top-level directories:
• client/ → React SPA, context providers, hooks, components, routes, store, styling, i18n
• api/ → controllers, routes, middleware, services, AI clients, models, cache, config, utils
• packages/ → shared libraries: data-provider (client/server GraphQL/REST client libs), data-schemas (Zod schemas), mcp (Model Context Protocol)
• helm/ → Kubernetes charts for main LibreChat and RAG API
• docker-compose & Dockerfiles → container definitions for client, api, vector service, DB, cache
• .github/ → CI/CD workflows, tests, release scripts
README for additional insights
• Multi-AI provider routing, code interpreter sandbox, agents & tools, RAG API link, file storage options, multi-auth (OAuth2, LDAP, email), cache usage, vector search.
• Deployment: Docker, Railway, Helm/K8s, Zeabur, Sealos.
a. Main components
• Frontend (React SPA)
• API Gateway / Backend (Express server)
• RAG API Service (vector search microservice)
• Data Stores:
• Primary DB: MongoDB (api/lib/db)
• Cache: Redis / Keyv stores
• Vector DB: (e.g., Pinecone, Qdrant, Weaviate) behind RAG API
• File Storage: S3, Azure Blob, Firebase, Local FS
• Authentication & Authorization: Passport strategies, OAuth2, LDAP
• External AI Providers: OpenAI, Anthropic, Google Vertex, AWS Bedrock, Azure, custom endpoints
• CI/CD & Infrastructure: GitHub Actions, Docker, Helm, Kubernetes
b. Relationships & interactions
• Browser → Frontend UI (React)
• Frontend → Backend API (HTTPS for REST calls; EventSource/SSE for streaming chat)
• Backend → MongoDB (CRUD for users, conversations, messages, tokens, plugins, presets)
• Backend → Redis/Keyv for rate-limiting, caching responses, session data
• Backend → File Storage services for upload/download
• Backend → External AI endpoints via api/app/clients/*
• Backend → RAG API Service to perform vector searches (SSE or REST)
• RAG API Service → Vector DB for similarity search
• CI/CD → Build & push Docker images → Helm → Kubernetes clusters
c. Architectural patterns & design principles
• Layered architecture: Presentation (client/) → Application (controllers/routes/services) → Data (models, db connectors)
• Microservice for RAG vector search (separate Helm chart)
• Adapter/Client factories for each AI provider (implements Strategy pattern)
• Middleware chain (Express) for auth, rate-limit, validation, error handling
• Context separation in front end via React Context & React-Query (data-provider)
• CICD pipeline automates lint, test, build, deploy
d. Key technologies & frameworks
• Frontend: React, Vite, TypeScript, React-Query, Tailwind, i18next
• Backend: Node.js, Express (or similar), TypeScript/JavaScript, Mongoose, ioredis, Keyv, Passport.js
• Vector Search: custom RAG API, Vector DB of choice
• File Handling: Multer, S3/Azure/Firebase SDKs
• CI/CD: GitHub Actions, Docker, Helm charts, Kubernetes
Detail without overthinking
• Multiple AI clients as separate adapters under the “AI Providers” cluster.
• Crucial architectural elements at the component level for clarity.