How bhanavikochhar/itheecreates works
Purpose and Entry Points
Ithee is a MongoDB-backed e-commerce system with a static browser storefront/admin UI and an Express REST API. The server entry point is server.js; database setup and initial category preparation run through migrate.js. Public pages begin at index.html; the administration UI begins at admin/index.html.
HTTP Application and API Boundary
server.js owns Express startup, MongoDB connection, API route mounting, static asset delivery, upload-directory creation, and default-category initialization. API resources are split by domain under routes/: authentication, catalog, user state, orders, blogs/categories, and analytics. The browser-facing static pages call these endpoints through page-specific JavaScript.
Paths: server.js, routes/products.js, routes/users.js.
Identity and Authorization
Registration/login issue JWT-based identity, while request authentication is enforced before user-specific operations. A separate role gate protects administrative catalog, order, user, and analytics mutations/reads; admin registration requires an environment-supplied key. This creates a clear boundary between anonymous catalog/content access, authenticated customer state, and admin operations.
Paths: routes/auth.js, middleware/auth.js, middleware/admin.js.
Persistent Commerce Domain
Mongoose models define the primary MongoDB collections: users carry cart and wishlist state; products represent searchable/filterable inventory; orders preserve purchase lifecycle data; categories and blogs support catalog/content. Product, cart, and order operations depend on these models, with indexes and query/aggregation behavior intended for catalog lookup and reporting.
Paths: models/User.js, models/Product.js, models/Order.js.
Cart-to-Order Transaction Flow
Authenticated users modify embedded cart and wishlist state through user routes. Order creation consumes the cart, verifies inventory, decrements stock, creates the order, and sends a confirmation. Customers can request cancellation; administrators update order status and receive cancellation-related notifications. Inventory correctness and order state are therefore concentrated at the order-route/model boundary.
Paths: routes/users.js, routes/orders.js, utils/sendEmail.js.
Catalog, Content, and Uploads
Product and blog APIs provide public reads and admin-managed CRUD. Product/category routes support search, category and price filtering, sorting, and pagination. Multipart image uploads are accepted by product/blog management and stored under the server-managed uploads area (not present in the supplied tree); static frontend product and story pages render this content.
Paths: routes/products.js, routes/blogs.js, models/Category.js.
Reporting and Client Surfaces
Admin-only analytics endpoints execute MongoDB aggregation pipelines for sales, revenue, trends, category performance, and customer metrics. The admin pages provide the management/reporting client, while the root HTML pages plus js/ are a separate static storefront client. Shared headers/footers are loaded from partials.
Paths: routes/analytics.js, admin/analytics.js, js/global.js.
Runtime and External Dependencies
The material runtime is Node.js 14+ with Express and MongoDB 4+. Configuration comes from .env values represented by .env.example: Mongo connection, JWT secret, admin key, port/runtime mode, and Gmail SMTP credentials. Gmail SMTP is the external notification service; uploaded media is local server filesystem storage.
Paths: package.json, .env.example, utils/sendEmail.js.
Main entry points: server.js Express server · orders.js Order API · products.js Catalog API · users.js Customer state API
Components 21
Storefront
- Storefront pages · Public catalog, content, and shopping pages.
index.html - Storefront client · Calls APIs and loads shared page chrome.
js/global.js
Admin UI
- Admin pages · Management and reporting interface.
admin/index.html - Analytics client
admin/analytics.js
Node API
- Express server · Starts HTTP, mounts routes, serves static assets, and initializes storage.
server.js - Database setup · Connects MongoDB and prepares initial categories.
migrate.js - Auth API · Registration and login issue JWT identity.
routes/auth.js - Authentication · Validates JWTs for customer operations.
middleware/auth.js - Admin authorization · Enforces administrative role and registration key policy.
middleware/admin.js - Catalog API · Public product reads plus admin product management and filtering.
routes/products.js - Customer state API · Manages embedded carts and wishlists.
routes/users.js - Order API · Creates orders, verifies stock, and manages cancellation/status.
routes/orders.js - Blog & category API · Serves content and admin-managed categories/blogs.
routes/blogs.js - Analytics API · Runs sales, revenue, trend, category, and customer aggregations.
routes/analytics.js
Data & services
- MongoDB · Persistent commerce collections and aggregation source.
- User model · Stores accounts plus cart and wishlist state.
models/User.js - Product model · Searchable inventory with stock.
models/Product.js - Order model · Preserves purchase lifecycle data.
models/Order.js - Category model
models/Category.js - Local uploads · Server-managed multipart image storage.
- Gmail SMTP · Sends order and cancellation notifications.
utils/sendEmail.js
Connections 31
- Storefront pages → Storefront client: runs
- Storefront client → Express server: REST requests
- Admin pages → Analytics client: runs
- Analytics client → Express server: admin requests
- Express server → Auth API: mounts
- Express server → Catalog API: mounts
- Express server → Customer state API: mounts
- Express server → Order API: mounts
- Express server → Blog & category API: mounts
- Express server → Analytics API: mounts
- Express server → Local uploads: serves and creates
- Database setup → MongoDB: initializes
- Customer state API → Authentication: requires
- Order API → Authentication: requires
- Catalog API → Admin authorization: protects writes
- Order API → Admin authorization: protects status changes
- Analytics API → Admin authorization: protects
- Customer state API → User model: updates cart/wishlist
- Catalog API → Product model: queries and manages
- Blog & category API → Category model: manages
- Order API → User model: consumes cart
- Order API → Product model: verifies and decrements stock
- Order API → Order model: creates and updates
- User model → MongoDB: persists
- Product model → MongoDB: persists
- Order model → MongoDB: persists
- Category model → MongoDB: persists
- Analytics API → MongoDB: aggregation pipelines
- Catalog API → Local uploads: stores images
- Blog & category API → Local uploads: stores images
- Order API → Gmail SMTP: order notifications