# dhruthiaithal/themis-legal architecture

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

- Interactive diagram: https://gitdiagram.com/dhruthiaithal/themis-legal
- Repository: https://github.com/dhruthiaithal/themis-legal

## Overview

##### Project type and purpose
- This is a full-stack web application (“AI Legal Aid Platform”) that offers an AI-driven legal chatbot, document generation, and text summarization.
- Key features: React-based frontend, Node/Express backend, a separate Python FastAPI microservice for LLaMA inference, and a data directory holding legal texts and model files.

##### File structure
- Top-level directories:
- client/ – React SPA, serves UI pages (chatbot.html, login.html, etc.) and components under src/
- server/ – Node/Express server with REST routes (documentProcessing.js, digilockerSimulator.js)
- llama_service/ – FastAPI microservice (main.py) for LLaMA model inference
- data/ – static legal documents and a placeholder for the LLaMA model file
- Supporting files: .gitignore, package.json at root, README.md
- No traditional database: users.csv in server/ acts as a simple user store; legal-docs/*.txt are static content.

##### README for additional insights
- Architecture overview under “Project Structure.”
- Setup and run instructions for each component.
- API endpoints:
- Backend: GET /, POST /api/chat
- LLaMA: GET /, POST /api/llama

##### Main components
a. Frontend (React SPA)
- Components: Chatbot.jsx, DocumentProcessor.js, Navbar.jsx, Login.jsx
- Hosted by npm dev server at localhost:3000
b. Backend (Node/Express)
- Routes: /api/chat → handles incoming chat, invokes documentProcessing and/or proxies to LLaMA service
- digilockerSimulator.js (external integration simulator)
- Data store: users.csv, static files in data/legal-docs
c. LLaMA Service (FastAPI microservice)
- main.py: loads the LLaMA model file from data/llama-2-7b-chat.Q4_K_M.gguf
- Endpoint POST /api/llama to accept questions and return AI responses
d. Data Layer
- data/legal-docs/*.txt – source documents for summarization or form generation
- data/llama-2-7b-chat…gguf – LLaMA model binary (external resource)
e. External Services
- LLaMA open-source model loaded locally
- (Optional) Future extension: actual DigiLocker API

##### Relationships and interactions
- The React frontend issues REST calls to the Express backend (POST /api/chat, file uploads, form generation requests).
- The backend, upon receiving a chat or document operation, may:
- Read static legal docs from data/legal-docs
- Generate RTI or legal forms via server-side logic
- Forward queries to the LLaMA microservice (HTTP POST /api/llama) for AI responses
- The LLaMA service loads the model and returns generated text.
- All components run independently:
- Frontend (port 3000)
- Backend (port 5000, for example)
- LLaMA service (port 8000)

##### Architectural patterns and design principles
- Microservices: separate AI inference engine (FastAPI) from business logic (Express).
- SPA-backend separation: React frontend vs. REST API.
- File-based data storage for documents and lightweight CSV user store.
- Clear modularization: UI components, API routes, AI logic.

##### Elements
- Component names and technologies: React/JSX, Express/Node.js, FastAPI/Python, File System
- Ports or endpoints (e.g., :3000, :5000/api/chat, :8000/api/llama)
- Annotations on data assets (legal-docs/*.txt, llama-2-7b-chat…gguf, users.csv)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% UI Layer
    subgraph "Client / React SPA (localhost:3000)"
        direction TB
        App["App.js"]:::ui
        Chatbot["Chatbot.jsx"]:::ui
        DocumentProcessor["DocumentProcessor.js"]:::ui
        Navbar["Navbar.jsx"]:::ui
        LoginPage["Login.jsx"]:::ui
        HTMLChat["chatbot.html"]:::ui
        HTMLLogin["login.html"]:::ui
        HTMLDocGen["doc-generator.html"]:::ui
        HTMLUpload["upload-summarize.html"]:::ui
    end

    %% Backend Layer
    subgraph "Server / Express API (localhost:5000)"
        direction TB
        ExpressServer["server.js"]:::backend
        DocRoute["documentProcessing.js"]:::backend
        DigiSim["digilockerSimulator.js"]:::backend
    end

    %% AI Microservice Layer
    subgraph "LLaMA Service / FastAPI (localhost:8000)"
        direction TB
        FastAPI["main.py"]:::ai
        Requirements["requirements.txt"]:::ai
    end

    %% Data Layer
    subgraph "Data Storage"
        direction TB
        LegalDocs["data/legal-docs/"]:::data
        UsersCSV["users.csv"]:::data
        ModelsMD["MODELS.md"]:::data
    end

    %% Relationships
    App -->|"HTTP POST /api/chat"| ExpressServer
    Chatbot --> ExpressServer
    DocumentProcessor --> ExpressServer
    LoginPage --> ExpressServer

    ExpressServer --> DocRoute
    ExpressServer --> DigiSim
    ExpressServer -->|"read/write"| LegalDocs
    ExpressServer -->|"read/write"| UsersCSV
    ExpressServer -->|"HTTP POST /api/llama"| FastAPI

    FastAPI -->|"loads model"| ModelsMD
    FastAPI --> Requirements

    %% Click Events - UI
    click App "https://github.com/dhruthiaithal/themis-legal/blob/main/client/src/App.js"
    click Chatbot "https://github.com/dhruthiaithal/themis-legal/blob/main/client/src/components/Chatbot.jsx"
    click DocumentProcessor "https://github.com/dhruthiaithal/themis-legal/blob/main/client/src/components/DocumentProcessor.js"
    click Navbar "https://github.com/dhruthiaithal/themis-legal/blob/main/client/src/components/Navbar.jsx"
    click LoginPage "https://github.com/dhruthiaithal/themis-legal/blob/main/client/src/pages/Login.jsx"
    click HTMLChat "https://github.com/dhruthiaithal/themis-legal/blob/main/client/public/chatbot.html"
    click HTMLLogin "https://github.com/dhruthiaithal/themis-legal/blob/main/client/public/login.html"
    click HTMLDocGen "https://github.com/dhruthiaithal/themis-legal/blob/main/client/public/doc-generator.html"
    click HTMLUpload "https://github.com/dhruthiaithal/themis-legal/blob/main/client/public/upload-summarize.html"
    click client "https://github.com/dhruthiaithal/themis-legal/tree/main/client/"

    %% Click Events - Backend
    click ExpressServer "https://github.com/dhruthiaithal/themis-legal/blob/main/server/server.js"
    click DocRoute "https://github.com/dhruthiaithal/themis-legal/blob/main/server/routes/documentProcessing.js"
    click DigiSim "https://github.com/dhruthiaithal/themis-legal/blob/main/server/digilockerSimulator.js"
    click UsersCSV "https://github.com/dhruthiaithal/themis-legal/blob/main/server/users.csv"
    click server "https://github.com/dhruthiaithal/themis-legal/tree/main/server/"

    %% Click Events - AI Service
    click FastAPI "https://github.com/dhruthiaithal/themis-legal/blob/main/llama_service/main.py"
    click Requirements "https://github.com/dhruthiaithal/themis-legal/blob/main/llama_service/requirements.txt"
    click llama_service "https://github.com/dhruthiaithal/themis-legal/tree/main/llama_service/"

    %% Click Events - Data
    click LegalDocs "https://github.com/dhruthiaithal/themis-legal/tree/main/data/legal-docs/"
    click ModelsMD "https://github.com/dhruthiaithal/themis-legal/blob/main/data/MODELS.md"

    %% Styles
    classDef ui fill:#cde8ff,stroke:#0366d6,color:#0366d6,stroke-width:2px;
    classDef backend fill:#d3f9d8,stroke:#2c662d,color:#2c662d,stroke-width:2px;
    classDef ai fill:#ffe5b4,stroke:#cc8400,color:#cc8400,stroke-width:2px;
    classDef data fill:#e2e2e2,stroke:#666666,color:#333333,stroke-width:2px;
```
