Skip to content

yashav-shukla/E-Commerce-API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Ecommerce Startup API

A modular Node.js + Express REST API scaffold for users, products, and shopping carts β€” built for learning, interviews, and production-style growth.

Node.js Express License Status

Ecommerce Startup API


Table of contents


Overview

Ecommerce Startup API is a backend service that exposes REST endpoints for users, products, and per-user carts. The server uses Express middleware for JSON parsing and mounts feature routes under clear URL prefixes (/users, /products, /cart).

Current stage: Route handlers return placeholder responses. The structure (separate route modules, centralized server.js) is production-oriented and ready for controllers, validation, persistence, and auth.

API demo in Postman or browser
Add a screenshot at docs/images/api-demo.png after running the server.


Features

Area Status Description
REST routing βœ… Modular routers for users, products, cart
JSON body parsing βœ… express.json() enabled
Health / welcome βœ… GET / returns welcome message
Database πŸ”œ MongoDB / PostgreSQL (planned)
Auth (JWT) πŸ”œ Register, login, protected routes
Validation πŸ”œ Request schema validation (e.g. Zod/Joi)
Tests πŸ”œ Unit + integration (Jest/Supertest)
Docker / CI πŸ”œ Container + GitHub Actions

Architecture

flowchart TB
  subgraph Client
    C[Web / Mobile / Postman]
  end

  subgraph Server["Express Server :3000"]
    S[server.js]
    S --> U["/users β†’ userRoutes"]
    S --> P["/products β†’ productRoutes"]
    S --> CART["/cart β†’ cartRoutes"]
  end

  subgraph Future["Planned layers"]
    CTRL[Controllers]
    SVC[Services]
    DB[(Database)]
    U --> CTRL
    P --> CTRL
    CART --> CTRL
    CTRL --> SVC --> DB
  end

  C -->|HTTP JSON| S
Loading

System architecture diagram

System architecture diagram

Request flow (today):

  1. Client sends HTTP request to Express.
  2. server.js applies global middleware and mounts route modules.
  3. Route handler responds (placeholder text until controllers/DB are added).

Tech stack

Layer Technology
Runtime Node.js
Framework Express 5.x
Module style CommonJS (require)
API style REST

Project structure

ecommerce-startup/
β”œβ”€β”€ server.js              # App entry: middleware, route mounting, listen
β”œβ”€β”€ routes/
β”‚   β”œβ”€β”€ userRoutes.js      # User CRUD-style endpoints
β”‚   β”œβ”€β”€ productRoutes.js   # Product catalog endpoints
β”‚   └── cartRoutes.js      # Cart per userId
β”œβ”€β”€ package.json
β”œβ”€β”€ package-lock.json
└── docs/
    └── images/            # README assets (banner, diagrams, screenshots)

Getting started

Prerequisites

  • Node.js 18+ (LTS recommended)
  • npm (comes with Node)

Installation

git clone https://github.com/<your-username>/ecommerce-startup.git
cd ecommerce-startup
npm install

Run locally

node server.js

Server listens on port 3000:

Server is running on port 3000

Open http://localhost:3000 β€” you should see the welcome HTML message.

Environment variables (recommended next step)

Create .env (do not commit secrets):

PORT=3000
NODE_ENV=development
# DATABASE_URL=
# JWT_SECRET=

Update server.js to use process.env.PORT || 3000 when you add dotenv.

Suggested npm scripts (add to package.json)

"scripts": {
  "start": "node server.js",
  "dev": "node --watch server.js"
}

API reference

Base URL: http://localhost:3000

Root

Method Endpoint Description
GET / Welcome message

Users (/users)

Method Endpoint Description
GET /users List all users (placeholder)
POST /users Create user (placeholder)
GET /users/:id Get user by ID (placeholder)

Products (/products)

Method Endpoint Description
GET /products List all products (placeholder)
POST /products Create product (placeholder)
GET /products/:id Get product by ID (placeholder)

Cart (/cart)

Method Endpoint Description
GET /cart/:userId Get cart for user
POST /cart/:userId Add item to user's cart

Example requests

Welcome

curl http://localhost:3000/

Users

curl http://localhost:3000/users
curl -X POST http://localhost:3000/users -H "Content-Type: application/json" -d "{\"name\":\"Jane\"}"
curl http://localhost:3000/users/42

Products

curl http://localhost:3000/products
curl http://localhost:3000/products/101

Cart

curl http://localhost:3000/cart/42
curl -X POST http://localhost:3000/cart/42 -H "Content-Type: application/json" -d "{\"productId\":\"101\",\"qty\":2}"

Roadmap

Production-minded milestones you can implement and mention in interviews:

  • Layered architecture: routes β†’ controllers β†’ services β†’ repositories
  • Database: persist users, products, cart lines
  • Auth: JWT + hashed passwords (bcrypt)
  • Validation & errors: consistent { success, data, error } responses
  • Security: helmet, rate limiting, CORS
  • Observability: structured logging (pino/winston), health check /health
  • Testing: Supertest integration tests per route
  • Deploy: Docker + Render/Railway/Fly.io + GitHub Actions CI

Interview talking points

Use this repo to demonstrate how you think about backend systems, not only syntax:

  1. Separation of concerns β€” Route files isolate domains (users vs products vs cart); next step is controllers so routes stay thin.
  2. REST design β€” Resource-oriented URLs; cart scoped by userId mirrors real e-commerce patterns.
  3. Express middleware β€” express.json() for body parsing; global vs route-level middleware.
  4. Scalability path β€” Stateless API β†’ horizontal scaling behind a load balancer once sessions/JWT and DB are in place.
  5. Trade-offs β€” Placeholder handlers ship fast for learning; production needs validation, idempotency on cart updates, and transactional inventory.
  6. What you’d do next β€” Pick one vertical slice (e.g. POST /products with DB + tests) and complete it end-to-end β€” strong interview story.

Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Commit changes with clear messages
  4. Open a Pull Request

License

This project is licensed under the ISC License β€” see package.json.


Built with Express Β· Ready to grow into a production e-commerce backend

About

E-commerce API built with Node.js and Express.js, showcasing RESTful architecture, modular routing, middleware integration, and scalable backend design for user, product, and cart management.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors