Skip to content

ornella-beza/API-ECOMMERCE

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

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

Repository files navigation

πŸ›’ E-Commerce API

Node.js TypeScript Express.js MongoDB JWT

A complete Node.js/TypeScript REST API for e-commerce applications with authentication, role-based access control, and comprehensive CRUD operations.

License: MIT GitHub stars GitHub forks


πŸ‘©β€πŸ’» Author

SIMBI BEZA Ornella

Email GitHub


✨ Features

Feature Description
πŸ” JWT Authentication Secure user authentication with token-based system
πŸ‘₯ Role-Based Access Control Admin, Vendor, and Customer roles
πŸ“¦ Product Management Full CRUD operations with advanced filtering
πŸ›’ Shopping Cart Complete cart management system
πŸ“‚ Category Management Organize products by categories
πŸ‘€ User Management Admin user management capabilities
πŸ“§ Email Notifications Password reset and welcome emails
πŸ“– API Documentation Complete Swagger/OpenAPI documentation
πŸ” Advanced Search Text search and filtering capabilities
πŸ“Š Analytics Product statistics and reporting

πŸ› οΈ Tech Stack

Backend

Node.js TypeScript Express.js

Database

MongoDB Mongoose

Authentication & Security

JWT bcrypt

Documentation & Testing

Swagger Postman

Development Tools

Nodemailer dotenv


API Endpoints

Authentication (6 endpoints)
Method Endpoint Description Access
POST /api/auth/register User registration Public
POST /api/auth/login User login Public
POST /api/auth/forgot-password Request password reset Public
PATCH /api/auth/reset-password/:token Reset password Public
PATCH /api/auth/change-password Change password Authenticated
GET /api/auth/profile Get user profile Authenticated
πŸ“‚ Categories (5 endpoints)
Method Endpoint Description Access
GET /api/categories Get all categories Public
GET /api/categories/:id Get category by ID Public
POST /api/categories Create category Admin
PUT /api/categories/:id Update category Admin
DELETE /api/categories/:id Delete category Admin
Products (8 endpoints)
Method Endpoint Description Access
GET /api/products Get all products with pagination/filtering Public
GET /api/products/stats Get product statistics Public
GET /api/products/top Get top 10 most expensive products Public
GET /api/products/low-stock Get low stock products Public
GET /api/products/:id Get product by ID Public
POST /api/products Create product Vendor/Admin
PUT /api/products/:id Update product Owner/Admin
DELETE /api/products/:id Delete product Owner/Admin
Users (5 endpoints)
Method Endpoint Description Access
GET /api/users Get all users Admin
GET /api/users/:id Get user by ID Admin
POST /api/users Create user Admin
PUT /api/users/:id Update user Admin
DELETE /api/users/:id Delete user Admin
πŸ›’ Cart (5 endpoints)
Method Endpoint Description Access
GET /api/cart/:userId Get cart by user ID Authenticated
POST /api/cart/:userId/items Add item to cart Authenticated
PUT /api/cart/:userId/items/:id Update cart item Authenticated
DELETE /api/cart/:userId/items/:id Remove item from cart Authenticated
DELETE /api/cart/:userId Delete entire cart Authenticated

Installation

Prerequisites

  • Node.js
  • MongoDB
  • npm

Setup Steps

# 1️⃣ Clone the repository
git clone https://github.com/ornella-beza/API-ECOMMERCE.git
cd API-ECOMMERCE

# 2️⃣ Install dependencies
npm install

# 3️⃣ Create environment file
cp .env.example .env

# 4️⃣ Start MongoDB service
# Make sure MongoDB is running on your system

# 5️⃣ Run the application
npm run dev

πŸ”§ Environment Variables

Create a .env file in the root directory:

PORT=3000
MONGODB_URI=mongodb://localhost:27017/ecommerce
JWT_SECRET=your-super-secret-jwt-key
JWT_EXPIRES_IN=7d
EMAIL_HOST=smtp.gmail.com
EMAIL_PORT=587
EMAIL_USER=your-email@gmail.com
EMAIL_PASS=your-app-password

Usage

API Documentation

Access the interactive Swagger documentation:

http://localhost:3000/api-docs

Postman Collection

Import API-ECOMMERCE.postman_collection.json into Postman for easy testing.

Authentication Flow

  1. Register a new user or login with existing credentials
  2. Use the returned JWT token in Authorization header: Bearer <token>
  3. Access protected endpoints based on your role

Role Permissions

Role Permissions
** Admin** Full access to all endpoints
** Vendor** Manage own products, access cart and profile
** Customer** View products, manage cart and profile

Project Structure

 API-ECOMMERCE
β”œβ”€β”€ πŸ“‚ src/
β”‚   β”œβ”€β”€ πŸ“‚ config/
β”‚   β”‚   β”œβ”€β”€ πŸ—„οΈ database.ts
β”‚   β”‚   β”œβ”€β”€ βš™οΈ env.ts
β”‚   β”‚   └── πŸ“– swagger.ts
β”‚   β”œβ”€β”€ πŸ“‚ controllers/
β”‚   β”‚   β”œβ”€β”€ πŸ” auth.controller.ts
β”‚   β”‚   β”œβ”€β”€ πŸ“‚ category.controller.ts
β”‚   β”‚   β”œβ”€β”€ πŸ“¦ product.controller.ts
β”‚   β”‚   β”œβ”€β”€ πŸ‘€ user.controller.ts
β”‚   β”‚   └── πŸ›’ cart.controller.ts
β”‚   β”œβ”€β”€ πŸ“‚ middlewares/
β”‚   β”‚   └── πŸ›‘οΈ auth.middleware.ts
β”‚   β”œβ”€β”€ πŸ“‚ models/
β”‚   β”‚   β”œβ”€β”€ πŸ‘€ user.model.ts
β”‚   β”‚   β”œβ”€β”€ πŸ“‚ category.model.ts
β”‚   β”‚   β”œβ”€β”€ πŸ“¦ product.model.ts
β”‚   β”‚   └── πŸ›’ cart.models.ts
β”‚   β”œβ”€β”€ πŸ“‚ routes/
β”‚   β”‚   β”œβ”€β”€ πŸ” auth.routes.ts
β”‚   β”‚   β”œβ”€β”€ πŸ“‚ category.routes.ts
β”‚   β”‚   β”œβ”€β”€ πŸ“¦ product.routes.ts
β”‚   β”‚   β”œβ”€β”€ πŸ‘€ user.routes.ts
β”‚   β”‚   β”œβ”€β”€ πŸ›’ cart.routes.ts
β”‚   β”‚   └── πŸ“‹ index.ts
β”‚   β”œβ”€β”€ πŸ“‚ utils/
β”‚   β”‚   └── πŸ“§ email.ts
β”‚   └── πŸš€ app.ts
β”œβ”€β”€ πŸ“„ package.json
β”œβ”€β”€ πŸ“„ README.md
β”œβ”€β”€ πŸ“„ LICENSE
└── πŸ“„ .env

🎯 Scripts

npm run dev      # πŸ”₯ Start development server with hot reload
npm start        # πŸš€ Start production server
npm run build    # πŸ—οΈ Build TypeScript to JavaScript

🀝 Contributing

We welcome contributions! Here's how you can help:

Fork

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

License: MIT


πŸ“ž Contact

SIMBI BEZA Ornella

Email GitHub


⭐ If you found this project helpful, please give it a star!

GitHub stars

About

A complete Node.js/TypeScript REST API for e-commerce applications with authentication, role-based access control, and comprehensive CRUD operations.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors