AI-powered legal assistance platform providing accessible legal guidance 24/7
[Your legal companion in your pocket]
PocketLawyer is a full-stack web application that leverages Google's Gemini AI to provide intelligent legal consultations, document analysis, and personalized legal guidance. The platform features a modern React frontend with Django REST API backend, supporting real-time chat sessions, user authentication, and comprehensive case management.
Frontend Features:
- Responsive Design: Mobile-first approach with progressive enhancement
- Theme Switching: Seamless light/dark mode toggle
- Modern UI/UX: Built with React, TypeScript, and TailwindCSS
- Smooth Animations: Framer Motion for fluid transitions
- Real-time Updates: WebSocket integration for live chat
Gemini AI Integration:
- Bangladeshi Law Context: Specialized knowledge base for local legal system
- Contextual Responses: Full conversation history awareness
- Multi-Style Support: Supportive, Casual, and Deep analysis modes
- Real-time Processing: Async responses with status tracking
Frontend:
- React 19.2.3 with TypeScript
- Vite 6.2.0 for build tooling
- React Router 7.12.0 for navigation
- Framer Motion 12.28.1 for animations
- TailwindCSS for styling
- Lucide React for icons
Backend:
- Django 6.0.1 with Django REST Framework
- PostgreSQL 17.1 database
- Celery with RabbitMQ for background tasks
- Google Gemini AI for legal assistance
- JWT authentication with Simple JWT
- Docker containerization
Infrastructure:
- Docker Compose for orchestration
- PostgreSQL for data persistence
- AI Legal Consultation: Real-time chat with Gemini AI models using sophisticated prompt engineering
- Advanced Session Management: Persistent chat history with AI-generated contextual titles
- Multi-Model AI Support: Intelligent fallback hierarchy across multiple Gemini models
- Background Task Processing: Celery workers with RabbitMQ for scalable async operations
- Secure API Key Management: Per-account API key configuration with field-level encryption
- Database Optimization: PostgreSQL with optimized queries and indexing
- JWT Authentication: Secure token-based authentication with refresh mechanisms
- RESTful API Design: Comprehensive API with OpenAPI/Swagger documentation
- Error Handling & Logging: Comprehensive exception handling with detailed logging
- Performance Monitoring: Real-time request tracking and performance metrics
- Responsive Design: Mobile-first design with progressive enhancement
- Real-time Updates: WebSocket integration for live chat updates
- Theme Switching: Seamless light/dark mode toggle
- Modern UI/UX: Built with React, TypeScript, and TailwindCSS
- Document Export: Export chat sessions and legal documents
- Newsletter System: Email subscription management with Django email backend
- Contact Management: Professional contact form handling
- Admin Panel: Comprehensive Django admin for content management
pocket-lawyer/
├── backend/ # Django backend
│ ├── core/ # Core Django settings
│ ├── users/ # User management
│ ├── accounts/ # Account profiles
│ ├── chat_bot/ # AI chat functionality
│ ├── api_key/ # API key management
│ ├── newsletter/ # Newsletter subscriptions
│ ├── contact_us/ # Contact form handling
│ └── BASE/ # Base models and utilities
├── frontend/ # React frontend
│ ├── components/ # Reusable React components
│ ├── context/ # React context providers
│ ├── services/ # API service layer
│ └── pages/ # Page components
├── docs/ # Documentation
├── docker-compose.yml # Docker orchestration
├── Dockerfile # Backend container
├── Dockerfile.frontend # Frontend container
└── requirements.txt # Python dependencies
POST /v1/api/users/register/- User registrationPOST /v1/api/users/login/- User loginPOST /v1/api/users/refresh/- Token refresh
POST /v1/api/assistant/- Create AI consultationGET /v1/api/assistant/sessions/- List chat sessionsGET /v1/api/assistant/sessions/{id}/- Get session details
GET /v1/api/accounts/profile/- User profilePUT /v1/api/accounts/profile/- Update profilePOST /v1/api/accounts/api-key/- Manage API keys
POST /v1/api/newsletter/subscribe/- Newsletter subscriptionPOST /v1/api/contact-us/- Contact form submission
The chat system is engineered with sophisticated backend architecture:
Chat Request Processing:
- Request Reception:
AiRequestmodel captures user queries with metadata - API Key Management: Secure per-account API key retrieval and validation
- Model Selection: Intelligent fallback hierarchy (Gemini 3 Flash → Gemini 2.5 Flash → Gemma 3 27B)
- Background Processing: Celery workers handle AI requests asynchronously
- Response Storage: Structured storage with engine and style metadata
Session Management:
- Auto-Session Creation: Automatic session generation for new conversations
- Title Generation: AI-powered title creation using conversation context
- Message History: JSON-based message storage with full conversation context
- Status Tracking: Real-time status updates (PENDING → RUNNING → COMPLETED/FAILED)
Key Backend Features:
- Multi-Model Support: Seamless fallback between Gemini models
- Error Handling: Comprehensive exception handling with graceful degradation
- Performance Optimization: Async processing with Celery workers
- Data Encryption: Secure API key storage using Django field encryption
- Conversation Context: Full history awareness for contextual responses
- User: Custom user model with extended fields
- Account: User profile and subscription information
- ChatSession: Chat conversation history with auto-generated titles
- AiRequest: Individual AI consultation requests with multi-model support
- ApiKey: Per-account API key management with encryption
- User → Account (1:1)
- Account → ChatSession (1:N)
- Account → AiRequest (1:N)
- ChatSession → AiRequest (1:N)
- Account → ApiKey (1:N)
Create a .env file in the project root:
# Database
DB_HOST=localhost
DB_NAME=pocket_lawyer
DB_USER=postgres
DB_PASS=password
DB_PORT=5432
# Django
SECRET_KEY=your-secret-key
DEBUG=True
# AI Services
GEMINI_API_KEY=your-gemini-api-key
DJANGO_CRYPTO_KEY=your-encryption-key
# Message Queue
CELERY_BROKER_URL=amqp://user:pass@localhost:5672//
RABBITMQ_DEFAULT_USER=rabbitmq
RABBITMQ_DEFAULT_PASS=password
# Email
EMAIL_HOST_USER=your-email@gmail.com
EMAIL_HOST_PASSWORD=your-app-password
DEFAULT_FROM_EMAIL=noreply@pocketlawyer.ai- Docker & Docker Compose
- Node.js 18+ (for local development)
- Python 3.12+ (for local development)
- Clone the repository
git clone <repository-url>
cd pocket-lawyer- Configure environment
cp .env.example .env
# Edit .env with your configuration- Start all services
clear && docker compose down && docker compose up --build- Access the application
- Frontend: http://localhost:3000
- Backend API: http://localhost:8000
- API Documentation: http://localhost:8000/api/schema/swagger-ui/
- Admin Panel: http://localhost:8000/admin/
Create new Django app:
docker compose run --rm backend sh -c "python manage.py startapp <app_name>"Start development server:
clear && docker compose down && docker compose up --buildBackend Setup:
cd backend
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r ../requirements.txt
python manage.py migrate
python manage.py runserverFrontend Setup:
cd frontend
npm install
npm run devBackground Worker:
cd backend
celery -A core worker -l INFO- Gemini 3 Flash: Fast responses, cost-effective
- Gemini 2.5 Flash: Balanced performance
- Gemini 2.5 Flash Lite: Lightweight option
- Gemma 3 27B: Advanced reasoning
The system automatically falls back between models based on availability and performance, ensuring reliable service delivery.
- JWT-based authentication with refresh tokens
- Encrypted API key storage
- CORS configuration
- CSRF protection
- SQL injection prevention
- Rate limiting capabilities
- Celery background task processing
- Database query optimization
- Frontend code splitting
- Image optimization
- Caching strategies
- CDN-ready architecture
- Comprehensive error logging
- AI request tracking
- Performance metrics
- User activity monitoring
- System health checks
- Configure production environment variables
- Set up PostgreSQL database
- Configure Redis cache
- Deploy with Docker Compose or Kubernetes
- Set up reverse proxy (Nginx)
- Configure SSL certificates
- Development: Debug mode, local database
- Staging: Production-like setup with test data
- Production: Optimized settings, monitoring enabled
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
For support and inquiries:
- Email: thesheikh255@gmail.com
- Documentation: Check the
/docsdirectory - Issues: Create an issue on the repository
PocketLawyer provides AI-assisted legal guidance and is not a substitute for professional legal advice. Always consult with qualified legal professionals for specific legal matters.






