Skip to content

aamit2267/NYAYA-AI

Repository files navigation

Nyaya-AI Logo

⚖️ NYAYA-AI

Legal Guidance for Every Indian Citizen.

Status Architecture Languages Made with Love


Caution

CRITICAL LEGAL DISCLAIMER

Nyaya-AI is an experimental Artificial Intelligence tool and NOT a registered advocate or human legal authority. This platform provides factual information retrieved from official Indian legal acts and defines possibilities for genuine case filings. It cannot make binding judgments or provide actionable legal representation.

⚠️ Limitations:

  • Cannot replace professional legal counsel
  • Should not be used for contested matters
  • Users should verify information with qualified lawyers
  • Platform assumes no liability for misuse or misguidance

For serious legal matters, always consult a registered practitioner under the Bar Council of India.


🎬 Project Vision & Impact

A glimpse of the future of legal knowledge in India Nyaya AI Home Page Nyaya AI Home Page [Hindi] Nyaya AI Home Page [Dark Mode] Nyaya AI Home Page [Colour Blind Mode] Nyaya AI Admin Ingest Page Nyaya Chat AI

The Problem

India's legal system is one of the world's largest and most complex. With over 50 million pending cases in Indian courts, citizens face tremendous barriers to understanding their rights:

  • 📜 Legal jargon in Acts & statutes is incomprehensible to average citizens
  • 🔍 Knowledge asymmetry between lawyers and common people
  • 💰 High consultation costs make legal advice inaccessible
  • 🌐 Language barriers exclude 70% of non-English speakers
  • Time constraints for quick legal information retrieval

The Solution

Nyaya-AI democratizes legal knowledge through:

  • 🤖 Intelligent RAG Pipeline that retrieves relevant legal sections instantly
  • 🔒 Privacy-First Architecture with local LLMs (no data sent to third parties)
  • 🌍 Bilingual Support (English & Hindi) for broader accessibility
  • Real-Time Streaming responses for engaging user experience
  • 📱 Responsive Design optimized for mobile-first India

🚀 The Engineering Ambition

As a Full Stack Engineer with enterprise experience, Nyaya-AI demonstrates mastery across the AI/ML stack:

Backend Innovations:

  • ✅ Local LLM orchestration (Ollama) eliminating data privacy risks
  • ✅ Vector database optimization (pgvector + HNSW indexing)
  • ✅ Production-grade RAG pipeline from document ingestion to streaming
  • ✅ Spring Boot microservices with async processing & caching

Frontend Excellence:

  • ✅ MVVM architecture in Next.js for testability & maintainability
  • ✅ Real-time SSE streaming for token-by-token LLM responses
  • ✅ Bilingual state management with language toggling
  • ✅ Accessibility-first design (dark mode, color-blind modes)

System Design Highlights:

  • ✅ Horizontal scalability with stateless services
  • ✅ Multi-layer security (API keys, CORS, input validation)
  • ✅ Observable architecture with health checks & logging
  • ✅ Cost-optimized deployment on free cloud tiers

💻 Tech Stack & Architecture

Technology Stack by Layer

Layer Technology Purpose
Frontend UI Next JS React TypeScript MVVM architecture, SSE streaming, bilingual UI state
Styling TailwindCSS Lucide Responsive design, dark/light modes, accessibility
Backend API Spring Java Spring Boot 4.0.5, REST APIs, exception handling
AI/ML LangChain Ollama Local LLMs, prompt orchestration, RAG pipeline
Vector DB Postgres pgvector Semantic search, HNSW indexing
Orchestration Docker Docker Compose Container management, networking

Architecture Pattern

┌─────────────────────────────────────────┐
│   Next.js Frontend (MVVM)               │
│   • Real-time SSE Streaming             │
│   • Bilingual Support                   │
│   • Dark/Accessible Modes               │
└─────────────┬───────────────────────────┘
              │ HTTP/REST
              ↓
┌─────────────────────────────────────────┐
│   Spring Boot API Layer                 │
│   • API Key Authentication              │
│   • CORS Configuration                  │
│   • Global Exception Handling           │
└─────────────┬───────────────────────────┘
              │
    ┌─────────┴──────────┐
    ↓                    ↓
┌─────────────────┐  ┌──────────────────┐
│  Chat Service   │  │  Admin Service   │
│  + RAG Pipeline │  │  + Ingestion     │
└────────┬────────┘  └────────┬─────────┘
         │                    │
         └──────────┬─────────┘
                    ↓
      ┌─────────────────────────┐
      │  LangChain4J Agent      │
      │  • Prompt Templates     │
      │  • LLM Orchestration    │
      └───────────┬─────────────┘
                  ↓
    ┌─────────────────────────┐
    ↓                         ↓
