Skip to main content

Prerequisites

Before you begin, ensure you have the following installed on your machine:
  • Node.js (v18 or higher)
  • npm, yarn, or bun package manager
  • Git

Installation

1

Clone the repository

Clone the PDF AI repository to your local machine:
git clone https://github.com/Srijan-D/pdf.ai
cd pdf.ai
2

Install dependencies

Install the required dependencies using your preferred package manager:
npm install
The project includes these key dependencies:
  • Next.js 13.5.6 (React framework)
  • Clerk for authentication
  • Pinecone for vector database
  • OpenAI for AI capabilities
  • Stripe for payments
  • AWS SDK for S3 storage
  • Drizzle ORM with Neon database
3

Configure environment variables

Set up your environment variables by creating a .env file in the root directory. See the Environment Variables page for detailed configuration.
touch .env
Add all required API keys and configuration values to this file.
4

Set up the database

Run the database migrations using Drizzle Kit:
npx drizzle-kit push
This will create the necessary tables in your Neon database.
5

Start the development server

Start the local development server:
npm run dev
The application will be available at http://localhost:3000.
The dev script uses cross-env NODE_OPTIONS=--max-old-space-size=8192 to allocate 8GB of memory to Node.js, which is necessary for processing large PDFs.

Development Scripts

The following npm scripts are available:
ScriptCommandDescription
devnpm run devStarts the development server with increased memory allocation
buildnpm run buildCreates an optimized production build
startnpm startRuns the production build locally
lintnpm run lintRuns ESLint to check code quality

Project Structure

pdf.ai/
├── src/
│   ├── app/              # Next.js App Router pages
│   │   └── api/          # API routes
│   │       ├── chat/     # Chat endpoint
│   │       ├── stripe/   # Stripe integration
│   │       └── webhook/  # Webhook handlers
│   ├── components/       # React components
│   ├── lib/              # Utility libraries
│   │   ├── db/           # Database schema and config
│   │   ├── embeddings.ts # OpenAI embeddings
│   │   ├── pinecone.ts   # Pinecone vector DB
│   │   ├── s3.ts         # AWS S3 client
│   │   ├── stripe.ts     # Stripe client
│   │   └── context.ts    # Context retrieval
│   └── middleware.ts     # Clerk authentication
├── drizzle.config.ts     # Drizzle ORM configuration
├── next.config.js        # Next.js configuration
└── package.json          # Project dependencies

Troubleshooting

Memory Issues

If you encounter memory errors during development, the project already includes increased memory allocation in the dev script. If you still face issues, you can increase it further:
cross-env NODE_OPTIONS=--max-old-space-size=16384 next dev

Database Connection

If you have issues connecting to the database:
  1. Verify your DATABASE_URL is correctly set in .env
  2. Ensure your Neon database is accessible
  3. Check that you’ve run the Drizzle migrations

API Key Errors

If you see authentication or API errors:
  1. Double-check all API keys are correctly set in .env
  2. Ensure there are no extra spaces or quotes around the values
  3. Restart the development server after changing environment variables
The application works perfectly in local development but may have issues when deployed. See the Deployment page for known issues and workarounds.

Build docs developers (and LLMs) love