A Next.js application that uses advanced AI technology to analyze, interpret, and extract insights from professional documents. Features employee/employer authentication, document upload and management, AI-powered chat, and comprehensive predictive document analysis that identifies missing documents, provides recommendations, and suggests related content.
- Missing Document Detection: AI automatically identifies critical documents that should be present but are missing
- Priority Assessment: Categorizes missing documents by priority (high, medium, low) for efficient workflow management
- Smart Recommendations: Provides actionable recommendations for document organization and compliance
- Related Document Suggestions: Suggests relevant external resources and related documents
- Page-Level Analysis: Pinpoints specific pages where missing documents are referenced
- Real-time Analysis: Instant analysis with caching for improved performance
- Comprehensive Reporting: Detailed breakdown of analysis results with actionable insights
- Advanced AI algorithms analyze documents and extract key information
- AI-Powered Chat: Interactive chat interface for document-specific questions and insights
- Role-Based Authentication: Separate interfaces for employees and employers using Clerk
- Document Management: Upload, organize, and manage documents with category support
- Employee Management: Employer dashboard for managing employee access and approvals
- Real-time Chat History: Persistent chat sessions for each document
- Responsive Design: Modern UI with Tailwind CSS
The Predictive Document Analysis feature is the cornerstone of PDR AI, providing intelligent document management and compliance assistance:
- Document Upload: Upload your professional documents (PDFs, contracts, manuals, etc.)
- AI Analysis: Our advanced AI scans through the document content and structure
- Missing Document Detection: Identifies references to documents that should be present but aren't
- Priority Classification: Automatically categorizes findings by importance and urgency
- Smart Recommendations: Provides specific, actionable recommendations for document management
- Related Content: Suggests relevant external resources and related documents
- Compliance Assurance: Never miss critical documents required for compliance
- Workflow Optimization: Streamline document management with AI-powered insights
- Risk Mitigation: Identify potential gaps in documentation before they become issues
- Time Savings: Automated analysis saves hours of manual document review
- Proactive Management: Stay ahead of document requirements and deadlines
The system provides comprehensive analysis including:
- Missing Documents Count: Total number of missing documents identified
- High Priority Items: Critical documents requiring immediate attention
- Recommendations: Specific actions to improve document organization
- Suggested Related Documents: External resources and related content
- Page References: Exact page numbers where missing documents are mentioned
The predictive analysis feature automatically scans uploaded documents and provides comprehensive insights:
{
"success": true,
"documentId": 123,
"analysisType": "predictive",
"summary": {
"totalMissingDocuments": 5,
"highPriorityItems": 2,
"totalRecommendations": 3,
"totalSuggestedRelated": 4,
"analysisTimestamp": "2024-01-15T10:30:00Z"
},
"analysis": {
"missingDocuments": [
{
"documentName": "Employee Handbook",
"documentType": "Policy Document",
"reason": "Referenced in section 2.1 but not found in uploaded documents",
"page": 15,
"priority": "high",
"suggestedLinks": [
{
"title": "Sample Employee Handbook Template",
"link": "https://example.com/handbook-template",
"snippet": "Comprehensive employee handbook template..."
}
]
}
],
"recommendations": [
"Consider implementing a document version control system",
"Review document retention policies for compliance",
"Establish regular document audit procedures"
],
"suggestedRelatedDocuments": [
{
"title": "Document Management Best Practices",
"link": "https://example.com/best-practices",
"snippet": "Industry standards for document organization..."
}
]
}
}- Upload Documents: Use the employer dashboard to upload your documents
- Run Analysis: Click the "Predictive Analysis" tab in the document viewer
- Review Results: Examine missing documents, recommendations, and suggestions
- Take Action: Follow the provided recommendations and suggested links
- Track Progress: Re-run analysis to verify improvements
Ask questions about your documents and get AI-powered responses:
// Example API call for document Q&A
const response = await fetch('/api/LangChain', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
question: "What are the key compliance requirements mentioned?",
documentId: 123,
style: "professional" // or "casual", "technical", "summary"
})
});- Contract Management: Identify missing clauses, attachments, and referenced documents
- Regulatory Compliance: Ensure all required documentation is present and up-to-date
- Due Diligence: Comprehensive document review for mergers and acquisitions
- Risk Assessment: Identify potential legal risks from missing documentation
- Employee Documentation: Ensure all required employee documents are collected
- Policy Compliance: Verify policy documents are complete and current
- Onboarding Process: Streamline new employee documentation requirements
- Audit Preparation: Prepare for HR audits with confidence
- Financial Reporting: Ensure all supporting documents are included
- Audit Trail: Maintain complete documentation for financial audits
- Compliance Reporting: Meet regulatory requirements for document retention
- Process Documentation: Streamline financial process documentation
- Patient Records: Ensure complete patient documentation
- Regulatory Compliance: Meet healthcare documentation requirements
- Quality Assurance: Maintain high standards for medical documentation
- Risk Management: Identify potential documentation gaps
- Automated Analysis: Reduce manual document review time by 80%
- Instant Insights: Get immediate feedback on document completeness
- Proactive Management: Address issues before they become problems
- Compliance Assurance: Never miss critical required documents
- Error Prevention: Catch documentation gaps before they cause issues
- Audit Readiness: Always be prepared for regulatory audits
- Standardized Workflows: Establish consistent document management processes
- Quality Control: Maintain high standards for document organization
- Continuous Improvement: Use AI insights to optimize processes
- Document Review Time: 80% reduction in manual review time
- Compliance Risk: 95% reduction in missing document incidents
- Audit Preparation: 90% faster audit preparation time
- Process Efficiency: 70% improvement in document management workflows
- Framework: Next.js 15 with TypeScript
- Authentication: Clerk
- Database: PostgreSQL with Drizzle ORM
- AI Integration: OpenAI + LangChain
- File Upload: UploadThing
- Styling: Tailwind CSS
- Package Manager: pnpm
Before you begin, ensure you have the following installed:
- Node.js (version 18.0 or higher)
- pnpm (recommended) or npm
- Docker (for local database)
- Git
git clone <repository-url>
cd pdr_ai_v2-2pnpm installCreate a .env file in the root directory with the following variables:
# Database
DATABASE_URL="postgresql://postgres:password@localhost:5432/pdr_ai_v2"
# Clerk Authentication (get from https://clerk.com/)
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=your_clerk_publishable_key
CLERK_SECRET_KEY=your_clerk_secret_key
# OpenAI API (get from https://platform.openai.com/)
OPENAI_API_KEY=your_openai_api_key
# UploadThing (get from https://uploadthing.com/)
UPLOADTHING_SECRET=your_uploadthing_secret
UPLOADTHING_APP_ID=your_uploadthing_app_id
# Environment
NODE_ENV=development# Make the script executable
chmod +x start-database.sh
# Start the database container
./start-database.shThis will:
- Create a Docker container with PostgreSQL
- Set up the database with proper credentials
- Generate a secure password if using default settings
# Generate migration files
pnpm db:generate
# Apply migrations to database
pnpm db:migrate
# Alternative: Push schema directly (for development)
pnpm db:push- Create account at Clerk
- Create a new application
- Copy the publishable and secret keys to your
.envfile - Configure sign-in/sign-up methods as needed
- Create account at OpenAI
- Generate an API key
- Add the key to your
.envfile
- Create account at UploadThing
- Create a new app
- Copy the secret and app ID to your
.envfile
pnpm devThe application will be available at http://localhost:3000
# Build the application
pnpm build
# Start production server
pnpm start# Database management
pnpm db:studio # Open Drizzle Studio (database GUI)
pnpm db:generate # Generate new migrations
pnpm db:migrate # Apply migrations
pnpm db:push # Push schema changes directly
# Code quality
pnpm lint # Run ESLint
pnpm lint:fix # Fix ESLint issues
pnpm typecheck # Run TypeScript type checking
pnpm format:write # Format code with Prettier
pnpm format:check # Check code formatting
# Development
pnpm check # Run linting and type checking
pnpm preview # Build and start production previewsrc/
βββ app/ # Next.js App Router
β βββ api/ # API routes
β β βββ predictive-document-analysis/ # Predictive analysis endpoints
β β β βββ route.ts # Main analysis API
β β β βββ agent.ts # AI analysis agent
β β βββ LangChain/ # AI chat functionality
β β βββ ... # Other API endpoints
β βββ employee/ # Employee dashboard pages
β βββ employer/ # Employer dashboard pages
β β βββ documents/ # Document viewer with predictive analysis
β βββ signup/ # Authentication pages
β βββ _components/ # Shared components
βββ server/
β βββ db/ # Database configuration and schema
βββ styles/ # CSS modules and global styles
βββ env.js # Environment validation
Key directories:
- `/employee` - Employee interface for document viewing and chat
- `/employer` - Employer interface for management and uploads
- `/api/predictive-document-analysis` - Core predictive analysis functionality
- `/api` - Backend API endpoints for all functionality
- `/server/db` - Database schema and configuration
POST /api/predictive-document-analysis- Analyze documents for missing content and recommendationsGET /api/fetchDocument- Retrieve document content for analysisPOST /api/uploadDocument- Upload documents for processing
POST /api/LangChain- AI-powered document Q&AGET /api/Questions/fetch- Retrieve Q&A historyPOST /api/Questions/add- Add new questions
GET /api/fetchCompany- Get company documentsPOST /api/deleteDocument- Remove documentsGET /api/Categories/GetCategories- Get document categories
- View assigned documents
- Chat with AI about documents
- Access document analysis and insights
- Pending approval flow for new employees
- Upload and manage documents
- Manage employee access and approvals
- View analytics and statistics
- Configure document categories
- Employee management dashboard
| Variable | Description | Required |
|---|---|---|
DATABASE_URL |
PostgreSQL connection string | β |
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY |
Clerk publishable key | β |
CLERK_SECRET_KEY |
Clerk secret key | β |
OPENAI_API_KEY |
OpenAI API key for AI features | β |
UPLOADTHING_SECRET |
UploadThing secret for file uploads | β |
UPLOADTHING_APP_ID |
UploadThing application ID | β |
NODE_ENV |
Environment mode | β |
- Ensure Docker is running before starting the database
- Check if the database container is running:
docker ps - Restart the database:
docker restart pdr_ai_v2-postgres
- Verify all required environment variables are set
- Check
.envfile formatting (no spaces around=) - Ensure API keys are valid and have proper permissions
- Clear Next.js cache:
rm -rf .next - Reinstall dependencies:
rm -rf node_modules && pnpm install - Check TypeScript errors:
pnpm typecheck
- Fork the repository
- Create a feature branch:
git checkout -b feature-name - Make your changes
- Run tests and linting:
pnpm check - Commit your changes:
git commit -m 'Add feature' - Push to the branch:
git push origin feature-name - Submit a pull request
This project is private and proprietary.
For support or questions, contact the development team or create an issue in the repository.