# naresh8k/kjn-ecommerce-site architecture

> Architecture diagram of the GitHub repository naresh8k/kjn-ecommerce-site, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/naresh8k/kjn-ecommerce-site
- Repository: https://github.com/naresh8k/kjn-ecommerce-site

## Overview

KJN Shop is an ecommerce storefront with a separate admin experience, backed by an Express/Prisma API. The customer journey spans account access, product discovery, cart and coupon management, checkout, payment, and order tracking; administrators manage catalog content, customers, orders, and payments. The graph includes those domain stages plus supporting authentication, email, reviews, and shipping integrations. Several backend links are evidenced by the SOURCE INDEX; frontend-to-API routing and some unsampled subsystem wiring are not shown, so those links are omitted or marked unverified.

Main entry points: [`backend/src/config/db.js`](https://github.com/naresh8k/kjn-ecommerce-site/blob/main/backend/src/config/db.js) (Prisma database), [`backend/src/modules/auth/auth.controller.js`](https://github.com/naresh8k/kjn-ecommerce-site/blob/main/backend/src/modules/auth/auth.controller.js) (Authentication), [`backend/src/config/mailer.js`](https://github.com/naresh8k/kjn-ecommerce-site/blob/main/backend/src/config/mailer.js) (Email delivery), [`backend/src/modules/orders/order.controller.js`](https://github.com/naresh8k/kjn-ecommerce-site/blob/main/backend/src/modules/orders/order.controller.js) (Orders and invoices)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_storefront["Customer storefront"]
  node_storefront_pages["Storefront pages"]
  node_auth_pages["Account pages<br/>[page.js]"]
  node_cart_store["Cart state<br/>[useCartStore.js]"]
  node_api_client["API client<br/>[api.js]"]
end

subgraph group_commerce["Commerce API"]
  node_catalog["Product catalog"]
  node_cart_api["Cart and coupons<br/>[cart.controller.js]"]
  node_orders["Orders and invoices"]
  node_payments["Payments and refunds"]
  node_auth_api["Authentication<br/>[auth.controller.js]"]
  node_reviews["Product reviews"]
end

subgraph group_operations["Admin and fulfillment"]
  node_admin["Admin operations"]
  node_shipping["Shipment management"]
end

subgraph group_platform["Shared services"]
  node_database[("Prisma database<br/>[db.js]")]
  node_mailer["Email delivery<br/>[mailer.js]"]
  node_auth_helpers["Auth helpers<br/>[otp.js]"]
  node_token_storage["Refresh-token storage<br/>[tokenStorage.js]"]
  node_invoice_service["Invoice generation<br/>[invoice.service.js]"]
  node_shipmozo_service["ShipMozo client<br/>[shipmozo.js]"]
end

node_customer(("Customer"))
node_razorpay{{"Razorpay"}}
node_shipmozo_external{{"ShipMozo"}}

node_customer -.->|"browses"| node_storefront_pages
node_customer -.->|"signs in"| node_auth_pages
node_cart_store -->|"calls"| node_api_client
node_api_client -.->|"requests"| node_cart_api
node_storefront_pages -.->|"loads products"| node_catalog
node_auth_pages -.->|"authenticates"| node_auth_api
node_cart_api -->|"reads and writes"| node_database
node_catalog -->|"reads catalog"| node_database
node_orders -->|"reads and writes"| node_database
node_orders -->|"generates invoices"| node_invoice_service
node_orders -->|"sends lifecycle email"| node_mailer
node_payments -->|"updates payment records"| node_database
node_payments -.->|"uses payments API"| node_razorpay
node_payments -->|"sends refund email"| node_mailer
node_auth_api -->|"reads and writes"| node_database
node_auth_api -->|"sends OTP email"| node_mailer
node_auth_api -->|"uses OTP helpers"| node_auth_helpers
node_auth_api -->|"stores refresh tokens"| node_token_storage
node_token_storage -->|"reads and writes"| node_database
node_reviews -->|"reads and writes"| node_database
node_admin -->|"reads and writes"| node_database
node_shipping -->|"updates shipment data"| node_database
node_shipping -->|"dispatches tracking"| node_shipmozo_service
node_shipmozo_service -.->|"calls carrier API"| node_shipmozo_external
node_shipping -->|"sends order email"| node_mailer

click node_storefront_pages "https://github.com/naresh8k/kjn-ecommerce-site/tree/main/frontend/app"
click node_auth_pages "https://github.com/naresh8k/kjn-ecommerce-site/blob/main/frontend/app/login/page.js"
click node_cart_store "https://github.com/naresh8k/kjn-ecommerce-site/blob/main/frontend/src/store/useCartStore.js"
click node_api_client "https://github.com/naresh8k/kjn-ecommerce-site/blob/main/frontend/src/lib/api.js"
click node_catalog "https://github.com/naresh8k/kjn-ecommerce-site/blob/main/backend/src/modules/products/product.controller.js"
click node_cart_api "https://github.com/naresh8k/kjn-ecommerce-site/blob/main/backend/src/modules/cart/cart.controller.js"
click node_orders "https://github.com/naresh8k/kjn-ecommerce-site/blob/main/backend/src/modules/orders/order.controller.js"
click node_payments "https://github.com/naresh8k/kjn-ecommerce-site/blob/main/backend/src/modules/payments/payment.controller.js"
click node_auth_api "https://github.com/naresh8k/kjn-ecommerce-site/blob/main/backend/src/modules/auth/auth.controller.js"
click node_reviews "https://github.com/naresh8k/kjn-ecommerce-site/blob/main/backend/src/modules/reviews/review.controller.js"
click node_admin "https://github.com/naresh8k/kjn-ecommerce-site/blob/main/backend/src/modules/admin/admin.controller.js"
click node_shipping "https://github.com/naresh8k/kjn-ecommerce-site/blob/main/backend/src/modules/shipmozo/shipmozo.controller.js"
click node_database "https://github.com/naresh8k/kjn-ecommerce-site/blob/main/backend/src/config/db.js"
click node_mailer "https://github.com/naresh8k/kjn-ecommerce-site/blob/main/backend/src/config/mailer.js"
click node_auth_helpers "https://github.com/naresh8k/kjn-ecommerce-site/blob/main/backend/src/utils/otp.js"
click node_token_storage "https://github.com/naresh8k/kjn-ecommerce-site/blob/main/backend/src/utils/tokenStorage.js"
click node_invoice_service "https://github.com/naresh8k/kjn-ecommerce-site/blob/main/backend/src/modules/orders/invoice.service.js"
click node_shipmozo_service "https://github.com/naresh8k/kjn-ecommerce-site/blob/main/backend/src/config/shipmozo.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_auth_pages,node_cart_store,node_api_client toneBlue
class node_catalog,node_cart_api,node_orders,node_payments,node_auth_api,node_reviews toneAmber
class node_admin,node_shipping toneMint
class node_database,node_mailer,node_auth_helpers,node_token_storage,node_invoice_service,node_shipmozo_service toneRose
class node_customer,node_razorpay,node_shipmozo_external toneIndigo
```

## Components

### Customer storefront

- [Storefront pages](https://github.com/naresh8k/kjn-ecommerce-site/tree/main/frontend/app): `frontend/app`
- [Account pages](https://github.com/naresh8k/kjn-ecommerce-site/blob/main/frontend/app/login/page.js): `frontend/app/login/page.js`
- [Cart state](https://github.com/naresh8k/kjn-ecommerce-site/blob/main/frontend/src/store/useCartStore.js): `frontend/src/store/useCartStore.js`
- [API client](https://github.com/naresh8k/kjn-ecommerce-site/blob/main/frontend/src/lib/api.js): `frontend/src/lib/api.js`

### Commerce API

- [Product catalog](https://github.com/naresh8k/kjn-ecommerce-site/blob/main/backend/src/modules/products/product.controller.js): `backend/src/modules/products/product.controller.js`
- [Cart and coupons](https://github.com/naresh8k/kjn-ecommerce-site/blob/main/backend/src/modules/cart/cart.controller.js): `backend/src/modules/cart/cart.controller.js`
- [Orders and invoices](https://github.com/naresh8k/kjn-ecommerce-site/blob/main/backend/src/modules/orders/order.controller.js): `backend/src/modules/orders/order.controller.js`
- [Payments and refunds](https://github.com/naresh8k/kjn-ecommerce-site/blob/main/backend/src/modules/payments/payment.controller.js): `backend/src/modules/payments/payment.controller.js`
- [Authentication](https://github.com/naresh8k/kjn-ecommerce-site/blob/main/backend/src/modules/auth/auth.controller.js): `backend/src/modules/auth/auth.controller.js`
- [Product reviews](https://github.com/naresh8k/kjn-ecommerce-site/blob/main/backend/src/modules/reviews/review.controller.js): `backend/src/modules/reviews/review.controller.js`

### Admin and fulfillment

- [Admin operations](https://github.com/naresh8k/kjn-ecommerce-site/blob/main/backend/src/modules/admin/admin.controller.js): `backend/src/modules/admin/admin.controller.js`
- [Shipment management](https://github.com/naresh8k/kjn-ecommerce-site/blob/main/backend/src/modules/shipmozo/shipmozo.controller.js): `backend/src/modules/shipmozo/shipmozo.controller.js`

### Shared services

- [Prisma database](https://github.com/naresh8k/kjn-ecommerce-site/blob/main/backend/src/config/db.js): `backend/src/config/db.js`
- [Email delivery](https://github.com/naresh8k/kjn-ecommerce-site/blob/main/backend/src/config/mailer.js): `backend/src/config/mailer.js`
- [Auth helpers](https://github.com/naresh8k/kjn-ecommerce-site/blob/main/backend/src/utils/otp.js): `backend/src/utils/otp.js`
- [Refresh-token storage](https://github.com/naresh8k/kjn-ecommerce-site/blob/main/backend/src/utils/tokenStorage.js): `backend/src/utils/tokenStorage.js`
- [Invoice generation](https://github.com/naresh8k/kjn-ecommerce-site/blob/main/backend/src/modules/orders/invoice.service.js): `backend/src/modules/orders/invoice.service.js`
- [ShipMozo client](https://github.com/naresh8k/kjn-ecommerce-site/blob/main/backend/src/config/shipmozo.js): `backend/src/config/shipmozo.js`

### Other components

- **Customer**
- **Razorpay**
- **ShipMozo**

## Connections

- Customer → Storefront pages: browses
- Customer → Account pages: signs in
- Cart state → API client: calls (evidence: `frontend/src/store/useCartStore.js`)
- API client → Cart and coupons: requests
- Storefront pages → Product catalog: loads products
- Account pages → Authentication: authenticates
- Cart and coupons → Prisma database: reads and writes (evidence: `backend/src/modules/cart/cart.controller.js`)
- Product catalog → Prisma database: reads catalog (evidence: `backend/src/modules/products/product.controller.js`)
- Orders and invoices → Prisma database: reads and writes (evidence: `backend/src/modules/orders/order.controller.js`)
- Orders and invoices → Invoice generation: generates invoices (evidence: `backend/src/modules/orders/order.controller.js`)
- Orders and invoices → Email delivery: sends lifecycle email
- Payments and refunds → Prisma database: updates payment records (evidence: `backend/src/modules/payments/payment.controller.js`)
- Payments and refunds → Razorpay: uses payments API
- Payments and refunds → Email delivery: sends refund email (evidence: `backend/src/modules/payments/payment.controller.js`)
- Authentication → Prisma database: reads and writes (evidence: `backend/src/modules/auth/auth.controller.js`)
- Authentication → Email delivery: sends OTP email (evidence: `backend/src/modules/auth/auth.controller.js`)
- Authentication → Auth helpers: uses OTP helpers (evidence: `backend/src/modules/auth/auth.controller.js`)
- Authentication → Refresh-token storage: stores refresh tokens (evidence: `backend/src/modules/auth/auth.controller.js`)
- Refresh-token storage → Prisma database: reads and writes (evidence: `backend/src/utils/tokenStorage.js`)
- Product reviews → Prisma database: reads and writes (evidence: `backend/src/modules/reviews/review.controller.js`)
- Admin operations → Prisma database: reads and writes (evidence: `backend/src/modules/admin/admin.controller.js`)
- Shipment management → Prisma database: updates shipment data (evidence: `backend/src/modules/shipmozo/shipmozo.controller.js`)
- Shipment management → ShipMozo client: dispatches tracking (evidence: `backend/src/modules/shipmozo/shipmozo.controller.js`)
- ShipMozo client → ShipMozo: calls carrier API
- Shipment management → Email delivery: sends order email (evidence: `backend/src/modules/shipmozo/shipmozo.controller.js`)
