Skip to content

Latest commit

Β 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ›’ CodeAlpha Simple E-commerce Store

A full-stack Simple E-commerce Store built as Task 1 for the CodeAlpha Full Stack Development Internship.

The application provides a complete e-commerce workflow including product browsing, product details, authentication, shopping cart, checkout, order processing, and an administrative dashboard.


✨ Features

πŸ›οΈ Customer Features

  • 🏠 Home page with featured products and categories

  • πŸ“¦ Product listing

  • πŸ”Ž Product search

  • πŸ—‚οΈ Category filtering

  • πŸ“„ Product details with related products

  • πŸ›’ Shopping cart

    • Add products
    • Update quantities
    • Remove products
    • Automatic total calculation
  • πŸ’³ Checkout with shipping information

  • πŸ‘€ User registration

  • πŸ” User login/logout

  • πŸ“¦ Order processing

  • πŸ“‹ My Orders

  • πŸ“Š Customer order history

πŸ” Authentication & Security

  • JWT-based authentication
  • Password hashing with bcryptjs
  • Protected customer routes
  • Protected admin routes
  • Admin authorization middleware
  • Environment variables for sensitive configuration
  • Protected API endpoints

πŸ‘¨β€πŸ’Ό Admin Features

  • πŸ“Š Admin dashboard
  • πŸ“ˆ Product, order, and revenue statistics
  • βž• Add products
  • ✏️ Edit products
  • πŸ—‘οΈ Delete products
  • πŸ–ΌοΈ Product image upload
  • πŸ“¦ View customer orders
  • πŸ”„ Update order status
  • πŸ” Admin-only access

πŸ› οΈ Tech Stack

Layer Technology
Frontend HTML5, CSS3, Vanilla JavaScript
Backend Node.js, Express.js
Database MongoDB
ODM Mongoose
Authentication JWT
Password Security bcryptjs
File Uploads Multer
HTTP Client Fetch API

πŸ—οΈ Application Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚          Frontend            β”‚
β”‚     HTML + CSS + JavaScript  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
               β”‚
               β”‚ Fetch API / REST API
               β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚         Express.js           β”‚
β”‚      REST API + Server       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
               β”‚
               β”‚ Mongoose
               β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚           MongoDB            β”‚
β”‚ Users / Products / Orders    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

The Express server provides the REST API and serves the static frontend from the same application.


πŸ“ Project Structure

