# shawmica/real-time-rag-ai-assistant architecture

> Architecture diagram of the GitHub repository shawmica/real-time-rag-ai-assistant, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-06-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/shawmica/real-time-rag-ai-assistant
- Repository: https://github.com/shawmica/real-time-rag-ai-assistant

## Overview

1. **What this repo is**
   This is a Python-based Retrieval-Augmented Generation (RAG) assistant that combines a chat UI, an API layer, document ingestion, vector search, and an LLM response generator. The architecture is split into a user-facing Streamlit app, a FastAPI backend, and local storage for documents and vectors.

2. **Primary runtime split**
   The app appears to run as two cooperating services:
   - **Streamlit** for the interactive user interface
   - **FastAPI** for backend orchestration and request handling  
   The README’s flow is consistent with: user interaction in Streamlit, backend retrieval via FastAPI, then generation through Groq.

3. **User interface layer**
   The frontend lives in `streamlit-app.py`, with `login-page.py` suggesting a separate authentication or onboarding screen. This layer handles user interaction, chat input, file/upload actions, and rendering answers, but it should be treated as a thin client rather than the place where retrieval or generation logic lives.

4. **API / application boundary**
   `api.py` is the central backend entry point. It likely exposes endpoints for chat, retrieval, upload/ingestion, and possibly authentication/session-related operations. This file is the main boundary between the UI and the RAG pipeline.

5. **RAG orchestration layer**
   `rag-system.py` is the core application glue. It likely coordinates:
   - query preprocessing
   - retrieval from the vector store
   - prompt/context assembly
   - calling the Groq LLM
   - returning a final answer  
   This is the highest-level “business logic” layer of the assistant.

6. **Document ingestion and parsing**
   `contract-parser.py` and the `docs/` plus `extracted/` folders indicate a document-processing path, probably for PDFs. The presence of `docs/#2 - Securing Enterprise Networks.pdf` and `extracted/fixed_extracted_text.txt` suggests a pipeline where raw PDF content is parsed/extracted into normalized text before indexing. This is the offline or pre-chat ingestion side of the system.

7. **Embeddings and indexing**
   `embeddings.py` is the embedding-generation component, likely using HuggingFace models as noted in the README. `vector_store.py` likely manages ChromaDB collection creation, persistence, upserts, and similarity search. Together these form the retrieval substrate: text chunks become embeddings, and embeddings are stored for semantic lookup.

8. **Data flow through the RAG path**
   The end-to-end flow is:
   - document/PDF input enters the ingestion pipeline
   - text is extracted and normalized
   - chunks are embedded
   - embeddings are stored in ChromaDB
   - a user query comes in through Streamlit
   - FastAPI hands the query to the RAG system
   - retriever pulls relevant chunks from ChromaDB
   - Groq LLM generates the final answer using retrieved context  
   This is the main architecture diagram backbone.

9. **Persistence and state**
   `db.py` indicates a separate persistence layer beyond the vector store, likely for users, login state, metadata, or application records. In this repo, persistent state is therefore split between:
   - **ChromaDB** for semantic document retrieval
   - a **traditional database** for app/user data
   - local files for source PDFs and extracted text artifacts

10. **Operational and admin utilities**
   `check-groqapi.py` is a health/test utility for validating Groq connectivity. `reset-users.py` is an admin/maintenance script for clearing or reinitializing user records. These are not part of the main request path, but they matter operationally because they support setup, troubleshooting, and lifecycle management.

11. **External dependencies that shape the architecture**
   The major external services/frameworks are:
   - **Groq LLM** for generation
   - **HuggingFace embeddings** for vectorization
   - **ChromaDB** for vector retrieval
   - **FastAPI** for backend APIs
   - **Streamlit** for UI
   - **LangChain** as the integration layer around retrieval/LLM composition  
   These are not incidental libraries; they define the architecture and the separation of concerns.

12. **How to draw the diagram**
   The most accurate diagram should show:
   - a **user** interacting with **Streamlit**
   - **Streamlit** calling **FastAPI**
   - **FastAPI** delegating to **RAG orchestration**
   - RAG calling **ChromaDB** for retrieval
   - RAG calling **Groq** for completion
   - an offline/side ingestion path from **PDF/docs** to **text extraction** to **embeddings** to **ChromaDB**
   - a separate **DB** for app/user state  
   That separation captures both the live chat path and the indexing/maintenance path without conflating them.

