# sandipkatel/unified-infosec-qna-assistant architecture

> Architecture diagram of the GitHub repository sandipkatel/unified-infosec-qna-assistant, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sandipkatel/unified-infosec-qna-assistant
- Repository: https://github.com/sandipkatel/unified-infosec-qna-assistant

## Overview

##### Project Type and Purpose
- This is a full-stack Retrieval-Augmented Generation (RAG) AI system called “Unified InfoSec QnA Assistant.”
- Frontend: Next.js (TypeScript, Tailwind, React Query) for multi-page UI (batch upload, chat).
- Backend: Django REST API delivering endpoints that drive FAISS-based vector search + LLM invocation (Ollama via LangChain).
- Knowledge Base: CSV Q&A pairs + PDF policy docs indexed by FAISS.

##### File-Structure Analysis
- Top level:
- Backend/ – Django project and virtual-env requirements
– Backend/Backend/: Django settings, URLs, ASGI/WGI, views, utils (chat_data, history, main).
– faiss_csv_index/, faiss_pdf_index/: pre-built FAISS indexes (.faiss + .pkl).
- Frontend/ – Next.js project
– src/app/: page.js, layout.js, multiple pages (page1.js, page3.js).
– src/components/: chatHistory.js, policyDocumentList.js.
– public/: static PDF policy files.
- README: confirms Tech Stack, features (batch & conversational modes), vector search + LLM details, startup instructions.

##### Key Components
a. User Interface (Next.js)
- Pages: Batch Upload, Chat Interface
- Components: Policy List, Chat History
b. API Layer (Django REST)
- Endpoints: /upload-questionnaire, /chat
- Business Logic: uses utils/history.py, utils/main.py for context management
c. Vector Store (FAISS)
- CSV Index service (faiss_csv_index)
- PDF Index service (faiss_pdf_index)
d. LLM Service (Ollama via LangChain)
- Chat & prompt orchestration
e. Knowledge Base Storage
- Static CSV files (in Backend/utils/chat_data/threads)
- PDF policies (public/)
- User metadata (users.json)

##### Relationships and Data Flow
1. User → Next.js UI (select upload or chat)
2. Next.js → Django REST API
3. Django API
- loads user/chat history → utils/history.py
- performs hybrid retrieval:
– SentenceTransformers embedding
– FAISS lookup (CSV and/or PDF index)
- builds prompt with citations
- calls LLM (Ollama via LangChain)
4. LLM → Django returns answer + metadata
5. Django → Next.js UI (renders response with citations)

##### Architectural Patterns & Principles
- Separation of concerns: UI, API logic, retrieval, LLM integration.
- Monolithic backend with service-style modules (utils, faiss index).
- Hybrid semantic search + symbolic retrieval.
- Stateless API layer; external local services (Ollama) and file-based vector stores.

