A complete legal assistance platform providing Bangladeshi legal information through multiple channels. The system combines a sophisticated RAG (Retrieval-Augmented Generation) engine with social media automation to help the general public access legal information through their preferred communication channels.
Here's how user queries flow through our dual-channel system to provide intelligent legal assistance:
┌─────────────────────────────────────────────────────────────────────────────────┐
│ USER QUERY CHANNELS │
└─────────────────────────────────────────────────────────────────────────────────┘
Channel A: Facebook Messenger Channel B: Web Application
┌─────────────────────┐ ┌─────────────────────┐
│ 👤 User sends │ │ 👤 User types │
│ message to │ │ query in web │
│ Facebook Page │ │ interface │
└─────────┬───────────┘ └─────────┬───────────┘
│ │
▼ ▼
┌─────────────────────┐ ┌─────────────────────┐
│ 📘 Facebook │ │ ⚛️ React │
│ Messenger API │ │ Frontend │
│ (Webhook) │ │ (Vercel) │
└─────────┬───────────┘ └─────────┬───────────┘
│ │
▼ ▼
┌─────────────────────┐ ┌─────────────────────┐
│ 🤖 Messenger Bot │ │ 🌐 Web Backend │
│ (Spring Boot) │ │ (Spring Boot) │
│ │ │ │
│ • Webhook Handler │ │ • REST API │
│ • User Management │ │ • Authentication │
│ • Message Queue │ │ • Session Mgmt │
└─────────┬───────────┘ └─────────┬───────────┘
│ │
│ ┌─────────────────────┐ │
├─┤ 📊 MongoDB Atlas │ │
│ │ • User Profiles │ │
│ │ • Message History │◄──────────────────────┤
│ │ • Analytics │ │
│ └─────────────────────┘ │
│ │
│ ┌─────────────────────┐ │
└─┤ 🔴 Redis Queue │ │
│ • Message Buffer │ │
│ • Background Jobs │ │
│ • Rate Limiting │ │
└─────────┬───────────┘ │
│ │
└─────────────┬─────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────┐
│ 🧠 RAG SERVICE │
│ (FastAPI) │
│ │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ 🔍 Query │ │ 📚 Document │ │ 🎯 LangGraph│ │
│ │ Analysis │ │ Retrieval │ │ Workflow │ │
│ │ │ │ │ │ │ │
│ │ • Scope │ │ • Semantic │ │ • Legal │ │
│ │ • Intent │ │ • Keyword │ │ • Lawyer │ │
│ │ • Context │ │ • Hybrid │ │ • Answer │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
│ │
│ ┌─────────────────────────────────────────────────┐ │
│ │ 📊 Qdrant Vector DB │ │
│ │ │ │
│ │ • Bangladeshi Laws • Legal Articles │ │
│ │ • Government Portals • Court Cases │ │
│ │ • Legal Precedents • Lawyer Directory │ │
│ └─────────────────────────────────────────────────┘ │
└─────────────────────┬───────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────┐
│ 💡 AI RESPONSE │
│ │
│ • Structured Legal Answer │
│ • Relevant Law Sections │
│ • Lawyer Recommendations │
│ • Source Citations │
└─────────────────────┬───────────────────────────────────┘
│
┌───────────────┴───────────────┐
│ │
▼ ▼
┌─────────────────────────┐ ┌─────────────────────────┐
│ 📱 Facebook Response │ │ 🌐 Web Response │
│ │ │ │
│ • Formatted Message │ │ • Rich UI Display │
│ • Quick Reply Options │ │ • Downloadable PDF │
│ • Follow-up Prompts │ │ • Share Options │
└─────────────┬───────────┘ └─────────────┬───────────┘
│ │
▼ ▼
┌─────────────────┐ ┌─────────────────┐
│ 👤 User │ │ 👤 User │
│ receives │ │ receives │
│ response via │ │ response in │
│ Messenger │ │ browser │
└─────────────────┘ └─────────────────┘
- ⚡ Real-time Processing: Instant responses through optimized queuing
- 🔄 Cross-Channel Consistency: Same AI engine powers both channels
- 📊 Unified Analytics: All interactions stored in centralized database
- ⚖️ Legal Accuracy: Specialized RAG pipeline for legal document retrieval
- 💬 Facebook Messenger: Direct AI chat via Facebook Page
- 🌐 Web Application: Interactive frontend at ask-law-frontend.vercel.app
This platform consists of two main components working together:
- Repository: JurisMind Backend
- Purpose: Handles Facebook Page Messenger integration with AI-powered responses
- Technology: Spring Boot + Redis Queue + MongoDB
- Backend: AskLaw Backend
- Frontend: AskLaw Frontend
- Purpose: Core legal information retrieval and processing using advanced NLP
- Technology: FastAPI + LangChain + LangGraph + Qdrant Vector DB
- 📚 Comprehensive Legal Database: Trained on scraped Bangladeshi laws, government portals, and legal blogs
- 🔍 Advanced Search: Hybrid semantic search combining sparse embeddings, dense embeddings, and late interaction embeddings
- 🧠 Intelligent Workflow: LangGraph-powered decision-making pipeline for different types of legal queries
- 💾 Persistent Memory: Chat history stored in MongoDB for revisiting past queries
- 📱 Social Media Integration: 24/7 automated responses via Facebook Messenger
- 🌐 Web Interface: Interactive React-based frontend for detailed legal research
- ⚡ Real-time Processing: Asynchronous message handling with Redis queues
- 👥 Contact Management: Automatic user profile management and conversation tracking
- 🔄 Scalable Architecture: Microservices approach with independent scaling
- 📊 Analytics & Monitoring: Comprehensive metrics and health checks
- 🧪 Robust Testing: Unit, integration, and end-to-end test coverage
- 📝 API Documentation: Complete OpenAPI/Swagger documentation
Our LangGraph-powered system intelligently processes legal queries through a structured decision tree:
- Node:
isLegalScope - Function: Determines if the query relates to legal matters
- Decision: Legal query → proceed to interpretation | Non-legal → fallback response
- Node:
interpret_query_actions - Routes:
- Specific Law Section →
specificLaw - General Legal Inquiry →
doc_retrieval - Lawyer Consultation →
IdentifyLawyerType
- Specific Law Section →
specificLaw: Direct law section retrieval by number/referencedoc_retrieval: Semantic + keyword search through Qdrant vector databaseIdentifyLawyerType: Legal specialization classification for referrals
- Node:
metadata_based_retrieval - Function: Enriches results with law metadata (act names, sections, amendments)
- Node:
llm_answer_with_context - Function: Generates comprehensive, structured responses using retrieved legal content
- Lawyer Type Identified →
find_lawyersfor professional referrals - Legal Answer Generated → Direct response to user
| Component | Technology | Purpose |
|---|---|---|
| Application Framework | Spring Boot 3.0+ | Backend service architecture |
| Language | Java 17+ | Core application development |
| Message Queue | Redis 7.0+ | Asynchronous message processing |
| Database | MongoDB Atlas | User profiles and message storage |
| Integration | Facebook Graph API | Messenger webhook handling |
| Documentation | SpringDoc OpenAPI | API documentation |
| Testing | JUnit 5 + Testcontainers | Comprehensive test coverage |
| Component | Technology | Purpose |
|---|---|---|
| AI Framework | LangChain + LangGraph | Legal query processing pipeline |
| Backend API | FastAPI | High-performance API service |
| Vector Database | Qdrant | Hybrid search with multiple embeddings |
| Language | Python 3.8+ | RAG pipeline development |
| Frontend | React | Interactive web interface |
| Data Storage | MongoDB | Legal documents and metadata |
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ Facebook │ │ Web Users │ │ Admin Panel │
│ Messenger │ │ │ │ │
└─────┬───────────┘ └─────┬───────────┘ └─────┬───────────┘
│ │ │
▼ ▼ ▼
┌─────────────────────────────────────────────────────────────────┐
│ Load Balancer │
└─────┬───────────────────────────┬───────────────────────────────┘
│ │
▼ ▼
┌─────────────────┐ ┌─────────────────┐
│ Messenger Bot │ │ RAG Service │
│ (Spring Boot) │◄────────┤ (FastAPI) │
│ │ │ │
│ • Webhook │ │ • LangGraph │
│ • Redis Queue │ │ • Qdrant DB │
│ • User Mgmt │ │ • Legal Engine │
└─────┬───────────┘ └─────┬───────────┘
│ │
▼ ▼
┌─────────────────┐ ┌─────────────────┐
│ MongoDB │ │ React Web │
│ Atlas │ │ Frontend │
│ │ │ (Vercel) │
│ • Messages │ │ │
│ • Contacts │ │ • UI/UX │
│ • Analytics │ │ • Chat History │
└─────────────────┘ └─────────────────┘
- 🔄 Messenger Bot: Render (with Redis & MongoDB Atlas)
- 🧠 RAG Service: Render (connected to Qdrant Cloud)
- 🌐 Frontend: Vercel (optimized for fast global access)
- 💾 Databases: MongoDB Atlas (global clusters)
This repository contains the RAG service component. The complete platform consists of:
AskLaw/
├── README.md # This file - project overview
├── AskLaw_RAG/ # RAG service (FastAPI + LangChain)
│ ├── main.py # FastAPI application entry point
│ ├── graph.py # LangGraph workflow definition
│ ├── connection.py # Database connections
│ ├── requirements.txt # Python dependencies
│ ├── all_law_names.json # Legal document metadata
│ └── graph_nodes/ # Individual workflow nodes
│ ├── isLegalScope.py # Legal scope detection
│ ├── docRetrieval.py # Document retrieval
│ ├── interpretQueryActions.py # Query classification
│ ├── specificLaw.py # Specific law lookup
│ ├── llmAnswerWithContext.py # Answer generation
│ └── ... # Other specialized nodes
└── AskLaw_backend/ # Submodule: Messenger bot service
└── backend/ # Spring Boot application
├── src/main/java/ # Java source code
├── src/test/ # Test suites
├── pom.xml # Maven configuration
└── README.md # Messenger bot documentation
- Messenger Bot Backend: Spring Boot service for Facebook integration
- Web Backend: Spring Boot API for web frontend
- Web Frontend: React application for web interface
- Python 3.8+ (for RAG service)
- Java 17+ (for Messenger bot)
- Node.js 16+ (for frontend development)
- Docker (optional, for containerized deployment)
# Clone the repository
git clone --recurse-submodules https://github.com/abtaamim/AskLaw.git
cd AskLaw
# Set up RAG service
cd AskLaw_RAG
pip install -r requirements.txt
# Configure environment variables
cp .env.example .env
# Edit .env with your API keys and database URLs
# Start the RAG service
python main.py# Navigate to messenger bot
cd AskLaw_backend/backend
# Configure environment
cp .env.example .env
# Edit .env with Facebook credentials and database URLs
# Build and run
mvn clean package
mvn spring-boot:runBoth services require proper configuration:
RAG Service (.env):
QDRANT_URL=your_qdrant_cluster_url
QDRANT_API_KEY=your_qdrant_api_key
OPENAI_API_KEY=your_openai_api_key
MONGODB_URI=your_mongodb_connection_stringMessenger Bot (.env):
FACEBOOK_VERIFY_TOKEN=your_verify_token
FACEBOOK_PAGE_ACCESS_TOKEN=your_page_token
FACEBOOK_PAGE_ID=your_page_id
MONGODB_URI=your_mongodb_connection_string
REDIS_HOST=your_redis_host
AI_SERVICE_URL=http://localhost:8000/chat # RAG service URLcd AskLaw_RAG
python -m pytest tests/ -vcd AskLaw_backend/backend
mvn testTest the complete flow by:
- Starting both services locally
- Using the web frontend to submit queries
- Sending messages to the Facebook page
- Monitoring logs and responses
We welcome contributions to improve AskLaw! Here's how you can help:
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Make your changes and add tests
- Ensure all tests pass
- Submit a pull request with a clear description
- 🧠 AI/ML: Improve RAG pipeline accuracy and performance
- 📱 Integration: Add new social media platforms or communication channels
- 🎨 Frontend: Enhance user experience and accessibility
- 📚 Legal Content: Expand legal database coverage
- 🔧 DevOps: Improve deployment and monitoring
- 📝 Documentation: Help others understand and contribute
- Follow existing code style and conventions
- Write comprehensive tests for new features
- Update documentation for API changes
- Use meaningful commit messages
- Response Time: < 2 seconds for most legal queries
- Accuracy: 85%+ relevance score on legal document retrieval
- Availability: 99.5% uptime across all services
- Scalability: Handles 1000+ concurrent users
- Health Checks: Built-in endpoints for service monitoring
- Logging: Structured logging with different levels
- Metrics: Custom metrics for business KPIs
- Alerts: Automated alerts for service degradation
This project is licensed under the MIT License - see individual repository LICENSE files for details.
- 📧 Email: info@alaminia.com
- 💼 LinkedIn: alaminxpro
- 🐛 Issues: Use GitHub Issues in respective repositories
- 💬 Discussions: Join our community discussions
- Facebook Developer Community for Messenger platform support
- LangChain Team for the excellent RAG framework
- Qdrant for high-performance vector search
- Spring Boot Community for robust backend framework
- All Contributors who help make legal information accessible
⭐ Star this repository if you find it useful!