E-Commerce Application:
This is a simple e-commerce application that allows users to view products, add products to cart, and checkout. The admin can manage products, users, and orders.
The application is built using the following technologies:
-
Frontend: React, Axios, React-Router-Dom V6, Bootstrap, Redux.
-
Backend: Node.js, Express.js, MongoDB, Mongoose, JWT, Bcrypt, Multer, Nodemailer, Nodemon, Dotenv, Morgan, Cors, cookie-parser.
-
Tools: Postman, VS Code, Git, GitHub, Netlify, Render, Vite.
Steps:
Backend:
- Create an empty directory and open it in VS Code.
- Open the terminal and run the following command to create a package.json file:
npm init
- create an entry point file (index.js).
- Configure the package.json file. Add the following code:
"scripts": {
"start": "node index.js"
}
- Create a readme.md file and add the project description.
- Create an empty repository in GitHub.Com. Copy the repository URL.
- Initialize the git repository in the project directory:
git init
- Add the remote repository URL:
git remote add origin <repository-url>
- Create a .gitignore file and add the following code:
node_modules
package-lock.json
DS_Store
.env
- Rename the default branch from master to main:
git branch -m main
- Add the changes to the staging area:
git add .
- Commit the changes:
git commit -m "basic backend application setup"
- Push the changes to the remote repository:
git push -u origin main
Database Setup:
- Visit MongoDB.Com and create an account.
- Create a new project and cluster.
- Create a new user and password.
- Open database access if necessary to change the user credentials and privileges.
- Open network access to allow connections from anywhere by adding the IP address 0.0.0.0/0.
- Create a new database and a collection.
- Copy the connecting string from the cluster.
- Install mongodb compass and connect to the database using the connecting string.
From the backend, connect to the database:
- Copy the connection string from the cluster.
- Install mongoose:
npm install mongoose
- In the index.js file, add the following code:
const mongoose = require('mongoose');
mongoose.connect(connection_string);
- Install dotenv:
npm install dotenv
- Create a .env file and add the connection string:
MONGODB_URI=connection_string
- Require the dotenv package in the index.js file:
require('dotenv').config();
- Change the connection string in index.js inside mongoose.connect() function to
process.env.MONGODB_URI
- Add the .env file to the .gitignore file.
- Create a config.js file under the utils folder and add the following code:
require('dotenv').config();
const MONGODB_URI = process.env.MONGODB_URI;
module.exports = {
MONGODB_URI
};
- Require the config.js file in the index.js file:
const { MONGODB_URI } = require('./utils/config');
- Update the variable process.env.MONGODB_URI to MONGODB_URI in the mongoose.connect() function.
Connect to the server using Express.js:
- Install express:
npm install express
- update the index.js file:
const express = require('express');
const app = express();
app.get('/', (req, res) => {
res.send('Hello World');
});
app.listen(3001, () => {
console.log('Server is running on port 3001');
});
This is a simple e-commerce application that allows users to view products, add products to cart, and checkout. The admin can manage products, users, and orders.
User Stories:
- As a user, I should be able to register and login to the application.
- As a user, I should be able to view all products.
- As a user, I should be able to view a single product.
- As a user, I should be able to add a product to the cart.
- As a user, I should be able to remove a product from the cart.
- As a user, I should be able to view the cart.
- As a user, I should be able to checkout.
- As an admin, I should be able to add a user.
- As an admin, I should be able to view all users.
- As an admin, I should be able to view a single user.
- As an admin, I should be able to update a user.
- As an admin, I should be able to delete a user.
- As an admin, I should be able to add a product.
- As an admin, I should be able to view all products.
- As an admin, I should be able to view a single product.
- As an admin, I should be able to update a product.
- As an admin, I should be able to delete a product.
- As an admin, I should be able to view all orders.
- As an admin, I should be able to view a single order.
- As an admin, I should be able to update an order.
- As an admin, I should be able to delete an order.
Tasks:
Backend:
- Setup the project with Node.js and Express.js. (Done)
- Setup the environment variables (Dotenv). (Done)
- Connect to the MongoDB database. (Done)
- Run the server and test the connection. (Done)
- Setup the architecture of the project (Models, Routes, Controllers, Middlewares). (Done)
- Basic housekeeping (Error handling, Logging, Parsing). (Done)
- Setup the authentication system (Register, Login, Logout). (Done)
- Setup the authorization system (Roles, Permissions). (Not Done)
- Setup the product system (CRUD). (Done)
- Setup the user system (CRUD). (Done)
- Setup the order system (CRUD). (Done)
- Setup the cart system (CRUD). (Not Done)
- Setup the email system (Nodemailer). (Not Done)
- Setup the image system (Multer). (Not Done)
- Setup the deployment system (Netlify, Render). (Not Done)
Frontend:
- Setup the project with React. (Done)
- Setup the architecture of the project (Components, Pages, Routes). (Done)
- Setup the authentication system (Register, Login, Logout). (Done) a. Create the Register component. b. Create the Login component. c. Create the Logout component. d. Create the Auth component.
- Setup the authorization system (Roles, Permissions). (Done)
- Setup the product system (CRUD). (In Progress)
- Setup the user system (CRUD). (Not Done)
- Setup the order system (CRUD). (In Progress)
- Setup the cart system (CRUD). (Not Done)
- Setup the email system (Nodemailer). (Not Done)
- Setup the image system (Multer). (Not Done)
- Setup the deployment system (Netlify, Render). (Not Done)
Models:
- User Model:
{
name: String,
email: String,
password: String,
role: String,
cart: [
{
product: {
type: mongoose.Schema.Types.ObjectId,
ref: 'Product'
},
quantity: Number
}
]
}
- Product Model:
{
name: String,
description: String,
price: Number,
image: String
stock: Number
}
- Order Model:
{
user: {
type: mongoose.Schema.Types.ObjectId,
ref: 'User'
},
products: [
{
product: {
type: mongoose.Schema.Types.ObjectId,
ref: 'Product'
},
quantity: Number
}
],
total: Number,
status: String
}
- Cart Model:
{
user: {
type: mongoose.Schema.Types.ObjectId,
ref: 'User'
},
products: [
{
product: {
type: mongoose.Schema.Types.ObjectId,
ref: 'Product'
},
quantity: Number
}
]
}
Routes:
User Routes:
- POST /api/users/register (Done)
- POST /api/users/login (Done)
- POST /api/users/logout (Done)
- GET /api/users/profile (Done)
- PUT /api/users/profile
- DELETE /api/users/profile
Product Routes:
- POST /api/products
- GET /api/products
- GET /api/products/:id
- PUT /api/products/:id
- DELETE /api/products/:id
Order Routes:
- POST /api/orders
- GET /api/orders
- GET /api/orders/:id
- PUT /api/orders/:id
- DELETE /api/orders/:id
Cart Routes:
- POST /api/carts
- GET /api/carts
- GET /api/carts/:id
- PUT /api/carts/:id
- DELETE /api/carts/:id