# nguyen-hong-tham/may architecture

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

- Interactive diagram: https://gitdiagram.com/nguyen-hong-tham/may
- Repository: https://github.com/nguyen-hong-tham/may

## Overview

MAY Coffee is a F&B ordering platform with a customer storefront, an administrative dashboard, and a NestJS API. Customers discover and customize drinks, authenticate, check out using COD or VNPay, and track orders and loyalty points; staff administer orders and products while admins manage users and reporting. The README documents the platform-level integrations and business flow. Source excerpts confirm checkout orchestration and selected API calls; unsampled subsystem connections are shown only where documented.

Main entry points: [`may-api/src/orders/orders.service.ts`](https://github.com/nguyen-hong-tham/may/blob/main/may-api/src/orders/orders.service.ts) (Order processing), [`may-api/src/prisma/prisma.service.ts`](https://github.com/nguyen-hong-tham/may/blob/main/may-api/src/prisma/prisma.service.ts) (PostgreSQL), [`MAY/src/checkout/hooks/useCheckout.ts`](https://github.com/nguyen-hong-tham/may/blob/main/MAY/src/checkout/hooks/useCheckout.ts) (Checkout), [`may-api/src/payments/payments.controller.ts`](https://github.com/nguyen-hong-tham/may/blob/main/may-api/src/payments/payments.controller.ts) (Payments)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_customer["Customer app"]
  node_storefront["Storefront<br/>[App.tsx]"]
  node_catalog["Browse catalog<br/>[useProducts.ts]"]
  node_customer_auth["Customer auth<br/>[AuthContext.tsx]"]
  node_cart["Cart<br/>[CartContext.tsx]"]
  node_checkout["Checkout<br/>[useCheckout.ts]"]
  node_customer_orders["Order tracking<br/>[OrdersContext.tsx]"]
  node_profile_loyalty["Profile and loyalty<br/>[useProfile.ts]"]
  node_chat_ui["AI chat UI<br/>[Chatbox.tsx]"]
end

subgraph group_admin["Admin dashboard"]
  node_admin_app["Admin app<br/>[App.tsx]"]
  node_admin_auth["Admin auth<br/>[useAuth.ts]"]
  node_admin_catalog["Catalog management<br/>[ProductForm.tsx]"]
  node_admin_orders["Order management<br/>[index.tsx]"]
  node_admin_users["User management<br/>[Users.tsx]"]
  node_admin_reports["Dashboards and reports<br/>[index.tsx]"]
end

subgraph group_api["Backend domains"]
  node_auth_api["Authentication API<br/>[auth.service.ts]"]
  node_catalog_api["Catalog API"]
  node_orders_api["Order processing<br/>[orders.service.ts]"]
  node_payments_api["Payments"]
  node_users_api["Users and loyalty"]
  node_realtime["Order realtime<br/>[orders.gateway.ts]"]
  node_personalization["Personalization and chat"]
  node_analytics_api["Analytics API"]
end

subgraph group_platform["Data and integrations"]
  node_database[("PostgreSQL<br/>[prisma.service.ts]")]
end

node_shopper(("Customer"))
node_staff(("Staff and admins"))
node_firebase["Firebase Auth"]
node_vnpay["VNPay"]
node_openai["OpenAI"]

node_shopper -->|"uses"| node_storefront
node_storefront -->|"shows products"| node_catalog
node_shopper -.->|"signs in"| node_customer_auth
node_customer_auth -->|"authenticates"| node_auth_api
node_customer_auth -.->|"verifies OTP"| node_firebase
node_shopper -.->|"customizes drinks"| node_cart
node_cart -->|"checks out"| node_checkout
node_checkout -->|"creates order"| node_customer_orders
node_checkout -->|"reads profile"| node_profile_loyalty
node_checkout -.->|"submits order"| node_orders_api
node_customer_orders -.->|"fetches orders"| node_orders_api
node_profile_loyalty -.->|"reads loyalty"| node_users_api
node_shopper -.->|"asks for advice"| node_chat_ui
node_chat_ui -.->|"requests recommendations"| node_personalization
node_staff -.->|"uses"| node_admin_app
node_admin_app -->|"routes auth"| node_admin_auth
node_admin_catalog -.->|"manages catalog"| node_catalog_api
node_admin_orders -.->|"updates orders"| node_orders_api
node_admin_users -.->|"manages users"| node_users_api
node_admin_reports -.->|"requests reports"| node_analytics_api
node_orders_api -->|"reads and writes"| node_database
node_orders_api -->|"emits updates"| node_realtime
node_checkout -->|"starts payment"| node_payments_api
node_payments_api -->|"creates payment session"| node_vnpay
node_payments_api -->|"creates or updates order"| node_orders_api
node_payments_api -->|"reads and writes"| node_database
node_auth_api -->|"reads and writes"| node_database
node_auth_api -.->|"verifies token"| node_firebase
node_catalog_api -.->|"reads and writes"| node_database
node_users_api -.->|"reads and writes"| node_database
node_analytics_api -.->|"queries sales data"| node_database
node_personalization -.->|"requests AI"| node_openai
node_realtime -.->|"notifies status"| node_customer_orders
node_realtime -.->|"notifies new orders"| node_admin_orders

click node_storefront "https://github.com/nguyen-hong-tham/may/blob/main/MAY/src/App.tsx"
click node_catalog "https://github.com/nguyen-hong-tham/may/blob/main/MAY/src/hooks/useProducts.ts"
click node_customer_auth "https://github.com/nguyen-hong-tham/may/blob/main/MAY/src/contexts/AuthContext.tsx"
click node_cart "https://github.com/nguyen-hong-tham/may/blob/main/MAY/src/contexts/CartContext.tsx"
click node_checkout "https://github.com/nguyen-hong-tham/may/blob/main/MAY/src/checkout/hooks/useCheckout.ts"
click node_customer_orders "https://github.com/nguyen-hong-tham/may/blob/main/MAY/src/contexts/OrdersContext.tsx"
click node_profile_loyalty "https://github.com/nguyen-hong-tham/may/blob/main/MAY/src/profile/hooks/useProfile.ts"
click node_chat_ui "https://github.com/nguyen-hong-tham/may/blob/main/MAY/src/components/Chatbox.tsx"
click node_admin_app "https://github.com/nguyen-hong-tham/may/blob/main/MAY-admin/src/App.tsx"
click node_admin_auth "https://github.com/nguyen-hong-tham/may/blob/main/MAY-admin/src/pages/auth/hook/useAuth.ts"
click node_admin_catalog "https://github.com/nguyen-hong-tham/may/blob/main/MAY-admin/src/pages/products/components/ProductForm.tsx"
click node_admin_orders "https://github.com/nguyen-hong-tham/may/blob/main/MAY-admin/src/pages/orders/index.tsx"
click node_admin_users "https://github.com/nguyen-hong-tham/may/blob/main/MAY-admin/src/pages/users/Users.tsx"
click node_admin_reports "https://github.com/nguyen-hong-tham/may/blob/main/MAY-admin/src/pages/revenues/index.tsx"
click node_auth_api "https://github.com/nguyen-hong-tham/may/blob/main/may-api/src/auth/auth.service.ts"
click node_catalog_api "https://github.com/nguyen-hong-tham/may/blob/main/may-api/src/products/products.controller.ts"
click node_orders_api "https://github.com/nguyen-hong-tham/may/blob/main/may-api/src/orders/orders.service.ts"
click node_payments_api "https://github.com/nguyen-hong-tham/may/blob/main/may-api/src/payments/payments.controller.ts"
click node_users_api "https://github.com/nguyen-hong-tham/may/blob/main/may-api/src/users/users.controller.ts"
click node_realtime "https://github.com/nguyen-hong-tham/may/blob/main/may-api/src/orders/orders.gateway.ts"
click node_personalization "https://github.com/nguyen-hong-tham/may/blob/main/may-api/src/personalized/personalization.service.ts"
click node_analytics_api "https://github.com/nguyen-hong-tham/may/blob/main/may-api/src/revenues/revenues.service.ts"
click node_database "https://github.com/nguyen-hong-tham/may/blob/main/may-api/src/prisma/prisma.service.ts"

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,node_customer_auth,node_cart,node_checkout,node_customer_orders,node_profile_loyalty,node_chat_ui toneBlue
class node_admin_app,node_admin_auth,node_admin_catalog,node_admin_orders,node_admin_users,node_admin_reports toneAmber
class node_auth_api,node_catalog_api,node_orders_api,node_payments_api,node_users_api,node_realtime,node_personalization,node_analytics_api toneMint
class node_database toneRose
class node_shopper,node_staff,node_firebase,node_vnpay,node_openai toneIndigo
```

## Components

### Customer app

- [Storefront](https://github.com/nguyen-hong-tham/may/blob/main/MAY/src/App.tsx): `MAY/src/App.tsx`
- [Browse catalog](https://github.com/nguyen-hong-tham/may/blob/main/MAY/src/hooks/useProducts.ts): `MAY/src/hooks/useProducts.ts`
- [Customer auth](https://github.com/nguyen-hong-tham/may/blob/main/MAY/src/contexts/AuthContext.tsx): `MAY/src/contexts/AuthContext.tsx`
- [Cart](https://github.com/nguyen-hong-tham/may/blob/main/MAY/src/contexts/CartContext.tsx): `MAY/src/contexts/CartContext.tsx`
- [Checkout](https://github.com/nguyen-hong-tham/may/blob/main/MAY/src/checkout/hooks/useCheckout.ts): `MAY/src/checkout/hooks/useCheckout.ts`
- [Order tracking](https://github.com/nguyen-hong-tham/may/blob/main/MAY/src/contexts/OrdersContext.tsx): `MAY/src/contexts/OrdersContext.tsx`
- [Profile and loyalty](https://github.com/nguyen-hong-tham/may/blob/main/MAY/src/profile/hooks/useProfile.ts): `MAY/src/profile/hooks/useProfile.ts`
- [AI chat UI](https://github.com/nguyen-hong-tham/may/blob/main/MAY/src/components/Chatbox.tsx): `MAY/src/components/Chatbox.tsx`

### Admin dashboard

- [Admin app](https://github.com/nguyen-hong-tham/may/blob/main/MAY-admin/src/App.tsx): `MAY-admin/src/App.tsx`
- [Admin auth](https://github.com/nguyen-hong-tham/may/blob/main/MAY-admin/src/pages/auth/hook/useAuth.ts): `MAY-admin/src/pages/auth/hook/useAuth.ts`
- [Catalog management](https://github.com/nguyen-hong-tham/may/blob/main/MAY-admin/src/pages/products/components/ProductForm.tsx): `MAY-admin/src/pages/products/components/ProductForm.tsx`
- [Order management](https://github.com/nguyen-hong-tham/may/blob/main/MAY-admin/src/pages/orders/index.tsx): `MAY-admin/src/pages/orders/index.tsx`
- [User management](https://github.com/nguyen-hong-tham/may/blob/main/MAY-admin/src/pages/users/Users.tsx): `MAY-admin/src/pages/users/Users.tsx`
- [Dashboards and reports](https://github.com/nguyen-hong-tham/may/blob/main/MAY-admin/src/pages/revenues/index.tsx): `MAY-admin/src/pages/revenues/index.tsx`

### Backend domains

- [Authentication API](https://github.com/nguyen-hong-tham/may/blob/main/may-api/src/auth/auth.service.ts): `may-api/src/auth/auth.service.ts`
- [Catalog API](https://github.com/nguyen-hong-tham/may/blob/main/may-api/src/products/products.controller.ts): `may-api/src/products/products.controller.ts`
- [Order processing](https://github.com/nguyen-hong-tham/may/blob/main/may-api/src/orders/orders.service.ts): `may-api/src/orders/orders.service.ts`
- [Payments](https://github.com/nguyen-hong-tham/may/blob/main/may-api/src/payments/payments.controller.ts): `may-api/src/payments/payments.controller.ts`
- [Users and loyalty](https://github.com/nguyen-hong-tham/may/blob/main/may-api/src/users/users.controller.ts): `may-api/src/users/users.controller.ts`
- [Order realtime](https://github.com/nguyen-hong-tham/may/blob/main/may-api/src/orders/orders.gateway.ts): `may-api/src/orders/orders.gateway.ts`
- [Personalization and chat](https://github.com/nguyen-hong-tham/may/blob/main/may-api/src/personalized/personalization.service.ts): `may-api/src/personalized/personalization.service.ts`
- [Analytics API](https://github.com/nguyen-hong-tham/may/blob/main/may-api/src/revenues/revenues.service.ts): `may-api/src/revenues/revenues.service.ts`

### Data and integrations

- [PostgreSQL](https://github.com/nguyen-hong-tham/may/blob/main/may-api/src/prisma/prisma.service.ts): `may-api/src/prisma/prisma.service.ts`

### Other components

- **Customer**
- **Staff and admins**
- **Firebase Auth**
- **VNPay**
- **OpenAI**

## Connections

- Customer → Storefront: uses (evidence: `MAY/src/App.tsx`)
- Storefront → Browse catalog: shows products (evidence: `MAY/src/App.tsx`)
- Customer → Customer auth: signs in (evidence: `README.md`)
- Customer auth → Authentication API: authenticates (evidence: `MAY/src/contexts/AuthContext.tsx`)
- Customer auth → Firebase Auth: verifies OTP (evidence: `README.md`)
- Customer → Cart: customizes drinks (evidence: `README.md`)
- Cart → Checkout: checks out (evidence: `MAY/src/checkout/hooks/useCheckout.ts`)
- Checkout → Order tracking: creates order (evidence: `MAY/src/checkout/hooks/useCheckout.ts`)
- Checkout → Profile and loyalty: reads profile (evidence: `MAY/src/checkout/hooks/useCheckout.ts`)
- Checkout → Order processing: submits order (evidence: `README.md`)
- Order tracking → Order processing: fetches orders (evidence: `README.md`)
- Profile and loyalty → Users and loyalty: reads loyalty (evidence: `README.md`)
- Customer → AI chat UI: asks for advice (evidence: `README.md`)
- AI chat UI → Personalization and chat: requests recommendations (evidence: `README.md`)
- Staff and admins → Admin app: uses (evidence: `README.md`)
- Admin app → Admin auth: routes auth (evidence: `MAY-admin/src/App.tsx`)
- Catalog management → Catalog API: manages catalog (evidence: `README.md`)
- Order management → Order processing: updates orders (evidence: `README.md`)
- User management → Users and loyalty: manages users (evidence: `README.md`)
- Dashboards and reports → Analytics API: requests reports (evidence: `README.md`)
- Order processing → PostgreSQL: reads and writes (evidence: `may-api/src/orders/orders.service.ts`)
- Order processing → Order realtime: emits updates (evidence: `may-api/src/orders/orders.service.ts`)
- Checkout → Payments: starts payment (evidence: `MAY/src/checkout/hooks/useCheckout.ts`)
- Payments → VNPay: creates payment session (evidence: `may-api/src/payments/payments.controller.ts`)
- Payments → Order processing: creates or updates order (evidence: `may-api/src/payments/payments.controller.ts`)
- Payments → PostgreSQL: reads and writes (evidence: `may-api/src/payments/payments.controller.ts`)
- Authentication API → PostgreSQL: reads and writes (evidence: `may-api/src/auth/auth.service.ts`)
- Authentication API → Firebase Auth: verifies token (evidence: `README.md`)
- Catalog API → PostgreSQL: reads and writes (evidence: `README.md`)
- Users and loyalty → PostgreSQL: reads and writes (evidence: `README.md`)
- Analytics API → PostgreSQL: queries sales data (evidence: `README.md`)
- Personalization and chat → OpenAI: requests AI (evidence: `README.md`)
- Order realtime → Order tracking: notifies status (evidence: `README.md`)
- Order realtime → Order management: notifies new orders (evidence: `README.md`)
