Skip to content

Local Development

harshcode1 edited this page Jun 20, 2026 · 3 revisions

Local Development

Prerequisites

  • Node.js 18+
  • A MongoDB instance (local mongod or a free MongoDB Atlas cluster)
  • (Optional) an OpenAI API key for live AI chat
  • (Optional) Google OAuth credentials for Calendar sync

Setup

git clone https://github.com/harshcode1/BetterMind.git
cd BetterMind
npm install
cp .env.example .env.local   # create and fill in (see below)
npm run dev

App runs at http://localhost:3000. The fastest way to see everything is the “Explore as Guest” button — no DB writes required (see Guest-Mode).

Environment variables

# ── Required ───────────────────────────────
MONGODB_URI=mongodb://localhost:27017/bettermind
JWT_SECRET=a_long_random_string
ENCRYPTION_KEY=a_32_byte_key_for_aes

# ── Optional (features degrade gracefully) ──
OPENAI_API_KEY=sk-...                 # AI chat → keyword fallback if absent
GOOGLE_CLIENT_ID=...                  # Calendar sync
GOOGLE_CLIENT_SECRET=...
GOOGLE_REDIRECT_URI=http://localhost:3000/api/auth/google/callback

The MongoDB URI check is deferred to request time, so the app boots even if some optional vars are missing — handy for UI-only work.

Scripts

Command Purpose
npm run dev Start the dev server (hot reload)
npm run build Production build (also runs lint/type checks)
npm run start Serve the production build
npm run lint ESLint

Creating test accounts

  1. Patient — sign up at /signup.
  2. Doctor — sign up at /signup/doctor (lands as pending verification).
  3. Admin — set a user's role to admin directly in MongoDB, then visit /admin/dashboard to approve the doctor.

Verifying key flows

Flow How
2FA /settings/security → enable → scan QR in an authenticator app → confirm → log out → log back in and complete the challenge
AI chat Set OPENAI_API_KEY, open /chat, send a message (without the key you'll get the keyword fallback)
Calendar sync Configure Google OAuth, connect on /appointments, book an appointment, confirm the event appears
Reviews Complete an appointment, leave a review, confirm the doctor's averageRating updates
Rate limiting Hit /api/auth/register or /api/chat rapidly → expect HTTP 429

Troubleshooting

Symptom Fix
Port 3000 in use Stop the other process or run next dev -p 3001
MONGODB_URI errors at request time Ensure Mongo is running and the URI is correct
AI replies look like canned keyword matches OPENAI_API_KEY is missing/invalid — that's the intended fallback
Build warnings about react-hooks/exhaustive-deps Non-blocking; pre-existing intentional effect deps

Related

Clone this wiki locally