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.
- 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.
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
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
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
┌─────────────────────────────────────────┐
│ 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 │
└──────────────────────┘
- 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]
- 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
- 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
- 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
- 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
- Docker & Docker Compose: v20+
- Node.js: v18+
- Java: OpenJDK 21+
- Git: Latest version
- 4GB+ RAM, 20GB+ Disk Space
git clone https://github.com/aamit2267/NYAYA-AI.git
cd nyaya-ai# 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# 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;"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.htmlcd ../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# Test Backend Health
curl http://localhost:8080/actuator/health
# Test Frontend
open http://localhost:3000
# Try a simple query in the chat interfaceSuccess! 🎉 Your Nyaya-AI instance is now running locally.
- Navigate to Homepage:
http://localhost:3000 - Select Language: Toggle between English/Hindi (top-right)
- Ask Legal Question: Type your query in the chat box
- Example: "What is the Consumer Protection Act?"
- Review Response: Read streamed response with citations
- Check Status: Look at footer health indicator
- Access Admin Portal:
http://localhost:3000/admin - Authenticate: Use your
ADMIN_API_KEY - Upload Document:
- Click "Upload Document"
- Select PDF or TXT file
- Add metadata (optional)
- Click "Process"
- Monitor Status:
- View "Chunks Processed"
- Verify "Embeddings Indexed"
- Verify Upload:
- Ask a query related to uploaded content
- Confirm AI retrieves correct sections
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 SSEcurl -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 }✅ 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 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
✅ Global Exception Handler: Never exposes stack traces to clients
✅ Secure Defaults: HTTPS enforced, security headers included
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
- 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
- Document ingestion batch processing optimization
- Prompt injection detection & prevention
- Response caching with Redis
- Enhanced LLM model evaluation
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Follow existing code style
- Add unit tests for new features
- Update documentation for API changes
- Test locally before submitting PR
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.
- 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
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.


![Nyaya AI Home Page [Hindi]](https://github.com/aamit2267/NYAYA-AI/raw/master/assets/nyaya-home-hindi.png)
![Nyaya AI Home Page [Dark Mode]](https://github.com/aamit2267/NYAYA-AI/raw/master/assets/nyaya-home-dark.png)
![Nyaya AI Home Page [Colour Blind Mode]](https://github.com/aamit2267/NYAYA-AI/raw/master/assets/nyaya-home-colourblind.png)