- Step 6: Show static file store (CSV files, PDF policy docs) feeding into “Vector Store.”

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Device
    User["User Device"]:::external
    User -->|"Interacts via HTTP"| FrontendUI

    %% Frontend Layer
    subgraph "Frontend (Next.js)" 
        direction TB
        FrontendUI["Frontend: Next.js UI"]:::frontend
        Pages["Pages & Layout"]:::frontend
        Components["UI Components"]:::frontend
        Config["Config Files"]:::frontend
        FrontendUI --> Pages
        FrontendUI --> Components
        FrontendUI --> Config
    end

    %% Frontend Pages & Components
    Pages -->|"layout, routes"| LayoutPage["layout.js"]:::frontend
    Pages --> PageJS["page.js"]:::frontend
    Pages --> Page1["page1.js"]:::frontend
    Pages --> Page3["page3.js"]:::frontend

    Components --> ChatHistory["chatHistory.js"]:::frontend
    Components --> PolicyList["policyDocumentList.js"]:::frontend

    Config --> NextConfig["next.config.mjs"]:::frontend
    Config --> JSConfig["jsconfig.json"]:::frontend

    %% API Layer
    FrontendUI -->|"REST API (HTTP)"| API["API: Django REST"]:::backend
    subgraph "Django REST API"
        direction TB
        URLs["urls.py"]:::backend
        Views["views.py"]:::backend
        Settings["settings.py"]:::backend
        ASGI["asgi.py"]:::backend
        WSGI["wsgi.py"]:::backend
        Manage["manage.py"]:::backend
        Req["requirements.txt"]:::backend

        Utils{"Business Logic & Context"}:::backend
        Utils --> History["history.py"]:::backend
        Utils --> Main["main.py"]:::backend
    end

    API --> URLs
    API --> Views
    API --> Settings
    API --> ASGI
    API --> WSGI
    API --> Manage
    API --> Req
    API --> Utils

    %% Vector Store
    API -->|"Embedding + Search"| VectorStore["Vector Store"]:::datastore
    subgraph "Vector Store (FAISS Indexes)"
        direction TB
        CSVIndex["CSV Index"]:::datastore
        PDFIndex["PDF Index"]:::datastore
    end
    VectorStore --> CSVIndex
    VectorStore --> PDFIndex

    %% Knowledge Base Storage
    subgraph "Knowledge Base Storage"
        direction TB
        CSVData["CSV Q&A Threads"]:::datastore
        Users["users.json"]:::datastore
        PDFDocs["PDF Policy Docs"]:::datastore
    end
    CSVData --> CSVIndex
    PDFDocs --> PDFIndex

    %% LLM Service
    API -->|"Prompt Call"| LLM["LLM Service (Ollama/LangChain)"]:::service
    LLM --> API

    %% Response back to UI
    API -->|"Response with citations"| FrontendUI

    %% Click Events
    click LayoutPage "https://github.com/sandipkatel/unified-infosec-qna-assistant/blob/main/Frontend/src/app/layout.js"
    click PageJS "https://github.com/sandipkatel/unified-infosec-qna-assistant/blob/main/Frontend/src/app/page.js"
    click Page1 "https://github.com/sandipkatel/unified-infosec-qna-assistant/blob/main/Frontend/src/app/page1.js"
    click Page3 "https://github.com/sandipkatel/unified-infosec-qna-assistant/blob/main/Frontend/src/app/page3.js"
    click ChatHistory "https://github.com/sandipkatel/unified-infosec-qna-assistant/blob/main/Frontend/src/components/chatHistory.js"
    click PolicyList "https://github.com/sandipkatel/unified-infosec-qna-assistant/blob/main/Frontend/src/components/policyDocumentList.js"
    click NextConfig "https://github.com/sandipkatel/unified-infosec-qna-assistant/blob/main/Frontend/next.config.mjs"
    click JSConfig "https://github.com/sandipkatel/unified-infosec-qna-assistant/blob/main/Frontend/jsconfig.json"
    click URLs "https://github.com/sandipkatel/unified-infosec-qna-assistant/blob/main/Backend/Backend/Backend/urls.py"
    click Views "https://github.com/sandipkatel/unified-infosec-qna-assistant/blob/main/Backend/Backend/Backend/views.py"
    click Settings "https://github.com/sandipkatel/unified-infosec-qna-assistant/blob/main/Backend/Backend/Backend/settings.py"
    click ASGI "https://github.com/sandipkatel/unified-infosec-qna-assistant/blob/main/Backend/Backend/Backend/asgi.py"
    click WSGI "https://github.com/sandipkatel/unified-infosec-qna-assistant/blob/main/Backend/Backend/Backend/wsgi.py"
    click Manage "https://github.com/sandipkatel/unified-infosec-qna-assistant/blob/main/Backend/Backend/manage.py"
    click Req "https://github.com/sandipkatel/unified-infosec-qna-assistant/blob/main/Backend/requirements.txt"
    click History "https://github.com/sandipkatel/unified-infosec-qna-assistant/blob/main/Backend/Backend/Backend/utils/history.py"
    click Main "https://github.com/sandipkatel/unified-infosec-qna-assistant/blob/main/Backend/Backend/Backend/utils/main.py"
    click CSVData "https://github.com/sandipkatel/unified-infosec-qna-assistant/tree/main/Backend/Backend/Backend/utils/chat_data/threads/"
    click Users "https://github.com/sandipkatel/unified-infosec-qna-assistant/blob/main/Backend/Backend/Backend/utils/chat_data/users.json"
    click PDFDocs "https://github.com/sandipkatel/unified-infosec-qna-assistant/tree/main/Frontend/public/"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#5B9BD5,color:#000
    classDef backend fill:#E5F7E0,stroke:#28A745,color:#000
    classDef datastore fill:#FFE7C1,stroke:#F39C12,color:#000
    classDef service fill:#E8D0FF,stroke:#8E44AD,color:#000
    classDef external fill:#F0F0F0,stroke:#CCCCCC,color:#000
```
