Welcome to the DoubtDesk local environment setup guide! DoubtDesk connects to several external services to power authentication, data storage, and AI inference.
To run the project locally, you must configure your .env file correctly. This guide will walk you through the setup order, what is strictly required, and how to verify your setup before starting the development server.
To avoid cascading errors, we highly recommend setting up your services in this specific order:
- Authentication (Clerk): The app middleware protects almost every route. If Clerk is not configured first, the application will immediately redirect you or crash on load.
- Database (Neon PostgreSQL): Once authenticated, the app will try to fetch your profile data from the database.
- AI Engine (Groq): Once the basic UI and data fetching work, you can configure Groq to enable the core AI solver features.
- Optional Services: Only set up Inngest (Background Jobs), Upstash (Rate Limiting), Resend (Emails), or Supabase (Storage) if you are actively working on those specific features.
You must populate these variables in your .env file, or the application will fail to start.
Create a free application at Clerk to get your API keys.
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY: Your publishable key (starts withpk_test_).CLERK_SECRET_KEY: Your secret key (starts withsk_test_).NEXT_PUBLIC_CLERK_SIGN_IN_URL&NEXT_PUBLIC_CLERK_SIGN_UP_URL: Set these to/sign-inand/sign-up.
Create a free serverless Postgres instance at Neon.
DATABASE_URL: Your connection string. Crucial: Ensure you append?sslmode=requireto the end of the URL.
Create a free API key at the Groq Console.
GROQ_API_KEY: Your Groq API key (starts withgsk_).
NEXT_PUBLIC_SITE_URL&NEXT_PUBLIC_APP_URL: Leave these ashttp://localhost:3000.UNSUBSCRIBE_SECRET: Generate a long, random alphanumeric string.
The local UI will run perfectly fine without these, but certain background/production features will be disabled or fail if triggered.
- Background Jobs (Inngest):
INNGEST_EVENT_KEY/INNGEST_SIGNING_KEY- What breaks: Asynchronous tasks and event-driven background jobs will not execute.
- Rate Limiting (Upstash Redis):
UPSTASH_REDIS_REST_URL/UPSTASH_REDIS_REST_TOKEN- What breaks: API rate limiting will be bypassed locally. (This is required for production).
- Email Delivery (Resend):
RESEND_API_KEY- What breaks: Transactional emails (like moderation warnings) will fail to send.
- File Storage (Supabase):
NEXT_PUBLIC_SUPABASE_URL/NEXT_PUBLIC_SUPABASE_ANON_KEY- What breaks: Image uploads for doubts will fail.
Before running npm run dev, verify your environment:
- I have copied
.env.exampleto.env. - My
DATABASE_URLends with?sslmode=require. - Both Clerk keys (
PUBLISHABLE_KEYandSECRET_KEY) are populated. -
GROQ_API_KEYis populated.
Once verified, start the server:
npm run devIf you encounter issues starting the application, check these common failures:
Error: Invalid URL or PrismaClientInitializationError
- Fix: Your
DATABASE_URLis malformed. Ensure there are no spaces, and you included?sslmode=require.
Error: Clerk: Missing secret key or Infinite Redirect Loops
- Fix: You are missing the
CLERK_SECRET_KEYor you accidentally put your publishable key in the secret key field.
Error: Groq API Error: 401 Unauthorized
- Fix: Your Groq API key is invalid or has been revoked. Ensure there are no trailing spaces in your
.envfile.
Error: Event payload missing (Inngest)
- Fix: You triggered a background job but haven't configured the Inngest optional variables.