# inatanayaxsk/nyayasahaya architecture

> Architecture diagram of the GitHub repository inatanayaxsk/nyayasahaya, 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/inatanayaxsk/nyayasahaya
- Repository: https://github.com/inatanayaxsk/nyayasahaya

## Overview

##### Component Interactions and Data Flow
- Flow from the React frontend:
- User interactions in the UI trigger calls to the backend API endpoints (e.g., POST /api/chat for legal inquiries).
- How navigation could initiate document generation processes (for example, launching Streamlit’s document generator).
- Backend API Interaction:
- For the Chat API, make sure to show the expected request (a JSON payload with the user’s question) and the structured response (detailed sections like Applicable Law, Legal Consequences, etc.).
- Internal Service Communication:
- If applicable, illustrate how document processing might interact with the PDF generator and reference material stored under “legal_document_generator/reference”.

##### Architectural Patterns and Technologies
- Separation of concerns: separate modules for the legal chatbot, document generator, and summarizer.
- Point out that the backend uses modern Python frameworks (FastAPI, LangChain) to handle conversational context and AI-driven responses.
- Frontend’s modular React component structure (with routing and state management).
- Mention security patterns such as CORS middleware, API key protection (environment variables), and input validation.

## Diagram (Mermaid)

```mermaid
graph TD
    A["User"]:::external

    subgraph "Frontend (React UI)"
        App["App.jsx"]:::frontend
        Main["main.jsx"]:::frontend
        Home["Home"]:::frontend
        Chatbot["Chatbot"]:::frontend
        DocGenFront["DocGenerator"]:::frontend
        DocSummariser["DocSummariser"]:::frontend
        AboutUs["About Us"]:::frontend
    end

    subgraph "Backend Legal Chatbot Service (FastAPI)"
        Bot["app.py"]:::backend
        Ingest["Ingest.py"]:::backend
        Footer["footer.py"]:::backend
        Data["Data Resources"]:::backend
    end

    subgraph "Document Generator (Streamlit)"
        DocMain["main.py"]:::doc
        DocGen["doc_generator.py"]:::doc
        Reference["Reference Documents"]:::doc
    end

    External["External AI/Vector DB"]:::external

    A -->|"initiates"| App
    App -->|"routes"| Home
    App -->|"routes"| Chatbot
    App -->|"routes"| DocGenFront
    App -->|"routes"| DocSummariser
    App -->|"routes"| AboutUs

    Chatbot -->|"POST/api/chat"| Bot
    DocGenFront -->|"request-document"| DocMain

    Bot -->|"fetch-AI"| External
    External -->|"response"| Bot

    Bot -->|"utilizes"| Ingest
    Bot -->|"utilizes"| Footer
    Bot -->|"reads"| Data

    DocMain -->|"uses"| DocGen
    DocMain -->|"uses"| Reference

    click App "https://github.com/inatanayaxsk/nyayasahaya/blob/main/src/App.jsx"
    click Main "https://github.com/inatanayaxsk/nyayasahaya/blob/main/src/main.jsx"
    click Home "https://github.com/inatanayaxsk/nyayasahaya/blob/main/src/components/Home.jsx"
    click Home "https://github.com/inatanayaxsk/nyayasahaya/blob/main/src/components/Home.css"
    click Chatbot "https://github.com/inatanayaxsk/nyayasahaya/blob/main/src/components/Chatbot/Chatbot.jsx"
    click Chatbot "https://github.com/inatanayaxsk/nyayasahaya/blob/main/src/components/Chatbot/Chatbot.css"
    click DocGenFront "https://github.com/inatanayaxsk/nyayasahaya/blob/main/src/components/DocGenerator.tsx"
    click DocSummariser "https://github.com/inatanayaxsk/nyayasahaya/blob/main/src/components/DocSummariser.jsx"
    click AboutUs "https://github.com/inatanayaxsk/nyayasahaya/blob/main/src/components/AboutUs/AboutUs.jsx"
    click AboutUs "https://github.com/inatanayaxsk/nyayasahaya/blob/main/src/components/AboutUs/AboutUs.css"

    click Bot "https://github.com/inatanayaxsk/nyayasahaya/blob/main/NyayaSahaya-bot/app.py"
    click Ingest "https://github.com/inatanayaxsk/nyayasahaya/blob/main/NyayaSahaya-bot/Ingest.py"
    click Footer "https://github.com/inatanayaxsk/nyayasahaya/blob/main/NyayaSahaya-bot/footer.py"
    click Data "https://github.com/inatanayaxsk/nyayasahaya/tree/main/NyayaSahaya-bot/data"

    click DocMain "https://github.com/inatanayaxsk/nyayasahaya/blob/main/legal_document_generator/main.py"
    click DocGen "https://github.com/inatanayaxsk/nyayasahaya/blob/main/legal_document_generator/doc_generator.py"
    click Reference "https://github.com/inatanayaxsk/nyayasahaya/tree/main/legal_document_generator/reference"

    classDef frontend fill:#f9c,stroke:#333,stroke-width:2px;
    classDef backend fill:#ccf,stroke:#333,stroke-width:2px;
    classDef doc fill:#cfc,stroke:#333,stroke-width:2px;
    classDef external fill:#fc9,stroke:#333,stroke-width:2px;
```
