# hey-ashik/ghorerbazar architecture

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

- Interactive diagram: https://gitdiagram.com/hey-ashik/ghorerbazar
- Repository: https://github.com/hey-ashik/ghorerbazar

## Overview

Ghorer Bazar is a full-stack storefront and commerce API. Customers browse and search the catalogue, manage a cart, get server-priced checkout totals, place and track orders, and use account features; a separate chat flow answers store questions using catalogue context. The graph follows the documented Next.js-to-Express API boundary and sampled controller/service calls. Several frontend and backend subsystems are represented at directory level because their source was not sampled; their internal wiring is therefore not expanded.

Main entry points: [`backend/src/routes/index.js`](https://github.com/hey-ashik/ghorerbazar/blob/main/backend/src/routes/index.js) (API routes), [`frontend/src/app`](https://github.com/hey-ashik/ghorerbazar/tree/main/frontend/src/app) (Storefront routes), [`backend/src/services/productService.js`](https://github.com/hey-ashik/ghorerbazar/blob/main/backend/src/services/productService.js) (Product queries), [`backend/src/config/db.js`](https://github.com/hey-ashik/ghorerbazar/blob/main/backend/src/config/db.js) (MySQL)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_storefront["Storefront"]
  node_web["Storefront routes"]
  node_product_ui["Product and shop UI"]
  node_shop_ui["Collection UI"]
  node_cart_state["Cart state<br/>[CartContext.jsx]"]
  node_api_client["API client<br/>[api.js]"]
end

subgraph group_commerce["Commerce API"]
  node_express["API application<br/>[app.js]"]
  node_routes["API routes<br/>[index.js]"]
  node_product_controller["Catalogue handlers"]
  node_product_service["Product queries<br/>[productService.js]"]
  node_order_controller["Order handlers<br/>[orderController.js]"]
  node_order_service["Order pricing and lifecycle<br/>[orderService.js]"]
end

subgraph group_accounts["Accounts"]
  node_auth_controller["Authentication handlers<br/>[authController.js]"]
  node_account_controller["Account handlers"]
end

subgraph group_support["Chat Support"]
  node_chat_ui["Chat widget<br/>[ChatWidget.jsx]"]
  node_chat_controller["Chat handlers<br/>[chatController.js]"]
  node_chat_limit["Chat rate limiting"]
  node_groq["AI chat service<br/>[groqService.js]"]
end

subgraph group_infrastructure["Runtime Data"]
  node_mysql[("MySQL<br/>[db.js]")]
  node_cache["Catalogue cache<br/>[cacheService.js]"]
  node_redis[("Optional Redis<br/>[redis.js]")]
end

node_customer(("Customer"))
node_groq_service["Groq API"]

node_customer -->|"browses and checks out"| node_web
node_web -->|"renders catalogue"| node_product_ui
node_web -->|"renders collections"| node_shop_ui
node_web -->|"manages cart"| node_cart_state
node_web -->|"requests data"| node_api_client
node_chat_ui -->|"sends messages"| node_api_client
node_api_client -->|"calls API"| node_express
node_express -->|"dispatches"| node_routes
node_routes -->|"dispatches catalogue"| node_product_controller
node_routes -->|"dispatches orders"| node_order_controller
node_routes -->|"dispatches auth"| node_auth_controller
node_routes -->|"dispatches accounts"| node_account_controller
node_routes -->|"dispatches chat"| node_chat_controller
node_product_controller -->|"queries products"| node_product_service
node_product_controller -->|"caches catalogue"| node_cache
node_product_service -->|"reads catalogue"| node_mysql
node_order_controller -->|"prices and places orders"| node_order_service
node_order_service -->|"loads products"| node_product_service
node_order_service -->|"reads and writes orders"| node_mysql
node_auth_controller -->|"reads and writes users"| node_mysql
node_account_controller -->|"reads and writes account data"| node_mysql
node_account_controller -->|"loads wishlist products"| node_product_service
node_chat_controller -->|"checks message limits"| node_chat_limit
node_chat_controller -->|"requests reply"| node_groq
node_groq -->|"loads catalogue context"| node_cache
node_groq -->|"sends prompt"| node_groq_service
node_cache -.->|"uses when configured"| node_redis
node_chat_limit -.->|"uses when configured"| node_redis

click node_web "https://github.com/hey-ashik/ghorerbazar/tree/main/frontend/src/app"
click node_product_ui "https://github.com/hey-ashik/ghorerbazar/tree/main/frontend/src/components/product"
click node_shop_ui "https://github.com/hey-ashik/ghorerbazar/tree/main/frontend/src/components/shop"
click node_cart_state "https://github.com/hey-ashik/ghorerbazar/blob/main/frontend/src/context/CartContext.jsx"
click node_api_client "https://github.com/hey-ashik/ghorerbazar/blob/main/frontend/src/lib/api.js"
click node_express "https://github.com/hey-ashik/ghorerbazar/blob/main/backend/src/app.js"
click node_routes "https://github.com/hey-ashik/ghorerbazar/blob/main/backend/src/routes/index.js"
click node_product_controller "https://github.com/hey-ashik/ghorerbazar/blob/main/backend/src/controllers/productController.js"
click node_product_service "https://github.com/hey-ashik/ghorerbazar/blob/main/backend/src/services/productService.js"
click node_order_controller "https://github.com/hey-ashik/ghorerbazar/blob/main/backend/src/controllers/orderController.js"
click node_order_service "https://github.com/hey-ashik/ghorerbazar/blob/main/backend/src/services/orderService.js"
click node_auth_controller "https://github.com/hey-ashik/ghorerbazar/blob/main/backend/src/controllers/authController.js"
click node_account_controller "https://github.com/hey-ashik/ghorerbazar/blob/main/backend/src/controllers/accountController.js"
click node_chat_ui "https://github.com/hey-ashik/ghorerbazar/blob/main/frontend/src/components/layout/ChatWidget.jsx"
click node_chat_controller "https://github.com/hey-ashik/ghorerbazar/blob/main/backend/src/controllers/chatController.js"
click node_chat_limit "https://github.com/hey-ashik/ghorerbazar/blob/main/backend/src/services/chatRateLimitService.js"
click node_groq "https://github.com/hey-ashik/ghorerbazar/blob/main/backend/src/services/groqService.js"
click node_mysql "https://github.com/hey-ashik/ghorerbazar/blob/main/backend/src/config/db.js"
click node_cache "https://github.com/hey-ashik/ghorerbazar/blob/main/backend/src/services/cacheService.js"
click node_redis "https://github.com/hey-ashik/ghorerbazar/blob/main/backend/src/config/redis.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_web,node_product_ui,node_shop_ui,node_cart_state,node_api_client toneBlue
class node_express,node_routes,node_product_controller,node_product_service,node_order_controller,node_order_service toneAmber
class node_auth_controller,node_account_controller,node_groq_service toneMint
class node_chat_ui,node_chat_controller,node_chat_limit,node_groq toneRose
class node_mysql,node_cache,node_redis,node_customer toneIndigo
```

## Components

### Storefront

- [Storefront routes](https://github.com/hey-ashik/ghorerbazar/tree/main/frontend/src/app): `frontend/src/app`
- [Product and shop UI](https://github.com/hey-ashik/ghorerbazar/tree/main/frontend/src/components/product): `frontend/src/components/product`
- [Collection UI](https://github.com/hey-ashik/ghorerbazar/tree/main/frontend/src/components/shop): `frontend/src/components/shop`
- [Cart state](https://github.com/hey-ashik/ghorerbazar/blob/main/frontend/src/context/CartContext.jsx): `frontend/src/context/CartContext.jsx`
- [API client](https://github.com/hey-ashik/ghorerbazar/blob/main/frontend/src/lib/api.js): `frontend/src/lib/api.js`

### Commerce API

- [API application](https://github.com/hey-ashik/ghorerbazar/blob/main/backend/src/app.js): `backend/src/app.js`
- [API routes](https://github.com/hey-ashik/ghorerbazar/blob/main/backend/src/routes/index.js): `backend/src/routes/index.js`
- [Catalogue handlers](https://github.com/hey-ashik/ghorerbazar/blob/main/backend/src/controllers/productController.js): `backend/src/controllers/productController.js`
- [Product queries](https://github.com/hey-ashik/ghorerbazar/blob/main/backend/src/services/productService.js): `backend/src/services/productService.js`
- [Order handlers](https://github.com/hey-ashik/ghorerbazar/blob/main/backend/src/controllers/orderController.js): `backend/src/controllers/orderController.js`
- [Order pricing and lifecycle](https://github.com/hey-ashik/ghorerbazar/blob/main/backend/src/services/orderService.js): `backend/src/services/orderService.js`

### Accounts

- [Authentication handlers](https://github.com/hey-ashik/ghorerbazar/blob/main/backend/src/controllers/authController.js): `backend/src/controllers/authController.js`
- [Account handlers](https://github.com/hey-ashik/ghorerbazar/blob/main/backend/src/controllers/accountController.js): `backend/src/controllers/accountController.js`

### Chat Support

- [Chat widget](https://github.com/hey-ashik/ghorerbazar/blob/main/frontend/src/components/layout/ChatWidget.jsx): `frontend/src/components/layout/ChatWidget.jsx`
- [Chat handlers](https://github.com/hey-ashik/ghorerbazar/blob/main/backend/src/controllers/chatController.js): `backend/src/controllers/chatController.js`
- [Chat rate limiting](https://github.com/hey-ashik/ghorerbazar/blob/main/backend/src/services/chatRateLimitService.js): `backend/src/services/chatRateLimitService.js`
- [AI chat service](https://github.com/hey-ashik/ghorerbazar/blob/main/backend/src/services/groqService.js): `backend/src/services/groqService.js`

### Runtime Data

- [MySQL](https://github.com/hey-ashik/ghorerbazar/blob/main/backend/src/config/db.js): `backend/src/config/db.js`
- [Catalogue cache](https://github.com/hey-ashik/ghorerbazar/blob/main/backend/src/services/cacheService.js): `backend/src/services/cacheService.js`
- [Optional Redis](https://github.com/hey-ashik/ghorerbazar/blob/main/backend/src/config/redis.js): `backend/src/config/redis.js`

### Other components

- **Customer**
- **Groq API**

## Connections

- Customer → Storefront routes: browses and checks out
- Storefront routes → Product and shop UI: renders catalogue
- Storefront routes → Collection UI: renders collections
- Storefront routes → Cart state: manages cart
- Storefront routes → API client: requests data
- Chat widget → API client: sends messages
- API client → API application: calls API
- API application → API routes: dispatches
- API routes → Catalogue handlers: dispatches catalogue
- API routes → Order handlers: dispatches orders
- API routes → Authentication handlers: dispatches auth
- API routes → Account handlers: dispatches accounts
- API routes → Chat handlers: dispatches chat
- Catalogue handlers → Product queries: queries products
- Catalogue handlers → Catalogue cache: caches catalogue
- Product queries → MySQL: reads catalogue
- Order handlers → Order pricing and lifecycle: prices and places orders
- Order pricing and lifecycle → Product queries: loads products
- Order pricing and lifecycle → MySQL: reads and writes orders
- Authentication handlers → MySQL: reads and writes users
- Account handlers → MySQL: reads and writes account data
- Account handlers → Product queries: loads wishlist products
- Chat handlers → Chat rate limiting: checks message limits
- Chat handlers → AI chat service: requests reply
- AI chat service → Catalogue cache: loads catalogue context
- AI chat service → Groq API: sends prompt
- Catalogue cache → Optional Redis: uses when configured
- Chat rate limiting → Optional Redis: uses when configured
