A full-stack e-commerce learning project. The frontend is built with Next.js, TypeScript, and CSS Modules; the backend is an Express API backed by PostgreSQL.
This project started as a frontend exercise for routing, dynamic product pages, component structure, React state, and cart management. It now includes a real backend so the cart is persisted in a database instead of only React state.
Live demo: https://ecommerce-store-nine-amber.vercel.app/
- Home page with featured products
- Products listing page
- Dynamic product detail pages
- Cart page
- Add products to cart
- Increase and decrease item quantity
- Remove items from cart
- Clear cart
- Cart total and item count calculated on the server
- Cart persisted in PostgreSQL via an Express REST API
- Products seeded into the database from a JSON file
- Responsive layout using CSS Modules
Frontend
- Next.js
- TypeScript
- React
- CSS Modules
Backend
- Node.js + Express
- PostgreSQL (
pg) - CORS
- dotenv
Deployment
- Vercel for the Next.js frontend
- Render for the Express API
- Neon for hosted PostgreSQL
- cron-job.org health ping for the backend
/api/healthroute
.
├── src # Next.js frontend
│ ├── app
│ │ ├── page.tsx
│ │ ├── products
│ │ │ ├── page.tsx
│ │ │ └── [id]
│ │ │ └── page.tsx
│ │ ├── cart
│ │ │ └── page.tsx
│ │ └── layout.tsx
│ │
│ ├── components
│ │ ├── Navbar.tsx
│ │ ├── AddToCartButton.tsx
│ │ └── CartItems.tsx
│ │
│ ├── context
│ │ └── CartContext.tsx # talks to the API via NEXT_PUBLIC_API_URL
│ │
│ └── data
│ └── products.json # source data, seeded into Postgres
│
└── server # Express + Postgres backend
├── index.js # Express app and cart API routes
├── db.js # Postgres connection pool
├── schema.sql # products + cart_items tables
├── seed.js # loads products.json into the database
└── package.json- Node.js
- A PostgreSQL database
- Local PostgreSQL for local development
- Neon PostgreSQL for the deployed version
From the server/ folder:
cd server
npm installCreate server/.env:
DATABASE_URL=postgres://USER:PASSWORD@localhost:5432/ecommerceFor the deployed database, use the Neon pooled connection string as DATABASE_URL on Render. Do not commit the real connection string.
Create the tables, seed products, and start the API:
npm run seed # creates tables and seeds products from ../src/data/products.json
npm run dev # starts the API on http://localhost:4000Note: run
npm run seedfrom inside theserver/directory because it readsschema.sqland../src/data/products.jsonrelative to that folder.
From the project root:
npm installCreate .env.local:
NEXT_PUBLIC_API_URL=http://localhost:4000Then start the dev server:
npm run dev # http://localhost:3000The app is deployed as a split full-stack project:
- Frontend: Vercel
- Backend API: Render
- Database: Neon PostgreSQL
- Health check:
/api/health
Production URLs:
- Frontend: https://ecommerce-store-nine-amber.vercel.app
- Backend API: https://ecommerce-store-api-dk85.onrender.com
- Backend health check: https://ecommerce-store-api-dk85.onrender.com/api/health
Production environment variables:
# Vercel
NEXT_PUBLIC_API_URL=https://ecommerce-store-api-dk85.onrender.com
# Render
DATABASE_URL=postgresql://...Render provides the backend port through process.env.PORT, and the API falls back to 4000 for local development.
A cron-job.org health check pings /api/health every 10 minutes to reduce Render cold starts without waking the Neon database.
Local base URL:
http://localhost:4000Production base URL:
https://ecommerce-store-api-dk85.onrender.com| Method | Endpoint | Body | Description |
|---|---|---|---|
GET |
/api/health |
— | Health check, returns { status: "ok" } |
GET |
/api/cart |
— | Get cart items, total, and count |
POST |
/api/cart/items |
{ productId } |
Add a product to the cart, quantity +1 |
PATCH |
/api/cart/items/:productId |
{ delta } |
Change quantity by delta, removes item at 0 |
DELETE |
/api/cart/items/:productId |
— | Remove a product from the cart |
DELETE |
/api/cart |
— | Clear the cart |
All cart endpoints return the updated cart:
{
"items": [],
"total": 0,
"count": 0
}products (
id,
name,
description,
price,
image,
category,
stock
)
cart_items (
product_id -> references products(id) ON DELETE CASCADE,
quantity
)Root frontend
npm run dev— start Next.js in developmentnpm run build— build for productionnpm start— run the production buildnpm run lint— run ESLint
server/ backend
npm run dev— start the API with--watchauto-reloadnpm start— start the APInpm run seed— create tables and seed products


