Comprehensive Technical Specification & Architecture Plan
Nature Think is a full-stack e-commerce platform dedicated to natural products. Built with a modern React frontend and a robust Node.js/Express backend, it features a custom file-based database (EveloDB) for data persistence. The platform supports user authentication, product management, order processing, and a comprehensive admin dashboard.
The system uses a collection-based JSON storage engine. Key collections include:
| Collection | Description & Key Fields |
|---|---|
users |
Stores user profiles. Key fields: id, name, email,
password (hashed), phone, address,
avatarUrl, role (user/seller/admin), isActive,
favourites (array of item ids), suggestion,
lastLogin, loginsIpHistory (last N IPs), and
cartItemsCount.
|
stock |
Product inventory. Key fields: id, name, seller,
sellerId, desc, currency, quantity,
images, videos, category, subcategory,
keywords, rating, sellCount, freeze, and
product variants products[] with label, price,
mass (grams), and optional discountedPrice. |
orders |
Customer orders. Key fields: id, user (user id),
items (array of CartType entries with product snapshot),
deliveryFee, totalPrice, totalMass,
address, phone, name, email,
type ('pickup'|'cod'), timestamp, state
(pending|accepted|ontheway|rejected|delivered|cancelled), optional notes
(timeline entries), trackingCode, deliveryDate, and
podData (QR data / proof of delivery). Delivery events set
deliveredAt when applicable.
|
cart |
Per-user cart items. Each record contains id, user,
item (stock id), quantity, product snapshot (label,
mass, price), total, and itemData (name, image, currency) for
rendering and consistency.
|
revenue |
Financial tracking. Records: timestamp, revenue, and
packageWeight (used for analytics and reporting). |
comments |
Product comments and reviews. Fields: id, item (stock id),
user, optional userName, userAvatar,
rating (0–5), text, optional media[], and
timestamp.
|
delivery |
Delivery services and configuration. Fields: name, icon,
description, website, phone,
authorization, and prices (e.g., basic,
up). Used for calculating fees and courier integrations.
|
notifications |
In-app and push notifications. Fields: id, title,
body, optional html, url (link target),
timestamp, icon ('info'|'warning'|'error'|'success'), and numeric
code for categorization.
|
/api/get-verify-email - Send OTP
for signup or password reset (returns success/error)/api/signup - Register
(Validates OTP, hashes password)/api/login - Authenticate &
return JWT/api/get-user - Retrieve profile
by token/api/edit-user - Update profile
details/api/reset-password - Reset
password using OTP. Request body: { email, newPassword, otp }. Server validates the OTP
(stored per-email with an expireAt timestamp), enforces attempt limits, hashes the new
password with bcrypt (salt rounds: 10), and updates the user's password via the
database db.edit. Returns detailed error messages for missing fields, expired/invalid
OTP, too many attempts, or DB failures./api/change-password - Change
password for authenticated users (protected by authenticateUser). Request body:
{ oldPassword, newPassword }. The route delegates to
userFunctions.changePassword which validates the current password, hashes the new
password, and persists the update./api/cart - Manage cart
(Add/Remove/Get)/api/favourites - Toggle user
favourites/api/order - Place new order
/api/stock - Retrieve product
list/api/comment-item - Rate &
review products/api/admin/users - Manage user
accounts/api/admin/orders - Order
fulfillment & tracking/api/proof-of-delivery - Mark
order delivered via QR scan (protected by authCourier). Request body:
{ qrData }. Server decodes qrData to an order ID, validates the order,
ensures it isn't already delivered, sets state: 'delivered' and records
deliveredAt timestamp via db.edit('orders', ...). Returns errors for
missing QR, order not found, already delivered, or DB failures./api/admin/stock - Inventory
management/api/admin/delivery - Configure
delivery fees/api/admin/data - System
analytics/api/backup-restore - Create
backup (download zip) or restore from zip. Protected by authenticateAdmin.Purpose: Improve organic discoverability and rich result coverage for product pages while keeping crawlability and performance high.
robots.txt, and submit to
Search Consoles./store/item/:slugId with preRenderItemSlug).updateSiteMap(items) to produce XML; run on
product create/update/delete and as a scheduled job.hreflang support for multi-lingual pages./cdn/images route +
server-side resizing & quality query params for fast thumbnails and social images./robots.txt and enforce canonical &
noindex/noarchive where applicable.updateSiteMap to persist sitemap file and return the XML correctly; add
unit/integration tests.preRenderItemSlug outputs valid Product JSON-LD and canonical tag using
process.env.SITE_URL.sitemap.xml with
lastmod dates.process.env.SITE_URL is set in production and used
consistently for canonical and sitemap generation.updateRevenue() aggregates data from 'delivered'
orders to track income and package weights.updateSellCount(orderId) automatically decrements
inventory and increments 'sellCount' upon order placement.calculateRating(itemId) dynamically computes average
scores from the comments collection.deleteUser(userId) ensures data integrity by
removing associated comments, orders, cart items, and favourites.proofOfDelivery(req) handles
courier-authenticated QR scans. It decodes qrData to an order ID, verifies the order
exists and is not already delivered, sets state to 'delivered' and records
deliveredAt (ISO timestamp). The endpoint is protected by authCourier
middleware and returns informative error responses for missing/invalid QR data, non-existent orders,
idempotent deliveries, or DB update failures.bcrypt (Salt rounds: 10).emailVerifyCodes) with an
expireAt timestamp (typical expiry: 10 minutes). Invalid OTP submissions
increment an attempts counter and the server enforces a max attempts limit
(default: 5).db.edit('users', ...); detailed error responses are returned for
missing/expired/invalid OTPs or DB failures./api/change-password is protected by authenticateUser and
delegates to userFunctions.changePassword which verifies the old password,
hashes the new password, and persists the update.handleBackupAndRestore allows admins to generate a
full system backup (database + files) as a ZIP archive and restore from it. The system handles file
buffering, validation, and secure cleanup of temporary files.
nature-think/
├── backend/
│ ├── index.js # Start Application
│ ├── apiServer.js # Express Application Entry Point
│ ├── package.json # Backend Dependencies
│ ├── database/ # Database Schema & Models
│ └── middleware/
│ ├── auth.js # Authentication Middleware
│ ├── utills.js # Core Database & Business Logic
│ ├── backup.js # Backup & Restore logic
│ ├── sendEmail.js # Email Service (Nodemailer)
│ ├── tools.js # Utility Functions (Token, Formatting)
│ ├── evelodb-config.js # Database Configuration
│ ├── dataManager.js # Data Management Utilities
│ ├── updateSiteMap.js # Generate Sitemap
│ └── resendMail.js # Email Resending Logic
└── frontend/
├── vite.config.ts # Vite Configuration
├── tailwind.config.js # Tailwind Configuration
├── project_plan.html # This Document
└── src/
├── main.tsx # React Entry Point
├── App.tsx # Main App Component
├── admin/ # Admin Dashboard
│ ├── AdminHome.tsx
│ ├── AdminActions.tsx
│ └── components/
│ ├── ManageUsers.tsx
│ ├── ManageOrders.tsx
│ ├── PackageLabel.tsx
│ ├── Stock.tsx
│ ├── CreateItem.tsx
│ ├── EditItem.tsx
│ ├── DeliveryService.tsx
│ └── ManageUpdates.tsx
└── routes/ # User Facing Routes
├── Home.tsx
├── Store.tsx
├── Item.tsx
├── Cart.tsx
├── Orders.tsx
├── Favourites.tsx
├── ChangePassword.tsx
├── ResetPassword.tsx
├── Login.tsx
├── Signup.tsx
├── Settings.tsx
├── About.tsx
├── Help.tsx
├── Updates.tsx
├── PrivacyPolicy.tsx
├── TermsConditions.tsx
├── WarrantyInfo.tsx
├── ShippingPolicy.tsx
├── Footer.tsx
└── components/ # Shared Components
├── NavBar.tsx
├── ItemComponent.tsx
├── Loading.tsx
├── Rain.tsx
├── types.ts # TypeScript Interfaces
├── utils.ts # Frontend Utilities
├── sendReq.ts # API Request Helper
├── categories.ts # Category Definitions
├── cart/ # Cart Specific Components
│ ├── CartItem.tsx
│ └── PlaceOrderSection.tsx
├── home/ # Home Page Components
│ ├── Hero.tsx
│ ├── Overview.tsx
│ └── TopItems.tsx
└── settings/ # Settings Page Components
├── Account.tsx
└── Suggestions.tsx