# Harvest Market

Harvest Market is a local farmers-market marketplace that helps shoppers discover nearby vendors, browse seasonal products, place orders, and schedule pickup at participating markets. Vendors can manage inventory, pricing, pickup windows, and incoming orders from a simple dashboard.

## Features

- Browse products by market, vendor, category, and availability
- Search for produce, baked goods, dairy, meat, pantry items, and more
- View vendor profiles, growing practices, and pickup locations
- Add products from multiple vendors to a single cart
- Select an available market date and pickup window
- Place and track orders
- Receive order confirmation and pickup reminders
- Vendor dashboard for products, inventory, and order fulfillment
- Responsive interface for desktop and mobile devices

## Requirements

- Node.js 20 or later
- npm 10 or later
- PostgreSQL 15 or later

## Installation

Clone the repository and install dependencies:

```bash
git clone https://github.com/example/harvest-market.git
cd harvest-market
npm install
```

Create a local environment file:

```bash
cp .env.example .env
```

Create the database and run migrations:

```bash
createdb harvest_market
npm run db:migrate
npm run db:seed
```

Start the development server:

```bash
npm run dev
```

Open [http://localhost:3000](http://localhost:3000) in your browser.

## Usage

The seed command creates sample markets, vendors, products, and development accounts.

| Role | Email | Password |
| --- | --- | --- |
| Shopper | `shopper@example.com` | `password` |
| Vendor | `vendor@example.com` | `password` |

Shoppers can browse products without signing in. An account is required to place orders, view order history, and manage saved pickup details.

Vendors can sign in to:

1. Create and update product listings.
2. Set inventory for upcoming market dates.
3. Review new orders.
4. Mark orders as packed or collected.

Useful development commands:

```bash
npm run dev          # Start the development server
npm run build        # Create a production build
npm start            # Run the production server
npm test             # Run the test suite
npm run lint         # Check code style
npm run db:migrate   # Apply database migrations
npm run db:seed      # Load sample data
```

## Configuration

Harvest Market is configured with environment variables in `.env`.

```dotenv
NODE_ENV=development
PORT=3000
APP_URL=http://localhost:3000

DATABASE_URL=postgresql://localhost:5432/harvest_market
SESSION_SECRET=replace-with-a-long-random-value

PAYMENTS_PROVIDER=stripe
STRIPE_SECRET_KEY=
STRIPE_WEBHOOK_SECRET=

EMAIL_PROVIDER=console
EMAIL_FROM=orders@harvestmarket.local
SMTP_HOST=
SMTP_PORT=587
SMTP_USER=
SMTP_PASSWORD=

DEFAULT_CURRENCY=CAD
DEFAULT_TIMEZONE=America/Toronto
ORDER_CUTOFF_HOURS=18
```

### Required settings

- `DATABASE_URL`: PostgreSQL connection string.
- `SESSION_SECRET`: Secret used to sign authentication sessions. Use a unique, randomly generated value in production.
- `APP_URL`: Public application URL used for links and redirects.

### Payments

Set `PAYMENTS_PROVIDER=stripe` and provide valid Stripe keys to accept online payments. For local development without payment processing, use:

```dotenv
PAYMENTS_PROVIDER=mock
```

Never use the mock provider in production.

### Email

The default `console` provider prints outgoing messages to the server log. To send email through SMTP, set `EMAIL_PROVIDER=smtp` and configure the related SMTP variables.

### Market rules

- `DEFAULT_CURRENCY` controls displayed and charged currency.
- `DEFAULT_TIMEZONE` is used for market dates, pickup windows, and order deadlines.
- `ORDER_CUTOFF_HOURS` sets how many hours before a market opens that ordering closes.

Restart the application after changing environment variables. Do not commit `.env` files or production credentials to source control.