This is a backend part of Fullstack project at Intergify 2024.
This backend provides a bunch of APIs to accomodate nice features in E-commerce transactioins with data saved in MongoDB.
Basically try to mimic the E-commerce site and make the site fully functional both frontend and backend side in my own way.
Simulate the way of Payment, Mailing, Hosting Images, Authenticate, Google account login etc.
I enjoyed the project with full of joy and also with lots of obstacles, but really had fun!
Check out the result here
Frontend: https://cool-awsome-shopping.netlify.app
Backend: https://fs17-fullstack.onrender.com/api/v1/products
Entities
- Users
- Products
- Categories
- Orders
- OrderItems
Enums
- Size
- OrderStatus
- UserRole
- node
^19.2.0
- npm
^9.2.0
Make sure you have npm installed globally.
$ git clone https://github.com/Woongsik/fullstack-e-commerce-api.git
$ cd fullstack-e-commerce-api
Check the .envExample
file and set variables into .env
!Important This should be done to run the the app
$ npm install # Install project dependencies
$ npm run start # Compile and launch on local environment
4. Navigate to http://localhost:{yourPortFromEnv}
In the package.json, below scripts are used.
"scripts": {
"start": "node dist/server.js",
"dev": "nodemon --watch 'src/**/*.ts' --exec ts-node src/server.ts",
"build": "tsc -p .",
"test": "jest --runInBand --forceExit --detectOpenHandles --coverage --verbose false"
}
-
Products
- Get list of all products with/without pagination(limit, offset)
- Get list of products, filtering (search) by: title, categories, sizes, price range
- Get list of sorted products by createdAt, price, title (ASC, DESC)
- Get a product by product id
-
Categories
- Get list of all categories
- Get a category by category id
-
Users
- Sign up a new user (username, password, first name, last name, email, address)
- Sign in user with email/password
- Update user profile (username, first name, last name, address)
- Update password (old password, new password)
- Forget password request
-
Order
- Get list of all user's orders
- Get a user's order by order ID
-
Admin
- Create a new product and update, remove
- Create a new category and update, remove
- Update a User role to Admin/Customer,
- Update a User active to Active/Inactive
- Remove a user
-
Files
- Upload image to Cloudinary
- Delete image from Cloudinary
-
Welcoming email by Mailersend
- When new user is registered, welcoming email will be sent
- Wwhen user forget the password, reset password will be sent
-
Image hosting by Cloudinary
- Upload image to cloudinary
-
Payment by Stripe
- Simulate payment transaction
-
Google account login
- User is able to login/registeration by google account
- Welcoming email generate an initial password for plain email/passowrd login
-
Admin
- The Admin role will be given only accpeted/registered email
- Other email will be registered as only Customer but can be changed by Admin
- ie.
[email protected]
(only for test purpose in the project)
src
┣ assets
┃ ┗ images
┃ ┃ ┣ ERD.png
┃ ┃ ┗ test.png
┣ config
┃ ┣ email.ts
┃ ┗ passport.ts
┣ controllers
┃ ┣ util
┃ ┃ ┗ controllerUtil.ts
┃ ┣ adminController.ts
┃ ┣ categoriesController.ts
┃ ┣ filesController.ts
┃ ┣ ordersController.ts
┃ ┣ productsController.ts
┃ ┗ usersController.ts
┣ errors
┃ ┗ ApiError.ts
┣ middlewares
┃ ┣ adminCheck.ts
┃ ┗ apiErrorHandlerMiddleware.ts
┣ misc
┃ ┣ types
┃ ┃ ┣ Category.ts
┃ ┃ ┣ GoogleCredential.ts
┃ ┃ ┣ JwtPayload.ts
┃ ┃ ┣ Order.ts
┃ ┃ ┣ Passport.ts
┃ ┃ ┣ Password.ts
┃ ┃ ┣ Payment.ts
┃ ┃ ┣ Product.ts
┃ ┃ ┣ Size.ts
┃ ┃ ┣ Sort.ts
┃ ┃ ┗ User.ts
┃ ┗ utils
┃ ┃ ┗ AuthUtil.ts
┣ model
┃ ┣ AddressModel.ts
┃ ┣ CategoryModel.ts
┃ ┣ OrderItemModel.ts
┃ ┣ OrderModel.ts
┃ ┣ ProductModel.ts
┃ ┗ UserModel.ts
┣ routers
┃ ┣ adminRouter.ts
┃ ┣ categoriesRouter.ts
┃ ┣ filesRouter.ts
┃ ┣ orderRouter.ts
┃ ┣ productsRouter.ts
┃ ┗ usersRouter.ts
┣ services
┃ ┣ categoriesService.ts
┃ ┣ filesService.ts
┃ ┣ ordersService.ts
┃ ┣ productsService.ts
┃ ┗ usersService.ts
┣ .DS_Store
┣ app.ts
┗ server.ts
Total 41 tests, 7 suits succeeded
Tests
- Controllers
- categoriesController.test.ts
- productsController.test.ts
- usersController.test.ts
- Middlewares
- adminCheck.spec.ts
- Services
- categoreisService.test.ts
- productsService.test.ts
- usersService.test.ts
Check test code in src/tests
$ npm run test
The API is live now hosted by AMAZON EC2 and RENDER For the best practice, I deployed it to both.
-
Amazon
- Check the live link here From EC2 instance
- Some examples
-
Render
- Check the live link here From Render instance
- Some examples
Other features requires authenticate via login/register