# lilfanq/fang_store architecture

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

- Interactive diagram: https://gitdiagram.com/lilfanq/fang_store
- Repository: https://github.com/lilfanq/fang_store

## Overview

Shop Hip-Hop Ma Mị is a Next.js streetwear storefront with customer accounts, cart checkout, inventory, and an admin console. The main customer journey runs from product discovery to cart, order placement, and invoice; authentication can precede account actions. The graph also covers catalog and inventory APIs, administration, and the documented AI stylist and SEO capabilities. Source excerpts establish selected calls; README statements support documented but unsampled features, so some internal links are omitted where wiring was not shown.

Main entry points: [`pages/api/orders/create.js`](https://github.com/lilfanq/fang_store/blob/main/pages/api/orders/create.js) (Order creation), [`lib/auth.js`](https://github.com/lilfanq/fang_store/blob/main/lib/auth.js) (JWT auth), [`lib/prisma.js`](https://github.com/lilfanq/fang_store/blob/main/lib/prisma.js) (Application database), [`pages/products`](https://github.com/lilfanq/fang_store/tree/main/pages/products) (Catalog UI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_storefront["Storefront"]
  node_storefront["Store pages"]
  node_catalog_ui["Catalog UI"]
  node_product_detail["Product detail<br/>[&#91;id&#93;.js]"]
  node_product_components["Discovery components"]
  node_catalog_data["Catalog data<br/>[catalogProducts.js]"]
  node_ai_stylist["AI stylist<br/>[stylist.js]"]
end

subgraph group_commerce["Commerce"]
  node_cart_ui["Cart and checkout<br/>[cart.js]"]
  node_cart_state["Cart state<br/>[CartContext.js]"]
  node_order_api["Order creation<br/>[create.js]"]
  node_invoice["Order invoice<br/>[&#91;id&#93;.js]"]
  node_coupon_api["Coupon validation<br/>[validate.js]"]
  node_coupon_rules["Coupon rules<br/>[coupon.js]"]
end

subgraph group_identity["Identity"]
  node_auth_ui["Account UI<br/>[AccountModal.js]"]
  node_auth_api["Authentication APIs"]
  node_auth_service["JWT auth<br/>[auth.js]"]
  node_profile_api["Account profile<br/>[profile.js]"]
end

subgraph group_operations["Operations"]
  node_admin_ui["Admin console<br/>[index.js]"]
  node_admin_api["Admin APIs"]
  node_inventory_api["Inventory APIs"]
  node_inventory_events["Inventory events<br/>[inventoryEvents.js]"]
end

subgraph group_shared["Shared services"]
  node_currency["Currency settings<br/>[CurrencyContext.js]"]
  node_api_helpers["API responses<br/>[api.js]"]
  node_email["Email delivery<br/>[email.js]"]
  node_database[("Application database<br/>[prisma.js]")]
end

node_customer(("Shopper"))
node_exchange_rates["Exchange-rate service"]
node_stripe["Stripe"]
node_smtp["SMTP"]

node_customer -->|"browses"| node_storefront
node_storefront -->|"renders"| node_product_components
node_customer -->|"browses"| node_catalog_ui
node_catalog_ui -->|"reads"| node_catalog_data
node_catalog_ui -->|"renders filters"| node_product_components
node_catalog_ui -->|"formats prices"| node_currency
node_customer -->|"selects product"| node_product_detail
node_product_detail -->|"adds item"| node_cart_state
node_product_detail -->|"formats price"| node_currency
node_customer -->|"checks out"| node_cart_ui
node_cart_ui -->|"reads cart"| node_cart_state
node_cart_ui -->|"places order"| node_order_api
node_order_api -->|"reads and writes"| node_database
node_order_api -->|"requires auth"| node_auth_service
node_order_api -->|"calculates discount"| node_coupon_rules
node_order_api -->|"emits updates"| node_inventory_events
node_order_api -->|"sends confirmation"| node_email
node_order_api -.->|"creates payment intent"| node_stripe
node_order_api -->|"redirects after order"| node_invoice
node_customer -->|"signs in"| node_auth_ui
node_auth_ui -.->|"authenticates"| node_auth_api
node_auth_api -->|"uses tokens"| node_auth_service
node_auth_service -->|"looks up user"| node_database
node_customer -->|"manages account"| node_profile_api
node_profile_api -->|"requires auth"| node_auth_service
node_profile_api -->|"reads and writes"| node_database
node_customer -->|"validates coupon"| node_coupon_api
node_coupon_api -->|"calculates discount"| node_coupon_rules
node_coupon_api -->|"reads coupon"| node_database
node_customer -->|"manages store"| node_admin_ui
node_admin_ui -.->|"requests operations data"| node_admin_api
node_admin_api -.->|"reads and updates"| node_database
node_admin_api -->|"authorizes admin"| node_auth_service
node_customer -->|"checks availability"| node_inventory_api
node_inventory_api -->|"reads and updates"| node_database
node_inventory_api -->|"authorizes updates"| node_auth_service
node_inventory_api -->|"publishes updates"| node_inventory_events
node_customer -->|"asks stylist"| node_ai_stylist
node_ai_stylist -->|"uses product catalog"| node_catalog_data
node_currency -->|"fetches rates"| node_exchange_rates
node_profile_api -->|"formats errors"| node_api_helpers
node_order_api -.->|"sends mail via"| node_smtp

click node_storefront "https://github.com/lilfanq/fang_store/tree/main/pages"
click node_catalog_ui "https://github.com/lilfanq/fang_store/tree/main/pages/products"
click node_product_detail "https://github.com/lilfanq/fang_store/blob/main/pages/product/%5Bid%5D.js"
click node_product_components "https://github.com/lilfanq/fang_store/tree/main/components"
click node_catalog_data "https://github.com/lilfanq/fang_store/blob/main/data/catalogProducts.js"
click node_cart_ui "https://github.com/lilfanq/fang_store/blob/main/pages/cart.js"
click node_cart_state "https://github.com/lilfanq/fang_store/blob/main/context/CartContext.js"
click node_order_api "https://github.com/lilfanq/fang_store/blob/main/pages/api/orders/create.js"
click node_invoice "https://github.com/lilfanq/fang_store/blob/main/pages/order/%5Bid%5D.js"
click node_coupon_api "https://github.com/lilfanq/fang_store/blob/main/pages/api/coupons/validate.js"
click node_coupon_rules "https://github.com/lilfanq/fang_store/blob/main/lib/coupon.js"
click node_auth_ui "https://github.com/lilfanq/fang_store/blob/main/components/AccountModal.js"
click node_auth_api "https://github.com/lilfanq/fang_store/tree/main/pages/api/auth"
click node_auth_service "https://github.com/lilfanq/fang_store/blob/main/lib/auth.js"
click node_profile_api "https://github.com/lilfanq/fang_store/blob/main/pages/api/account/profile.js"
click node_admin_ui "https://github.com/lilfanq/fang_store/blob/main/pages/admin/index.js"
click node_admin_api "https://github.com/lilfanq/fang_store/tree/main/pages/api/admin"
click node_inventory_api "https://github.com/lilfanq/fang_store/tree/main/pages/api/inventory"
click node_inventory_events "https://github.com/lilfanq/fang_store/blob/main/lib/inventoryEvents.js"
click node_ai_stylist "https://github.com/lilfanq/fang_store/blob/main/pages/api/ai/stylist.js"
click node_currency "https://github.com/lilfanq/fang_store/blob/main/context/CurrencyContext.js"
click node_api_helpers "https://github.com/lilfanq/fang_store/blob/main/lib/api.js"
click node_email "https://github.com/lilfanq/fang_store/blob/main/lib/email.js"
click node_database "https://github.com/lilfanq/fang_store/blob/main/lib/prisma.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,node_catalog_ui,node_product_detail,node_product_components,node_catalog_data,node_ai_stylist toneBlue
class node_cart_ui,node_cart_state,node_order_api,node_invoice,node_coupon_api,node_coupon_rules toneAmber
class node_auth_ui,node_auth_api,node_auth_service,node_profile_api toneMint
class node_admin_ui,node_admin_api,node_inventory_api,node_inventory_events toneRose
class node_currency,node_api_helpers,node_email,node_database,node_customer,node_exchange_rates,node_stripe,node_smtp toneIndigo
```

## Components

### Storefront

- [Store pages](https://github.com/lilfanq/fang_store/tree/main/pages): `pages`
- [Catalog UI](https://github.com/lilfanq/fang_store/tree/main/pages/products): `pages/products`
- [Product detail](https://github.com/lilfanq/fang_store/blob/main/pages/product/%5Bid%5D.js): `pages/product/[id].js`
- [Discovery components](https://github.com/lilfanq/fang_store/tree/main/components): `components`
- [Catalog data](https://github.com/lilfanq/fang_store/blob/main/data/catalogProducts.js): `data/catalogProducts.js`
- [AI stylist](https://github.com/lilfanq/fang_store/blob/main/pages/api/ai/stylist.js): `pages/api/ai/stylist.js`

### Commerce

- [Cart and checkout](https://github.com/lilfanq/fang_store/blob/main/pages/cart.js): `pages/cart.js`
- [Cart state](https://github.com/lilfanq/fang_store/blob/main/context/CartContext.js): `context/CartContext.js`
- [Order creation](https://github.com/lilfanq/fang_store/blob/main/pages/api/orders/create.js): `pages/api/orders/create.js`
- [Order invoice](https://github.com/lilfanq/fang_store/blob/main/pages/order/%5Bid%5D.js): `pages/order/[id].js`
- [Coupon validation](https://github.com/lilfanq/fang_store/blob/main/pages/api/coupons/validate.js): `pages/api/coupons/validate.js`
- [Coupon rules](https://github.com/lilfanq/fang_store/blob/main/lib/coupon.js): `lib/coupon.js`

### Identity

- [Account UI](https://github.com/lilfanq/fang_store/blob/main/components/AccountModal.js): `components/AccountModal.js`
- [Authentication APIs](https://github.com/lilfanq/fang_store/tree/main/pages/api/auth): `pages/api/auth`
- [JWT auth](https://github.com/lilfanq/fang_store/blob/main/lib/auth.js): `lib/auth.js`
- [Account profile](https://github.com/lilfanq/fang_store/blob/main/pages/api/account/profile.js): `pages/api/account/profile.js`

### Operations

- [Admin console](https://github.com/lilfanq/fang_store/blob/main/pages/admin/index.js): `pages/admin/index.js`
- [Admin APIs](https://github.com/lilfanq/fang_store/tree/main/pages/api/admin): `pages/api/admin`
- [Inventory APIs](https://github.com/lilfanq/fang_store/tree/main/pages/api/inventory): `pages/api/inventory`
- [Inventory events](https://github.com/lilfanq/fang_store/blob/main/lib/inventoryEvents.js): `lib/inventoryEvents.js`

### Shared services

- [Currency settings](https://github.com/lilfanq/fang_store/blob/main/context/CurrencyContext.js): `context/CurrencyContext.js`
- [API responses](https://github.com/lilfanq/fang_store/blob/main/lib/api.js): `lib/api.js`
- [Email delivery](https://github.com/lilfanq/fang_store/blob/main/lib/email.js): `lib/email.js`
- [Application database](https://github.com/lilfanq/fang_store/blob/main/lib/prisma.js): `lib/prisma.js`

### Other components

- **Shopper**
- **Exchange-rate service**
- **Stripe**
- **SMTP**

## Connections

- Shopper → Store pages: browses
- Store pages → Discovery components: renders (evidence: `pages/index.js`)
- Shopper → Catalog UI: browses
- Catalog UI → Catalog data: reads (evidence: `pages/products/index.js`)
- Catalog UI → Discovery components: renders filters (evidence: `pages/products/index.js`)
- Catalog UI → Currency settings: formats prices (evidence: `pages/products/index.js`)
- Shopper → Product detail: selects product
- Product detail → Cart state: adds item (evidence: `pages/product/[id].js`)
- Product detail → Currency settings: formats price (evidence: `pages/product/[id].js`)
- Shopper → Cart and checkout: checks out
- Cart and checkout → Cart state: reads cart (evidence: `pages/cart.js`)
- Cart and checkout → Order creation: places order
- Order creation → Application database: reads and writes (evidence: `pages/api/orders/create.js`)
- Order creation → JWT auth: requires auth (evidence: `pages/api/orders/create.js`)
- Order creation → Coupon rules: calculates discount (evidence: `pages/api/orders/create.js`)
- Order creation → Inventory events: emits updates (evidence: `pages/api/orders/create.js`)
- Order creation → Email delivery: sends confirmation (evidence: `pages/api/orders/create.js`)
- Order creation → Stripe: creates payment intent
- Order creation → Order invoice: redirects after order
- Shopper → Account UI: signs in
- Account UI → Authentication APIs: authenticates
- Authentication APIs → JWT auth: uses tokens (evidence: `pages/api/auth/register.js`)
- JWT auth → Application database: looks up user (evidence: `lib/auth.js`)
- Shopper → Account profile: manages account
- Account profile → JWT auth: requires auth (evidence: `pages/api/account/profile.js`)
- Account profile → Application database: reads and writes (evidence: `pages/api/account/profile.js`)
- Shopper → Coupon validation: validates coupon
- Coupon validation → Coupon rules: calculates discount (evidence: `pages/api/coupons/validate.js`)
- Coupon validation → Application database: reads coupon (evidence: `pages/api/coupons/validate.js`)
- Shopper → Admin console: manages store
- Admin console → Admin APIs: requests operations data
- Admin APIs → Application database: reads and updates (evidence: `pages/api/admin/coupons.js`)
- Admin APIs → JWT auth: authorizes admin (evidence: `pages/api/admin/coupons.js`)
- Shopper → Inventory APIs: checks availability
- Inventory APIs → Application database: reads and updates (evidence: `pages/api/inventory/update.js`)
- Inventory APIs → JWT auth: authorizes updates (evidence: `pages/api/inventory/update.js`)
- Inventory APIs → Inventory events: publishes updates (evidence: `pages/api/inventory/update.js`)
- Shopper → AI stylist: asks stylist
- AI stylist → Catalog data: uses product catalog (evidence: `pages/api/ai/stylist.js`)
- Currency settings → Exchange-rate service: fetches rates (evidence: `context/CurrencyContext.js`)
- Account profile → API responses: formats errors (evidence: `pages/api/account/profile.js`)
- Order creation → SMTP: sends mail via
