# Install / run locally

## 1. Stuff you need

**Node 18+** and npm (`node -v`, `npm -v`).

**Git** if cloning, or just unzip the project.

**Supabase project** (or any Postgres that matches the schema): URL, anon key, service role key, DB connection string from the dashboard.

## 2. Get the code

```bash
git clone <repo-url>
cd Pantry-System-App
```

Or unzip so you have this folder with `frontend/`, `backend/`, `Database/`, etc.

## 3. Dependencies

From repo root (where root `package.json` is):

```bash
npm run install:all
```

Or:

```bash
npm install && cd frontend && npm install && cd ../backend && npm install && cd ..
```

## 4. Env files

Don't commit `.env`.

**backend/.env** — copy from `backend/.env.example`:

| Var | What |
|-----|------|
| SUPABASE_URL | project URL |
| SUPABASE_ANON_KEY | anon key |
| SUPABASE_SERVICE_ROLE_KEY | service role (server only) |
| DATABASE_URL | Postgres URL (pooler is fine) |

Optional: `PORT`, `NODE_ENV`, `FRONTEND_URL` (prod CORS).

**frontend/.env** — copy from `frontend/.env.example`:

| Var | What |
|-----|------|
| VITE_SUPABASE_URL | same project |
| VITE_SUPABASE_ANON_KEY | anon key |
| VITE_API_URL | e.g. `http://localhost:5000/api` |

## 5. Database

Paste `Database/database.sql` into Supabase SQL editor and run, or:

```bash
psql "$DATABASE_URL" -f Database/database.sql
```

More detail: `Database/README.txt`.

**Optional test users:** `SUPABASE_SERVICE_ROLE_KEY` must be set, then from `backend/`:

```bash
npm run db:seed
```

Check terminal for demo emails/passwords.

## 6. Dev servers

Root:

```bash
npm run dev
```

Frontend: http://localhost:3000  
API: http://localhost:5000  

Or two terminals: `cd backend && npm run dev` and `cd frontend && npm run dev`.

### Screenshots (running locally)

Example dashboards after sign-in (paths relative to repo root):

![User dashboard](screenshots/userDash.png)

![Team (volunteer) dashboard](screenshots/teamDash.png)

![Admin dashboard](screenshots/adminDash.png)

## 7. Production build (optional)

```bash
npm run build
```

Ship `frontend` dist + run `backend` with `NODE_ENV=production`, set `FRONTEND_URL`, real `DATABASE_URL`.

## 8. When things break

| Problem | Check |
|---------|--------|
| Missing Supabase env (frontend) | `frontend/.env` + restart Vite |
| 401 / auth weird | Same Supabase project on client + server |
| DB connect fail | `DATABASE_URL`, firewall / SSL |
| CORS in prod | `FRONTEND_URL` + `NODE_ENV=production` |