CodeAlpha_SimpleEcommerce/
β”‚
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ config/
β”‚   β”‚   └── db.js
β”‚   β”‚
β”‚   β”œβ”€β”€ models/
β”‚   β”‚   β”œβ”€β”€ User.js
β”‚   β”‚   β”œβ”€β”€ Category.js
β”‚   β”‚   β”œβ”€β”€ Product.js
β”‚   β”‚   └── Order.js
β”‚   β”‚
β”‚   β”œβ”€β”€ middleware/
β”‚   β”‚   β”œβ”€β”€ auth.js
β”‚   β”‚   └── upload.js
β”‚   β”‚
β”‚   β”œβ”€β”€ controllers/
β”‚   β”‚   β”œβ”€β”€ authController.js
β”‚   β”‚   β”œβ”€β”€ productController.js
β”‚   β”‚   β”œβ”€β”€ categoryController.js
β”‚   β”‚   └── orderController.js
β”‚   β”‚
β”‚   β”œβ”€β”€ routes/
β”‚   β”‚   β”œβ”€β”€ authRoutes.js
β”‚   β”‚   β”œβ”€β”€ productRoutes.js
β”‚   β”‚   β”œβ”€β”€ categoryRoutes.js
β”‚   β”‚   └── orderRoutes.js
β”‚   β”‚
β”‚   β”œβ”€β”€ server.js
β”‚   β”œβ”€β”€ seed.js
β”‚   β”œβ”€β”€ package.json
β”‚   └── .env.example
β”‚
β”œβ”€β”€ frontend/
β”‚   β”œβ”€β”€ css/
β”‚   β”‚   └── style.css
β”‚   β”‚
β”‚   β”œβ”€β”€ js/
β”‚   β”‚   β”œβ”€β”€ api.js
β”‚   β”‚   β”œβ”€β”€ auth.js
β”‚   β”‚   β”œβ”€β”€ cart.js
β”‚   β”‚   β”œβ”€β”€ utils.js
β”‚   β”‚   β”œβ”€β”€ navbar.js
β”‚   β”‚   β”œβ”€β”€ home.js
β”‚   β”‚   β”œβ”€β”€ products.js
β”‚   β”‚   β”œβ”€β”€ product-details.js
β”‚   β”‚   β”œβ”€β”€ cart-page.js
β”‚   β”‚   β”œβ”€β”€ checkout.js
β”‚   β”‚   β”œβ”€β”€ order-success.js
β”‚   β”‚   β”œβ”€β”€ my-orders.js
β”‚   β”‚   β”œβ”€β”€ login.js
β”‚   β”‚   β”œβ”€β”€ register.js
β”‚   β”‚   β”œβ”€β”€ admin-dashboard.js
β”‚   β”‚   β”œβ”€β”€ admin-products.js
β”‚   β”‚   β”œβ”€β”€ admin-add-product.js
β”‚   β”‚   β”œβ”€β”€ admin-edit-product.js
β”‚   β”‚   └── admin-orders.js
β”‚   β”‚
β”‚   β”œβ”€β”€ images/
β”‚   β”‚
β”‚   β”œβ”€β”€ admin/
β”‚   β”‚   β”œβ”€β”€ dashboard.html
β”‚   β”‚   β”œβ”€β”€ products.html
β”‚   β”‚   β”œβ”€β”€ add-product.html
β”‚   β”‚   β”œβ”€β”€ edit-product.html
β”‚   β”‚   └── orders.html
β”‚   β”‚
β”‚   β”œβ”€β”€ index.html
β”‚   β”œβ”€β”€ products.html
β”‚   β”œβ”€β”€ product-details.html
β”‚   β”œβ”€β”€ cart.html
β”‚   β”œβ”€β”€ checkout.html
β”‚   β”œβ”€β”€ login.html
β”‚   β”œβ”€β”€ register.html
β”‚   β”œβ”€β”€ my-orders.html
β”‚   └── order-success.html
β”‚
β”œβ”€β”€ .gitignore
└── README.md

πŸš€ Getting Started

1. Prerequisites

Make sure the following are installed:

MongoDB Atlas can also be used instead of a local MongoDB server.

Check the installed versions:

node --version
npm --version
mongod --version

mongosh is optional and is only required if you want to inspect the MongoDB database manually from the command line.


2. Clone the Repository

git clone https://github.com/MBen213/CodeAlpha_SimpleEcommerce.git
cd CodeAlpha_SimpleEcommerce

Then move into the backend directory:

cd backend

3. Install Dependencies

npm install

4. Configure Environment Variables

Create a .env file inside the backend directory.

Use .env.example as a template:

PORT=5000
MONGO_URI=mongodb://127.0.0.1:27017/codealpha_ecommerce
JWT_SECRET=your_secure_jwt_secret

Important

Never commit your .env file to GitHub.

The repository should contain:

.env.example

and should not contain:

.env

5. Start MongoDB

Make sure your MongoDB server is running before starting the application.

On Windows, you can check the MongoDB service using:

services.msc

Look for the MongoDB service and make sure it is running.


6. Seed the Database

The project includes a seed script that creates sample categories, products, and an administrator account.

Run:

npm run seed

7. Start the Application

npm start

The application will be available at:

http://localhost:5000

Open this URL in your browser.


πŸ‘¨β€πŸ’Ό Admin Access

The seed script creates an administrator account for development and testing.

