# nguyenkhanhhungdev/brewlite-se architecture

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

- Interactive diagram: https://gitdiagram.com/nguyenkhanhhungdev/brewlite-se
- Repository: https://github.com/nguyenkhanhhungdev/brewlite-se

## Overview

BrewLite is a cashless drink-ordering application: customers browse and configure drinks, manage a cart, authenticate, place an order, pay through ZaloPay Sandbox, then review results and order history. Admins manage recipes and ingredients, track stock movements, progress orders, and review or reconcile payments. The README describes a REST API backed by PostgreSQL and transaction-based stock reservation. Some web-to-API and integration links below rely on README documentation; unsampled module internals are not asserted.

Main entry points: [`apps/api/src/orders/orders.service.ts`](https://github.com/nguyenkhanhhungdev/brewlite-se/blob/main/apps/api/src/orders/orders.service.ts) (Order placement), [`apps/api/src/payments/payments.service.ts`](https://github.com/nguyenkhanhhungdev/brewlite-se/blob/main/apps/api/src/payments/payments.service.ts) (Payment processing), [`apps/api/src/orders/admin-orders.controller.ts`](https://github.com/nguyenkhanhhungdev/brewlite-se/blob/main/apps/api/src/orders/admin-orders.controller.ts) (Admin order routes), [`apps/api/src/auth/auth.service.ts`](https://github.com/nguyenkhanhhungdev/brewlite-se/blob/main/apps/api/src/auth/auth.service.ts) (Authentication service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_storefront["Customer storefront"]
  node_storefront["Menu and product views<br/>[page.tsx]"]
  node_cart["Cart and preferences<br/>[page.tsx]"]
  node_checkout["Checkout<br/>[page.tsx]"]
  node_results["Payment and order views<br/>[page.tsx]"]
  node_history["Order history<br/>[page.tsx]"]
end

subgraph group_identity["Identity and access"]
  node_authui["Sign-in and profile<br/>[AuthForm.tsx]"]
  node_authapi["Authentication service<br/>[auth.service.ts]"]
  node_authroutes["Authentication routes<br/>[auth.controller.ts]"]
  node_access["Session and admin guards<br/>[jwt-auth.guard.ts]"]
end

subgraph group_commerce["Ordering and payment"]
  node_orders["Order placement<br/>[orders.service.ts]"]
  node_orderstate["Order state and cancellation"]
  node_promotions["Discount rules"]
  node_payments["Payment processing"]
  node_loyalty["Loyalty points<br/>[loyalty.service.ts]"]
end

subgraph group_catalog["Catalog and inventory"]
  node_products["Product menu API"]
  node_recipes["Recipe management<br/>[recipes.service.ts]"]
  node_ingredients["Ingredient inventory"]
end

subgraph group_operations["Admin operations"]
  node_adminorders["Admin order console<br/>[OrdersManager.tsx]"]
  node_admininventory["Admin inventory console"]
  node_adminrecipes["Admin recipe console<br/>[RecipeManager.tsx]"]
  node_adminpayments["Admin payment console"]
  node_adminorderapi["Admin order routes"]
  node_adminpaymentapi["Admin payment routes"]
end

node_customer(("Customer"))
node_zalopay{{"ZaloPay Sandbox"}}
node_db[("PostgreSQL")]

node_customer -->|"browses menu"| node_storefront
node_storefront -->|"requests menu"| node_products
node_customer -->|"configures drinks"| node_cart
node_cart -->|"proceeds to checkout"| node_checkout
node_customer -->|"signs in"| node_authui
node_authui -->|"submits credentials"| node_authroutes
node_authroutes -->|"delegates authentication"| node_authapi
node_authapi -->|"reads and updates users"| node_db
node_access -->|"checks session"| node_authapi
node_checkout -->|"creates order"| node_orders
node_orders -->|"applies discount"| node_promotions
node_orders -->|"reserves stock"| node_ingredients
node_orders -->|"persists order"| node_db
node_orders -.->|"initiates payment"| node_payments
node_payments -->|"starts or checks payment"| node_zalopay
node_zalopay -->|"returns payment status"| node_results
node_payments -->|"records transactions"| node_db
node_results -->|"views confirmed orders"| node_history
node_payments -->|"awards points"| node_loyalty
node_admininventory -->|"manages stock"| node_ingredients
node_ingredients -->|"records movements"| node_db
node_adminrecipes -->|"manages recipes"| node_recipes
node_recipes -->|"stores recipes"| node_db
node_adminorders -->|"manages orders"| node_adminorderapi
node_adminorderapi -->|"lists order records"| node_orders
node_adminorderapi -->|"changes order state"| node_orderstate
node_adminpayments -->|"reviews transactions"| node_adminpaymentapi
node_adminpaymentapi -->|"rechecks payments"| node_payments

click node_storefront "https://github.com/nguyenkhanhhungdev/brewlite-se/blob/main/apps/web/app/page.tsx"
click node_cart "https://github.com/nguyenkhanhhungdev/brewlite-se/blob/main/apps/web/app/cart/page.tsx"
click node_checkout "https://github.com/nguyenkhanhhungdev/brewlite-se/blob/main/apps/web/app/checkout/page.tsx"
click node_results "https://github.com/nguyenkhanhhungdev/brewlite-se/blob/main/apps/web/app/payment/result/page.tsx"
click node_history "https://github.com/nguyenkhanhhungdev/brewlite-se/blob/main/apps/web/app/history/page.tsx"
click node_authui "https://github.com/nguyenkhanhhungdev/brewlite-se/blob/main/apps/web/components/AuthForm.tsx"
click node_authapi "https://github.com/nguyenkhanhhungdev/brewlite-se/blob/main/apps/api/src/auth/auth.service.ts"
click node_authroutes "https://github.com/nguyenkhanhhungdev/brewlite-se/blob/main/apps/api/src/auth/auth.controller.ts"
click node_access "https://github.com/nguyenkhanhhungdev/brewlite-se/blob/main/apps/api/src/auth/jwt-auth.guard.ts"
click node_products "https://github.com/nguyenkhanhhungdev/brewlite-se/blob/main/apps/api/src/products/products.service.ts"
click node_recipes "https://github.com/nguyenkhanhhungdev/brewlite-se/blob/main/apps/api/src/recipes/recipes.service.ts"
click node_ingredients "https://github.com/nguyenkhanhhungdev/brewlite-se/blob/main/apps/api/src/ingredients/ingredients.service.ts"
click node_orders "https://github.com/nguyenkhanhhungdev/brewlite-se/blob/main/apps/api/src/orders/orders.service.ts"
click node_orderstate "https://github.com/nguyenkhanhhungdev/brewlite-se/blob/main/apps/api/src/orders/order-state.service.ts"
click node_promotions "https://github.com/nguyenkhanhhungdev/brewlite-se/blob/main/apps/api/src/promotions/promotions.service.ts"
click node_payments "https://github.com/nguyenkhanhhungdev/brewlite-se/blob/main/apps/api/src/payments/payments.service.ts"
click node_loyalty "https://github.com/nguyenkhanhhungdev/brewlite-se/blob/main/apps/api/src/loyalty/loyalty.service.ts"
click node_adminorders "https://github.com/nguyenkhanhhungdev/brewlite-se/blob/main/apps/web/components/admin/orders/OrdersManager.tsx"
click node_admininventory "https://github.com/nguyenkhanhhungdev/brewlite-se/blob/main/apps/web/components/admin/ingredients/IngredientManager.tsx"
click node_adminrecipes "https://github.com/nguyenkhanhhungdev/brewlite-se/blob/main/apps/web/components/admin/recipes/RecipeManager.tsx"
click node_adminpayments "https://github.com/nguyenkhanhhungdev/brewlite-se/blob/main/apps/web/components/admin/payments/PaymentsManager.tsx"
click node_adminorderapi "https://github.com/nguyenkhanhhungdev/brewlite-se/blob/main/apps/api/src/orders/admin-orders.controller.ts"
click node_adminpaymentapi "https://github.com/nguyenkhanhhungdev/brewlite-se/blob/main/apps/api/src/payments/payment-operations.controller.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_cart,node_checkout,node_results,node_history toneBlue
class node_authui,node_authapi,node_authroutes,node_access,node_db toneAmber
class node_orders,node_orderstate,node_promotions,node_payments,node_loyalty toneMint
class node_products,node_recipes,node_ingredients toneRose
class node_adminorders,node_admininventory,node_adminrecipes,node_adminpayments,node_adminorderapi,node_adminpaymentapi,node_customer,node_zalopay toneIndigo
```

## Components

### Customer storefront

- [Menu and product views](https://github.com/nguyenkhanhhungdev/brewlite-se/blob/main/apps/web/app/page.tsx): `apps/web/app/page.tsx`
- [Cart and preferences](https://github.com/nguyenkhanhhungdev/brewlite-se/blob/main/apps/web/app/cart/page.tsx): `apps/web/app/cart/page.tsx`
- [Checkout](https://github.com/nguyenkhanhhungdev/brewlite-se/blob/main/apps/web/app/checkout/page.tsx): `apps/web/app/checkout/page.tsx`
- [Payment and order views](https://github.com/nguyenkhanhhungdev/brewlite-se/blob/main/apps/web/app/payment/result/page.tsx): `apps/web/app/payment/result/page.tsx`
- [Order history](https://github.com/nguyenkhanhhungdev/brewlite-se/blob/main/apps/web/app/history/page.tsx): `apps/web/app/history/page.tsx`

### Identity and access

- [Sign-in and profile](https://github.com/nguyenkhanhhungdev/brewlite-se/blob/main/apps/web/components/AuthForm.tsx): `apps/web/components/AuthForm.tsx`
- [Authentication service](https://github.com/nguyenkhanhhungdev/brewlite-se/blob/main/apps/api/src/auth/auth.service.ts): `apps/api/src/auth/auth.service.ts`
- [Authentication routes](https://github.com/nguyenkhanhhungdev/brewlite-se/blob/main/apps/api/src/auth/auth.controller.ts): `apps/api/src/auth/auth.controller.ts`
- [Session and admin guards](https://github.com/nguyenkhanhhungdev/brewlite-se/blob/main/apps/api/src/auth/jwt-auth.guard.ts): `apps/api/src/auth/jwt-auth.guard.ts`

### Ordering and payment

- [Order placement](https://github.com/nguyenkhanhhungdev/brewlite-se/blob/main/apps/api/src/orders/orders.service.ts): `apps/api/src/orders/orders.service.ts`
- [Order state and cancellation](https://github.com/nguyenkhanhhungdev/brewlite-se/blob/main/apps/api/src/orders/order-state.service.ts): `apps/api/src/orders/order-state.service.ts`
- [Discount rules](https://github.com/nguyenkhanhhungdev/brewlite-se/blob/main/apps/api/src/promotions/promotions.service.ts): `apps/api/src/promotions/promotions.service.ts`
- [Payment processing](https://github.com/nguyenkhanhhungdev/brewlite-se/blob/main/apps/api/src/payments/payments.service.ts): `apps/api/src/payments/payments.service.ts`
- [Loyalty points](https://github.com/nguyenkhanhhungdev/brewlite-se/blob/main/apps/api/src/loyalty/loyalty.service.ts): `apps/api/src/loyalty/loyalty.service.ts`

### Catalog and inventory

- [Product menu API](https://github.com/nguyenkhanhhungdev/brewlite-se/blob/main/apps/api/src/products/products.service.ts): `apps/api/src/products/products.service.ts`
- [Recipe management](https://github.com/nguyenkhanhhungdev/brewlite-se/blob/main/apps/api/src/recipes/recipes.service.ts): `apps/api/src/recipes/recipes.service.ts`
- [Ingredient inventory](https://github.com/nguyenkhanhhungdev/brewlite-se/blob/main/apps/api/src/ingredients/ingredients.service.ts): `apps/api/src/ingredients/ingredients.service.ts`

### Admin operations

- [Admin order console](https://github.com/nguyenkhanhhungdev/brewlite-se/blob/main/apps/web/components/admin/orders/OrdersManager.tsx): `apps/web/components/admin/orders/OrdersManager.tsx`
- [Admin inventory console](https://github.com/nguyenkhanhhungdev/brewlite-se/blob/main/apps/web/components/admin/ingredients/IngredientManager.tsx): `apps/web/components/admin/ingredients/IngredientManager.tsx`
- [Admin recipe console](https://github.com/nguyenkhanhhungdev/brewlite-se/blob/main/apps/web/components/admin/recipes/RecipeManager.tsx): `apps/web/components/admin/recipes/RecipeManager.tsx`
- [Admin payment console](https://github.com/nguyenkhanhhungdev/brewlite-se/blob/main/apps/web/components/admin/payments/PaymentsManager.tsx): `apps/web/components/admin/payments/PaymentsManager.tsx`
- [Admin order routes](https://github.com/nguyenkhanhhungdev/brewlite-se/blob/main/apps/api/src/orders/admin-orders.controller.ts): `apps/api/src/orders/admin-orders.controller.ts`
- [Admin payment routes](https://github.com/nguyenkhanhhungdev/brewlite-se/blob/main/apps/api/src/payments/payment-operations.controller.ts): `apps/api/src/payments/payment-operations.controller.ts`

### Other components

- **Customer**
- **ZaloPay Sandbox**
- **PostgreSQL**

## Connections

- Customer → Menu and product views: browses menu (evidence: `README.md`)
- Menu and product views → Product menu API: requests menu (evidence: `README.md`)
- Customer → Cart and preferences: configures drinks (evidence: `README.md`)
- Cart and preferences → Checkout: proceeds to checkout (evidence: `README.md`)
- Customer → Sign-in and profile: signs in (evidence: `README.md`)
- Sign-in and profile → Authentication routes: submits credentials (evidence: `README.md`)
- Authentication routes → Authentication service: delegates authentication (evidence: `apps/api/src/auth/auth.controller.ts`)
- Authentication service → PostgreSQL: reads and updates users (evidence: `apps/api/src/auth/auth.service.ts`)
- Session and admin guards → Authentication service: checks session (evidence: `apps/api/src/auth/jwt-auth.guard.ts`)
- Checkout → Order placement: creates order (evidence: `README.md`)
- Order placement → Discount rules: applies discount (evidence: `apps/api/src/orders/orders.service.ts`)
- Order placement → Ingredient inventory: reserves stock (evidence: `README.md`)
- Order placement → PostgreSQL: persists order (evidence: `README.md`)
- Order placement → Payment processing: initiates payment
- Payment processing → ZaloPay Sandbox: starts or checks payment (evidence: `README.md`)
- ZaloPay Sandbox → Payment and order views: returns payment status (evidence: `README.md`)
- Payment processing → PostgreSQL: records transactions (evidence: `README.md`)
- Payment and order views → Order history: views confirmed orders (evidence: `README.md`)
- Payment processing → Loyalty points: awards points (evidence: `README.md`)
- Admin inventory console → Ingredient inventory: manages stock (evidence: `README.md`)
- Ingredient inventory → PostgreSQL: records movements (evidence: `README.md`)
- Admin recipe console → Recipe management: manages recipes (evidence: `README.md`)
- Recipe management → PostgreSQL: stores recipes (evidence: `README.md`)
- Admin order console → Admin order routes: manages orders (evidence: `README.md`)
- Admin order routes → Order placement: lists order records (evidence: `apps/api/src/orders/admin-orders.controller.ts`)
- Admin order routes → Order state and cancellation: changes order state (evidence: `apps/api/src/orders/admin-orders.controller.ts`)
- Admin payment console → Admin payment routes: reviews transactions (evidence: `README.md`)
- Admin payment routes → Payment processing: rechecks payments (evidence: `apps/api/src/payments/payment-operations.controller.ts`)
