Data models
The 31 Mongoose models behind the API, how the core ones relate, and the exact values of every important enum.
The API stores everything in MongoDB through 31 Mongoose models, one file
each in apps/api/models/. The enum values on this page are copied from those
files. The same shapes are shared with the apps as TypeScript types in
@babyshop/types.
How the core models relate
Section titled “How the core models relate”erDiagram
USER ||--o{ ORDER : places
USER ||--o| CART : owns
USER ||--o| VENDOR : "may become"
ORDER }o--|{ PRODUCT : "items reference"
CART }o--o{ PRODUCT : holds
PRODUCT }o--|| CATEGORY : "belongs to"
PRODUCT }o--o| BRAND : has
PRODUCT }o--o| PRODUCT_TYPE : "typed as"
PRODUCT }o--o| VENDOR : "sold by"
CATEGORY }o--o| CATEGORY : parent
ORDER ||--o{ CASH_COLLECTION : "COD tracked by"
PURCHASE }o--|| SUPPLIER : "bought from"
PAGE ||--o{ PAGE_SECTION : contains
Some data is embedded rather than stored in its own collection. A user’s
addresses, wishlist and cart items live inside User. A product’s reviews and
ratings live inside Product. An order’s line items and its
status_history live inside Order.
All models
Section titled “All models”| Model | File | Key fields |
|---|---|---|
| User | userModel.ts |
role, employee_role, authProvider, addresses[], wishlist[], cart[], tokenVersion |
| Order | orderModel.ts |
userId, items[], status, paymentStatus, paymentMethod, payment_info, assignedPacker, assignedDeliveryman, codAmount, status_history[] |
| Product | productModel.ts |
name, slug, price, purchasePrice, discountPercentage, stock, images, category, brand, productType, vendor, approvalStatus, colors[], sizes[], reviews[], averageRating, viewCount |
| Category | categoryModel.ts |
name, type, parent (self-reference for subcategories) |
| Brand | brandModel.ts |
name, image |
| ProductType | productTypeModel.ts |
Home-page product groups |
| ProductBase | productBaseModel.ts |
Curated collections with a slug |
| Color, Size | colorModel.ts, sizeModel.ts |
Variant lookups |
| Cart | cartModel.ts |
userId (unique), items[] |
| Vendor | vendorModel.ts |
userId (unique), storeName (unique), status |
| VendorConfig | vendorConfigModel.ts |
Global switch and settings for vendors |
| CashCollection | cashCollectionModel.ts |
Order, deliveryman, accounts employee, status |
| Purchase | purchaseModel.ts |
purchaseNumber, items[], supplier, status, createdBy / approvedBy / purchasedBy / receivedBy, statusHistory[] |
| Supplier | supplierModel.ts |
Contact details, payment terms |
| Salary | salaryModel.ts |
Employee, month and year (unique together), status, payment method |
| Notification | notificationModel.ts |
type, priority, target, optional order |
| Subscription | subscriptionModel.ts |
Newsletter email, source, status |
| Banner, AdsBanner | bannerModel.ts, adsBannerModel.ts |
Hero and promo banners |
| WebsiteIcon | websiteIconModel.ts |
Logos and icons by key and category |
| WebsiteConfig | websiteConfigModel.ts |
Page sections by pageType, with layout options |
| ComponentType | componentTypeModel.ts |
Reusable section component definitions |
| Menu | menuModel.ts |
Navigation and mega-menu items |
| Page | pageModel.ts |
CMS pages, unique slug, at most one homepage |
| PageSection | pageSectionModel.ts |
page, type, layout, products[] or category or autoRule |
| Blog | blogModel.ts |
Post, author, category, linked product bases |
| BlogAuthor, BlogCategory, BlogTag | blog*Model.ts |
Blog lookups |
| SocialMedia | socialMediaModel.ts |
Platform and link |
| Field | Values |
|---|---|
status |
pending, address_confirmed, confirmed, processing, packed, delivering, delivered, completed, cancelled |
paymentStatus |
pending, paid, failed, refunded, cod_collected |
paymentMethod |
stripe, sslcommerz, cod |
The order lifecycle is explained on How it works.
apps/api/models/userModel.ts| Field | Values |
|---|---|
role |
admin, user, employee, vendor, preview |
employee_role |
packer, deliveryman, accounts, incharge, call_center (required when role is employee) |
authProvider |
local, google, github |
What each role may do is on Auth and roles.
Catalog
Section titled “Catalog”| Model.field | Values |
|---|---|
Product.approvalStatus |
draft, pending, approved, rejected |
Category.type |
Featured, Hot Categories, Top Categories |
AdsBanner.type |
advertisement, promotional, seasonal, offer |
Vendors and staff
Section titled “Vendors and staff”| Model.field | Values |
|---|---|
Vendor.status |
pending, approved, rejected |
Purchase.status |
requisition, approved, purchased, received, cancelled |
Supplier payment terms |
cash, bank-transfer, check, credit, online, other |
Salary.status |
pending, paid, cancelled |
Salary payment method |
cash, bank_transfer, cheque, mobile_banking, other |
CashCollection.status |
collected, submitted, confirmed |
Notifications and subscriptions
Section titled “Notifications and subscriptions”| Model.field | Values |
|---|---|
Notification.type |
order_placed, order_confirmed, order_shipped, order_delivered, order_cancelled, payment_success, payment_failed, account_update, general, offer, deal, announcement, promotion, alert, admin_message |
Notification.priority |
low, normal, high, urgent |
Notification target |
all, specific, role-based |
Subscription.source |
homepage_modal, footer, popup, other |
Subscription.status |
active, unsubscribed |
| Field | Values |
|---|---|
PageSection.type |
manual, category, auto, banner |
PageSection.layout |
grid, carousel, banner, featured, two-column |
PageSection.autoRule |
newest, bestSelling, topRated, mostViewed, discounted, trending, lowStock |
WebsiteConfig.pageType |
home, product, blog, category, about, contact |
WebsiteIcon.category |
logo, favicon, social, footer, header, other |
An auto section fills itself from its autoRule, so a “Newest” or “Best
selling” row stays current without anyone editing it.