This is my full-stack e-commerce shop project. Frontend is located in this repository. I've used PERN (PostgreSQL + Express + ReactJS + NodeJS) stack with some additional technologies (Sequelize, bcrypt, JWT Authorization etc.) which will be mentioned later in this document.
First of all, I want to present PostreSQL DB relationships schema, it will help to fully undestand what's going on in this app. As you can see, I have 8 tables and a bunch of connections between them. I am using Sequelize as an ORM (Object-Relational Mapping) technology:
For example, this is how Vehicles table looks like in Postico (MAC PostgreSQL client):
I've implemented two middlewares - the first to check user role and the second to verify jwt token (using jwt.verify()
from jsonwebtoken package).
When user has signed up he has USER
role by default. It is stored as a role
attribute in a Users table as long as user password
(whic is hashed with salt by bcrypt) and email. ADMIN
role can be set only programmatically.
Admin can attach file as a vehicle image when he creating a new vehicle in his panel:
In vehicleController.js
server is getting this image from req.files
, generating a random name for it (using uuid package)
and putting it in the /static/images folder. Then we are storing only img name in the DB, not the exact file. It can be then accessed by its name on client:
/* index.js */
app.use(fileUpload({}))
app.use(express.static(path.resolve(__dirname, '..', 'static', 'images')))
/* vehicleController.js */
// Getting image from request using express-fileupload
const { img } = req.files
// Generating random name for image
const fileName = uuid.v4() + '.jpg'
// Saving image to static folder (move to -> ../static/images)
img.mv(path.resolve(__dirname, '..', 'static', 'images', fileName))
//...
As was mentioned in frontend repository, in controllers I've implemented logic for client to:
- Handle authorization, password encryption and session.
- Get vehicles info, images and attributes. Sort them by various options in various orders.
- Roles and ability to check role.
- Ability to add and delete vehicles from cart, get specific user's cart.
- Ability to set and change rating for a vehicle.
- Ability for
ADMIN
to create and delete types, brands and vehicles. - Validate user input data (via express-validator).
- PostreSQL (Postico as a client, Sequelize as an ORM technology)
- NodeJS
- Express (+ express-validator, express-fileupload)
- jsonwebtoken
- bcrypt, uuid