A Next.js application that allows users to upload HR documents and query them using natural language.
✅ Update: The application now uses Vercel Blob Storage for storing uploaded files. This makes it compatible with Vercel's read-only filesystem and provides a scalable solution for file storage.
Key changes:
- Files are uploaded to Vercel Blob Storage
- File URLs are stored in the PostgreSQL database
- Document processing fetches files from Blob Storage when needed
- Vector embeddings are stored in the database for efficient searching
BLOB_READ_WRITE_TOKEN to your environment variables:
-
Create a Blob Store in your Vercel dashboard:
- Go to your Vercel dashboard
- Select your project
- Go to Storage > Blob
- Click "Create Blob Store"
-
Add the
BLOB_READ_WRITE_TOKENto your environment variables:BLOB_READ_WRITE_TOKEN="your-vercel-blob-read-write-token"
.env file to use a PostgreSQL database:
DATABASE_URL="postgresql://username:password@hostname:port/database"
If you prefer to use cloud storage instead of database storage for large files:
- Sign up for a cloud storage service (AWS S3, Google Cloud Storage, etc.)
- Update the file upload API route to upload files to the cloud storage
- Update the file deletion logic to delete files from the cloud storage
- Update the document processor to read files from the cloud storage
- PDF Upload: Securely upload PDF documents through a user-friendly interface
- Document Processing: Extract and index text from PDF documents
- Natural Language Queries: Ask questions about your documents and get accurate answers
- Document Management: View and manage your uploaded documents
- User Authentication: Secure access with NextAuth.js
- Frontend: Next.js, React, TailwindCSS
- PDF Processing: PDF.js
- Vector Database: PostgreSQL with vector storage for efficient similarity search
- AI: Google's Gemini model for generating responses and embeddings
- Authentication: NextAuth.js with Prisma adapter
- Database: PostgreSQL (both development and production)
- Node.js 18.x or higher
- npm or yarn
- Google API key for Gemini
-
Clone the repository:
git clone https://github.com/yourusername/hr-bot.git cd hr-bot -
Install dependencies:
npm install
-
Set up environment variables:
- Copy
.env.exampleto.env.localand fill in the values
cp .env.example .env.local
- Copy
-
Initialize the database:
npx prisma migrate dev
-
Start the development server:
npm run dev
-
Open http://localhost:3000 in your browser to see the application.
The application uses SQLite by default, which is not suitable for production deployments on Vercel. For production, you need to use a PostgreSQL database:
- Create a PostgreSQL database using Vercel Postgres, Supabase, Railway, or any other PostgreSQL provider.
- Get your PostgreSQL connection string.
Before deploying, update your Prisma schema to use PostgreSQL:
- Open
prisma/schema.prisma - Change the database provider from
sqlitetopostgresql:datasource db { provider = "postgresql" url = env("DATABASE_URL") }
- Commit and push these changes to your repository.
- Push your code to GitHub
- Create a new project in Vercel and link it to your GitHub repository
- Set up the following environment variables in Vercel:
DATABASE_URL: Your PostgreSQL connection stringNEXTAUTH_SECRET: A secure random string for NextAuth.jsNEXTAUTH_URL: Your production URL (e.g.,https://your-app.vercel.app)GOOGLE_API_KEY: Your Google API key for Gemini AIGEMINI_API_KEY: Your Gemini API key (if different from GOOGLE_API_KEY)- OAuth provider credentials if you're using social login
- Deploy the application
After deploying, you need to run migrations on your production database:
- Install Vercel CLI:
npm install -g vercel
- Link your local project to the Vercel project:
vercel link
- Pull the environment variables:
vercel env pull .env.production
- Run the migrations:
npx prisma migrate deploy
- Upload Documents: Navigate to the Upload page to upload PDF documents.
- Query Documents: Once documents are processed, go to the Query page to ask questions.
- Manage Documents: View and manage your uploaded documents on the Documents page.
- The application stores uploaded documents directly in the database as binary data.
- Document processing happens on the server, and the extracted text is stored in the database.
- Authentication is implemented using NextAuth.js.
If you encounter issues with Prisma during deployment:
-
Make sure the
postinstallscript is in yourpackage.json:"postinstall": "prisma generate"
-
Make sure the
buildscript includes Prisma generation:"build": "prisma generate && next build"
-
Check that your environment variables are correctly set in Vercel.
-
If you're seeing the error "Prisma has detected that this project was built on Vercel, which caches dependencies", make sure you have both the
postinstallscript and the updatedbuildscript. -
If you're having issues with file uploads, remember that Vercel's filesystem is read-only in production. You'll need to use a cloud storage solution like AWS S3, Google Cloud Storage, or similar for storing uploaded files.
This project is licensed under the MIT License - see the LICENSE file for details.