┌─────────────────┐  ┌──────────────────┐
│  Ollama (LLM)   │  │  Ollama (Embed)  │
│  • Llama 3      │  │  • nomic-embed   │
│  • Mistral      │  │  • mxbai-embed   │
└─────────────────┘  └──────────────────┘
         │                    │
         └──────────┬─────────┘
                    ↓
        ┌──────────────────────┐
        │  PostgreSQL 16       │
        │  + pgvector          │
        │  • Document Store    │
        │  • Vector Index      │
        │  • Session History   │
        └──────────────────────┘

🛠️ Core Features & Capabilities

1. 💬 Intelligent Legal Chat Interface

  • Real-Time Streaming: Token-by-token response generation via SSE
  • Context-Aware Responses: RAG pipeline retrieves relevant legal sections
  • Conversation History: Persists across sessions with unique IDs
  • Error Handling: Graceful degradation and user-friendly error messages

Example:

User: "What are my rights as a tenant?"
Nyaya-AI: [Retrieves Rent Control Act sections]
          [Generates bilingual response with citations]
          [Streams response in real-time]

2. 🔐 Secure Administrator Portal

  • API-Key Authentication: X-API-KEY header validation
  • Document Management: Upload PDFs or raw text files
  • Intelligent Chunking: Automatic text splitting with overlap
  • Batch Processing: Async ingestion for performance
  • Audit Logging: Track all admin actions for compliance

Workflow:

Admin uploads PDF
    ↓
Spring Boot parses & chunks
    ↓
LangChain4J generates embeddings
    ↓
pgvector indexes with HNSW
    ↓
"Ready for queries" notification

3. 🆘 Emergency Helplines Directory

  • Verified Contacts: Curated list of Indian helplines
  • Multi-Category: Legal, mental health, cyber crime, consumer rights
  • Quick Access: Interactive carousel for easy browsing
  • Always Updated: Admin-managed database

Coverage:

  • 🚔 Cyber Crime Department
  • 👨‍⚖️ Bar Council Associations
  • 💪 Consumer Rights Commission
  • 🧠 Mental Health Crisis Lines (KIRAN)
  • 🏥 Emergency Medical Services

4. 📊 Health & Observability

  • Live Health Checks: Actuator endpoint monitoring
  • Component Status: DB, LLM, Vector DB real-time status
  • Performance Metrics: Response latency, cache hit rates
  • Visual Feedback: Glowing status indicator in footer

Endpoints:

  • /actuator/health - Full system health
  • /actuator/metrics - Performance data
  • /actuator/prometheus - Metrics export

5. 🌍 Bilingual Support (EN/HI)

  • Complete Localization: All UI text in English & Hindi
  • Legal Terminology: Context-aware translations
  • Language Persistence: User preference saved
  • RTL Support: Ready for future 20+ Indian Languages

🚀 Quick Start

Prerequisites

  • Docker & Docker Compose: v20+
  • Node.js: v18+
  • Java: OpenJDK 21+
  • Git: Latest version
  • 4GB+ RAM, 20GB+ Disk Space

Step 1️⃣ Clone the Repository

git clone https://github.com/aamit2267/NYAYA-AI.git
cd nyaya-ai

Step 2️⃣ Environment Setup

# Copy environment files
cp .env.example .env
cp .env.local.example .env.local

# Edit .env with your configuration
nano .env

# Required variables:
# POSTGRES_USER=nyaya_user
# POSTGRES_PASSWORD=your_secure_password
# POSTGRES_DB=nyaya
# ADMIN_API_KEY=your_admin_api_key

Step 3️⃣ Database & Service Startup

# Start PostgreSQL + pgvector (Docker)
docker-compose -f docker-compose.dev.yml up -d

# Verify PostgreSQL is running
docker ps

# Initialize database (if not auto-initialized)
docker exec nyaya_postgres_dev psql -U nyaya_user -d nyaya -c "CREATE EXTENSION IF NOT EXISTS vector;"

Step 4️⃣ Backend Setup

cd nyaya-backend

# Build Maven project
mvn clean install -DskipTests

# Start Spring Boot (Dev Mode)
mvn spring-boot:run

# Backend runs on http://localhost:8080
# Swagger UI: http://localhost:8080/swagger-ui.html

Step 5️⃣ Frontend Setup

cd ../nyaya-frontend

# Install dependencies
npm install

# Create .env.local
cp .env.local.example .env.local

# Set Backend URL
echo "NEXT_PUBLIC_API_URL=http://localhost:8080" >> .env.local

# Start development server
npm run dev

# Frontend runs on http://localhost:3000

Step 6️⃣ Verify Installation

# Test Backend Health
curl http://localhost:8080/actuator/health

# Test Frontend
open http://localhost:3000

# Try a simple query in the chat interface

Success! 🎉 Your Nyaya-AI instance is now running locally.


📖 Usage Guide

