Intelligent Document Auto-Fill System
LexiFill is a modern web application that streamlines the process of filling out legal documents and templates. Upload any document with placeholders, and LexiFill will intelligently extract them, create a user-friendly form, and generate a completed document ready for use.
-
Smart Placeholder Detection - Automatically identifies placeholders in multiple formats:
[PLACEHOLDER]- Standard bracket format β{{PLACEHOLDER}}- Double curly brace format β$[_______]- Currency placeholders (partial support)β οΈ _____________- Underscore/blank line format (No support yet)
-
AI-Powered Analysis - Uses Google Gemini AI to:
- Generate conversational questions for each placeholder
- Determine the appropriate input type (text, date, currency)
- Provide contextual hints based on surrounding text
- Prioritize fields intelligently
-
Interactive Form Builder - Creates dynamic forms with:
- Text inputs for names and addresses
- Date pickers for dates
- Currency inputs with proper formatting
- Contextual hints for each field
-
Document Preview - Real-time preview of your filled document
-
AI Chat Assistant - Interactive chatbot that helps you:
- Understand complex legal terminology
- Get guidance on how to fill specific fields
- Ask questions about the document in natural language
- Receive contextual suggestions based on the document type
- Navigate through the form efficiently
-
Export Options - Download completed documents in various formats
- Node.js (v16 or higher)
- npm or yarn
- Google Gemini API key (optional - enhances analysis quality, but app works without it using pattern matching fallback)
- Clone the repository:
git clone https://github.com/Nisarg20/LexiFill.git
cd LexiFill- Install dependencies:
npm install
# or
yarn install- Create a
.envfile in the root directory:
VITE_GEMINI_API_KEY=your_gemini_api_key_here- Start the development server:
npm run dev
# or
yarn dev- Open your browser and navigate to
http://localhost:5173
- Visit Google AI Studio
- Click "Create API Key"
- Copy the generated key
- Add it to your
.envfile asVITE_GEMINI_API_KEY
Note: The application works in two modes:
- With API key: Gemini AI provides intelligent analysis, conversational questions, and context-aware hints
- Without API key: Falls back to pattern-based analysis using keyword matching (less sophisticated but functional)
- Click the upload area or drag and drop a
.docxfile - Supported formats: Word documents (.docx)
- LexiFill automatically extracts all placeholders
- Each placeholder is analyzed for context
- Fields are prioritized (company names first, then amounts, dates, etc.)
- Answer each question in the generated form
- Use the hints provided for guidance
- All fields are validated based on their type
- Need help? Click the chat icon to open the AI assistant
- Ask questions about specific fields
- Get explanations for legal terms
- Request examples or clarifications
- Click "Generate Document" when ready
- Preview the completed document
- Download your filled document
LexiFill follows a modern client-side architecture with AI integration:
- Document Upload β User uploads a .docx file through the FileUpload component
- Text Extraction β Mammoth.js extracts raw text content from the document
- Placeholder Detection β Custom regex patterns identify placeholders in various formats (REQUIRED step)
- Supports
[PLACEHOLDER],{{PLACEHOLDER}}, and$[_____]formats - Extracts paragraph context for each placeholder
- Supports
- AI Analysis (Optional with Fallback) β Google Gemini API analyzes detected placeholders to:
- Generate conversational questions for each placeholder
- Determine appropriate input types (text, date, currency)
- Extract contextual hints from surrounding text
- Prioritize fields based on importance
- Fallback: If no API key or AI fails, uses pattern-based analysis (keyword matching)
- Form Generation β PlaceholderForm component dynamically creates input fields
- User Input β User fills out the generated form with real values
- Document Generation β Original document is recreated with placeholders replaced
- Preview & Export β User can preview and download the completed document
App.tsx (Main Container)
βββ FileUpload.tsx
β βββ Handles document upload and initial extraction
βββ PlaceholderForm.tsx
β βββ Generates dynamic form fields
β βββ Validates user input
β βββ Manages form state
βββ DocumentPreview.tsx
β βββ Shows real-time preview of filled document
βββ ChatAssistant.tsx
βββ AI-powered conversational interface
βββ Helps users fill out complex forms
User Document
β
Mammoth.js (Extract Text)
β
Regex Patterns (Extract Placeholders) β ALWAYS RUNS
β
Found Placeholders with Context
β
βββ [Has API Key?]
β β YES
β Gemini AI Analysis
β β
β [Success?]
β β YES β NO
β Enhanced Metadata β Fallback
β Pattern
βββ [No API Key] β Fallback Matching
Pattern
Matching
β
Form Fields β User Input β Filled Document
Mode 1: AI-Powered (with Gemini API key)
- Gemini analyzes each placeholder with its paragraph context
- Generates natural, conversational questions
- Provides context-aware hints from surrounding text
- Intelligently determines field types and priorities
- Falls back to pattern matching if API call fails
Mode 2: Pattern Matching (without API key or as fallback)
- Uses keyword-based analysis (
determinePlaceholderType()) - Generates questions from placeholder text (
generateQuestion()) - Provides generic hints based on field type (
generateHint()) - Less sophisticated but fully functional
- React useState hooks manage component-level state
- Props drilling for sharing data between components
- No external state management library (Redux/Context) needed due to simple architecture
- React - UI framework
- TypeScript - Type-safe JavaScript
- Vite - Build tool and dev server
- Mammoth.js - Extract text from Word documents
- python-docx (planned) - Generate filled documents
- Regex Pattern Extraction - Primary placeholder detection using custom patterns (always runs)
- Google Gemini API - Optional AI-powered analysis for enhanced question generation and field typing
- Pattern-based Fallback - Keyword matching system when AI is unavailable
- CSS Modules - Scoped component styling
- Modern, responsive design
LexiFill/
βββ src/
β βββ components/
β β βββ FileUpload.tsx # Document upload component
β β βββ PlaceholderForm.tsx # Dynamic form generator
β β βββ DocumentPreview.tsx # Preview component
β β βββ ChatAssistant.tsx # AI chat helper
β βββ utils/
β β βββ extractPlaceholders.ts # Core extraction logic
β βββ App.tsx # Main application
β βββ main.tsx # Entry point
β βββ index.css # Global styles
βββ public/ # Static assets
βββ .env # Environment variables
βββ package.json # Dependencies
βββ tsconfig.json # TypeScript config
βββ vite.config.ts # Vite configuration
βββ README.md # This file
The repository includes sample legal documents for testing:
- NDA Template - Non-Disclosure Agreement with
[PLACEHOLDER]format - Employment Agreement - Uses
{{PLACEHOLDER}}format - Service Agreement - Contains underscore blanks
- Lease Agreement - Mixed format with checkboxes
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
- β Word Documents (.docx)
- β Templates with standard placeholders
- Gemini API key enhances analysis quality but is not required (falls back to pattern matching)
- Underscore placeholders (
_______) are not yet fully supported - Documents without any placeholders will show an error
- Some complex placeholder formats may need manual review
- Large documents (>100 pages) may take longer to process
- Pattern-based fallback provides basic analysis (less sophisticated than AI mode)
- All document processing happens in your browser
- No documents are stored on external servers
- API calls are made directly to Google's Gemini API
- Your data never touches our servers
- Legal Firms - Quickly fill out contracts, agreements, and legal documents
- HR Departments - Process employment agreements and onboarding documents
- Real Estate - Complete lease agreements and property documents
- Startups - Handle SAFE agreements, NDAs, and investor documents
- Individuals - Fill any template document efficiently