A production-ready legal document scanner and summarizer built with Next.js 14. Scan, OCR, and analyze legal documents with AI-powered insights.
- Document Capture: Use Scanbot SDK for high-quality document scanning with auto-detection
- OCR Processing: Google Document AI or AWS Textract (configurable via environment)
- AI Summarization: Claude-powered analysis extracting parties, dates, obligations, and risks
- Redaction UI: Click-to-redact interface with AI-suggested sensitive data detection
- GDPR Compliant: On-device mode option to skip server uploads
- Framework: Next.js 14 (App Router)
- Language: TypeScript
- Styling: TailwindCSS with custom color palette
- OCR: Google Document AI / AWS Textract
- LLM: Anthropic Claude
- Scanner: Scanbot Web SDK
| Name | Hex | Usage |
|---|---|---|
| Floral White | #fffcf2 |
Background |
| Silver | #ccc5b9 |
Surface, borders |
| Charcoal Brown | #403d39 |
Secondary text |
| Carbon Black | #252422 |
Primary text |
| Spicy Paprika | #eb5e28 |
Primary accent |
npm installCopy the example environment file:
cp .env.example .env.localEdit .env.local and add your credentials:
- Create a Google Cloud project
- Enable Document AI API
- Create a processor (Document OCR or Form Parser)
- Create a service account with Document AI User role
- Download the service account key JSON
GOOGLE_APPLICATION_CREDENTIALS=/path/to/service-account-key.json
GOOGLE_CLOUD_PROJECT_ID=your-project-id
GOOGLE_CLOUD_LOCATION=us
GOOGLE_DOCUMENT_AI_PROCESSOR_ID=your-processor-idOCR_PROVIDER=aws
AWS_ACCESS_KEY_ID=your-access-key
AWS_SECRET_ACCESS_KEY=your-secret-key
AWS_REGION=us-east-1Get your API key from console.anthropic.com
ANTHROPIC_API_KEY=your-api-keyGet your license key from scanbot.io
NEXT_PUBLIC_SCANBOT_LICENSE_KEY=your-license-keynpm run devnpm testTests the full OCR → Summarization pipeline:
# With mock LLM (no API key needed)
SKIP_LLM=true npm run test:pipeline
# Full pipeline (requires API keys)
npm run test:pipelineSet SKIP_LLM=true to use mock responses for development:
SKIP_LLM=trueProcess a document with OCR.
Request:
{
"document": "base64-encoded-document",
"filename": "document.pdf",
"mimeType": "application/pdf"
}Response:
{
"meta": {
"filename": "document.pdf",
"pages": 1,
"provider": "google-document-ai",
"processedAt": "2024-01-01T00:00:00.000Z"
},
"ocr": [{
"page": 1,
"text": "extracted text...",
"blocks": [...],
"entities": [...],
"confidence": 0.95
}]
}Analyze OCR results with AI.
Request:
{
"ocr_result": { /* OCR response */ },
"user_instructions": "Focus on payment terms"
}Response:
{
"short_summary": "...",
"parties": [...],
"important_dates": [...],
"obligations": [...],
"payment_terms": "...",
"termination_clauses": "...",
"governing_law": "...",
"risk_flags": [...],
"suggested_redactions": [...],
"confidence_score": 0.85
}lawscanner/
├── app/
│ ├── api/
│ │ ├── ocr/route.ts # OCR processing endpoint
│ │ └── summarize/route.ts # AI summarization endpoint
│ ├── globals.css # Global styles
│ ├── layout.tsx # Root layout
│ └── page.tsx # Main dashboard
├── components/
│ ├── ui/
│ │ ├── Button.tsx # Button component
│ │ ├── Card.tsx # Card component
│ │ └── index.ts # UI exports
│ ├── CaptureScanner.tsx # Scanbot integration
│ └── DocumentReview.tsx # Summary & redaction UI
├── scripts/
│ └── test-pipeline.ts # Integration test
├── __tests__/
│ └── utils/
│ ├── ocr-parser.test.ts # OCR validation tests
│ └── llm-output.test.ts # LLM output tests
├── .env.example # Environment template
├── tailwind.config.ts # Tailwind configuration
└── README.md
Enable "On-device only mode" in the UI to prevent document uploads to the server. In this mode:
- Documents are processed locally only
- Scanner captures stay on the device
- No data leaves the user's browser
By default, LawScanner does not store any documents. Configure retention if needed:
DOCUMENT_RETENTION_DAYS=0 # 0 = no retentionEnable audit logging for compliance:
ENABLE_AUDIT_LOG=true- Right to Access: Export all processed data via the Export button
- Right to Erasure: Documents are not stored by default
- Data Portability: Export in JSON format
- API Keys: Never commit API keys. Use environment variables.
- Document Storage: By default, documents are processed in memory only.
- Redaction: Redacted PDFs flatten redactions permanently (black rectangles).
- TLS: Always use HTTPS in production.
- Push to GitHub
- Import in Vercel
- Add environment variables in Vercel dashboard
- Deploy
FROM node:20-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build
EXPOSE 3000
CMD ["npm", "start"]Ensure all required environment variables are set:
GOOGLE_CLOUD_PROJECT_ID(or AWS credentials)ANTHROPIC_API_KEYNEXT_PUBLIC_SCANBOT_LICENSE_KEY
- Check file format (PDF, PNG, JPG, TIFF supported)
- Verify image quality (minimum 300 DPI recommended)
- Check OCR provider credentials
- Verify
ANTHROPIC_API_KEYis set - Check API rate limits
- Use
SKIP_LLM=truefor mock responses during development
- Verify Scanbot license key
- Check browser camera permissions
- Use HTTPS (required for camera access)
- Validate bounding box calculations
- Test entity extraction for different document types
- Verify confidence score normalization
- Validate JSON structure
- Test LOW_CONFIDENCE handling
- Verify risk score categorization
- Test redaction position validation
- End-to-end pipeline with sample documents
- Error handling for invalid inputs
- Rate limiting behavior
- Fork the repository
- Create a feature branch
- Add tests for new functionality
- Submit a pull request
MIT
For issues and feature requests, please open a GitHub issue.