Skip to main content

Getting Started

Prerequisites

  • Node.js >= 18
  • pnpm (package manager)
  • Docker (for the local PostgreSQL database)

Setup

1. Clone and install

git clone https://github.com/JaydenThai/EMV3.1.git
cd EMV3.1
pnpm install

2. Environment variables

Create a .env file in the project root. Copy from .env.example and fill in the values:

cp .env.example .env

You'll need credentials for:

  • NextAuth (secret + Google OAuth)
  • Google Maps API key
  • Supabase (URL + anon key)
  • Upstash Redis (URL + token)
  • Sanity (project ID + dataset)
  • Resend (API key for magic link emails)
  • PostHog (API key)

Ask a team lead for the development environment values.

3. Database setup

Start a local PostgreSQL container with PostGIS:

./start-database.sh

This creates a Docker container with PostgreSQL + PostGIS. To clear your database, delete the container and re-run the script.

Push the schema to your local database:

pnpm db:migrate
warning

running pnpm run db:push does not work right now please use pnpm db:migrate

Optionally seed with test data:

pnpm db:seed

4. Run the dev server

pnpm dev

The app runs on http://localhost:3000 using Turbopack.

Available Commands

CommandDescription
pnpm devStart dev server (Turbopack)
pnpm buildProduction build
pnpm lintRun ESLint
pnpm formatFormat with Prettier
pnpm db:generateGenerate Drizzle migration files
pnpm db:migrateRun pending migrations
pnpm db:studioOpen Drizzle Studio (DB browser)
pnpm db:seedSeed database with test data

Database Workflow

  • Before merging: Clear the DB, run pnpm db:generate then pnpm db:migrate, and test the branch
  • Spatial data: The places table uses PostGIS geometry(point) with a GiST spatial index

Troubleshooting

Docker container won't start or port is already in use

Make sure Docker Desktop is running (check the menu bar icon on macOS). If you see a port conflict, stop any existing PostgreSQL instances:

docker ps
docker stop <container_id>

Then re-run ./start-database.sh.

pnpm db:push doesn't work

This command is currently broken. Use pnpm db:migrate instead to push schema changes to your local database.

When running pnpm db:migrate, you should see a tick as the last message saying something like:

  Migrations completed successfully
Missing environment variables or app crashes on startup

Make sure you've copied .env.example to .env and filled in all required values. Ask me (Jayden) or Shenbo for the development environment credentials if you don't have them.

Google OAuth not working locally

Verify your .env has the correct GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET. Also ensure that http://localhost:3000/api/auth/callback/google is listed as an authorized redirect URI in your Google Cloud Console project.

pnpm install fails or dependencies are out of sync

Try clearing the cache and reinstalling:

rm -rf node_modules
pnpm install

Make sure you're using the correct Node.js version (>= 18).