# yashchavanweb/legal-mitra architecture

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

- Interactive diagram: https://gitdiagram.com/yashchavanweb/legal-mitra
- Repository: https://github.com/yashchavanweb/legal-mitra

## Overview

##### Project Type and Purpose
- The name “Legal_Mitra” and the file structure indicate that this is a full-stack application built for providing legal advice or legal document/knowledge retrieval.
- The backend is organized as an API server with multiple endpoints handling different legal domains (e.g., case judgements, common laws, FIR/IPC matters, Indian constitution data, etc.).
- The frontend uses modern JavaScript tooling (React with Vite) to present legal advice interfaces and interactive components (e.g., PdfChat, SearchBar, SideDrawer, LegalAdvice page).
- A separate Python directory includes utilities like speech_to_text.py and translate.py, which suggest integration of voice-based interactions/message conversion.

##### Analyzing the File Structure
- Top-Level Directories:
- frontend: Contains React components (App.jsx, Header.jsx, PdfChat.jsx), pages, and styling, indicating a modern web UI.
- backend: Uses Node.js (with app.js, controllers, routes, models). This structure follows an MVC-ish pattern wherein controllers manage business logic, models represent data, and routes define the API.
- Python: Includes scripts related to speech-to-text conversion and translation, indicating additional functionalities—likely for handling voice commands or converting speech into textual queries.
- In the backend, additional folders like “faiss_index” (files such as index.faiss, index.pkl) hint at the usage of FAISS for fast similarity search, possibly for retrieving legal cases or documents based on keyword extraction.
- The keyword_extraction folder in the backend contains a file named “keyword_api.py”, reinforcing the importance of language processing or extraction in the project.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend UI"
        A["App"]:::frontend
        B["Header"]:::frontend
        C["PdfChat"]:::frontend
        D["SearchBar"]:::frontend
        E["SideDrawer"]:::frontend
        F["LegalAdvice Page"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend API Server"
        G["API Server"]:::backend
        H["Controllers"]:::backend
        I["Routes"]:::backend
        J["Models"]:::backend
        K["DB Module"]:::db
    end

    %% Search & Indexing Components
    subgraph "Search & Indexing"
        L["FAISS Indexing"]:::indexing
        M["Keyword Extraction"]:::indexing
    end

    %% Python Processing Services
    subgraph "Python Processing"
        N["Speech-to-Text"]:::python
        O["Translation Service"]:::python
    end

    %% Connections: Frontend to Backend
    F -->|"sendsRequest"| G

    %% Internal Backend Flow
    G -->|"calls"| H
    G -->|"routesTo"| I
    G -->|"utilizes"| J
    J -->|"queries"| K

    %% Backend to Search & Indexing Flow
    H -->|"performsSearch"| L
    H -->|"extractsKeywords"| M

    %% Backend to Python Processing Flow
    H -->|"voiceProcessing"| N
    H -->|"translateText"| O

    %% Click Events for Frontend Components
    click A "https://github.com/yashchavanweb/legal-mitra/blob/main/frontend/src/App.jsx"
    click B "https://github.com/yashchavanweb/legal-mitra/blob/main/frontend/src/components/Header.jsx"
    click C "https://github.com/yashchavanweb/legal-mitra/blob/main/frontend/src/components/PdfChat.jsx"
    click D "https://github.com/yashchavanweb/legal-mitra/blob/main/frontend/src/components/SearchBar.jsx"
    click E "https://github.com/yashchavanweb/legal-mitra/blob/main/frontend/src/components/SideDrawer.jsx"
    click F "https://github.com/yashchavanweb/legal-mitra/blob/main/frontend/src/pages/LegalAdvice.jsx"

    %% Click Events for Backend Components
    click G "https://github.com/yashchavanweb/legal-mitra/blob/main/backend/src/app.js"
    click H "https://github.com/yashchavanweb/legal-mitra/tree/main/backend/src/controllers"
    click I "https://github.com/yashchavanweb/legal-mitra/tree/main/backend/src/routes"
    click J "https://github.com/yashchavanweb/legal-mitra/tree/main/backend/src/models"
    click K "https://github.com/yashchavanweb/legal-mitra/blob/main/backend/src/db/index.js"

    %% Click Events for Search & Indexing Components
    click L "https://github.com/yashchavanweb/legal-mitra/tree/main/backend/faiss_index/"
    click M "https://github.com/yashchavanweb/legal-mitra/blob/main/backend/keyword_extraction/keyword_api.py"

    %% Click Events for Python Processing Services
    click N "https://github.com/yashchavanweb/legal-mitra/blob/main/Python/speech_to_text.py"
    click O "https://github.com/yashchavanweb/legal-mitra/blob/main/Python/translate.py"

    %% Styles
    classDef frontend fill:#AED6F1,stroke:#2874A6,stroke-width:2px;
    classDef backend fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef db fill:#A9DFBF,stroke:#27AE60,stroke-width:2px;
    classDef python fill:#F5B7B1,stroke:#CB4335,stroke-width:2px;
    classDef indexing fill:#D2B4DE,stroke:#8E44AD,stroke-width:2px;
```