For Citizens (Chat Interface)

  1. Navigate to Homepage: http://localhost:3000
  2. Select Language: Toggle between English/Hindi (top-right)
  3. Ask Legal Question: Type your query in the chat box
    • Example: "What is the Consumer Protection Act?"
  4. Review Response: Read streamed response with citations
  5. Check Status: Look at footer health indicator

For Administrators (Document Upload)

  1. Access Admin Portal: http://localhost:3000/admin
  2. Authenticate: Use your ADMIN_API_KEY
  3. Upload Document:
    • Click "Upload Document"
    • Select PDF or TXT file
    • Add metadata (optional)
    • Click "Process"
  4. Monitor Status:
    • View "Chunks Processed"
    • Verify "Embeddings Indexed"
  5. Verify Upload:
    • Ask a query related to uploaded content
    • Confirm AI retrieves correct sections

For Developers (API Integration)

Chat Query Endpoint

curl -X POST http://localhost:8080/api/chat/ \
  -H "Content-Type: application/json" \
  -d '{
    "question": "What are my rights as an employee?"
  }'

# Response: Streams text via SSE

Document Upload Endpoint

curl -X POST http://localhost:8080/api/admin/ingest/pdf \
  -H "X-API-KEY: your_admin_api_key" \
  -F "file=@Legal_Document.pdf" \
  -F "metadata={\"source\": \"Supreme Court\"}"

# Response: { "status": "success", "documentsProcessed": 5 }

🔒 Security Posture

Data Privacy

Zero External API Calls: All LLM processing happens locally via Ollama
No Data Leakage: User queries never sent to OpenAI/Anthropic/other third parties
Encrypted Storage: Sensitive fields encrypted at rest (future enhancement)

API Security

API Key Authentication: X-API-KEY header validation for admin endpoints
CORS Protection: Strict origin validation per environment
Rate Limiting: 10 requests/minute per IP for chat

Application Security

Global Exception Handler: Never exposes stack traces to clients
Secure Defaults: HTTPS enforced, security headers included


🗂️ Project Structure

nyaya-ai/
├── nyaya-backend/                   # Spring Boot API
│   ├── src/main/java/com/nyaya/backend/
│   │   ├── agent/                  # LangChain4J orchestration
│   │   ├── controller/             # REST endpoints
│   │   ├── service/                # Business logic
│   │   ├── config/                 # Spring configuration
│   │   ├── security/               # Auth & filters
│   │   ├── exception/              # Error handling
│   │   └── ...
│   ├── pom.xml                     # Maven dependencies
│   └── Dockerfile                  # Container image
│
├── nyaya-frontend/                  # Next.js UI
│   ├── src/
│   │   ├── app/                    # App Router pages
│   │   ├── components/             # React components
│   │   ├── hooks/                  # Custom React hooks
│   │   ├── utils/                  # Utilities
│   │   └── types/                  # TypeScript types
│   ├── package.json
│   └── Dockerfile
│
├── docker-compose.dev.yml          # Local development
├── .env.example                    # Environment template
└── README.md                       # This file


🚧 Current Status & Roadmap

✅ Completed

  • Full-stack RAG pipeline architecture
  • Spring Boot API with LangChain4J integration
  • PostgreSQL + pgvector vector database
  • Next.js MVVM frontend with SSE streaming
  • Bilingual support (EN/HI)
  • API Key authentication for admin endpoints
  • Docker Compose local development setup
  • Health check & observability endpoints

🔄 In Progress

  • Document ingestion batch processing optimization
  • Prompt injection detection & prevention
  • Response caching with Redis
  • Enhanced LLM model evaluation

🤝 Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Development Guidelines

  • Follow existing code style
  • Add unit tests for new features
  • Update documentation for API changes
  • Test locally before submitting PR

🐳 Deployment

I regret to inform you that, due to the backend’s requirement for a VM server with high CPU and GPU capacity, deploying Nyaya-AI is not feasible at this stage.

I would appreciate any suggestions or recommendations for hosting the backend using free resources.


🙏 Acknowledgments

  • LangChain Community: For the incredible LangChain4J framework
  • Ollama Team: For enabling local LLM inference
  • pgvector Contributors: For vector database capabilities
  • Spring Boot Team: For the enterprise framework
  • Next.js Community: For frontend excellence
  • Indian Legal System: For inspiring this project

📈 Impact & Vision

We believe that justice should be accessible to all, regardless of economic status or language. Nyaya-AI is a step toward democratizing legal knowledge in India.

Our Mission: To bridge the gap between India's complex legal system and its 1.4+ billion citizens.

Our Vision: A future where every Indian can understand their rights, without barriers of language, cost, or complexity.


🌟 Star this Repository if You Believe in Accessible Justice! ⚖️

"Law is for everyone, and everyone deserves access to law."


Architected & Developed by Amit Agarwal

Built with ❤️ for India | 🇮🇳

About

Disclaimer: This tool offers only general law details for informational purposes. It does not constitute legal advice. Always consult a qualified lawyer before acting on any information.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors