# giabaot400-boop/brewlite architecture

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

- Interactive diagram: https://gitdiagram.com/giabaot400-boop/brewlite
- Repository: https://github.com/giabaot400-boop/brewlite

## Overview

BrewLite is a coffee-store application with a Next.js storefront and a NestJS API backed by PostgreSQL. The shopper-facing journey covers browsing products, maintaining a cart, creating an order, and viewing order history; the documented Sprint 3 workflow adds payment, cancellation, expiry, loyalty points, and stock control. The graph includes authentication and PWA capabilities as separate branches. Some frontend route wiring and unsampled workflow details are not shown, so edges are limited to documented or indexed relationships.

Main entry points: [`apps/api/src/database/prisma.service.ts`](https://github.com/giabaot400-boop/brewlite/blob/main/apps/api/src/database/prisma.service.ts) (Prisma connection), [`apps/api/src/orders/order-workflow.service.ts`](https://github.com/giabaot400-boop/brewlite/blob/main/apps/api/src/orders/order-workflow.service.ts) (Order workflow), [`apps/api/src/orders/orders.controller.ts`](https://github.com/giabaot400-boop/brewlite/blob/main/apps/api/src/orders/orders.controller.ts) (Order endpoints), [`apps/api/src/orders/orders.service.ts`](https://github.com/giabaot400-boop/brewlite/blob/main/apps/api/src/orders/orders.service.ts) (Order creation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_storefront["Storefront"]
  node_menu["Product menu<br/>[menu.tsx]"]
  node_cart["Cart state<br/>[cart-reducer.ts]"]
  node_cart_storage[("Cart persistence<br/>[cart-storage.ts]")]
  node_cart_checkout["Checkout UI"]
  node_pwa["PWA support<br/>[pwa-support.tsx]"]
end

subgraph group_identity["Identity"]
  node_auth_ui["Authentication UI<br/>[auth-client.ts]"]
  node_auth_api["Authentication service<br/>[auth.service.ts]"]
  node_auth_guard["Session guard<br/>[auth.guard.ts]"]
end

subgraph group_orders["Order lifecycle"]
  node_orders_ui["Order views"]
end

subgraph group_api["Backend API"]
  node_order_routes["Order endpoints"]
  node_order_actions["Payment and cancel"]
  node_order_create["Order creation<br/>[orders.service.ts]"]
  node_order_reader["Order reads"]
  node_workflow["Order workflow"]
  node_products_api["Product API"]
  node_stock["Stock control<br/>[stock.ts]"]
  node_loyalty["Loyalty points<br/>[loyalty.ts]"]
end

subgraph group_persistence["Persistence"]
  node_prisma["Prisma connection<br/>[prisma.service.ts]"]
  node_postgres[("PostgreSQL")]
end

node_shopper(("Shopper"))

node_shopper -->|"browses"| node_menu
node_shopper -->|"checks out"| node_cart_checkout
node_shopper -->|"views orders"| node_orders_ui
node_cart_storage -->|"persists state"| node_cart
node_auth_ui -.->|"calls auth routes"| node_auth_api
node_auth_api -->|"reads and writes sessions"| node_prisma
node_auth_guard -->|"validates sessions"| node_auth_api
node_order_routes -->|"guards requests"| node_auth_guard
node_order_routes -->|"creates orders"| node_order_create
node_order_routes -->|"reads orders"| node_order_reader
node_order_actions -->|"guards requests"| node_auth_guard
node_order_actions -->|"dispatches actions"| node_workflow
node_order_create -->|"checks and reserves"| node_stock
node_workflow -->|"changes reservations"| node_stock
node_workflow -->|"awards or reverses"| node_loyalty
node_order_create -->|"persists orders"| node_prisma
node_order_reader -->|"queries orders"| node_prisma
node_workflow -->|"runs transactions"| node_prisma
node_products_api -->|"reads products"| node_prisma
node_prisma -->|"connects to"| node_postgres

click node_menu "https://github.com/giabaot400-boop/brewlite/blob/main/apps/web/src/features/products/components/menu.tsx"
click node_cart "https://github.com/giabaot400-boop/brewlite/blob/main/apps/web/src/features/cart/cart-reducer.ts"
click node_cart_storage "https://github.com/giabaot400-boop/brewlite/blob/main/apps/web/src/features/cart/cart-storage.ts"
click node_cart_checkout "https://github.com/giabaot400-boop/brewlite/blob/main/apps/web/src/features/cart/components/checkout-v2-panel.tsx"
click node_pwa "https://github.com/giabaot400-boop/brewlite/blob/main/apps/web/src/features/pwa/pwa-support.tsx"
click node_auth_ui "https://github.com/giabaot400-boop/brewlite/blob/main/apps/web/src/features/auth/auth-client.ts"
click node_auth_api "https://github.com/giabaot400-boop/brewlite/blob/main/apps/api/src/auth/auth.service.ts"
click node_auth_guard "https://github.com/giabaot400-boop/brewlite/blob/main/apps/api/src/auth/auth.guard.ts"
click node_orders_ui "https://github.com/giabaot400-boop/brewlite/blob/main/apps/web/src/features/orders/components/order-history-page.tsx"
click node_order_routes "https://github.com/giabaot400-boop/brewlite/blob/main/apps/api/src/orders/orders.controller.ts"
click node_order_actions "https://github.com/giabaot400-boop/brewlite/blob/main/apps/api/src/orders/order-actions.controller.ts"
click node_order_create "https://github.com/giabaot400-boop/brewlite/blob/main/apps/api/src/orders/orders.service.ts"
click node_order_reader "https://github.com/giabaot400-boop/brewlite/blob/main/apps/api/src/orders/orders-reader.service.ts"
click node_workflow "https://github.com/giabaot400-boop/brewlite/blob/main/apps/api/src/orders/order-workflow.service.ts"
click node_products_api "https://github.com/giabaot400-boop/brewlite/blob/main/apps/api/src/products/products.controller.ts"
click node_stock "https://github.com/giabaot400-boop/brewlite/blob/main/apps/api/src/database/stock.ts"
click node_loyalty "https://github.com/giabaot400-boop/brewlite/blob/main/apps/api/src/orders/loyalty.ts"
click node_prisma "https://github.com/giabaot400-boop/brewlite/blob/main/apps/api/src/database/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_menu,node_cart,node_cart_storage,node_cart_checkout,node_pwa toneBlue
class node_auth_ui,node_auth_api,node_auth_guard toneAmber
class node_orders_ui toneMint
class node_order_routes,node_order_actions,node_order_create,node_order_reader,node_workflow,node_products_api,node_stock,node_loyalty toneRose
class node_prisma,node_postgres,node_shopper toneIndigo
```

## Components

### Storefront

- [Product menu](https://github.com/giabaot400-boop/brewlite/blob/main/apps/web/src/features/products/components/menu.tsx): `apps/web/src/features/products/components/menu.tsx`
- [Cart state](https://github.com/giabaot400-boop/brewlite/blob/main/apps/web/src/features/cart/cart-reducer.ts): `apps/web/src/features/cart/cart-reducer.ts`
- [Cart persistence](https://github.com/giabaot400-boop/brewlite/blob/main/apps/web/src/features/cart/cart-storage.ts): `apps/web/src/features/cart/cart-storage.ts`
- [Checkout UI](https://github.com/giabaot400-boop/brewlite/blob/main/apps/web/src/features/cart/components/checkout-v2-panel.tsx): `apps/web/src/features/cart/components/checkout-v2-panel.tsx`
- [PWA support](https://github.com/giabaot400-boop/brewlite/blob/main/apps/web/src/features/pwa/pwa-support.tsx): `apps/web/src/features/pwa/pwa-support.tsx`

### Identity

- [Authentication UI](https://github.com/giabaot400-boop/brewlite/blob/main/apps/web/src/features/auth/auth-client.ts): `apps/web/src/features/auth/auth-client.ts`
- [Authentication service](https://github.com/giabaot400-boop/brewlite/blob/main/apps/api/src/auth/auth.service.ts): `apps/api/src/auth/auth.service.ts`
- [Session guard](https://github.com/giabaot400-boop/brewlite/blob/main/apps/api/src/auth/auth.guard.ts): `apps/api/src/auth/auth.guard.ts`

### Order lifecycle

- [Order views](https://github.com/giabaot400-boop/brewlite/blob/main/apps/web/src/features/orders/components/order-history-page.tsx): `apps/web/src/features/orders/components/order-history-page.tsx`

### Backend API

- [Order endpoints](https://github.com/giabaot400-boop/brewlite/blob/main/apps/api/src/orders/orders.controller.ts): `apps/api/src/orders/orders.controller.ts`
- [Payment and cancel](https://github.com/giabaot400-boop/brewlite/blob/main/apps/api/src/orders/order-actions.controller.ts): `apps/api/src/orders/order-actions.controller.ts`
- [Order creation](https://github.com/giabaot400-boop/brewlite/blob/main/apps/api/src/orders/orders.service.ts): `apps/api/src/orders/orders.service.ts`
- [Order reads](https://github.com/giabaot400-boop/brewlite/blob/main/apps/api/src/orders/orders-reader.service.ts): `apps/api/src/orders/orders-reader.service.ts`
- [Order workflow](https://github.com/giabaot400-boop/brewlite/blob/main/apps/api/src/orders/order-workflow.service.ts): `apps/api/src/orders/order-workflow.service.ts`
- [Product API](https://github.com/giabaot400-boop/brewlite/blob/main/apps/api/src/products/products.controller.ts): `apps/api/src/products/products.controller.ts`
- [Stock control](https://github.com/giabaot400-boop/brewlite/blob/main/apps/api/src/database/stock.ts): `apps/api/src/database/stock.ts`
- [Loyalty points](https://github.com/giabaot400-boop/brewlite/blob/main/apps/api/src/orders/loyalty.ts): `apps/api/src/orders/loyalty.ts`

### Persistence

- [Prisma connection](https://github.com/giabaot400-boop/brewlite/blob/main/apps/api/src/database/prisma.service.ts): `apps/api/src/database/prisma.service.ts`
- **PostgreSQL**

### Other components

- **Shopper**

## Connections

- Shopper → Product menu: browses
- Shopper → Checkout UI: checks out
- Shopper → Order views: views orders
- Cart persistence → Cart state: persists state (evidence: `apps/web/src/features/cart/cart-storage.ts`)
- Authentication UI → Authentication service: calls auth routes
- Authentication service → Prisma connection: reads and writes sessions (evidence: `apps/api/src/auth/auth.service.ts`)
- Session guard → Authentication service: validates sessions (evidence: `apps/api/src/auth/auth.guard.ts`)
- Order endpoints → Session guard: guards requests (evidence: `apps/api/src/orders/orders.controller.ts`)
- Order endpoints → Order creation: creates orders (evidence: `apps/api/src/orders/orders.controller.ts`)
- Order endpoints → Order reads: reads orders (evidence: `apps/api/src/orders/orders.controller.ts`)
- Payment and cancel → Session guard: guards requests (evidence: `apps/api/src/orders/order-actions.controller.ts`)
- Payment and cancel → Order workflow: dispatches actions (evidence: `apps/api/src/orders/order-actions.controller.ts`)
- Order creation → Stock control: checks and reserves (evidence: `apps/api/src/orders/orders.service.ts`)
- Order workflow → Stock control: changes reservations (evidence: `apps/api/src/orders/order-workflow.service.ts`)
- Order workflow → Loyalty points: awards or reverses (evidence: `apps/api/src/orders/order-workflow.service.ts`)
- Order creation → Prisma connection: persists orders (evidence: `apps/api/src/orders/orders.service.ts`)
- Order reads → Prisma connection: queries orders (evidence: `apps/api/src/orders/orders-reader.service.ts`)
- Order workflow → Prisma connection: runs transactions (evidence: `apps/api/src/orders/order-workflow.service.ts`)
- Product API → Prisma connection: reads products (evidence: `apps/api/src/products/products.controller.ts`)
- Prisma connection → PostgreSQL: connects to
