# aparimeyatiwari/yc_lawgic architecture

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

- Interactive diagram: https://gitdiagram.com/aparimeyatiwari/yc_lawgic
- Repository: https://github.com/aparimeyatiwari/yc_lawgic

## Overview

##### Project Type and Purpose
- LAWGIC is a full-stack AI-powered legal assistant targeted at the Indian legal ecosystem.
- It provides multimodal input (text, PDF, images, future speech), language translation, semantic retrieval of legal documents, LLM-based reasoning, and nearby lawyer lookup.
- Built as a modular Python application with a Chainlit UI frontend and Semantic Kernel-driven plugins for distinct tasks.

##### File Structure
Top-Level Files and Folders:
- README.md, requirement.txt, prompt.txt, chainlit.md – documentation and prompts.
- final.py (or main.py invoked by Chainlit) – application entrypoint.
- public/ – static assets for the Chainlit UI.
- SpeechModules/ – speech-to-text (stt.py) and text-to-speech (tts.py) modules (planned features).
- plugins/ – Semantic Kernel plugins organized by domain:
– LegalAgents/** – subfolders for tasks (document_analyzer, summarizer, query_classifier, etc.), each with config.json and skprompt.txt.
– LocationAgent/** – plugins for location_extractor and city_validator.
- __pycache__/ – compiled Python bytecode.
Configuration & Environment:
- requirement.txt – Python dependencies.
- .gitignore, .DS_Store – project housekeeping.

##### Extract Insights from the README
- Architecture Overview: shows a pipeline of input → translation → embedding → semantic search → LLM → translation → UI.
- Software Stack: Chainlit (frontend), Python & Semantic Kernel (backend), Azure OpenAI (embeddings & LLM), Azure Computer Vision, Azure Translator, Azure Blob & AI Search, Google Maps API.
- Plugins are orchestrated by Semantic Kernel to handle distinct functions (Translator, Lawyer AI, Nearby Lawyers).

##### Main Components and Their Interactions
A. User Interface (Chainlit UI)
– Receives user queries or document uploads (text, PDF, images).
– Displays multilingual results and “Nearby Lawyer” map.
B. Input Preprocessing
– SpeechModules (optional): STT module converts voice to text; TTS for responses.
– Azure Computer Vision OCR extracts text from images/PDF.
C. Translator Plugin
– Detects input language via Azure Translator.
– Converts input to English for internal processing.
D. Semantic Retrieval & Reasoning
– Embedding step: translates query to vector using Azure OpenAI Embeddings.
– Search step: queries Azure AI Search index of legal docs stored in Azure Blob Storage.
– Planner + Lawyer AI Plugin: feeds top-k retrieval to Azure LLM for grounded legal reasoning.
E. Location Plugin
– LocationExtractor and CityValidator determine user’s geolocation (IP, geocode, manual).
– Google Maps API fetches nearby lawyers.
F. Output Postprocessing
– Translates LLM result back into original language.
– Formats response with references and displays via Chainlit.
G. Configuration & Orchestration
– Semantic Kernel wires together plugins (config.json + skprompt.txt) under a Planner component.
– Environment variables hold all API keys/endpoints.

##### Architectural Patterns and Design Principles
- Modular Plugin Architecture: each capability is encapsulated as a Semantic Kernel plugin, enabling easy addition/removal of features.
- Separation of Concerns: distinct layers for UI, preprocessing, translation, retrieval, reasoning, and postprocessing.
- Human-in-the-Loop: optional handoff to verified lawyers for high-impact scenarios.
- Responsible AI: transparency (grounded references), multilingual fairness, traceability.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        direction TB
        Frontend["Chainlit UI Frontend"]:::ui
        StaticAssets["Static Assets (public/)"]:::ui
    end

    %% Preprocessing Layer
    subgraph "Preprocessing Layer"
        direction TB
        STT["Speech-to-Text Module (planned)"]:::processing
        OCR["Azure Computer Vision OCR"]:::external
    end

    %% Translation Layer
    subgraph "Translation Layer"
        direction TB
        Translator["Translator Plugin (Azure Translator)"]:::processing
    end

    %% Retrieval & Reasoning Layer
    subgraph "Retrieval & Reasoning Layer"
        direction TB
        Embeddings["Azure OpenAI Embeddings"]:::external
        SearchIndex["Azure AI Search Index"]:::storage
        subgraph "Semantic Kernel Orchestrator"
            direction TB
            Planner["Planner + config/skprompt"]:::plugin
            subgraph "LegalAgents Plugins"
                direction TB
                QC["Query Classifier"]:::plugin
                DocAnalyzer["Document Analyzer"]:::plugin
                DocSummarizer["Document Summarizer"]:::plugin
                ActionReq["Action Required Detection"]:::plugin
                AdviceNeed["Advice Need Detection"]:::plugin
                LawyerType["Lawyer Type Determination"]:::plugin
                LawyerNeeded["Lawyer Needed Identification"]:::plugin
            end
            subgraph "LocationAgent Plugins"
                direction TB
                LocExtract["Location Extraction"]:::plugin
                CityVal["City Validation"]:::plugin
            end
        end
        LLM["Azure OpenAI LLM (Lawyer AI Plugin)"]:::external
    end

    %% Location Layer
    subgraph "Location Layer"
        direction TB
        GP["Google Maps API"]:::external
    end

    %% Storage Layer
    subgraph "Storage Layer"
        direction TB
        BlobStorage["Azure Blob Storage"]:::storage
    end

    %% Docs & Config
    subgraph "Project Docs & Config"
        direction TB
        README["Project README"]:::docs
        ChainlitGuide["Chainlit Integration Guide"]:::docs
        PromptDefs["Global Prompt Definitions"]:::docs
        Requirements["Dependency Specifications"]:::docs
        GitIgnore[".gitignore"]:::docs
        DSStore[".DS_Store"]:::docs
    end

    %% Data Flow
    User["User"]:::external -->|uploads/query| Frontend
    Frontend -->|sends input| STT
    STT -->|text| OCR
    OCR -->|extracted text| Translator
    Translator -->|translated input| Embeddings
    Embeddings -->|vector| SearchIndex
    SearchIndex -->|top-k docs| Planner
    Planner -->|calls plugins| QC & DocAnalyzer & DocSummarizer & ActionReq & AdviceNeed & LawyerType & LawyerNeeded
    Planner -->|feeds to| LLM
    LLM -->|response| Translator
    Translator -->|translated output| Frontend
    Frontend -->|request location| LocExtract
    LocExtract --> CityVal
    CityVal -->|coordinates| GP
    GP -->|nearby lawyers| Frontend
    BlobStorage --> SearchIndex

    %% Click Events
    click Frontend "https://github.com/aparimeyatiwari/yc_lawgic/blob/main/final.py"
    click StaticAssets "https://github.com/aparimeyatiwari/yc_lawgic/tree/main/public/"
    click STT "https://github.com/aparimeyatiwari/yc_lawgic/blob/main/SpeechModules/stt.py"
    click OCR "https://github.com/aparimeyatiwari/yc_lawgic/blob/main/SpeechModules/tts.py"
    click QC "https://github.com/aparimeyatiwari/yc_lawgic/tree/main/plugins/LegalAgents/query_classifier/"
    click DocAnalyzer "https://github.com/aparimeyatiwari/yc_lawgic/tree/main/plugins/LegalAgents/document_analyzer/"
    click DocSummarizer "https://github.com/aparimeyatiwari/yc_lawgic/tree/main/plugins/LegalAgents/document_summarizer/"
    click ActionReq "https://github.com/aparimeyatiwari/yc_lawgic/tree/main/plugins/LegalAgents/action_required/"
    click AdviceNeed "https://github.com/aparimeyatiwari/yc_lawgic/tree/main/plugins/LegalAgents/needs_advice/"
    click LawyerType "https://github.com/aparimeyatiwari/yc_lawgic/tree/main/plugins/LegalAgents/lawyer_type/"
    click LawyerNeeded "https://github.com/aparimeyatiwari/yc_lawgic/tree/main/plugins/LegalAgents/lawyer_needed/"
    click LocExtract "https://github.com/aparimeyatiwari/yc_lawgic/tree/main/plugins/LocationAgent/location_extractor/"
    click CityVal "https://github.com/aparimeyatiwari/yc_lawgic/tree/main/plugins/LocationAgent/city_validator/"
    click PromptDefs "https://github.com/aparimeyatiwari/yc_lawgic/blob/main/prompt.txt"
    click Requirements "https://github.com/aparimeyatiwari/yc_lawgic/blob/main/requirement.txt"
    click README "https://github.com/aparimeyatiwari/yc_lawgic/blob/main/README.md"
    click ChainlitGuide "https://github.com/aparimeyatiwari/yc_lawgic/blob/main/chainlit.md"
    click GitIgnore "https://github.com/aparimeyatiwari/yc_lawgic/blob/main/.gitignore"
    click DSStore "https://github.com/aparimeyatiwari/yc_lawgic/blob/main/.DS_Store"

    %% Styles
    classDef ui fill:#D0E6FF,stroke:#1E3A8A,color:#1E3A8A;
    classDef processing fill:#DFF7D8,stroke:#166534,color:#166534;
    classDef plugin fill:#E0F2FE,stroke:#055160,color:#055160;
    classDef external fill:#FFE5D9,stroke:#C2410C,color:#C2410C;
    classDef storage fill:#F3F4F6,stroke:#4B5563,color:#4B5563;
    classDef docs fill:#FDE68A,stroke:#92400E,color:#92400E;
```
