A full-stack e-commerce application built with Next.js (App Router), TypeScript, Tailwind CSS and Prisma (PostgreSQL). It provides product and category management, sales/coupons, user accounts with roles (Admin, Vendor, User), a shopping cart, and vendor/admin pages.
This README explains how to run the project locally, required environment variables, Prisma/database workflow, and useful development tips.
- Quick start
- Scripts
- Environment variables (.env)
- Database & Prisma
- Project structure
- Authentication, email & uploads
- Deployment tips
Prerequisites
- Node.js (18+ recommended)
- pnpm (project uses pnpm)
- PostgreSQL database (local or remote)
- Install dependencies
cd online-store
pnpm install- Create an environment file
Create a .env.local at the repository root and add the variables shown in the "Environment variables" section below.
- Prepare the database and Prisma client
Use migrations (recommended during development):
pnpm migrate
pnpm generateOr push the schema directly (no migration files):
pnpm db:push
pnpm generate- Start the dev server
pnpm devOpen http://localhost:3000 to view the app.
The main scripts available in package.json:
pnpm dev— start Next.js dev serverpnpm build—prisma migrate deploy && prisma generate && next build(apply migrations, generate Prisma client, build)pnpm start— start production serverpnpm lint— run ESLintpnpm db:push—pnpm prisma db push(apply schema without migrations)pnpm migrate—pnpm prisma migrate dev(create & apply migrations)pnpm migrate:reset— reset the migrations (development only)pnpm migrate:status— show migration statuspnpm generate—pnpm prisma generate(regenerate Prisma client)pnpm studio—pnpm prisma studio(open Prisma Studio)pnpm db:wipe— runsts-node ./utils/truncate-table.ts(custom truncate script)
Note: The
buildscript already runsprisma migrate deploy— in CI you may prefer to run migrations as a separate step depending on your deployment flow.
Create .env.local in the project root. Example template (values are examples — replace with real secrets):
# Database
DATABASE_URL="postgresql://USER:PASSWORD@HOST:5432/DATABASE?schema=public"
# Client base URL (used by libs that call the API)
NEXT_PUBLIC_API_URL="http://localhost:3000/api"
# Nodemailer (transactional emails)
NODEMAILER_USER="your-smtp-user@example.com"
NODEMAILER_APP_PASSWORD="your-smtp-app-password"
# Admin and vendor email lists (semicolon-separated)
ADMIN_EMAILS="admin1@example.com;admin2@example.com"
VENDOR_EMAILS="vendor1@example.com;vendor2@example.com"
# Google OAuth (optional — used if you enable Google sign-in)
GOOGLE_CLIENT_ID="your-google-client-id"
GOOGLE_CLIENT_SECRET="your-google-client-secret"
# Cloudinary (optional — used by file upload hook)
NEXT_PUBLIC_PRESET_KEY="upload_preset_here"
NEXT_PUBLIC_CLOUD_NAME="your_cloud_name"Files and code check for missing keys and often guard access, so Cloudinary and Google values can be left blank in local development if you don't need those integrations.
Prisma is configured to use PostgreSQL (see prisma/schema.prisma). Primary models include User, Product, Category, Sale, Session, Account, and Verification. Enums include UserRole (Admin, Vendor, User) and Status (Hot, New, Sale).
Common Prisma commands:
pnpm migrate # create + apply migrations (dev)
pnpm db:push # apply schema directly without migrations
pnpm generate # generate Prisma client
pnpm studio # open Prisma StudioIf you change the schema, run pnpm migrate (dev) and pnpm generate to keep Prisma client in sync.
app/— Next.js App Router routes, layouts and API routes (server & client components)components/— React UI components (UI primitives undercomponents/ui/)lib/— server utilities and integrations (Prisma client, nodemailer, auth helpers)prisma/— Prisma schema and migrationsredux/— Redux store and sliceshooks/— React hooks (e.g.,useFileUpload.tsxfor Cloudinary)actions/— server actions (product/category/user/sale/email flows)services/— client-side API wrappersutils/— small utilities (includestruncate-table.tsused bydb:wipe)
- Roles are defined via Prisma
UserRoleenum:Admin,Vendor,User. lib/auth.tsreferencesADMIN_EMAILSandVENDOR_EMAILSenvironment variables (semicolon-separated). These are used to map email addresses to roles during sign-up or provisioning.- Google OAuth credentials (
GOOGLE_CLIENT_ID,GOOGLE_CLIENT_SECRET) are optional; code checks for their presence before enabling provider flows.
- Emails:
lib/nodemailer.tsusesNODEMAILER_USERandNODEMAILER_APP_PASSWORDfrom env to configure SMTP transport. Actions likeactions/send-email.tsand others rely on this. - File uploads:
hooks/useFileUpload.tsxsupports Cloudinary usingNEXT_PUBLIC_PRESET_KEYandNEXT_PUBLIC_CLOUD_NAME. Upload is optional and only active when those vars are present.
- On platforms like Vercel, add the environment variables to the project settings. Ensure the
DATABASE_URLpoints to your production Postgres instance. - CI: Consider running migrations before building. The
buildscript runsprisma migrate deployby default, which requires the build environment to have DB access. - If you prefer not to run migrations during
next build, run migrations as a separate deploy step:
pnpm migrate:status
pnpm migrate # or run prisma migrate deploy in CI
pnpm build