How patildarshan-13/climate-sustainability-intelligence-system works
1. Top-level architecture
- The repo is a two-tier application: a React frontend in frontend/ and a Python FastAPI backend in backend/.
- The backend is the orchestration layer for document ingestion, retrieval, and answer generation; the frontend is a thin interactive client.
2. User-facing UI boundary
- The frontend is a single-page app built with React, Tailwind CSS, and a component library in frontend/src/components/ui/.
- The main app surfaces three core UI paths: file upload (FileUpload), document browsing (DocumentCard), and question answering (QueryInterface).
- It talks only to the backend over HTTP, with the backend URL injected via REACT_APP_BACKEND_URL.
3. Backend API boundary
- backend/server.py is the entry point for the API service, intended to run with Uvicorn/FastAPI.
- This layer likely exposes endpoints for upload, query, health, and document/listing operations; it is the only component the frontend depends on directly.
- backend/env.template and the README show CORS and MongoDB configuration are externalized, so the API is environment-driven.
4. Document ingestion pipeline
- Uploaded files are persisted under backend/uploads/, indicating the first stage is durable filesystem storage of raw documents.
- backend/document_processor.py is responsible for parsing supported formats mentioned in the README: PDF, TXT, and Markdown.
- This subsystem likely normalizes text, chunks content, and prepares metadata needed for later retrieval and source citations.
5. Embedding and vector index layer
- backend/vector_store.py manages the semantic index, backed by FAISS on disk in backend/data/faiss_index/.
- The persisted index consists of index.faiss plus metadata.pkl, so retrieval is split between vector search and a local metadata mapping.
- This is the main low-latency search boundary: document chunks become embeddings, embeddings are stored in FAISS, and metadata preserves source references.
6. RAG orchestration
- backend/rag_engine.py sits above the vector store and drives the retrieval-augmented generation workflow.
- The README says the pipeline uses SentenceTransformers + FAISS + a local Hugging Face LLM, so query answering stays fully local with no external API dependency.
- This layer retrieves the most relevant chunks, assembles context, and generates the final answer with document citations.
7. Persistence model
- The system uses two persistence surfaces: local filesystem for uploaded files and FAISS artifacts, and MongoDB for application metadata/state as described in the README.
- MongoDB is configured via MONGO_URL and DB_NAME; it is the durable backing store outside the vector index, likely for document records and operational metadata.
- The FAISS store is not a database replacement; it is the semantic retrieval cache/index.
8. Operational and development tooling
- Startup scripts exist for both Windows and Unix shells (start-backend.*, start-frontend.*, run-project.ps1) to launch the two services independently.
- The frontend has custom CRACO plugins for health checks and visual edits, which affect local dev-server behavior but not core domain architecture.
- Tests are split by layer: backend_test.py for API/backend behavior and the frontend test harness under frontend/.
9. Deployment/runtime shape
- The runtime is designed for local development first: Python backend on port 8000 and React dev server on port 3000.
- Because inference is local, the main scaling pressure is on the backend process, FAISS index size, and MongoDB/file storage—not on third-party AI services.
- Any architecture diagram should show the backend as the hub connecting UI, uploaded files, vector index, and MongoDB.
10. Key data flow to capture in a diagram
- Upload path: browser → FastAPI → filesystem upload → document parsing/chunking → embeddings → FAISS + metadata.
- Query path: browser → FastAPI → FAISS similarity search → context assembly from stored metadata → local LLM generation → response with source references → browser.
Main entry points: server.py API server · App.js App shell · vector_store.py Vector store · rag_engine.py RAG engine
Components 18
Frontend
React single-page app and UI components
- App shell · Top-level client composition for upload, browse, and query workflows
frontend/src/App.js - File upload · Upload surface for ingesting documents
frontend/src/components/FileUpload.js - Document browse · Document listing and card-based browsing
frontend/src/components/DocumentCard.js - Ask question · Interactive question-answering interface
frontend/src/components/QueryInterface.js - UI kit · Shared design-system primitives used by the app
frontend/src/components/ui/button.jsx - Client config · Injects backend base URL for HTTP calls
frontend/env.template
Backend
FastAPI service for ingestion and RAG
- API server · HTTP boundary for upload, query, health, and document operations
backend/server.py - Doc processor · Parses PDFs, TXT, and Markdown into normalized chunks
backend/document_processor.py - RAG engine · Coordinates retrieval, context assembly, and answer generation
backend/rag_engine.py - Vector store · Manages embeddings and FAISS-backed retrieval
backend/vector_store.py - Backend config · Runtime settings for CORS, MongoDB, and service behavior
backend/env.template
Storage
Persistent files, vector index, and metadata surfaces
- Raw uploads · Durable storage for incoming documents
backend/uploads/14e0d0ff-6826-4064-b5e1-289d1ec3ff67.pdf - FAISS index · Persisted similarity index and metadata mapping
backend/data/faiss_index/index.faiss - Index metadata · Chunk and source-reference mapping for the vector index
backend/data/faiss_index/metadata.pkl - MongoDB · External application state and document metadata configured by environment
Tooling
Startup scripts, tests, and development helpers
- Run scripts · Cross-platform helpers for starting frontend and backend services
run-project.ps1 - Backend tests · Backend and API behavior checks
backend_test.py - Dev plugins · Health-check and visual-edit development server extensions
frontend/plugins/health-check/webpack-health-plugin.js
Connections 23
- App shell → File upload: renders · Application shell includes upload workflow
- App shell → Document browse: renders · Application shell includes document browsing
- App shell → Ask question: renders · Application shell includes question answering
- App shell → UI kit: uses · Shared UI primitives support the main client views
- App shell → Client config: calls API · Backend base URL is injected from client environment
- File upload → API server: HTTP upload · Documents are sent to the API for ingestion
- Document browse → API server: HTTP list · Document browsing depends on backend endpoints
- Ask question → API server: HTTP query · Questions are posted to the API for retrieval and answer generation
- API server → Backend config: reads config · Server behavior is driven by environment settings
- API server → Doc processor: orchestrates · API routes delegate file processing to ingestion logic
- API server → RAG engine: orchestrates · API routes delegate question answering to the RAG layer
- Doc processor → Raw uploads: stores raw files · Incoming uploads are persisted before processing
- Doc processor → Vector store: indexes chunks · Parsed chunks are embedded and indexed
- Vector store → FAISS index: persists · Semantic index is stored on disk
- Vector store → Index metadata: writes metadata · Source references and chunk mappings are stored alongside the index
- Vector store → MongoDB: records state · Application metadata is kept outside the vector index
- RAG engine → Vector store: retrieves context · Query answering starts with similarity search over embeddings
- RAG engine → MongoDB: loads state · RAG flow can consult stored application metadata
- RAG engine → API server: returns answers · Generated responses flow back through the API layer
- Run scripts → API server: starts · Helper scripts launch the backend service
- Run scripts → App shell: starts · Helper scripts launch the frontend service
- Backend tests → API server: validates · Tests exercise API and backend behavior
- Dev plugins → App shell: extends dev server · Local development plugins alter client dev-server behavior