Skip to main content

Tech Vault (E-Commerce App)

E-Commerce App.
Last updated: August 8, 2024

#Description

Tech Vault is a backend API for an ecommerce platform selling tech products like PC hardware, software, games, storage devices, office equipment, and more. Built with NestJS, Node.js, and TypeScript, it uses TypeORM with Postgres for persistent storage and Redis for caching, ensuring performance and reliability..

#Technology Stack

  1. TypeScript
  2. Nest.js
  3. Postgres SQL
  4. TypeORM
  5. Nodemailer
  6. Cloudinary
  7. Multer
  8. Winston
  9. Docker
  10. Stripe
  11. Passport
  12. …etc

#Database Design

#PDF

#code with dbml language

// Users Table
Table users {
id serial [primary key]
first_name varchar(50) [not null]
last_name varchar(50) [not null]
password varchar(50) [not null]
created_at timestamp [not null, default: `now()`]
updated_at timestamp [not null, default: `now()`]
}
// Phone Numbers
Table phones_numbers {
id serial [primary key]
phoneNumber varchar(25)
isPrimary boolean [not null, default: false]
user_id int [not null]
created_at timestamp [not null, default: `now()`]
updated_at timestamp [not null, default: `now()`]
}
Ref: phones_numbers.user_id > users.id [delete: cascade,update no action]
// Emails Table
Table emails {
id int [pk, increment]
user_id int [not null]
email varchar(25) [not null, unique]
isPrimary boolean [not null, default: false]
created_at timestamp [not null, default: `now()`]
updated_at timestamp [not null, default: `now()`]
}
Ref: emails.user_id > users.id [delete: cascade, update: no action]
// User Image
Table user_image {
id serial [primary key]
url varchar(255)
image_id varchar(255)
user_id int [not null, unique]
created_at timestamp [not null, default: `now()`]
updated_at timestamp [not null, default: `now()`]
}
Ref: user_image.user_id > users.id [delete: cascade, update: no action]
// Addresses Table
Table addresses {
id serial [primary key]
city varchar(100) [not null]
postCode varchar(20) [not null]
country varchar(20) [not null]
isPrimary boolean [not null, default: false]
user_id int [not null]
order_id int
created_at timestamp [not null, default: `now()`]
updated_at timestamp [not null, default: `now()`]
}
Ref: addresses.user_id > users.id [delete: cascade, update: no action]
Ref: addresses.order_id - orders.address_id [delete: cascade, update: no action]
// Notifications Table
Table notifications {
id serial [primary key]
user_id int [not null]
read boolean [not null, default: false]
message text [not null]
created_at timestamp [not null, default: `now()`]
updated_at timestamp [not null, default: `now()`]
}
Ref: notifications.user_id > users.id
// Products Table
Table products {
id serial [primary key]
name varchar(255) [not null]
price decimal [not null, default: 0]
category_id int
created_at timestamp [not null, default: `now()`]
updated_at timestamp [not null, default: `now()`]
}
Ref: products.category_id > categories.id [delete: set null, update: no action]
// Category Table
Table categories {
id serial [primary key]
name varchar(50) [not null]
description varchar(500)
created_at timestamp [not null, default: `now()`]
updated_at timestamp [not null, default: `now()`]
}
// Images Table
Table product_image {
id serial [primary key]
url varchar(255)
image_id varchar(255)
product_id int [not null]
created_at timestamp [not null, default: `now()`]
updated_at timestamp [not null, default: `now()`]
}
Ref: product_image.product_id > products.id [delete: cascade, update: no action]
// Reviews Table
Table reviews {
id serial [primary key]
user_id int [not null]
product_id int [not null]
rating int
created_at timestamp [not null, default: `now()`]
updated_at timestamp [not null, default: `now()`]
}
Ref: reviews.user_id > users.id
Ref: reviews.product_id > products.id
// WishList
Table wishlist {
id serial [primary key]
user_id int [not null]
product_id int [not null]
created_at timestamp [not null, default: `now()`]
updated_at timestamp [not null, default: `now()`]
}
Ref: wishlist.user_id - users.id [delete: cascade, update: no action]
Ref: wishlist.product_id > products.id [delete: set null, update: no action]
// Cart Table
Table carts {
id serial [primary key]
user_id int [not null, unique]
created_at timestamp [not null, default: `now()`]
updated_at timestamp [not null, default: `now()`]
}
Ref: carts.user_id > users.id
// Cart Items Table
Table cart_items {
id serial [primary key]
quantity int [not null]
cart_id int [not null]
product_id int [not null]
created_at timestamp [not null, default: `now()`]
updated_at timestamp [not null, default: `now()`]
}
Ref: cart_items.cart_id > carts.id [delete: cascade, update: no actions]
Ref: cart_items.product_id > products.id [delete: cascade, update: no actions]
// Order Table
Table orders {
id serial [primary key]
user_id int [not null]
total_amount decimal [not null]
order_date timestamp
address_id int [not null]
created_at timestamp [not null, default: `now()`]
updated_at timestamp [not null, default: `now()`]
}
Ref: orders.user_id > users.id [delete: cascade, update: no actions]
// Order Items Table
Table order_items {
id serial [primary key]
quantity int [not null]
price decimal [not null]
order_id int [not null]
product_id int [not null]
created_at timestamp [not null, default: `now()`]
updated_at timestamp [not null, default: `now()`]
}
Ref: order_items.order_id > orders.id [delete: cascade, update: no actions]
Ref: order_items.product_id > products.id [delete: cascade, update: no actions]
// Promo Codes Table
Table promo_codes {
id serial [primary key]
code varchar(50) [not null]
discount int [not null, default: 0]
expiration_date timestamp [not null, default: `now()`]
usage_limit int [not null, default: 0]
usage_count int [not null, default: 0]
is_active boolean [not null, default: true]
created_at timestamp [not null, default: `now()`]
updated_at timestamp [not null, default: `now()`]
}