# bharathajjarapu/lawai architecture

> Architecture diagram of the GitHub repository bharathajjarapu/lawai, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/bharathajjarapu/lawai
- Repository: https://github.com/bharathajjarapu/lawai

## Overview

##### Main Components
- Data Ingestion Module:
- A component responsible for reading and processing PDF files in the dataset folder (e.g., using PyPDF2).
- Text extraction and chunking.
- Vector Store/Indexing Module:
- Uses FAISS to store and query vector embeddings.
- Contains the FAISS index files (index.faiss and index.pkl in the “faiss_index” folder).
- Conversational Query Engine:
- Uses LangChain, Google Generative AI, and possibly other agent orchestration features to process and respond to user legal questions.
- Frontend / User Interface:
- Built with Streamlit, provides the chat interface and display.
- Backend Orchestrator:
- The main Python scripts (app.py, potential ingestion scripts referenced in the README such as a “run ingest.py” command) coordinate the interaction between ingestion, storage, and query components.
- Supporting Infrastructure:
- Configuration files (requirements.txt and environment variables like GROQ_API_KEY in the .env file)
- Documentation and licensing.

##### Out Relationships and Data Flow
- The system starts with ingestion: The Ingestion Module reads PDF files from the dataset, extracts content, splits text into chunks, and computes embeddings.
- The computed embeddings are stored in the FAISS index (vector store). This is crucial for fast, semantic searches.
- When a user poses a legal question on the Streamlit interface, the Conversational Query Engine leverages the vector store to retrieve relevant document chunks.
- The engine then uses a chain of AI agents (via LangChain and Google Generative AI) to process the query and formulate context-aware, legally informed answers.
- The Response is then displayed to the user via the Streamlit application.

##### Architectural Patterns & Technologies
- Layered Architectural Approach:
- Present a clear separation of concerns between data ingestion, vector storage/query, AI processing, and frontend interaction.
- Modular Design:
- Each component (e.g., PDF processing, FAISS indexing, Streamlit UI) is independent yet integrated through well-defined interfaces.
- AI Agent Pipeline:
- Employ a sequential chain (or possibly a microservice-like chain of AI agents) to ensure robust processing and response generation.
- Technology Stack:
- Python for main application logic.
- PyPDF2 for document parsing.
- FAISS for vector search and storage.
- LangChain and Google Generative AI for conversational intelligence.
- Streamlit for creating the interactive web interface.
- Environment configuration through .env files.

##### Additional Recommendations
- Potential extension points, such as additional legal data sources or upgraded AI agents, which might be integrated later.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Data Layer"
        DATASET["dataset (PDF Files)"]:::data
        INGEST["PDF Ingestion & Text Extraction\n(Built with PyPDF2)"]:::process
        CHUNK["Text Chunking & Embedding\n(Using LangChain)"]:::process
        FAISS["FAISS Vector Store\n(index.faiss, index.pkl)"]:::datastore
        DATASET -->|"reads"| INGEST
        INGEST -->|"extracts"| CHUNK
        CHUNK -->|"computes"| FAISS
    end
    
    subgraph "Processing Layer"
        BACKEND["Backend Orchestrator\n(app.py)"]:::backend
        QUERY["AI Query Processor\n(LangChain, Google Generative AI)"]:::process
        BACKEND -->|"triggers"| QUERY
        QUERY -->|"queries"| FAISS
    end
    
    subgraph "Presentation Layer"
        STREAMLIT["Streamlit UI\n(Chat Interface)"]:::frontend
        QUERY -->|"responds"| STREAMLIT
        STREAMLIT -->|"user_input"| BACKEND
    end
    
    subgraph "Supporting Infrastructure"
        CONFIG["Configuration & Docs\n(requirements.txt, LICENSE, README.md)"]:::support
    end

    %% Click Events
    click DATASET "https://github.com/bharathajjarapu/lawai/tree/main/dataset/"
    click FAISS "https://github.com/bharathajjarapu/lawai/tree/main/faiss_index/"
    click BACKEND "https://github.com/bharathajjarapu/lawai/blob/main/app.py"
    click STREAMLIT "https://github.com/bharathajjarapu/lawai/blob/main/app.py"
    click CONFIG "https://github.com/bharathajjarapu/lawai/blob/main/requirements.txt"

    %% Styles
    classDef data fill:#FFEEAD,stroke:#333,stroke-width:2px;
    classDef process fill:#B3E5FC,stroke:#333,stroke-width:2px;
    classDef datastore fill:#C8E6C9,stroke:#333,stroke-width:2px;
    classDef backend fill:#FFCDD2,stroke:#333,stroke-width:2px;
    classDef frontend fill:#F8BBD0,stroke:#333,stroke-width:2px;
    classDef support fill:#E0E0E0,stroke:#333,stroke-width:2px;
```
