# bhanavikochhar/itheecreates architecture

> Architecture diagram of the GitHub repository bhanavikochhar/itheecreates, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/bhanavikochhar/itheecreates
- Repository: https://github.com/bhanavikochhar/itheecreates

## Overview

#### 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`](https://github.com/bhanavikochhar/itheecreates/blob/main/server.js) (Express server), [`routes/orders.js`](https://github.com/bhanavikochhar/itheecreates/blob/main/routes/orders.js) (Order API), [`routes/products.js`](https://github.com/bhanavikochhar/itheecreates/blob/main/routes/products.js) (Catalog API), [`routes/users.js`](https://github.com/bhanavikochhar/itheecreates/blob/main/routes/users.js) (Customer state API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_storefront["Storefront"]
  node_storefront_pages["Storefront pages<br/>static HTML<br/>[index.html]"]
  node_storefront_js["Storefront client<br/>browser JavaScript<br/>[global.js]"]
end

subgraph group_admin["Admin UI"]
  node_admin_pages["Admin pages<br/>static HTML<br/>[index.html]"]
  node_admin_analytics["Analytics client<br/>browser JavaScript<br/>[analytics.js]"]
end

subgraph group_api["Node API"]
  node_server{{"Express server<br/>Node entry point<br/>[server.js]"}}
  node_migration["Database setup<br/>migration bootstrap<br/>[migrate.js]"]
  node_auth_routes["Auth API<br/>Express routes<br/>[auth.js]"]
  node_auth_middleware["Authentication<br/>Express middleware<br/>[auth.js]"]
  node_admin_middleware["Admin authorization<br/>Express middleware<br/>[admin.js]"]
  node_catalog_routes["Catalog API<br/>Express routes<br/>[products.js]"]
  node_user_routes["Customer state API<br/>Express routes<br/>[users.js]"]
  node_order_routes["Order API<br/>Express routes<br/>[orders.js]"]
  node_content_routes["Blog &amp; category API<br/>Express routes<br/>[blogs.js]"]
  node_analytics_routes["Analytics API<br/>Express routes<br/>[analytics.js]"]
end

subgraph group_data["Data &amp; services"]
  node_mongo[("MongoDB<br/>database")]
  node_user_model["User model<br/>Mongoose model<br/>[User.js]"]
  node_product_model["Product model<br/>Mongoose model<br/>[Product.js]"]
  node_order_model["Order model<br/>Mongoose model<br/>[Order.js]"]
  node_category_model["Category model<br/>Mongoose model<br/>[Category.js]"]
  node_uploads["Local uploads<br/>filesystem storage"]
  node_email["Gmail SMTP<br/>notification service<br/>[sendEmail.js]"]
end

node_storefront_pages -->|"runs"| node_storefront_js
node_storefront_js -->|"REST requests"| node_server
node_admin_pages -->|"runs"| node_admin_analytics
node_admin_analytics -->|"admin requests"| node_server
node_server -->|"mounts"| node_auth_routes
node_server -->|"mounts"| node_catalog_routes
node_server -->|"mounts"| node_user_routes
node_server -->|"mounts"| node_order_routes
node_server -->|"mounts"| node_content_routes
node_server -->|"mounts"| node_analytics_routes
node_server -->|"serves and creates"| node_uploads
node_migration -->|"initializes"| node_mongo
node_user_routes -->|"requires"| node_auth_middleware
node_order_routes -->|"requires"| node_auth_middleware
node_catalog_routes -->|"protects writes"| node_admin_middleware
node_order_routes -->|"protects status changes"| node_admin_middleware
node_analytics_routes -->|"protects"| node_admin_middleware
node_user_routes -->|"updates cart/wishlist"| node_user_model
node_catalog_routes -->|"queries and manages"| node_product_model
node_content_routes -->|"manages"| node_category_model
node_order_routes -->|"consumes cart"| node_user_model
node_order_routes -->|"verifies and decrements stock"| node_product_model
node_order_routes -->|"creates and updates"| node_order_model
node_user_model -->|"persists"| node_mongo
node_product_model -->|"persists"| node_mongo
node_order_model -->|"persists"| node_mongo
node_category_model -->|"persists"| node_mongo
node_analytics_routes -->|"aggregation pipelines"| node_mongo
node_catalog_routes -->|"stores images"| node_uploads
node_content_routes -->|"stores images"| node_uploads
node_order_routes -->|"order notifications"| node_email

