An AI-powered legal document organizer that uses Gemini multimodal AI and OpenAI GPT-4o to automatically classify and organize legal documents with advanced PDF signature detection.
- ๐ฎ Gemini Multimodal PDF Extraction: Revolutionary visual signature detection that finds ALL signers in PDFs
- ๐ค Dual AI Classification: Uses OpenAI GPT-4o for document classification and metadata extraction
- ๐ง Memory System: Pre-indexes information for instant answers to business questions
- ๐ Automatic Template Identification: Intelligently identifies and categorizes template documents
- ๐ Structured Organization: Organizes documents into a 10-folder business function structure
- ๐ Real-time Monitoring: Continuously monitors folders for new files and organizes them instantly
- ๐ Advanced PDF Processing: Detects visual signatures, filled form fields, and annotations
- ๐ Batch Processing: Can organize large numbers of existing files
- โก CLI Interface: Simple command-line interface for easy use
- ๐ค Discord Bot: Natural language document search and template requests
- ๐ Documenso Integration: Upload templates to Documenso for e-signature workflows
This system uses Google Gemini's multimodal capabilities to analyze PDFs visually, not just as text. This breakthrough allows it to:
- โ Find hidden signers: Detects signatures that appear visual but aren't in the text layer
- โ Extract complete metadata: Names, addresses, emails, contract values, dates
- โ Handle complex legal docs: SAFE agreements, employment contracts, investment documents
- โ Process annotations: Stamps, form fields, electronic signatures
Example Success: On test document NMM.pdf, traditional extraction found only 1 signer (Dan Shipper), but Gemini finds both signers (Dan Shipper + Nashilu Mouen) with complete contact information.
The enhanced memory system captures comprehensive information from documents and aggregates it into searchable markdown files, now with Claude Code autonomous search capabilities:
- Company Information: EIN, addresses, formation details, milestones
- People Directory: Employees, contractors, advisors, investors with contact info
- Financial Summary: Total capital raised, investment rounds, SAFE agreements, financial impact analysis
- Revenue & Sales: Customer contracts, revenue streams, business context, payment terms, obligations
- Contracts Summary: Active contracts, expiring soon, business context, key provisions, obligations
- Key Dates: Contract expirations, renewal deadlines, vesting schedules
The system now extracts and preserves:
- Business Context: 3-5 sentence narratives explaining strategic importance and implications
- Key Terms: 5-15 most important contractual provisions and conditions
- Obligations: All specific deliverables, milestones, and requirements
- Financial Terms: Payment schedules, pricing models, revenue shares, minimum commitments
- Critical Facts: Document-specific information like EIN numbers, policy numbers, addresses
When you ask a question, Claude Code:
- Searches memory files for quick answers
- Identifies information gaps and what's still needed
- Reads full documents to extract missing details
- Continues searching until it finds complete answers
- Provides comprehensive responses with source citations
Example: "How much has Austin Rief invested?" โ Claude finds the amount in memory, then reads the full SAFE agreement to extract valuation cap, discount rate, and other terms.
Memory files are automatically updated when new documents are added and enable instant detailed answers via Discord.
The system automatically identifies template documents using intelligent pattern matching:
- High Confidence: Documents with [BLANK], [FORM], (Form), or Template in filename
- Medium Confidence: Generic documents without specific party names
- Smart Exclusion: Won't mark EXECUTED or signed documents as templates
When you upload a template file to Discord, Para automatically detects it and offers to upload it to Documenso for e-signature workflows. Just reply "yes" to upload!
When a template is detected and Documenso is configured, the system will:
- Prompt you to upload the template to Documenso
- Upload the document if you confirm
- Return a configuration link to set up signature fields
- Update metadata with Documenso document ID and URL
Example prompt:
๐ฏ Template Document Detected!
๐ File: Employment Agreement [FORM].pdf
๐ Type: Employment Agreement
๐ท๏ธ Category: People_and_Employment
๐ Confidence: HIGH
๐ค Would you like to upload this template to Documenso for configuration? (yes/no): yes
๐ค Uploading template to Documenso...
โ
Template uploaded successfully!
๐ Configure your template here:
https://app.documenso.com/documents/12345/convert-to-template
๐ Document ID: 12345
๐ก Tip: Add signature fields, text fields, and other elements in the Documenso interface.
Templates are:
- Automatically categorized with status: "template"
- Organized into the 09_Templates folder
- Searchable via Discord with natural language
- Tagged with metadata including placeholders and use cases
- Clone or download this project
- Install dependencies:
npm install
- Set up your API keys:
cp .env.example .env # Edit .env and add your API keys
Edit the .env file to configure:
# Required for document classification
OPENAI_API_KEY=your_openai_api_key_here
# Required for advanced PDF extraction
GEMINI_API_KEY=your_gemini_api_key_here
# Optional for Discord bot
DISCORD_BOT_TOKEN=your_discord_bot_token_here
ORGANIZE_FOLDER_PATH=/path/to/your/documents
# Optional for Documenso integration
DOCUMENSO_API_URL=https://api.documenso.com
DOCUMENSO_API_TOKEN=your_documenso_api_token_here
DOCUMENSO_APP_URL=https://app.documenso.com
# Optional for Claude Code enhanced search
ANTHROPIC_API_KEY=your_anthropic_api_key_here
CLAUDE_CODE_MAX_ITERATIONS=10# Development mode
npm run dev
# Production mode
npm run build
npm start# Refresh memory files from all documents
npm run refresh-memoryThe memory system creates pre-indexed markdown files that enable instant answers to questions like:
- "What is our EIN number?"
- "How much revenue do we have?"
- "Who are our investors?"
- "What contracts expire this month?"
- "Who are our key partners?"
npm run discordThe Discord bot uses a thread-based conversation model:
- Activation: Bot only responds when @mentioned (e.g.,
@para help) - Thread Creation: Automatically creates a thread from your message
- Continued Conversation: In threads, no @ mention needed - just type naturally
- Auto-Archive: Threads archive after 24 hours of inactivity
- Clean Channels: Keeps main channels clutter-free
- "Show me all templates"
- "I need an employment agreement template"
- "Find SAFE template"
- "Get me a blank NDA"
- Upload files with
@para organize thisto start a thread - Bot processes files and responds with organization details in thread
- Multiple files are handled with progress updates
- "Upload this template to Documenso"
- "Show templates not in Documenso"
- "Upload employment agreement to Documenso"
- "Get Documenso link for NDA template"
# Test Gemini multimodal extraction
npx ts-node test-gemini.ts
# Test simplified workflow
npx ts-node test-simplified-workflow.ts
# Test production workflow
npx ts-node test-production-workflow.ts
# Test template identification
npx ts-node test-template-prompt.ts
npx ts-node test-mnda-form.ts
# Test enhanced information capture
npx ts-node test-enhanced-information-capture.ts <path-to-document>The enhanced information capture test will show:
- All extracted metadata fields including business context
- Key terms and obligations found in the document
- Financial terms and critical facts
- Which memory files were updated with the information
The organizer creates a structured folder system based on business functions:
- 01_Corporate_and_Governance - Formation, governance, board documents
- 02_People_and_Employment - Employment agreements, consulting, equity
- 03_Finance_and_Investment - Investment documents, banking, tax
- 04_Sales_and_Revenue - Customer agreements, sales contracts
- 05_Operations_and_Vendors - Vendor agreements, supplier contracts
- 06_Technology_and_IP - Patents, licenses, development agreements
- 07_Marketing_and_Partnerships - Partnership agreements, marketing
- 08_Risk_and_Compliance - Regulatory compliance, litigation
- 09_Templates - Document templates and forms
- 10_Archive - Expired or terminated documents
- Multimodal Analysis: Gemini analyzes the entire PDF including visual elements
- Signature Detection: Finds both company and individual signatures
- Metadata Extraction: Extracts names, dates, addresses, contract values
- Form Field Analysis: Reads filled form fields that appear blank in text
- AI Analysis: GPT-4o analyzes document content for classification
- Category Assignment: Determines primary folder and subfolder
- Confidence Scoring: Provides classification confidence levels
- File Detection: System detects new or existing files
- Content Extraction: Uses appropriate extraction method (Gemini for PDFs)
- AI Classification: Determines document category and destination
- File Movement: Moves files to organized folder structure
- Metadata Generation: Creates companion .metadata.json files
- Continuous Monitoring: Watches for new files
- PDF: Advanced Gemini multimodal extraction
- DOCX: Microsoft Word documents
- DOC: Legacy Word documents
- TXT: Plain text files
If using the optional web server:
- Health Check:
GET /health - Google Auth:
GET /auth/google - Organizations:
GET /organizations - Documents:
GET /documents
Each organized document gets a companion .metadata.json file with:
{
"filename": "document.pdf",
"status": "executed",
"category": "Investment_Fundraising",
"signers": [
{"name": "Dan Shipper", "date_signed": "2023-06-15"},
{"name": "Nashilu Mouen", "date_signed": "2023-06-15"}
],
"primary_parties": [...],
"effective_date": "2023-06-15",
"contract_value": "$50000",
"governing_law": "Delaware",
"template_analysis": {
"is_template": false,
"confidence": "HIGH",
"indicators": ["specific party names", "executed"]
}
}For templates:
{
"filename": "Employment Agreement [BLANK].pdf",
"status": "template",
"template_analysis": {
"is_template": true,
"confidence": "HIGH",
"indicators": ["[BLANK] in filename"],
"template_type": "Employment Agreement",
"field_placeholders": ["[EMPLOYEE NAME]", "[START DATE]", "[SALARY]"],
"typical_use_case": "Standard employment agreement for new hires"
}
}cd para/
./start.sh # Starts all services
overmind ps # View running processes- Missing API Keys: Graceful degradation with warnings
- Unsupported Files: Moved to default folder with error logging
- Large Files: Files >50MB ignored during monitoring
- Duplicate Names: Auto-resolved with counter suffixes
- System Files: Automatically ignored (.DS_Store, temp files)
The project includes comprehensive test scripts:
test-gemini.ts- Test Gemini PDF extractiontest-simplified-workflow.ts- Test streamlined processingtest-production-workflow.ts- Test full production pipeline
- Node.js 16+
- OpenAI API key (for document classification)
- Google Gemini API key (for advanced PDF extraction)
- Discord Bot Token (optional, for Discord integration)
Legal Document Organizer
โโโ Core Services
โ โโโ GeminiPdfService (multimodal PDF extraction)
โ โโโ FileReaderService (file content extraction)
โ โโโ MetadataService (metadata generation)
โ โโโ DocumentClassifierService (AI classification)
โ โโโ FileOrganizerService (file organization)
โโโ Monitoring
โ โโโ FileMonitorService (real-time file watching)
โโโ Integrations
โ โโโ DiscordBotService (Discord bot interface)
โโโ Utilities
โโโ CLIUtils (command-line interface)
This project demonstrates advanced AI integration for legal document processing. Feel free to extend it with additional features or file formats.
MIT License