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!