# EPOLaw Project Memory

## Recent Feature Implementations

### Business Law and Family Law Functions (Added: 2025-09-21)

#### Overview
Implemented specialized practice area functionality for business law and family law document analysis, providing targeted legal analysis based on document type and practice area.

#### Database Changes
Added practice area fields to existing tables:
- `cases.practice_area` - VARCHAR(50) field for case categorization
- `analysis_jobs.practice_area` - VARCHAR(50) field for analysis categorization
- `analysis_jobs.analysis_type` - VARCHAR(100) field for specific analysis types
- `summarization_jobs.practice_area` - VARCHAR(50) field for summary categorization

Migration script: `/var/www/lawbot/add_practice_area_fields.py`

#### New Files Created
1. **`/var/www/lawbot/practice_area_templates.py`**
   - Contains specialized prompts for business and family law
   - Business law templates: contract_review, merger_acquisition, corporate_compliance, intellectual_property
   - Family law templates: custody_evaluation, divorce_settlement, prenuptial_postnuptial, adoption_guardianship
   - Auto-detection function for document type identification

#### Modified Files

1. **`models.py`**
   - Added practice_area fields to Case, AnalysisJob, and SummarizationJob models
   - Added analysis_type field to AnalysisJob model

2. **`document_summarization_processor.py`**
   - Integrated practice area template system
   - Added `detect_practice_area()` method
   - Modified `get_summary_prompt()` to use practice-specific prompts
   - Added support for practice_area and analysis_type parameters

3. **`templates/index.html`** (New Analysis page)
   - Added practice area dropdown (General, Business, Family, Criminal, Civil)
   - Added dynamic analysis type dropdown
   - JavaScript for dynamic type updates based on practice area

4. **`templates/summarization/form.html`** (New Summary page)
   - Added practice area dropdown
   - Added document type dropdown
   - JavaScript for dynamic document type updates

5. **`templates/cases/new.html`** (Case Creation)
   - Added practice_area field to case creation form
   - Options: General Practice, Business Law, Family Law, Criminal Law, Civil Litigation

6. **`app.py`**
   - Modified `upload_file()` to capture practice_area and analysis_type
   - Updated AnalysisJob creation to include new fields

7. **`case_routes.py`**
   - Updated case creation to save practice_area field

#### Practice Area Types

**Business Law Analysis Types:**
- contract_review - Comprehensive contract analysis
- merger_acquisition - M&A document analysis
- corporate_compliance - Regulatory compliance review
- intellectual_property - IP document analysis

**Family Law Analysis Types:**
- custody_evaluation - Custody-related document analysis
- divorce_settlement - Divorce document review
- prenuptial_postnuptial - Marital agreement analysis
- adoption_guardianship - Adoption/guardianship review

#### Key Features
1. **Auto-Detection**: System can automatically detect document type from content
2. **Specialized Prompts**: Different analysis templates for each practice area
3. **Dynamic UI**: Dropdowns update based on selected practice area
4. **Backward Compatible**: General option available for non-specialized documents

#### Implementation Notes
- Practice area selection provides specialized analysis prompts via `practice_area_templates.py`
- Document processor automatically detects practice area if not specified
- All existing functionality preserved with 'general' as default
- System uses practice-specific prompts when available, falls back to general prompts

#### Testing Commands
```bash
# Run database migration
/var/www/lawbot/venv/bin/python3 /var/www/lawbot/add_practice_area_fields.py

# Restart service
systemctl restart epolaw

# Check logs
tail -f /var/log/epolaw/error.log
```

#### Future Enhancement Opportunities
1. Add more practice areas (Real Estate, Immigration, Tax Law)
2. Create practice-specific calculators (child support, alimony)
3. Implement jurisdiction-specific rules for family law
4. Add practice area filtering to search and reporting
5. Create specialized dashboards for each practice area

---

## System Architecture Notes

### Service Configuration
- Service: EPOLaw Flask Application
- WSGI: Gunicorn with 4 workers
- Timeout: 900 seconds (15 minutes)
- Virtual Environment: `/var/www/lawbot/venv`

### Key Integration Points
- OpenAI GPT-4o for document analysis
- Anthropic Claude for AI legal research
- Stripe for subscription management
- MySQL database backend

### Important Patterns
- Session-based authentication (NOT Flask-Login)
- Multi-tenant architecture with company_id isolation
- Background processing using threading for long operations
- Practice area templates for specialized analysis

---

Last Updated: 2025-09-21