click node_storefront_pages "https://github.com/bhanavikochhar/itheecreates/blob/main/index.html"
click node_storefront_js "https://github.com/bhanavikochhar/itheecreates/blob/main/js/global.js"
click node_admin_pages "https://github.com/bhanavikochhar/itheecreates/blob/main/admin/index.html"
click node_admin_analytics "https://github.com/bhanavikochhar/itheecreates/blob/main/admin/analytics.js"
click node_server "https://github.com/bhanavikochhar/itheecreates/blob/main/server.js"
click node_migration "https://github.com/bhanavikochhar/itheecreates/blob/main/migrate.js"
click node_auth_routes "https://github.com/bhanavikochhar/itheecreates/blob/main/routes/auth.js"
click node_auth_middleware "https://github.com/bhanavikochhar/itheecreates/blob/main/middleware/auth.js"
click node_admin_middleware "https://github.com/bhanavikochhar/itheecreates/blob/main/middleware/admin.js"
click node_catalog_routes "https://github.com/bhanavikochhar/itheecreates/blob/main/routes/products.js"
click node_user_routes "https://github.com/bhanavikochhar/itheecreates/blob/main/routes/users.js"
click node_order_routes "https://github.com/bhanavikochhar/itheecreates/blob/main/routes/orders.js"
click node_content_routes "https://github.com/bhanavikochhar/itheecreates/blob/main/routes/blogs.js"
click node_analytics_routes "https://github.com/bhanavikochhar/itheecreates/blob/main/routes/analytics.js"
click node_user_model "https://github.com/bhanavikochhar/itheecreates/blob/main/models/User.js"
click node_product_model "https://github.com/bhanavikochhar/itheecreates/blob/main/models/Product.js"
click node_order_model "https://github.com/bhanavikochhar/itheecreates/blob/main/models/Order.js"
click node_category_model "https://github.com/bhanavikochhar/itheecreates/blob/main/models/Category.js"
click node_email "https://github.com/bhanavikochhar/itheecreates/blob/main/utils/sendEmail.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_storefront_pages,node_storefront_js toneBlue
class node_admin_pages,node_admin_analytics toneAmber
class node_server,node_migration,node_auth_routes,node_auth_middleware,node_admin_middleware,node_catalog_routes,node_user_routes,node_order_routes,node_content_routes,node_analytics_routes toneMint
class node_mongo,node_user_model,node_product_model,node_order_model,node_category_model,node_uploads,node_email toneRose
```

## Components

### Storefront

- [Storefront pages](https://github.com/bhanavikochhar/itheecreates/blob/main/index.html): static HTML · Public catalog, content, and shopping pages. · `index.html`
- [Storefront client](https://github.com/bhanavikochhar/itheecreates/blob/main/js/global.js): browser JavaScript · Calls APIs and loads shared page chrome. · `js/global.js`

### Admin UI

- [Admin pages](https://github.com/bhanavikochhar/itheecreates/blob/main/admin/index.html): static HTML · Management and reporting interface. · `admin/index.html`
- [Analytics client](https://github.com/bhanavikochhar/itheecreates/blob/main/admin/analytics.js): browser JavaScript · `admin/analytics.js`

### Node API

- [Express server](https://github.com/bhanavikochhar/itheecreates/blob/main/server.js): Node entry point · Starts HTTP, mounts routes, serves static assets, and initializes storage. · `server.js`
- [Database setup](https://github.com/bhanavikochhar/itheecreates/blob/main/migrate.js): migration bootstrap · Connects MongoDB and prepares initial categories. · `migrate.js`
- [Auth API](https://github.com/bhanavikochhar/itheecreates/blob/main/routes/auth.js): Express routes · Registration and login issue JWT identity. · `routes/auth.js`
- [Authentication](https://github.com/bhanavikochhar/itheecreates/blob/main/middleware/auth.js): Express middleware · Validates JWTs for customer operations. · `middleware/auth.js`
- [Admin authorization](https://github.com/bhanavikochhar/itheecreates/blob/main/middleware/admin.js): Express middleware · Enforces administrative role and registration key policy. · `middleware/admin.js`
- [Catalog API](https://github.com/bhanavikochhar/itheecreates/blob/main/routes/products.js): Express routes · Public product reads plus admin product management and filtering. · `routes/products.js`
- [Customer state API](https://github.com/bhanavikochhar/itheecreates/blob/main/routes/users.js): Express routes · Manages embedded carts and wishlists. · `routes/users.js`
- [Order API](https://github.com/bhanavikochhar/itheecreates/blob/main/routes/orders.js): Express routes · Creates orders, verifies stock, and manages cancellation/status. · `routes/orders.js`
- [Blog & category API](https://github.com/bhanavikochhar/itheecreates/blob/main/routes/blogs.js): Express routes · Serves content and admin-managed categories/blogs. · `routes/blogs.js`
- [Analytics API](https://github.com/bhanavikochhar/itheecreates/blob/main/routes/analytics.js): Express routes · Runs sales, revenue, trend, category, and customer aggregations. · `routes/analytics.js`

### Data & services

- **MongoDB**: database · Persistent commerce collections and aggregation source.
- [User model](https://github.com/bhanavikochhar/itheecreates/blob/main/models/User.js): Mongoose model · Stores accounts plus cart and wishlist state. · `models/User.js`
- [Product model](https://github.com/bhanavikochhar/itheecreates/blob/main/models/Product.js): Mongoose model · Searchable inventory with stock. · `models/Product.js`
- [Order model](https://github.com/bhanavikochhar/itheecreates/blob/main/models/Order.js): Mongoose model · Preserves purchase lifecycle data. · `models/Order.js`
- [Category model](https://github.com/bhanavikochhar/itheecreates/blob/main/models/Category.js): Mongoose model · `models/Category.js`
- **Local uploads**: filesystem storage · Server-managed multipart image storage.
- [Gmail SMTP](https://github.com/bhanavikochhar/itheecreates/blob/main/utils/sendEmail.js): notification service · Sends order and cancellation notifications. · `utils/sendEmail.js`

## Connections

- 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
