# Hemp Farmers Marketplace

A scalable Express marketplace foundation for B2B hemp trade.

## What is included now

- Buyer, seller, and admin roles
- Login and signup
- Seller onboarding with license upload
- Role-based dashboards
- Listing creation with required COA upload
- Admin approval for users, listings, and documents
- Private inquiry and messaging flow
- Message moderation and anti-contact filtering
- Deal tracking with provider assignments
- Saved listings and sample requests
- SQLite database for local development and early deployment
- Email notification hooks using SMTP environment variables

## Tech stack

- Node.js
- Express
- EJS templates
- SQLite via `better-sqlite3`
- Prisma compatibility layer for cPanel deployments that still expect `config/prisma.js`
- File uploads with `multer`
- Session auth with `express-session`

## How to run locally

1. Open PowerShell and go to the project:

```powershell
cd C:\Users\hp\Documents\hemp-marketplace
```

2. Install packages:

```powershell
npm install
```

3. Start the app:

```powershell
npm run dev
```

4. Open:

```text
http://localhost:3000
```

## Seeded demo accounts

These are created automatically the first time the database starts:

- Admin: `admin@hempdemo.local` / `ChangeMe123!`
- Seller: `seller@hempdemo.local` / `ChangeMe123!`
- Buyer: `buyer@hempdemo.local` / `ChangeMe123!`

## Important folders

```text
hemp-marketplace/
|-- data/
|   |-- marketplace.db
|   `-- sessions/
|-- middleware/
|   |-- auth.js
|   `-- uploads.js
|-- public/
|   |-- styles.css
|   `-- uploads/
|-- services/
|   |-- db.js
|   |-- marketplace.js
|   `-- notifications.js
|-- views/
|   |-- admin/
|   |-- auth/
|   |-- buyer/
|   |-- categories/
|   |-- listings/
|   |-- seller/
|   `-- partials/
`-- server.js
`-- app.js
```

## Beginner reading order

If you want to learn this project without getting lost, read files in this order:

1. `server.js`
2. `services/db.js`
3. `services/marketplace.js`
4. `views/listings/show.ejs`
5. `views/seller/new-listing.ejs`
6. `views/admin/users.ejs`

## Environment variables

Optional for local use, recommended for deployment:

- `PORT`
- `SESSION_SECRET`
- `DATABASE_URL` with `file:./data/marketplace.db` or an absolute SQLite file path
- `SQLITE_DATABASE_PATH` if you prefer to point the SQLite runtime directly at a file path
- `SMTP_HOST`
- `SMTP_PORT`
- `SMTP_USER`
- `SMTP_PASS`
- `SMTP_FROM`
- `SMTP_SECURE`
- `SESSION_STORE` set to `file` if you want file-based session storage instead of the default in-memory local setup

## Namecheap deployment notes

Use cPanel's `Setup Node.js App` with:

- Application root: `/home/blacsthb/hemp-marketplace`
- Startup file: `app.js`

Recommended deployment commands inside that app root:

```bash
cd /home/blacsthb/hemp-marketplace
npm install
npx prisma generate
```

If you use cPanel environment variables, set at least:

- `NODE_ENV=production`
- `SESSION_SECRET=...`
- `DATABASE_URL=file:./data/marketplace.db`

This app's real runtime is `server.js`, but `app.js` is now the safe cPanel startup wrapper. That avoids stale startup files on shared hosting and keeps the current marketplace app booting correctly.

## Sensible next upgrades

- Move from SQLite to MySQL or PostgreSQL
- Add image uploads for listings
- Add audit logs for admin actions
- Add real notification emails with your SMTP account
- Add pagination and full-text search
- Add separate staff permissions
- Add deal milestones and payment tracking
- Add Stripe Connect onboarding and live payment webhooks

## Important note

Hemp regulations vary by country and region. This app is a software foundation only and does not replace licensing, compliance review, or legal advice.
