Skip to content

alaminXpro/test-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 

Repository files navigation

AskLaw - Comprehensive Legal Assistant Platform

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.

🔄 Message Flow Overview

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       │
        └─────────────────┘                  └─────────────────┘

🚀 Key Flow Benefits

  • ⚡ 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

🌟 Access Points

🏗️ Architecture Overview

This platform consists of two main components working together:

1. Social Media Automation (Facebook Messenger Bot)

  • Repository: JurisMind Backend
  • Purpose: Handles Facebook Page Messenger integration with AI-powered responses
  • Technology: Spring Boot + Redis Queue + MongoDB

2. RAG-Powered Legal Assistant

  • Backend: AskLaw Backend
  • Frontend: AskLaw Frontend
  • Purpose: Core legal information retrieval and processing using advanced NLP
  • Technology: FastAPI + LangChain + LangGraph + Qdrant Vector DB

✨ Key Features

Core Legal Intelligence

  • 📚 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

Multi-Channel Access

  • 📱 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

Technical Excellence

  • 🔄 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

🔄 RAG Workflow (LangGraph Pipeline)

Legal Query Processing Workflow

Our LangGraph-powered system intelligently processes legal queries through a structured decision tree:

🔍 Step 1: Legal Scope Detection

  • Node: isLegalScope
  • Function: Determines if the query relates to legal matters
  • Decision: Legal query → proceed to interpretation | Non-legal → fallback response

🎯 Step 2: Query Classification

  • Node: interpret_query_actions
  • Routes:
    • Specific Law SectionspecificLaw
    • General Legal Inquirydoc_retrieval
    • Lawyer ConsultationIdentifyLawyerType

⚙️ Step 3: Specialized Processing

  • specificLaw: Direct law section retrieval by number/reference
  • doc_retrieval: Semantic + keyword search through Qdrant vector database
  • IdentifyLawyerType: Legal specialization classification for referrals

🔍 Step 4: Enhanced Retrieval

  • Node: metadata_based_retrieval
  • Function: Enriches results with law metadata (act names, sections, amendments)

💡 Step 5: Answer Generation

  • Node: llm_answer_with_context
  • Function: Generates comprehensive, structured responses using retrieved legal content

🎯 Step 6: Final Routing

  • Lawyer Type Identifiedfind_lawyers for professional referrals
  • Legal Answer Generated → Direct response to user

🛠️ Technology Stack

Social Media Automation Layer

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

RAG Intelligence Layer

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

🚀 Deployment Architecture

┌─────────────────┐    ┌─────────────────┐    ┌─────────────────┐
│   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  │
└─────────────────┘         └─────────────────┘

Hosting & Infrastructure

  • 🔄 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)

📁 Project Structure

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

Related Repositories

🚀 Getting Started

Prerequisites

  • Python 3.8+ (for RAG service)
  • Java 17+ (for Messenger bot)
  • Node.js 16+ (for frontend development)
  • Docker (optional, for containerized deployment)

Quick Start - RAG Service

# 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

Quick Start - Messenger Bot

# 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:run

Environment Configuration

Both 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_string

Messenger 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 URL

🧪 Testing

RAG Service Testing

cd AskLaw_RAG
python -m pytest tests/ -v

Messenger Bot Testing

cd AskLaw_backend/backend
mvn test

Integration Testing

Test the complete flow by:

  1. Starting both services locally
  2. Using the web frontend to submit queries
  3. Sending messages to the Facebook page
  4. Monitoring logs and responses

🤝 Contributing

We welcome contributions to improve AskLaw! Here's how you can help:

Development Workflow

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Make your changes and add tests
  4. Ensure all tests pass
  5. Submit a pull request with a clear description

Contribution Areas

  • 🧠 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

Code Standards

  • Follow existing code style and conventions
  • Write comprehensive tests for new features
  • Update documentation for API changes
  • Use meaningful commit messages

📊 Performance & Analytics

Key Metrics

  • 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

Monitoring

  • 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

📄 License

This project is licensed under the MIT License - see individual repository LICENSE files for details.

🙋‍♂️ Support & Community

  • 📧 Email: info@alaminia.com
  • 💼 LinkedIn: alaminxpro
  • 🐛 Issues: Use GitHub Issues in respective repositories
  • 💬 Discussions: Join our community discussions

🏆 Acknowledgments

  • 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!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors