Database design - Learnathon-By-Geeky-Solutions/binary-brains GitHub Wiki
๐๏ธ Database Design Of AmarTech
AmarTech utilizes a relational database design with Entity Framework Core to manage entities and enforce relationships. Below is an overview of the core data models used in the system:
๐ง ApplicationUser (inherits from IdentityUser)
- Stores user profile details including name, address, and associated company.
- Linked to
Company
via CompanyId
.
- Supports role tracking via
Role
(non-persistent).
๐ข Company
- Holds company-specific information such as address, city, state, and phone.
- Used for associating users with business accounts.
๐ฆ Product
- Represents items for sale.
- Linked to
Category
through CategoryId
.
- Stores stock, discount, and audit metadata (created/updated).
๐๏ธ Category
- Classifies products.
- Includes display order and audit metadata.
๐ ShoppingCart
- Temporary cart for each
ApplicationUser
.
- Tracks selected product and quantity before checkout.
๐ OrderHeader
- Stores high-level order data.
- Includes user info, payment status, shipping, and billing address.
๐ฆ OrderDetail
- Line-item detail for each order.
- Links a specific product to an order with count and price.
ER Diagram Of AmarTech

๐ Database Relationships Overview
1. ApplicationUser โ Company
- Type: Optional One-to-One
- Foreign Key:
ApplicationUser.CompanyId
โ Company.Id
- Details: A user may or may not belong to a company.
2. ApplicationUser โ OrderHeader
- Type: One-to-Many
- Foreign Key:
OrderHeader.ApplicationUserId
โ ApplicationUser.Id
- Details: One user can place multiple orders.
3. ApplicationUser โ ShoppingCart
- Type: One-to-Many
- Foreign Key:
ShoppingCart.ApplicationUserId
โ ApplicationUser.Id
- Details: A user can have multiple items in their cart.
4. Category โ Product
- Type: One-to-Many
- Foreign Key:
Product.CategoryId
โ Category.Id
- Details: Each product belongs to one category.
5. Product โ ShoppingCart
- Type: One-to-Many
- Foreign Key:
ShoppingCart.ProductId
โ Product.Id
- Details: A product can exist in many users' carts.
6. OrderHeader โ OrderDetail
- Type: One-to-Many
- Foreign Key:
OrderDetail.OrderHeaderId
โ OrderHeader.Id
- Details: Each order can contain multiple order details (products).
7. Product โ OrderDetail
- Type: One-to-Many
- Foreign Key:
OrderDetail.ProductId
โ Product.Id
- Details: A product can appear in multiple orders.
๐ฆ 2๏ธโฃ Database Schema
๐ ApplicationUser Table
Column Name |
Data Type |
Description |
Id |
VARCHAR(450) |
Primary Key, unique identifier for each user. |
Name |
VARCHAR |
Full name of the user. |
StreetAddress |
VARCHAR |
Optional street address. |
City |
VARCHAR |
Optional city name. |
State |
VARCHAR |
Optional state name. |
PostalCode |
VARCHAR |
Optional postal/ZIP code. |
CompanyId |
INT |
Foreign key linking to Company. |
Role |
VARCHAR |
Not mapped. Used internally to store user role. |
๐ข Company Table
Column Name |
Data Type |
Description |
Id |
INT |
Primary Key. |
Name |
VARCHAR |
Name of the company. |
StreetAddress |
VARCHAR |
Company's street address. |
City |
VARCHAR |
City location of the company. |
State |
VARCHAR |
State location of the company. |
PostalCode |
VARCHAR |
Postal code of the company. |
PhoneNumber |
VARCHAR |
Contact phone number (BD format). |
๐๏ธ Category Table
Column Name |
Data Type |
Description |
Id |
INT |
Primary Key. |
Name |
VARCHAR(30) |
Name of the category. |
DisplayOrder |
INT |
Order in which category is displayed. |
IsActive |
BOOLEAN |
Whether category is active. |
CreatedBy |
VARCHAR |
User who created the category. |
CreatedDate |
DATETIME |
Date of creation. |
UpdatedBy |
VARCHAR |
User who last updated. |
UpdatedDate |
DATETIME |
Date of last update. |
๐ฆ Product Table
Column Name |
Data Type |
Description |
Id |
INT |
Primary Key. |
Title |
VARCHAR |
Product title. |
Description |
VARCHAR(1000) |
Description of the product. |
ImageUrl |
VARCHAR |
Image URL. |
Price |
DECIMAL |
Price of the product. |
CategoryId |
INT |
Foreign key linking to Category. |
StockQuantity |
INT |
Available quantity. |
DiscountAmount |
DECIMAL |
Discount on product. |
IsActive |
BOOLEAN |
Whether product is available. |
CreatedBy |
VARCHAR |
Created by user. |
CreatedDate |
DATETIME |
Date created. |
UpdatedBy |
VARCHAR |
Updated by user. |
UpdatedDate |
DATETIME |
Date updated. |
๐งพ OrderHeader Table
Column Name |
Data Type |
Description |
Id |
INT |
Primary Key. |
ApplicationUserId |
VARCHAR(450) |
Foreign key to ApplicationUser. |
OrderDate |
DATETIME |
Date of order. |
ShippingDate |
DATETIME |
Date of shipping. |
OrderTotal |
DOUBLE |
Total amount. |
OrderStatus |
VARCHAR |
Current order status. |
PaymentStatus |
VARCHAR |
Payment status. |
TrackingNumber |
VARCHAR |
Courier tracking number. |
Carrier |
VARCHAR |
Shipping carrier. |
PaymentDate |
DATETIME |
Date of payment. |
PaymentDueDate |
DATE |
Due date for payment. |
SessionId |
VARCHAR |
Stripe session ID. |
PaymentIntentId |
VARCHAR |
Stripe payment intent. |
PhoneNumber |
VARCHAR |
Shipping contact number. |
StreetAddress |
VARCHAR |
Shipping address. |
City |
VARCHAR |
City for shipping. |
State |
VARCHAR |
State for shipping. |
PostalCode |
VARCHAR |
Postal code. |
Name |
VARCHAR |
Recipient's name. |
๐งพ OrderDetail Table
Column Name |
Data Type |
Description |
Id |
INT |
Primary Key. |
OrderHeaderId |
INT |
Foreign key to OrderHeader. |
ProductId |
INT |
Foreign key to Product. |
Count |
INT |
Number of units ordered. |
Price |
DOUBLE |
Price per unit at the time of order. |
๐ ShoppingCart Table
Column Name |
Data Type |
Description |
Id |
INT |
Primary Key. |
ProductId |
INT |
Foreign key to Product. |
Count |
INT |
Quantity in cart. |
ApplicationUserId |
VARCHAR(450) |
Foreign key to ApplicationUser. |
Price |
DOUBLE |
Computed (not mapped) price. |
Thank you for reading our Database design wiki page, Happy Coding ๐ค