# madhan-200/minelawhub architecture

> Architecture diagram of the GitHub repository madhan-200/minelawhub, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/madhan-200/minelawhub
- Repository: https://github.com/madhan-200/minelawhub

## Overview

MineLawHub is a chat application for answering questions about Indian mining law, combining document retrieval, web updates, and generated cited responses. The main workflow runs from the React chat interface to the FastAPI chat endpoint, which classifies intent, retrieves legal text and/or current web results, and asks Gemini to compose an answer. The README also documents PDF extraction, text cleaning, optional English-page splitting, and embedding creation. Some backend and frontend wiring is supported only by the README or source index; those limits are reflected in the evidence paths.

Main entry points: [`frontend/src/App.jsx`](https://github.com/madhan-200/minelawhub/blob/master/frontend/src/App.jsx) (Chat app), [`frontend/src/components/ChatWindow.jsx`](https://github.com/madhan-200/minelawhub/blob/master/frontend/src/components/ChatWindow.jsx) (Chat display), [`backend/main.py`](https://github.com/madhan-200/minelawhub/blob/master/backend/main.py) (FastAPI endpoints), [`frontend/src/components/InputBox.jsx`](https://github.com/madhan-200/minelawhub/blob/master/frontend/src/components/InputBox.jsx) (Query input)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["Chat interface"]
  node_app["Chat app<br/>[App.jsx]"]
  node_input["Query input<br/>[InputBox.jsx]"]
  node_window["Chat display<br/>[ChatWindow.jsx]"]
  node_message["Answer and citations<br/>[MessageBubble.jsx]"]
  node_avatar["Assistant avatar<br/>[AnimatedAvatar.jsx]"]
  node_typewriter["Welcome text<br/>[TypewriterText.jsx]"]
  node_navbar["Navigation and theme<br/>[Navbar.jsx]"]
  node_sidebar["Suggested queries<br/>[Sidebar.jsx]"]
  node_theme["Design theme<br/>[theme.js]"]
end

subgraph group_api["Chat and answer services"]
  node_api["FastAPI endpoints<br/>[main.py]"]
  node_intent["Intent and answer generation<br/>[gemini_client.py]"]
end

subgraph group_sources["Legal and web sources"]
  node_search["Semantic retrieval<br/>[search_engine.py]"]
  node_vector[("Law vector collection")]
  node_tavily["Mining web search<br/>[tavily_client.py]"]
end

subgraph group_corpus["Document preparation"]
  node_pdfs["Source law PDFs"]
  node_extract["PDF text extraction<br/>[extract_text.py]"]
  node_text["Extracted text"]
  node_clean["Text cleaning<br/>[clean_text.py]"]
  node_cleaned["Cleaned law text"]
  node_english["English-page splitting<br/>[split_english.py]"]
  node_build["Embedding builder"]
end

node_user(("User"))
node_web["Tavily Search API"]
node_gemini["Gemini API"]

node_user -->|"enters query"| node_input
node_input -->|"submits query"| node_app
node_app -->|"posts chat"| node_api
node_app -->|"renders messages"| node_window
node_window -->|"renders answers"| node_message
node_window -->|"renders avatar"| node_avatar
node_window -->|"renders welcome"| node_typewriter
node_app -->|"renders input"| node_input
node_app -->|"renders navigation"| node_navbar
node_app -->|"renders sidebar"| node_sidebar
node_app -->|"configures theme"| node_theme
node_message -->|"renders avatar"| node_avatar
node_api -->|"classifies and generates"| node_intent
node_api -->|"retrieves law"| node_search
node_api -->|"searches updates"| node_tavily
node_search -->|"queries collection"| node_vector
node_tavily -->|"searches"| node_web
node_intent -.->|"generates response"| node_gemini
node_pdfs -->|"extracts text"| node_extract
node_extract -->|"writes text"| node_text
node_text -->|"normalizes text"| node_clean
node_clean -->|"writes cleaned text"| node_cleaned
node_pdfs -->|"splits pages"| node_english
node_cleaned -->|"builds embeddings"| node_build
node_build -->|"creates collection"| node_vector

click node_app "https://github.com/madhan-200/minelawhub/blob/master/frontend/src/App.jsx"
click node_input "https://github.com/madhan-200/minelawhub/blob/master/frontend/src/components/InputBox.jsx"
click node_window "https://github.com/madhan-200/minelawhub/blob/master/frontend/src/components/ChatWindow.jsx"
click node_message "https://github.com/madhan-200/minelawhub/blob/master/frontend/src/components/MessageBubble.jsx"
click node_avatar "https://github.com/madhan-200/minelawhub/blob/master/frontend/src/components/AnimatedAvatar.jsx"
click node_typewriter "https://github.com/madhan-200/minelawhub/blob/master/frontend/src/components/TypewriterText.jsx"
click node_navbar "https://github.com/madhan-200/minelawhub/blob/master/frontend/src/components/Navbar.jsx"
click node_sidebar "https://github.com/madhan-200/minelawhub/blob/master/frontend/src/components/Sidebar.jsx"
click node_theme "https://github.com/madhan-200/minelawhub/blob/master/frontend/src/theme/theme.js"
click node_api "https://github.com/madhan-200/minelawhub/blob/master/backend/main.py"
click node_intent "https://github.com/madhan-200/minelawhub/blob/master/backend/gemini_client.py"
click node_search "https://github.com/madhan-200/minelawhub/blob/master/backend/search_engine.py"
click node_vector "https://github.com/madhan-200/minelawhub/blob/master/embeddings/build_embeddings.py"
click node_tavily "https://github.com/madhan-200/minelawhub/blob/master/backend/tavily_client.py"
click node_pdfs "https://github.com/madhan-200/minelawhub/tree/master/data/pdfs"
click node_extract "https://github.com/madhan-200/minelawhub/blob/master/preprocessing/extract_text.py"
click node_text "https://github.com/madhan-200/minelawhub/tree/master/data/text"
click node_clean "https://github.com/madhan-200/minelawhub/blob/master/preprocessing/clean_text.py"
click node_cleaned "https://github.com/madhan-200/minelawhub/tree/master/data/cleaned"
click node_english "https://github.com/madhan-200/minelawhub/blob/master/preprocessing/split_english.py"
click node_build "https://github.com/madhan-200/minelawhub/blob/master/embeddings/build_embeddings.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_app,node_input,node_window,node_message,node_avatar,node_typewriter,node_navbar,node_sidebar,node_theme,node_user toneBlue
class node_api,node_intent toneAmber
class node_search,node_vector,node_tavily,node_web,node_gemini toneMint
class node_pdfs,node_extract,node_text,node_clean,node_cleaned,node_english,node_build toneRose
```

## Components

### Chat interface

- [Chat app](https://github.com/madhan-200/minelawhub/blob/master/frontend/src/App.jsx): `frontend/src/App.jsx`
- [Query input](https://github.com/madhan-200/minelawhub/blob/master/frontend/src/components/InputBox.jsx): `frontend/src/components/InputBox.jsx`
- [Chat display](https://github.com/madhan-200/minelawhub/blob/master/frontend/src/components/ChatWindow.jsx): `frontend/src/components/ChatWindow.jsx`
- [Answer and citations](https://github.com/madhan-200/minelawhub/blob/master/frontend/src/components/MessageBubble.jsx): `frontend/src/components/MessageBubble.jsx`
- [Assistant avatar](https://github.com/madhan-200/minelawhub/blob/master/frontend/src/components/AnimatedAvatar.jsx): `frontend/src/components/AnimatedAvatar.jsx`
- [Welcome text](https://github.com/madhan-200/minelawhub/blob/master/frontend/src/components/TypewriterText.jsx): `frontend/src/components/TypewriterText.jsx`
- [Navigation and theme](https://github.com/madhan-200/minelawhub/blob/master/frontend/src/components/Navbar.jsx): `frontend/src/components/Navbar.jsx`
- [Suggested queries](https://github.com/madhan-200/minelawhub/blob/master/frontend/src/components/Sidebar.jsx): `frontend/src/components/Sidebar.jsx`
- [Design theme](https://github.com/madhan-200/minelawhub/blob/master/frontend/src/theme/theme.js): `frontend/src/theme/theme.js`

### Chat and answer services

- [FastAPI endpoints](https://github.com/madhan-200/minelawhub/blob/master/backend/main.py): `backend/main.py`
- [Intent and answer generation](https://github.com/madhan-200/minelawhub/blob/master/backend/gemini_client.py): `backend/gemini_client.py`

### Legal and web sources

- [Semantic retrieval](https://github.com/madhan-200/minelawhub/blob/master/backend/search_engine.py): `backend/search_engine.py`
- [Law vector collection](https://github.com/madhan-200/minelawhub/blob/master/embeddings/build_embeddings.py): `embeddings/build_embeddings.py`
- [Mining web search](https://github.com/madhan-200/minelawhub/blob/master/backend/tavily_client.py): `backend/tavily_client.py`

### Document preparation

- [Source law PDFs](https://github.com/madhan-200/minelawhub/tree/master/data/pdfs): `data/pdfs`
- [PDF text extraction](https://github.com/madhan-200/minelawhub/blob/master/preprocessing/extract_text.py): `preprocessing/extract_text.py`
- [Extracted text](https://github.com/madhan-200/minelawhub/tree/master/data/text): `data/text`
- [Text cleaning](https://github.com/madhan-200/minelawhub/blob/master/preprocessing/clean_text.py): `preprocessing/clean_text.py`
- [Cleaned law text](https://github.com/madhan-200/minelawhub/tree/master/data/cleaned): `data/cleaned`
- [English-page splitting](https://github.com/madhan-200/minelawhub/blob/master/preprocessing/split_english.py): `preprocessing/split_english.py`
- [Embedding builder](https://github.com/madhan-200/minelawhub/blob/master/embeddings/build_embeddings.py): `embeddings/build_embeddings.py`

### Other components

- **User**
- **Tavily Search API**
- **Gemini API**

## Connections

- User → Query input: enters query (evidence: `frontend/src/components/InputBox.jsx`)
- Query input → Chat app: submits query (evidence: `frontend/src/App.jsx`)
- Chat app → FastAPI endpoints: posts chat (evidence: `frontend/src/App.jsx`)
- Chat app → Chat display: renders messages (evidence: `frontend/src/App.jsx`)
- Chat display → Answer and citations: renders answers (evidence: `frontend/src/components/ChatWindow.jsx`)
- Chat display → Assistant avatar: renders avatar (evidence: `frontend/src/components/ChatWindow.jsx`)
- Chat display → Welcome text: renders welcome (evidence: `frontend/src/components/ChatWindow.jsx`)
- Chat app → Query input: renders input (evidence: `frontend/src/App.jsx`)
- Chat app → Navigation and theme: renders navigation (evidence: `frontend/src/App.jsx`)
- Chat app → Suggested queries: renders sidebar (evidence: `frontend/src/App.jsx`)
- Chat app → Design theme: configures theme (evidence: `frontend/src/App.jsx`)
- Answer and citations → Assistant avatar: renders avatar (evidence: `frontend/src/components/MessageBubble.jsx`)
- FastAPI endpoints → Intent and answer generation: classifies and generates (evidence: `backend/main.py`)
- FastAPI endpoints → Semantic retrieval: retrieves law (evidence: `backend/main.py`)
- FastAPI endpoints → Mining web search: searches updates (evidence: `backend/main.py`)
- Semantic retrieval → Law vector collection: queries collection (evidence: `backend/search_engine.py`)
- Mining web search → Tavily Search API: searches (evidence: `backend/tavily_client.py`)
- Intent and answer generation → Gemini API: generates response
- Source law PDFs → PDF text extraction: extracts text (evidence: `README.md`)
- PDF text extraction → Extracted text: writes text (evidence: `README.md`)
- Extracted text → Text cleaning: normalizes text (evidence: `README.md`)
- Text cleaning → Cleaned law text: writes cleaned text (evidence: `README.md`)
- Source law PDFs → English-page splitting: splits pages (evidence: `README.md`)
- Cleaned law text → Embedding builder: builds embeddings (evidence: `README.md`)
- Embedding builder → Law vector collection: creates collection (evidence: `README.md`)
