ReWear is a PERN monorepo for the EcoThread Marketplace course project. It is a second-hand fashion marketplace with a sustainability engine that scores products, tracks water and carbon impact, and shows circular economy progress on a user dashboard.
client/- React, Vite, React Router, TanStack Query, Tailwind CSS v4, Lucide Reactserver/- Node.js, Express, MongoDB, Mongoose, JWT auth, bcrypt- root - npm workspaces and shared scripts
- Public landing page at
/with merged login and signup flow - Role-aware signup with
buyerorselleraccount type - Authenticated marketplace at
/marketplacewith earth-tone styling and live product feed - Product cards with real eco metrics, seller info, category, material, and mock clothing imagery
- Filterable marketplace feed by category, eco grade, and material
- Purchase confirmation page at
/purchase/:productIdfor buyers - Seller listing studio at
/sellwith real-time eco-score preview before submit - Seller listing management from the profile page, including edit and delete for active listings
- Buyer wishlist flow with save/remove actions and wishlist section on profile
- Dedicated authenticated profile page at
/account - Dedicated authenticated dashboard page at
/dashboard - Role-aware UI:
- buyers see purchases, wishlist, impact, and badges
- sellers see listings, sales history, active inventory, and sales totals
- Logout redirects back to the landing page
- Session refresh from
/api/auth/meso stored logins stay in sync with server data
- JWT authentication with signup, login, current-user lookup, and stored account role
- MongoDB collections for users, products, purchases, materials, badge definitions, user badges, and wishlist items
- Material registry seed data for sustainability calculations
- Sustainability engine with:
- condition weights
- eco-score numeric calculation
- A-E eco grade mapping
- water saved calculation
- CO2 diverted calculation
- Product create, update, delete, list, detail, and live preview endpoints
- Purchase endpoint with transaction safety and row locking to prevent duplicate purchase races
- Wishlist create, delete, and fetch endpoints
- Profile endpoint with role-aware activity summaries
- Dashboard endpoint with buyer-specific and seller-specific aggregate data
- Badge unlock syncing based on purchase count, water saved, CO2 diverted, and material-specific milestones
- Backend role enforcement middleware for buyer-only and seller-only actions
- Demo seller account
- Demo buyer account
- Seeded materials and badge rules
- Seeded marketplace catalog with 9 demo listings and mock clothing photos
/- public landing page with merged login/signup/marketplace- authenticated marketplace feed/sell- seller-only listing form and listing edit page/purchase/:productId- buyer-only purchase confirmation page/account- authenticated profile page with role-specific activity/dashboard- authenticated dashboard with role-specific metrics/login- redirects to/
Base URL: http://localhost:4000/api
GET /health- API status check
POST /auth/signup- body:
fullName,email,password,role - returns JWT token and created user
- body:
POST /auth/login- body:
email,password - returns JWT token and user
- body:
GET /auth/me- auth required
- returns the current authenticated user
GET /materials- returns all material registry entries with water cost, carbon cost, and base value
POST /products/preview-score- body:
materialId,conditionLabel - returns live sustainability preview metrics before listing submission
- body:
POST /products- auth required, seller only
- body:
title,description,category,price,materialId,conditionLabel,imageUrl - creates a product and stores calculated eco metrics
PUT /products/:productId- auth required, seller only
- body:
title,description,category,price,materialId,conditionLabel,imageUrl - updates an active listing and recalculates stored sustainability metrics
DELETE /products/:productId- auth required, seller only
- deletes an active listing owned by the seller
GET /products- query params supported:
category,ecoScore,material,status - returns marketplace feed items with joined seller and material data
- query params supported:
GET /products/:productId- returns a single product detail record
POST /purchases- auth required, buyer only
- body:
productId - purchases an available item, marks it sold, updates impact totals, and syncs badges
GET /wishlist- auth required, buyer only
- returns wishlist items for the current user
POST /wishlist- auth required, buyer only
- body:
productId - saves a product to the user's wishlist
DELETE /wishlist/:productId- auth required, buyer only
- removes a product from the user's wishlist
GET /users/me/profile- auth required
- returns profile details, account role, listing counts, recent listings, and recent purchases
GET /users/me/dashboard- auth required
- returns role-aware dashboard data:
- buyers: purchases, impact totals, badges
- sellers: listings, sales history, active listing summaries, sales totals
npm run db:setup --workspace server- initializes MongoDB collections and indexesnpm run db:seed --workspace server- seeds materials and badge definitionsnpm run db:seed-demo --workspace server- seeds demo buyer/seller accounts and sample listingsnpm run db:reset --workspace server- drops the ReWear MongoDB database
npm run dev- runs client and server togethernpm run dev:client- runs the React appnpm run dev:server- runs the Express APInpm run build- builds the client and runs the server build placeholdernpm run lint- runs client lint and server lint placeholdernpm run test- runs server tests
- Install dependencies with
npm install. - Copy
.env.exampleto.envand update the MongoDB connection string. - Create the schema with
npm run db:setup --workspace server. - Seed the material registry with
npm run db:seed --workspace server. - Seed demo users and listings with
npm run db:seed-demo --workspace server. - Start both apps with
npm run dev. - Open
http://localhost:5173for the client. - The API health check is available at
http://localhost:4000/api/health.
- Seller:
[email protected]/demo12345 - Buyer:
[email protected]/demo12345
- Log in as the seller and create a new listing from
/sell. - Open the marketplace and confirm the listing appears with an eco badge and image.
- Confirm the seller profile and dashboard show listing and sales-oriented information.
- Sign out and log in as the buyer.
- Open a product from
/marketplaceor use the quick purchase panel on/dashboard. - Purchase an available item and optionally save/remove wishlist items.
- Confirm that purchase history, water saved, CO2 diverted, wishlist, and badges update immediately.
The default local connection string is mongodb://127.0.0.1:27017/rewear. ReWear now uses MongoDB for all app data, including auth, products, purchases, badges, and wishlists.
The original static mockups remain in the repository root as design references while the production app is built in the monorepo.