This repository contains the backend implementation for the E-Commerce Product Page interview task, built with NestJS, Supabase, and TypeScript. It provides a RESTful API for products, comments, and cart management, with user authentication via Supabase.
- Authentication: Email/password signup & signin via Supabase
- Products: CRUD operations on products
- Comments: Post and retrieve comments with star ratings (1–5), only for logged-in users
- Cart Management: Add, retrieve, and remove cart items, with quantity accumulation
- Error Handling: Consistent HTTP status codes and messages, no raw DB errors leaked
- TypeScript: Strong typing for interfaces, DTOs, and Supabase interactions
- REST API: NestJS controllers, services, and guards with Supabase as the database layer
- Framework: NestJS (TypeScript)
- Database & Auth: Supabase (PostgreSQL + PostgREST + GoTrue)
- Validation: class-validator & class-transformer
- HTTP Client: Postman (collection included)
- Node.js v16+ / npm or Yarn
- A Supabase project (URL & Key)
- Git
- Clone the repo:
git clone https://https://github.com/kamimehrabi/e-commerce-api.git cd e-commerce-api - Install dependencies:
yarn install # or npm install
Create a .env file in the project root with the following values:
SUPABASE_URL=<your-supabase-url>
SUPABASE_KEY=<your-supabase-service-role-key>This project uses a Supabase backend with all tables, views, and functions already created. No manual migrations are required—simply point your .env at the provided database and you’re ready to go.
The following views are available out of the box:
- ``** view**: joins
comments→ `auth.users`, exposing each comment with the author’s `email` and `display_name`. - ``** view**: left‑joins
productswith `comments` and computes each product’s average star rating (`avg_rating`).
You can see their definitions under supabase/migrations/ for reference, but running them locally is optional since the live database already contains these objects.
Start the NestJS server in development mode:
npm run start:dev
# or
yarn start:devServer will be running at http://localhost:3000.
POST /auth/signup– Register a new user (displayName,email,password)POST /auth/signin– Log in and receive an access token (email,password)
GET /products– List all productsGET /products/:id– Retrieve a single product with average ratingPOST /products– Create a product (protected)PATCH /products/:id– Update a product (protected)DELETE /products/:id– Delete a product (protected)
GET /products/:productId/comments– List comments (with user display name)POST /products/:productId/comments– Add a comment (protected)
GET /cart– Retrieve current user’s cart items (protected)POST /cart– Add or increment a cart item (protected)DELETE /cart/:id– Remove a cart item (protected)
- Use the included Postman collection (
postman_collection.json) to test all endpoints. - Create a Postman environment (e.g.
Local Dev) with the following variables:Variable Initial Value Description basehttp://localhost:3000The root URL of your API tokenObtained from POST /auth/signinresponse
- Import the collection into Postman.
- Select the
Local Devenvironment. - Run the
signinrequest in the Auth folder to populate thetokenvariable. - All other protected requests will automatically use
{{base}}and theAuthorization: Bearer {{token}}header.
- Postman Collection:
postman_collection.jsonin the repository root - Environment Template:
.env.example
I will send an email containing the following test credentials(email and password) for the login route.