The credentials are defined by the project's seed configuration.

Security: The default development credentials should never be used in a production deployment. Change the password and JWT secret before deployment.


πŸ“‘ REST API

Authentication

Method Endpoint Description Authentication
POST /api/auth/register Register a customer Public
POST /api/auth/login Login Public
GET /api/auth/me Get current user Authenticated

Products

Method Endpoint Description Authentication
GET /api/products Get products with search/filter Public
GET /api/products/:id Get product details Public
POST /api/products Create product Admin
PUT /api/products/:id Update product Admin
DELETE /api/products/:id Delete product Admin

Categories

Method Endpoint Description Authentication
GET /api/categories Get categories Public
POST /api/categories Create category Admin

Orders

Method Endpoint Description Authentication
POST /api/orders Create an order Authenticated
GET /api/orders/my Get current user's orders Authenticated
GET /api/orders Get all orders Admin
GET /api/orders/:id Get an order Owner/Admin
PUT /api/orders/:id/status Update order status Admin

πŸ›’ Shopping Flow

Browse Products
      ↓
View Product Details
      ↓
Add to Cart
      ↓
Update Cart
      ↓
Checkout
      ↓
Enter Shipping Information
      ↓
Create Order
      ↓
Order Confirmation
      ↓
View Order History

πŸ” Authentication Flow

Register
   ↓
Login
   ↓
JWT Token
   ↓
Token stored in Browser
   ↓
Authorization Header
   ↓
Protected API Requests
   ↓
User / Admin Resources

Passwords are hashed with bcryptjs, and JWT tokens are used to authenticate protected API requests.


πŸ§ͺ Testing Checklist

Before submission, verify the following:

  • User registration works
  • User login works
  • Invalid credentials are rejected
  • Product listing works
  • Product search works
  • Category filtering works
  • Product details work
  • Add to cart works
  • Cart quantity updates work
  • Product removal works
  • Cart totals are calculated correctly
  • Checkout works
  • Orders are created successfully
  • Product stock is updated
  • My Orders works
  • Admin login works
  • Admin dashboard works
  • Admin can add products
  • Admin can edit products
  • Admin can delete products
  • Admin can view orders
  • Admin can update order status

πŸ“Έ Screenshots

🏠 Home Page

Home Page

πŸ›οΈ Products

Products Page

πŸ“„ Product Details

Product Details

πŸ›’ Shopping Cart

Shopping Cart

πŸ’³ Checkout

Checkout

πŸ“¦ My Orders

My Orders

πŸ‘¨β€πŸ’Ό Admin Dashboard

Admin Dashboard

πŸ› οΈ Product Management

Product Management

πŸ“‹ Order Management

Order Management


πŸ“Œ Project Notes

  • This project implements a simplified checkout process.
  • No real payment gateway is connected.
  • The shopping cart is stored client-side using localStorage.
  • Orders are permanently stored in MongoDB after checkout.
  • Product images are handled using Multer.
  • JWT is used for protected API endpoints.
  • Express serves both the REST API and the static frontend.
  • The project is intended for educational and internship purposes.

πŸŽ“ CodeAlpha Internship

This project was developed as part of the:

CodeAlpha Full Stack Development Internship

Task 1 β€” Simple E-commerce Store

Requirements Covered

  • βœ… Product listings
  • βœ… Shopping cart
  • βœ… Product details page
  • βœ… Order processing
  • βœ… User registration/login
  • βœ… Database for products, users, and orders
  • βœ… Express.js backend
  • βœ… HTML/CSS/JavaScript frontend

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

Mohamed Ben

Full Stack Web Developer | Software Engineer


πŸ“„ License

This project was created for educational and internship purposes as part of the CodeAlpha Full Stack Development Internship.

About

Full-stack Simple E-commerce Store built with Node.js, Express.js, MongoDB, and Vanilla JavaScript for CodeAlpha Task 1.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages