How nexpectarpit/stock_market_and_investment_analyser works
1. This repo is a small Retrieval-Augmented Generation app focused on a single domain: answering stock market / investment questions from an uploaded PDF textbook.
2. The architecture is split into two clear runtime boundaries:
- backend/: Python service that ingests the PDF, creates embeddings, stores/retrieves chunk data, and generates answers.
- frontend/: static browser UI served separately with python -m http.server.
3. backend/app.py is the main backend entry point. It is the orchestration layer that connects PDF ingestion, retrieval, and response generation. From the README, it is started directly with python app.py, so it likely exposes the HTTP endpoints used by the frontend.
4. backend/pdf_processor.py is the ingestion subsystem. Its job is to extract text from the uploaded PDF, split it into chunks, and prepare those chunks for indexing. This is the first step in the RAG pipeline.
5. backend/embeddings.py is the vectorization subsystem. It likely takes the processed chunks and turns them into embeddings so the system can do semantic retrieval later. This is the key bridge between raw document text and question answering.
6. The data flow is:
- user uploads the PDF in the UI
- backend extracts and chunks the document
- chunks are embedded
- chunk text + embeddings are stored in a database
- later questions retrieve the most relevant chunks
- retrieved context is sent to the LLM to generate the answer
7. backend/show_db.py is an inspection/debug utility. The README explicitly mentions viewing generated chunks and embeddings in the database, so this script is for verifying what the indexing pipeline stored.
8. The generated answers are powered by an external LLM service, Groq. The backend reads GROQ_API_KEY from backend/.env, so the model call is an external dependency and a clear architecture boundary.
9. The frontend is intentionally simple:
- frontend/index.html provides the page structure
- frontend/app.js drives interaction with the backend
It appears to support uploading the PDF and submitting the five required questions.
10. The repository is optimized for a local demo workflow rather than production deployment:
- backend runs as a Python app
- frontend is served as static files
- the document is a local PDF in the repo
- database contents are inspectable for assignment verification
11. The main architectural pattern is therefore: document ingestion + embedding index + retrieval + LLM generation, with a lightweight static UI on top.
12. For an architecture diagram, the most important boxes are:
- Browser UI
- Python backend API
- PDF processing/chunking
- Embedding generation
- Database/vector storage
- Groq LLM API
- DB inspection utility
Main entry points: app.py Backend API · pdf_processor.py PDF Processor · index.html Browser UI · app.js UI Logic
Components 16
Frontend
Static browser UI served separately for the demo.
- Browser UI · User-facing page for upload and Q&A.
frontend/index.html - UI Logic · Handles user interaction and backend calls.
frontend/app.js - Static Server · Simple local file server for the frontend.
Backend
Python runtime that ingests the PDF, retrieves context, and generates answers.
- Backend API · Main entry point that coordinates ingestion, retrieval, and generation.
backend/app.py - PDF Processor · Extracts text from the uploaded PDF and splits it into chunks.
backend/pdf_processor.py - Embeddings · Turns chunks into embeddings for semantic retrieval.
backend/embeddings.py - DB Viewer · Debug utility for viewing stored chunks and embeddings.
backend/show_db.py - Chunk Store · Persists chunk text and embedding data for later retrieval.
- Retriever · Fetches the most relevant chunks for a question.
- Answer Generator · Builds the final response from retrieved context.
- Q&A Flow · Routes user questions from the UI into the backend response path.
- Ingest Flow · Runs upload, extraction, chunking, and indexing.
- Index Build · Converts processed text into searchable vector data.
- Query Path · Retrieves context and asks the LLM for an answer.
Other components
- Textbook PDF · Domain document uploaded into the RAG pipeline.
rag assigment.pdf - Groq API · External model provider used to generate answers.
Connections 17
- Static Server → Browser UI: serves · The local server hosts the frontend files.
- Browser UI → UI Logic: runs · The page loads the client-side logic.
- UI Logic → Backend API: requests · Sends upload and question requests to the backend.
- Backend API → Ingest Flow: starts · Coordinates the document indexing workflow.
- Ingest Flow → PDF Processor: extracts · The backend hands the uploaded PDF to the processor.
- Textbook PDF → PDF Processor: input · The uploaded textbook is the ingestion source.
- PDF Processor → Index Build: chunks · Processed text is prepared for embedding.
- Index Build → Embeddings: vectorizes · Chunks are converted into embeddings.
- Embeddings → Chunk Store: stores · Embedding data and chunk text are persisted.
- Backend API → Q&A Flow: handles · Answers incoming user questions.
- Q&A Flow → Retriever: retrieves · Finds the most relevant stored chunks.
- Retriever → Chunk Store: reads · Looks up candidate chunks and vectors.
- Retriever → Query Path: passes context · Provides retrieved context to the answer path.
- Query Path → Answer Generator: builds · Prepares the prompt and response request.
- Answer Generator → Groq API: calls · Uses the external LLM service for generation.
- Backend API → DB Viewer: supports · The backend can be inspected through the DB viewer utility.
- DB Viewer → Chunk Store: reads · Shows stored chunks and embeddings for verification.