# dinojen19/brightbuy architecture

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

- Interactive diagram: https://gitdiagram.com/dinojen19/brightbuy
- Repository: https://github.com/dinojen19/brightbuy

## Overview

BrightBuy is a web storefront and commerce backend: customers browse products, manage a cart, place orders, and review order history; staff and administrators manage stock, catalog data, and reports. The React application routes users through these features and calls the Express API, whose controllers delegate business operations to services backed by MySQL. Authentication and role checks protect relevant routes. The README also documents SQL-backed delivery calculations, stock triggers, atomic order placement, and reporting. Several frontend pages and backend services were not sampled, so their detailed call paths are not asserted.

Main entry points: [`backend/app.js`](https://github.com/dinojen19/brightbuy/blob/main/backend/app.js) (API router), [`frontend/src/App.jsx`](https://github.com/dinojen19/brightbuy/blob/main/frontend/src/App.jsx) (App and routes), [`frontend/src/api/client.js`](https://github.com/dinojen19/brightbuy/blob/main/frontend/src/api/client.js) (HTTP client), [`backend/middleware/auth.js`](https://github.com/dinojen19/brightbuy/blob/main/backend/middleware/auth.js) (JWT and roles)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web storefront"]
  node_app["App and routes<br/>[App.jsx]"]
  node_authui["Account pages"]
  node_catalogueui["Product browsing"]
  node_cartui["Cart and checkout"]
  node_ordersui["Order history"]
  node_adminui["Admin and reports"]
  node_authcontext["Session context<br/>[AuthContext.jsx]"]
  node_api["HTTP client<br/>[client.js]"]
end

subgraph group_commerce["Commerce API"]
  node_authctrl["Account controller<br/>[auth.controller.js]"]
  node_authsvc["Account service<br/>[auth.service.js]"]
  node_cataloguectrl["Catalogue controller"]
  node_cataloguesvc["Catalogue service"]
  node_cartctrl["Cart controller<br/>[cart.controller.js]"]
  node_cartsvc["Cart service<br/>[cart.service.js]"]
  node_checkoutctrl["Checkout controller"]
  node_checkoutsvc["Checkout service"]
  node_ordersctrl["Order controller"]
  node_orderssvc["Order service<br/>[orders.service.js]"]
  node_customersctrl["Customer controller"]
  node_customerssvc["Customer service"]
end

subgraph group_operations["Store operations"]
  node_inventoryctrl["Inventory controller"]
  node_inventorysvc["Inventory service"]
end

subgraph group_foundation["API foundation"]
  node_express["API router<br/>[app.js]"]
  node_authroutes["Auth routes<br/>[auth.routes.js]"]
  node_authmw["JWT and roles<br/>[auth.js]"]
  node_dbpool[("MySQL pool<br/>[db.js]")]
  node_catalogueroutes["Catalogue routes"]
  node_cartroutes["Cart routes<br/>[cart.routes.js]"]
  node_checkoutroutes["Checkout routes<br/>[checkout.routes.js]"]
  node_ordersroutes["Order routes<br/>[orders.routes.js]"]
  node_customersroutes["Customer routes"]
  node_inventoryroutes["Inventory routes"]
end

node_shopper(("Shopper"))
node_api_actor(("Web client"))

node_shopper -->|"uses"| node_app
node_app -->|"routes"| node_authui
node_app -->|"routes"| node_catalogueui
node_app -->|"routes"| node_cartui
node_app -->|"routes"| node_ordersui
node_app -->|"routes"| node_adminui
node_app -->|"provides session"| node_authcontext
node_authcontext -->|"uses"| node_api
node_authui -.->|"calls API"| node_api
node_catalogueui -.->|"calls API"| node_api
node_cartui -.->|"calls API"| node_api
node_ordersui -.->|"calls API"| node_api
node_adminui -.->|"calls API"| node_api
node_api_actor -.->|"HTTP requests"| node_express
node_express -->|"mounts"| node_authroutes
node_express -->|"mounts"| node_catalogueroutes
node_express -->|"mounts"| node_cartroutes
node_express -->|"mounts"| node_checkoutroutes
node_express -->|"mounts"| node_ordersroutes
node_express -->|"mounts"| node_customersroutes
node_express -->|"mounts"| node_inventoryroutes
node_authroutes -->|"authenticates"| node_authmw
node_authroutes -->|"dispatches"| node_authctrl
node_authctrl -->|"delegates"| node_authsvc
node_authsvc -->|"queries"| node_dbpool
node_catalogueroutes -->|"dispatches"| node_cataloguectrl
node_cataloguectrl -->|"delegates"| node_cataloguesvc
node_cataloguesvc -.->|"queries"| node_dbpool
node_cartroutes -->|"dispatches"| node_cartctrl
node_cartroutes -->|"authenticates"| node_authmw
node_cartctrl -->|"delegates"| node_cartsvc
node_cartsvc -.->|"queries"| node_dbpool
node_checkoutroutes -->|"dispatches"| node_checkoutctrl
node_checkoutroutes -->|"authenticates"| node_authmw
node_checkoutctrl -.->|"places order"| node_checkoutsvc
node_checkoutsvc -.->|"queries"| node_dbpool
node_ordersroutes -->|"dispatches"| node_ordersctrl
node_ordersroutes -->|"authenticates"| node_authmw
node_ordersctrl -->|"delegates"| node_orderssvc
node_orderssvc -->|"queries"| node_dbpool
node_customersroutes -->|"dispatches"| node_customersctrl
node_customersroutes -->|"authenticates"| node_authmw
node_customersctrl -->|"delegates"| node_customerssvc
node_inventoryroutes -->|"dispatches"| node_inventoryctrl
node_inventoryroutes -->|"authorizes roles"| node_authmw
node_inventoryctrl -->|"delegates"| node_inventorysvc
node_inventorysvc -.->|"queries"| node_dbpool

click node_app "https://github.com/dinojen19/brightbuy/blob/main/frontend/src/App.jsx"
click node_authui "https://github.com/dinojen19/brightbuy/tree/main/frontend/src/features/auth/pages"
click node_catalogueui "https://github.com/dinojen19/brightbuy/tree/main/frontend/src/features/catalogue/pages"
click node_cartui "https://github.com/dinojen19/brightbuy/tree/main/frontend/src/features/cart/pages"
click node_ordersui "https://github.com/dinojen19/brightbuy/tree/main/frontend/src/features/orders/pages"
click node_adminui "https://github.com/dinojen19/brightbuy/tree/main/frontend/src/features/admin/pages"
click node_authcontext "https://github.com/dinojen19/brightbuy/blob/main/frontend/src/context/AuthContext.jsx"
click node_api "https://github.com/dinojen19/brightbuy/blob/main/frontend/src/api/client.js"
click node_express "https://github.com/dinojen19/brightbuy/blob/main/backend/app.js"
click node_authroutes "https://github.com/dinojen19/brightbuy/blob/main/backend/routes/auth.routes.js"
click node_authmw "https://github.com/dinojen19/brightbuy/blob/main/backend/middleware/auth.js"
click node_dbpool "https://github.com/dinojen19/brightbuy/blob/main/backend/config/db.js"
click node_authctrl "https://github.com/dinojen19/brightbuy/blob/main/backend/controllers/auth.controller.js"
click node_authsvc "https://github.com/dinojen19/brightbuy/blob/main/backend/services/auth.service.js"
click node_catalogueroutes "https://github.com/dinojen19/brightbuy/blob/main/backend/routes/catalogue.routes.js"
click node_cataloguectrl "https://github.com/dinojen19/brightbuy/blob/main/backend/controllers/catalogue.controller.js"
click node_cataloguesvc "https://github.com/dinojen19/brightbuy/blob/main/backend/services/catalogue.service.js"
click node_cartroutes "https://github.com/dinojen19/brightbuy/blob/main/backend/routes/cart.routes.js"
click node_cartctrl "https://github.com/dinojen19/brightbuy/blob/main/backend/controllers/cart.controller.js"
click node_cartsvc "https://github.com/dinojen19/brightbuy/blob/main/backend/services/cart.service.js"
click node_checkoutroutes "https://github.com/dinojen19/brightbuy/blob/main/backend/routes/checkout.routes.js"
click node_checkoutctrl "https://github.com/dinojen19/brightbuy/blob/main/backend/controllers/checkout.controller.js"
click node_checkoutsvc "https://github.com/dinojen19/brightbuy/blob/main/backend/services/checkout.service.js"
click node_ordersroutes "https://github.com/dinojen19/brightbuy/blob/main/backend/routes/orders.routes.js"
click node_ordersctrl "https://github.com/dinojen19/brightbuy/blob/main/backend/controllers/orders.controller.js"
click node_orderssvc "https://github.com/dinojen19/brightbuy/blob/main/backend/services/orders.service.js"
click node_customersroutes "https://github.com/dinojen19/brightbuy/blob/main/backend/routes/customers.routes.js"
click node_customersctrl "https://github.com/dinojen19/brightbuy/blob/main/backend/controllers/customers.controller.js"
click node_customerssvc "https://github.com/dinojen19/brightbuy/blob/main/backend/services/customers.service.js"
click node_inventoryroutes "https://github.com/dinojen19/brightbuy/blob/main/backend/routes/inventory.routes.js"
click node_inventoryctrl "https://github.com/dinojen19/brightbuy/blob/main/backend/controllers/inventory.controller.js"
click node_inventorysvc "https://github.com/dinojen19/brightbuy/blob/main/backend/services/inventory.service.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_app,node_authui,node_catalogueui,node_cartui,node_ordersui,node_adminui,node_authcontext,node_api,node_api_actor toneBlue
class node_authctrl,node_authsvc,node_cataloguectrl,node_cataloguesvc,node_cartctrl,node_cartsvc,node_checkoutctrl,node_checkoutsvc,node_ordersctrl,node_orderssvc,node_customersctrl,node_customerssvc toneAmber
class node_inventoryctrl,node_inventorysvc toneMint
class node_express,node_authroutes,node_authmw,node_dbpool,node_catalogueroutes,node_cartroutes,node_checkoutroutes,node_ordersroutes,node_customersroutes,node_inventoryroutes toneRose
class node_shopper toneIndigo
```

## Components

### Web storefront

- [App and routes](https://github.com/dinojen19/brightbuy/blob/main/frontend/src/App.jsx): `frontend/src/App.jsx`
- [Account pages](https://github.com/dinojen19/brightbuy/tree/main/frontend/src/features/auth/pages): `frontend/src/features/auth/pages`
- [Product browsing](https://github.com/dinojen19/brightbuy/tree/main/frontend/src/features/catalogue/pages): `frontend/src/features/catalogue/pages`
- [Cart and checkout](https://github.com/dinojen19/brightbuy/tree/main/frontend/src/features/cart/pages): `frontend/src/features/cart/pages`
- [Order history](https://github.com/dinojen19/brightbuy/tree/main/frontend/src/features/orders/pages): `frontend/src/features/orders/pages`
- [Admin and reports](https://github.com/dinojen19/brightbuy/tree/main/frontend/src/features/admin/pages): `frontend/src/features/admin/pages`
- [Session context](https://github.com/dinojen19/brightbuy/blob/main/frontend/src/context/AuthContext.jsx): `frontend/src/context/AuthContext.jsx`
- [HTTP client](https://github.com/dinojen19/brightbuy/blob/main/frontend/src/api/client.js): `frontend/src/api/client.js`

### Commerce API

- [Account controller](https://github.com/dinojen19/brightbuy/blob/main/backend/controllers/auth.controller.js): `backend/controllers/auth.controller.js`
- [Account service](https://github.com/dinojen19/brightbuy/blob/main/backend/services/auth.service.js): `backend/services/auth.service.js`
- [Catalogue controller](https://github.com/dinojen19/brightbuy/blob/main/backend/controllers/catalogue.controller.js): `backend/controllers/catalogue.controller.js`
- [Catalogue service](https://github.com/dinojen19/brightbuy/blob/main/backend/services/catalogue.service.js): `backend/services/catalogue.service.js`
- [Cart controller](https://github.com/dinojen19/brightbuy/blob/main/backend/controllers/cart.controller.js): `backend/controllers/cart.controller.js`
- [Cart service](https://github.com/dinojen19/brightbuy/blob/main/backend/services/cart.service.js): `backend/services/cart.service.js`
- [Checkout controller](https://github.com/dinojen19/brightbuy/blob/main/backend/controllers/checkout.controller.js): `backend/controllers/checkout.controller.js`
- [Checkout service](https://github.com/dinojen19/brightbuy/blob/main/backend/services/checkout.service.js): `backend/services/checkout.service.js`
- [Order controller](https://github.com/dinojen19/brightbuy/blob/main/backend/controllers/orders.controller.js): `backend/controllers/orders.controller.js`
- [Order service](https://github.com/dinojen19/brightbuy/blob/main/backend/services/orders.service.js): `backend/services/orders.service.js`
- [Customer controller](https://github.com/dinojen19/brightbuy/blob/main/backend/controllers/customers.controller.js): `backend/controllers/customers.controller.js`
- [Customer service](https://github.com/dinojen19/brightbuy/blob/main/backend/services/customers.service.js): `backend/services/customers.service.js`

### Store operations

- [Inventory controller](https://github.com/dinojen19/brightbuy/blob/main/backend/controllers/inventory.controller.js): `backend/controllers/inventory.controller.js`
- [Inventory service](https://github.com/dinojen19/brightbuy/blob/main/backend/services/inventory.service.js): `backend/services/inventory.service.js`

### API foundation

- [API router](https://github.com/dinojen19/brightbuy/blob/main/backend/app.js): `backend/app.js`
- [Auth routes](https://github.com/dinojen19/brightbuy/blob/main/backend/routes/auth.routes.js): `backend/routes/auth.routes.js`
- [JWT and roles](https://github.com/dinojen19/brightbuy/blob/main/backend/middleware/auth.js): `backend/middleware/auth.js`
- [MySQL pool](https://github.com/dinojen19/brightbuy/blob/main/backend/config/db.js): `backend/config/db.js`
- [Catalogue routes](https://github.com/dinojen19/brightbuy/blob/main/backend/routes/catalogue.routes.js): `backend/routes/catalogue.routes.js`
- [Cart routes](https://github.com/dinojen19/brightbuy/blob/main/backend/routes/cart.routes.js): `backend/routes/cart.routes.js`
- [Checkout routes](https://github.com/dinojen19/brightbuy/blob/main/backend/routes/checkout.routes.js): `backend/routes/checkout.routes.js`
- [Order routes](https://github.com/dinojen19/brightbuy/blob/main/backend/routes/orders.routes.js): `backend/routes/orders.routes.js`
- [Customer routes](https://github.com/dinojen19/brightbuy/blob/main/backend/routes/customers.routes.js): `backend/routes/customers.routes.js`
- [Inventory routes](https://github.com/dinojen19/brightbuy/blob/main/backend/routes/inventory.routes.js): `backend/routes/inventory.routes.js`

### Other components

- **Shopper**
- **Web client**

## Connections

- Shopper → App and routes: uses (evidence: `frontend/src/App.jsx`)
- App and routes → Account pages: routes
- App and routes → Product browsing: routes
- App and routes → Cart and checkout: routes
- App and routes → Order history: routes
- App and routes → Admin and reports: routes
- App and routes → Session context: provides session (evidence: `frontend/src/App.jsx`)
- Session context → HTTP client: uses (evidence: `frontend/src/context/AuthContext.jsx`)
- Account pages → HTTP client: calls API
- Product browsing → HTTP client: calls API
- Cart and checkout → HTTP client: calls API
- Order history → HTTP client: calls API
- Admin and reports → HTTP client: calls API
- Web client → API router: HTTP requests
- API router → Auth routes: mounts (evidence: `backend/app.js`)
- API router → Catalogue routes: mounts (evidence: `backend/app.js`)
- API router → Cart routes: mounts (evidence: `backend/app.js`)
- API router → Checkout routes: mounts (evidence: `backend/app.js`)
- API router → Order routes: mounts (evidence: `backend/app.js`)
- API router → Customer routes: mounts (evidence: `backend/app.js`)
- API router → Inventory routes: mounts (evidence: `backend/app.js`)
- Auth routes → JWT and roles: authenticates (evidence: `backend/routes/auth.routes.js`)
- Auth routes → Account controller: dispatches (evidence: `backend/routes/auth.routes.js`)
- Account controller → Account service: delegates (evidence: `backend/controllers/auth.controller.js`)
- Account service → MySQL pool: queries (evidence: `backend/services/auth.service.js`)
- Catalogue routes → Catalogue controller: dispatches (evidence: `backend/routes/catalogue.routes.js`)
- Catalogue controller → Catalogue service: delegates (evidence: `backend/controllers/catalogue.controller.js`)
- Catalogue service → MySQL pool: queries (evidence: `backend/services/catalogue.service.js`)
- Cart routes → Cart controller: dispatches (evidence: `backend/routes/cart.routes.js`)
- Cart routes → JWT and roles: authenticates (evidence: `backend/routes/cart.routes.js`)
- Cart controller → Cart service: delegates (evidence: `backend/controllers/cart.controller.js`)
- Cart service → MySQL pool: queries (evidence: `backend/services/cart.service.js`)
- Checkout routes → Checkout controller: dispatches (evidence: `backend/routes/checkout.routes.js`)
- Checkout routes → JWT and roles: authenticates (evidence: `backend/routes/checkout.routes.js`)
- Checkout controller → Checkout service: places order
- Checkout service → MySQL pool: queries
- Order routes → Order controller: dispatches (evidence: `backend/routes/orders.routes.js`)
- Order routes → JWT and roles: authenticates (evidence: `backend/routes/orders.routes.js`)
- Order controller → Order service: delegates (evidence: `backend/controllers/orders.controller.js`)
- Order service → MySQL pool: queries (evidence: `backend/services/orders.service.js`)
- Customer routes → Customer controller: dispatches (evidence: `backend/routes/customers.routes.js`)
- Customer routes → JWT and roles: authenticates (evidence: `backend/routes/customers.routes.js`)
- Customer controller → Customer service: delegates (evidence: `backend/controllers/customers.controller.js`)
- Inventory routes → Inventory controller: dispatches (evidence: `backend/routes/inventory.routes.js`)
- Inventory routes → JWT and roles: authorizes roles (evidence: `backend/routes/inventory.routes.js`)
- Inventory controller → Inventory service: delegates (evidence: `backend/controllers/inventory.controller.js`)
- Inventory service → MySQL pool: queries