Main entry points: [`rag-system.py`](https://github.com/shawmica/real-time-rag-ai-assistant/blob/main/rag-system.py) (RAG System), [`api.py`](https://github.com/shawmica/real-time-rag-ai-assistant/blob/main/api.py) (FastAPI), [`streamlit-app.py`](https://github.com/shawmica/real-time-rag-ai-assistant/blob/main/streamlit-app.py) (Streamlit App), [`embeddings.py`](https://github.com/shawmica/real-time-rag-ai-assistant/blob/main/embeddings.py) (Embeddings)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_g1["User Interface"]
  node_n1(("User<br/>actor"))
  node_n2["Streamlit App<br/>ui<br/>[streamlit-app.py]"]
  node_n3["Login Page<br/>ui screen<br/>[login-page.py]"]
end

subgraph group_g2["Backend Core"]
  node_n4["FastAPI<br/>api gateway<br/>[api.py]"]
  node_n5["RAG System<br/>orchestrator<br/>[rag-system.py]"]
  node_n6{{"Query Flow<br/>request path"}}
  node_n13{{"Groq LLM<br/>generation service"}}
  node_n16{{"LangChain<br/>integration layer"}}
end

subgraph group_g3["Ingestion"]
  node_n7["Parser<br/>[contract-parser.py]"]
  node_n8["Embeddings<br/>vectorizer<br/>[embeddings.py]"]
  node_n11["Documents<br/>source files"]
  node_n12["Extracted Text<br/>normalized corpus"]
  node_n15{{"HuggingFace<br/>embedding model"}}
end

subgraph group_g4["Storage"]
  node_n9[("Vector Store<br/>retrieval store<br/>[vector_store.py]")]
  node_n10[("App DB<br/>relational db<br/>[db.py]")]
  node_n14[("ChromaDB<br/>vector database")]
end

subgraph group_g5["Operations"]
  node_n17["Groq Check<br/>[check-groqapi.py]"]
  node_n18["Reset Users<br/>admin script<br/>[reset-users.py]"]
end

node_n1 -->|"uses"| node_n2
node_n2 -->|"auth entry"| node_n3
node_n2 -->|"requests"| node_n4
node_n4 -->|"delegates"| node_n5
node_n5 -->|"composes"| node_n16
node_n16 -->|"retrieves"| node_n9
node_n16 -->|"generates"| node_n13
node_n5 -->|"reads state"| node_n10
node_n11 -->|"ingests"| node_n7
node_n7 -->|"produces"| node_n12
node_n12 -->|"embeds"| node_n8
node_n8 -->|"stores"| node_n14
node_n14 -->|"backing store"| node_n9
node_n8 -->|"uses"| node_n15
node_n5 -->|"searches"| node_n14
node_n4 -.->|"ops check"| node_n17
node_n4 -.->|"admin"| node_n18
node_n5 -->|"calls"| node_n13
node_n4 -->|"handles"| node_n6
node_n6 -->|"routes to"| node_n5
node_n11 -->|"source to text"| node_n12

click node_n2 "https://github.com/shawmica/real-time-rag-ai-assistant/blob/main/streamlit-app.py"
click node_n3 "https://github.com/shawmica/real-time-rag-ai-assistant/blob/main/login-page.py"
click node_n4 "https://github.com/shawmica/real-time-rag-ai-assistant/blob/main/api.py"
click node_n5 "https://github.com/shawmica/real-time-rag-ai-assistant/blob/main/rag-system.py"
click node_n7 "https://github.com/shawmica/real-time-rag-ai-assistant/blob/main/contract-parser.py"
click node_n8 "https://github.com/shawmica/real-time-rag-ai-assistant/blob/main/embeddings.py"
click node_n9 "https://github.com/shawmica/real-time-rag-ai-assistant/blob/main/vector_store.py"
click node_n10 "https://github.com/shawmica/real-time-rag-ai-assistant/blob/main/db.py"
click node_n11 "https://github.com/shawmica/real-time-rag-ai-assistant/tree/main/docs"
click node_n12 "https://github.com/shawmica/real-time-rag-ai-assistant/blob/main/extracted/fixed_extracted_text.txt"
click node_n17 "https://github.com/shawmica/real-time-rag-ai-assistant/blob/main/check-groqapi.py"
click node_n18 "https://github.com/shawmica/real-time-rag-ai-assistant/blob/main/reset-users.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_n1,node_n2,node_n3 toneBlue
class node_n4,node_n5,node_n6,node_n13,node_n16 toneAmber
class node_n7,node_n8,node_n11,node_n12,node_n15 toneMint
class node_n9,node_n10,node_n14 toneRose
class node_n17,node_n18 toneIndigo
```

## Components

### User Interface

Interactive client and entry screens

- **User**: actor · End user asking questions and uploading documents
- [Streamlit App](https://github.com/shawmica/real-time-rag-ai-assistant/blob/main/streamlit-app.py): ui · Primary chat and upload interface · `streamlit-app.py`
- [Login Page](https://github.com/shawmica/real-time-rag-ai-assistant/blob/main/login-page.py): ui screen · Authentication or onboarding screen · `login-page.py`

### Backend Core

API and RAG orchestration

- [FastAPI](https://github.com/shawmica/real-time-rag-ai-assistant/blob/main/api.py): api gateway · Backend request entry point and orchestration boundary · `api.py`
- [RAG System](https://github.com/shawmica/real-time-rag-ai-assistant/blob/main/rag-system.py): orchestrator · Coordinates retrieval, prompt assembly, and generation · `rag-system.py`
- **Query Flow**: request path · Live chat request handling from user input to answer
- **Groq LLM**: generation service · External model used to generate final answers
- **LangChain**: integration layer · Composition layer for retrieval and LLM calls

### Ingestion

Document parsing and indexing path

- [Parser](https://github.com/shawmica/real-time-rag-ai-assistant/blob/main/contract-parser.py): document parser · Extracts and normalizes document text · `contract-parser.py`
- [Embeddings](https://github.com/shawmica/real-time-rag-ai-assistant/blob/main/embeddings.py): vectorizer · Creates embeddings for indexed text chunks · `embeddings.py`
- [Documents](https://github.com/shawmica/real-time-rag-ai-assistant/tree/main/docs): source files · PDF and document inputs for indexing · `docs`
- [Extracted Text](https://github.com/shawmica/real-time-rag-ai-assistant/blob/main/extracted/fixed_extracted_text.txt): normalized corpus · Parsed text artifacts used for downstream chunking · `extracted/fixed_extracted_text.txt`
- **HuggingFace**: embedding model · External embedding provider or model family

### Storage

Persistent state and retrieval backends

- [Vector Store](https://github.com/shawmica/real-time-rag-ai-assistant/blob/main/vector_store.py): retrieval store · Manages ChromaDB persistence and similarity search · `vector_store.py`
- [App DB](https://github.com/shawmica/real-time-rag-ai-assistant/blob/main/db.py): relational db · Stores application or user state beyond vectors · `db.py`
- **ChromaDB**: vector database · Semantic retrieval backend for embedded chunks

### Operations

Health and maintenance utilities

- [Groq Check](https://github.com/shawmica/real-time-rag-ai-assistant/blob/main/check-groqapi.py): utility · Connectivity test for Groq access · `check-groqapi.py`
- [Reset Users](https://github.com/shawmica/real-time-rag-ai-assistant/blob/main/reset-users.py): admin script · Maintenance script for user records · `reset-users.py`

## Connections

- User → Streamlit App: uses · User interacts through the Streamlit interface
- Streamlit App → Login Page: auth entry · Streamlit can route to the login or onboarding screen
- Streamlit App → FastAPI: requests · UI sends chat and upload actions to the backend API
- FastAPI → RAG System: delegates · FastAPI hands RAG work to the orchestration layer
- RAG System → LangChain: composes · RAG logic uses LangChain-style composition
- LangChain → Vector Store: retrieves · Retriever queries the vector store for relevant chunks
- LangChain → Groq LLM: generates · LLM call produces the final response
- RAG System → App DB: reads state · RAG or API may consult app/user persistence
- Documents → Parser: ingests · Raw documents are parsed into normalized text
- Parser → Extracted Text: produces · Parser outputs extracted text artifacts
- Extracted Text → Embeddings: embeds · Normalized text is transformed into vectors
- Embeddings → ChromaDB: stores · Embeddings and chunks are written to ChromaDB
- ChromaDB → Vector Store: backing store · Vector store manages the retrieval database
- Embeddings → HuggingFace: uses · Embedding generation relies on HuggingFace models
- RAG System → ChromaDB: searches · RAG retrieves context from the semantic index
- FastAPI → Groq Check: ops check · Utility validates Groq connectivity during setup or debugging
- FastAPI → Reset Users: admin · Utility resets user state when needed
- RAG System → Groq LLM: calls · Answer generation is performed by Groq
- FastAPI → Query Flow: handles · Represents the live request path through the backend
- Query Flow → RAG System: routes to · Query flow reaches the RAG orchestrator
- Documents → Extracted Text: source to text · Document inputs become extracted text for indexing
