Skip to content
kavithasudhakar1Public

About

A farmer-to-customer marketplace with cart and checkout — built with Node.js, Express, and MongoDB, connecting local farmers directly to buyers with zero middlemen.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

FarmTrust

A farmer-to-customer marketplace: farmers list produce, customers browse, add items to a cart, and check out directly — no middlemen.

What's included

  • Express REST API — products, farmers, orders, messages
  • Shopping cart + checkout — real add-to-cart, quantity controls, and a checkout flow that creates a persisted order
  • Contact Farmer — buyers can message a farmer directly about a listing
  • Two data-layer options, same API either way:
    • db/jsonStore.js — a local JSON file (data/db.json). This is what runs by default, with zero setup.
    • db/mongoStore.js + models/*.js — real MongoDB via Mongoose, ready to switch on.

Run it locally

npm install
npm start

Visit http://localhost:3000 — the site, cart, and checkout all work immediately using the bundled JSON file as storage.

Switching to real MongoDB

  1. Get a connection string — the easiest way is a free MongoDB Atlas cluster.
  2. Create a .env file in the project root:
    MONGO_URI=mongodb+srv://<user>:<password>@<cluster-url>/farmtrust
    
  3. Restart the server. You'll see [db] Connected to MongoDB in the console — db/index.js automatically switches from the JSON store to db/mongoStore.js, so no other code changes are needed.
  4. Optional: write a small seed script using models/Product.js and models/Farmer.js to load the same starter data into MongoDB (the JSON file in data/db.json is a ready-made reference for the fields each collection needs).

Project structure

server.js              Express app entry point
routes/api.js           REST endpoints (products, farmers, orders, messages)
db/index.js              Picks JSON store or MongoDB store based on .env
db/jsonStore.js          Default file-based data layer
db/mongoStore.js         MongoDB data layer (Mongoose)
models/                  Mongoose schemas: Product, Farmer, Order, Message
data/db.json              Seed data / default storage file
public/index.html        Frontend: marketplace, cart, checkout, contact form

API reference

Method Route Purpose
GET /api/products List produce (optional ?category=)
GET /api/farmers List farmers
POST /api/orders Place an order (cart checkout)
GET /api/orders List all placed orders
POST /api/messages Send a message to a farmer
GET /api/messages List all messages

Notes

  • All farmer names, farms, and prices are placeholder demo data.
  • This is a demo-grade project: there's no authentication, and stock counts don't decrement on checkout. Both are reasonable next steps if you want to take this further.

About

A farmer-to-customer marketplace with cart and checkout — built with Node.js, Express, and MongoDB, connecting local farmers directly to buyers with zero middlemen.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages