How arpitpatelsitapur/scholarlensai works
1. Overall shape
ScholarLens AI is split into two FastAPI-based services: the main application in app/ and a separate RAG backend in rag_service/. The boundary is intentional: the main app owns users, pages, and recommendations, while the RAG service owns paper ingestion, chunking, vector search, and answer generation.
2. Main application boundary
app/main.py is the entrypoint for the user-facing service. It serves HTML pages, handles browser navigation, and exposes API routes under app/api/. The app is not a pure JSON API; it is a server-rendered web app built around Jinja2 templates and static assets.
3. Web/UI subsystem
app/templates/ contains the primary views: home, dashboard, profile, bookmarks, chat, interests form, about, and 404. app/static/ provides CSS, JS, and images. This subsystem is the presentation layer and depends on the API layer plus session/user state to render personalized pages.
4. Authentication and user flow
app/api/auth.py implements Google OAuth login. app/api/users.py and the template-driven pages rely on authenticated identity to personalize dashboards, interests, and bookmarks. The auth boundary is external-facing: user identity is established with Google and then persisted in the app’s own database/session state.
5. Application data layer
app/db/ contains the persistence layer: SQLAlchemy models, session setup, and SQL helpers. This is where user records, bookmarks, and preference/interests data are stored. The app is configured via app/core/config.py, and the README indicates SQLite-backed persistence with Docker volume support for durability.
6. Recommendation subsystem
app/utils/recommend.py is the semantic discovery engine. It uses SPECTER2 embeddings and similarity-based ranking to recommend papers based on user interests and paper metadata. This subsystem is distinct from the RAG flow: it ranks papers for discovery, but does not answer questions from paper content.
7. RAG service boundary
rag_service/api.py exposes the paper Q&A endpoints, and rag_service/rag_engine.py contains the core retrieval-augmented generation pipeline. The main app calls this service over HTTP using httpx, so the chat feature is a cross-service interaction rather than an in-process library call.
8. RAG data flow
For each paper, the RAG service downloads or reads the PDF, extracts text, chunks it, embeds the chunks, and stores them in a per-paper FAISS index under rag_store/<paper_id>/. On a user question, it retrieves the top relevant chunks, builds a prompt, and sends it to Groq-hosted Llama 3.1 to produce the answer. Cached FAISS indexes avoid rebuilding on repeat access.
9. External services and model dependencies
The system depends on several external services that materially affect the architecture: Google OAuth for login, Groq for LLM inference, and Hugging Face / SentenceTransformers for embeddings. These dependencies are isolated mostly inside the RAG service and the auth layer to keep the main app lightweight.
10. Deployment and runtime separation
The repo is designed for Docker Compose deployment with two containers and separate dependency sets. This separation is important because the ML stack in rag_service/ has different package constraints from the web app. Persistent state is split as well: the app keeps its SQLite data, while the RAG service persists its FAISS store and cached paper artifacts.
11. Request-level architecture
A typical user journey crosses multiple subsystems: the browser loads a template from the app, login establishes identity, the dashboard pulls personalized recommendations from the app database and recommender, and clicking “chat” sends the paper/question to the RAG service, which returns a generated answer to be rendered back in the app UI.
12. What to show in an architecture diagram
The key boxes are: Browser/UI, Main FastAPI app, SQLite/SQLAlchemy persistence, Recommendation engine, RAG FastAPI service, FAISS per-paper store, and external providers (Google OAuth, Groq, Hugging Face). The main arrows are: browser ↔ app, app ↔ database, app ↔ RAG service over HTTP, and RAG service ↔ PDFs/embeddings/FAISS ↔ Groq.
Main entry points: main.py FastAPI App · pages.py Page Routes · rag_engine.py RAG Engine · users.py Users API
Components 19
Main App
Browser-facing FastAPI application with pages, auth, user data, and recommendations.
- Browser UI · User interaction layer that loads pages and sends chat/recommendation requests.
- FastAPI App · Entry point and request coordinator for the main ScholarLens UI and APIs.
app/main.py - Page Routes · Server-rendered page handlers for home, dashboard, profile, bookmarks, chat, and forms.
app/api/pages.py - Auth · Google OAuth login and identity establishment.
app/api/auth.py - Users API · User-facing API for profile, bookmarks, interests, and personalization data.
app/api/users.py - Templates · Jinja2 views for the rendered pages and error screens.
app/templates - Static Assets · CSS, JavaScript, logo, and image assets for the web UI.
app/static - Config · Application settings and environment configuration.
app/core/config.py - Data Models · SQLAlchemy models for users, bookmarks, interests, and related app state.
app/db/models.py - DB Session · Database connection and session setup for app data access.
app/db/session.py - SQL Helpers · Query and persistence helpers used by the application layer.
app/db/sql_helpers.py - Recommender · SPECTER2-based semantic ranking for paper discovery and personalized recommendations.
app/utils/recommend.py - RAG Client · HTTP bridge from the main app to the separate RAG backend.
app/utils/rag.py
RAG Service
Separate FastAPI service for paper ingestion, retrieval, and answer generation.
- RAG API · FastAPI endpoints for paper Q&A in the separate retrieval service.
rag_service/api.py - RAG Engine · Ingestion, chunking, retrieval, prompt building, and answer generation pipeline.
rag_service/rag_engine.py - FAISS Store · Per-paper vector indexes and cached artifacts under the RAG storage directory.
External Systems
Third-party identity, model, and storage dependencies.
- Google OAuth · External identity provider used for login.
- Groq LLM · Hosted Llama 3.1 inference used to generate chat answers.
- Embeddings · Hugging Face / SentenceTransformers embedding provider for retrieval and ranking.
Connections 19
- Browser UI → FastAPI App: HTTP · Browser loads pages and submits actions to the FastAPI app.
- FastAPI App → Page Routes: routes · Main app mounts the server-rendered page handlers.
- FastAPI App → Auth: routes · Main app exposes login and callback endpoints.
- FastAPI App → Users API: routes · Main app exposes user/profile/bookmark APIs.
- Page Routes → Templates: render · Pages render Jinja2 templates for the UI.
- Page Routes → Static Assets: serve · Rendered pages depend on static CSS, JS, and images.
- Auth → Google OAuth: oauth · Authentication delegates to Google.
- Users API → DB Session: read/write · User APIs persist and fetch application state.
- DB Session → Data Models: orm · Sessions operate on SQLAlchemy models.
- SQL Helpers → DB Session: use · Helpers execute database operations through the session layer.
- FastAPI App → Config: config · Application startup reads configured settings.
- Users API → Recommender: rank · User-facing discovery uses the semantic recommender.
- Recommender → Embeddings: embed · Recommendation ranking depends on embedding models.
- Page Routes → RAG Client: chat · Chat page sends paper questions through the RAG client.
- RAG Client → RAG API: http · Main app calls the separate RAG service over HTTP.
- RAG API → RAG Engine: delegate · API endpoints forward work to the retrieval pipeline.
- RAG Engine → FAISS Store: retrieve · Engine reads and updates per-paper vector indexes.
- RAG Engine → Embeddings: embed · Chunk and query embeddings come from Hugging Face/SentenceTransformers.
- RAG Engine → Groq LLM: generate · Retrieved context is sent to Groq-hosted Llama for answers.