Skip to content

primebless/e-commerce

Repository files navigation

Prime Store (PostgreSQL + Express + React + Node)

Production-style e-commerce platform implementing your requested architecture, adapted to PostgreSQL (instead of MongoDB).

Implemented Architecture

  • Public storefront: home, listing, product details, search/filter/sort, guest cart, live cart count.
  • Guest checkout: no login required, collects full name/email/phone/address/payment method, stores order with isGuest: true and email reference.
  • Authenticated checkout: links order to userId with isGuest: false.
  • JWT auth with Bearer token sent in Authorization header.
  • Password hashing with bcrypt.
  • Role-based admin routes (user, admin).
  • Guest cart in localStorage, user cart in DB (Cart, CartItem) with merge on login.
  • Wishlist, profile update, saved shipping addresses.
  • Order status workflow: pending, paid, shipped, delivered, cancelled.
  • Stock validation + stock decrement on purchase.
  • Action logs and admin reports/log pages.
  • Security middleware currently enabled: CORS and centralized error handling.
  • Stripe payment intent endpoint.
  • Backend tests for health, auth middleware behavior, protected routes.

Backend Structure

  • backend/src/controllers
  • backend/src/routes
  • backend/src/middleware
  • backend/src/utils
  • backend/src/config
  • backend/src/server.js

Frontend Structure

  • frontend/src/components
  • frontend/src/pages
  • frontend/src/features (Redux)
  • frontend/src/api/client.js
  • frontend/src/components/ProtectedRoute.jsx

Database Models (Prisma/PostgreSQL)

  • User
  • Product
  • Order
  • Review
  • Cart
  • plus: OrderItem, CartItem, Wishlist, ActionLog

Setup (Local)

  1. Install dependencies:
cd mern-ecommerce/backend && npm install
cd ../frontend && npm install
  1. Create env files:
cd ../backend
cp .env.example .env
cd ../frontend
cp .env.example .env
  1. Ensure PostgreSQL DB exists:
CREATE DATABASE mern_ecommerce;
  1. Apply schema + seed data:
cd ../backend
npm run prisma:generate
npm run prisma:push
npm run seed
  1. Run backend:
npm run dev
  1. Run frontend:
cd ../frontend
npm run dev
  1. Open app:
  • http://localhost:5173
  • http://localhost:5000/api/health

Demo Accounts

  • Admin: admin@mernstore.dev / Admin123!
  • User: user@mernstore.dev / User123!

Tests

cd backend
npm test
cd frontend
npm test -- --watch=false

Code Quality Automation

cd mern-ecommerce
npm install
  • Pre-commit hook runs lint-staged (ESLint + Prettier on staged files).
  • Manual checks:
    • npm run lint
    • npm run lint:fix
    • npm run format:check
    • npm run format

Deployment

  • Frontend: Vercel (frontend/)
  • Backend: Render/Railway (backend/)
  • Set env vars from backend/.env.example
  • Use managed PostgreSQL connection string for DATABASE_URL

Notes

  • Requirement requested MERN; implementation uses PostgreSQL by your instruction.
  • For full production payments, add Stripe webhook verification for payment finalization.

Automation (Phase 1)

  • In-process automation queue + scheduler starts with backend server startup.
  • Jobs implemented:
    • abandoned-cart-recovery
    • low-stock-alerts
    • weekly-kpi-digest
  • Admin endpoints:
    • GET /api/admin/automation/summary
    • POST /api/admin/automation/run with { "jobName": "abandoned-cart-recovery", "mode": "queue" }
  • Admin UI:
    • /admin/automation

About

Production-ready full-stack e-commerce platform built with React, Node.js, Express, and PostgreSQL. Features JWT authentication, guest checkout, cart merging, role-based admin dashboard, and Stripe payment integration.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages