# giabaot400-boop/brewlite-assignment2 architecture

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

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

## Overview

BrewLite is a coffee-shop ordering product: customers browse a catalog, manage a cart, create and read orders, pay or cancel, and follow order status. The repository splits the experience between a Next.js frontend/BFF and a NestJS API backed by PostgreSQL. The README documents checkout v2, mock payment, stock, loyalty points, expiry, PWA, and private product APIs. Some web route and checkout implementation details were not excerpted, so links involving those paths are omitted or marked unverified.

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

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web experience"]
  node_catalog["Product catalog<br/>[menu.tsx]"]
  node_cart["Cart and checkout"]
end

subgraph group_identity["Authentication"]
  node_web_auth["Auth client<br/>[auth-client.ts]"]
  node_auth_routes["Auth BFF routes"]
  node_auth_controller["Auth controller<br/>[auth.controller.ts]"]
  node_auth_service["Auth service<br/>[auth.service.ts]"]
  node_auth_guard["Auth guard<br/>[auth.guard.ts]"]
end

subgraph group_commerce["Ordering and checkout"]
  node_order_controller["Order endpoints"]
  node_order_service["Order creation<br/>[orders.service.ts]"]
  node_order_reader["Order reads"]
  node_action_controller["Payment and cancel"]
  node_workflow["Order workflow"]
  node_stock["Stock and reservations<br/>[stock.ts]"]
  node_loyalty["Loyalty points<br/>[loyalty.ts]"]
end

subgraph group_data["API and persistence"]
  node_product_controller["Products API"]
  node_product_service["Product queries"]
  node_postgres[("PostgreSQL<br/>[prisma.service.ts]")]
end

node_customer(("Customer"))

node_customer -->|"browses"| node_catalog
node_customer -->|"checks out"| node_cart
node_web_auth -->|"requests"| node_auth_routes
node_auth_controller -->|"delegates to"| node_auth_service
node_auth_guard -->|"validates with"| node_auth_service
node_auth_service -->|"reads and writes"| node_postgres
node_product_controller -->|"delegates to"| node_product_service
node_product_service -->|"queries"| node_postgres
node_order_controller -->|"creates order"| node_order_service
node_order_controller -->|"reads orders"| node_order_reader
node_order_service -->|"reserves stock"| node_stock
node_order_service -->|"transacts"| node_postgres
node_order_reader -->|"reads"| node_postgres
node_action_controller -->|"dispatches actions"| node_workflow
node_workflow -->|"updates reservations"| node_stock
node_workflow -->|"awards or reverses"| node_loyalty
node_workflow -->|"transacts"| node_postgres

click node_catalog "https://github.com/giabaot400-boop/brewlite-assignment2/blob/main/apps/web/src/features/products/components/menu.tsx"
click node_cart "https://github.com/giabaot400-boop/brewlite-assignment2/tree/main/apps/web/src/features/cart"
click node_web_auth "https://github.com/giabaot400-boop/brewlite-assignment2/blob/main/apps/web/src/features/auth/auth-client.ts"
click node_auth_routes "https://github.com/giabaot400-boop/brewlite-assignment2/tree/main/apps/web/src/app/api/auth"
click node_auth_controller "https://github.com/giabaot400-boop/brewlite-assignment2/blob/main/apps/api/src/auth/auth.controller.ts"
click node_auth_service "https://github.com/giabaot400-boop/brewlite-assignment2/blob/main/apps/api/src/auth/auth.service.ts"
click node_auth_guard "https://github.com/giabaot400-boop/brewlite-assignment2/blob/main/apps/api/src/auth/auth.guard.ts"
click node_product_controller "https://github.com/giabaot400-boop/brewlite-assignment2/blob/main/apps/api/src/products/products.controller.ts"
click node_product_service "https://github.com/giabaot400-boop/brewlite-assignment2/blob/main/apps/api/src/products/products-prisma.service.ts"
click node_order_controller "https://github.com/giabaot400-boop/brewlite-assignment2/blob/main/apps/api/src/orders/orders.controller.ts"
click node_order_service "https://github.com/giabaot400-boop/brewlite-assignment2/blob/main/apps/api/src/orders/orders.service.ts"
click node_order_reader "https://github.com/giabaot400-boop/brewlite-assignment2/blob/main/apps/api/src/orders/orders-reader.service.ts"
click node_action_controller "https://github.com/giabaot400-boop/brewlite-assignment2/blob/main/apps/api/src/orders/order-actions.controller.ts"
click node_workflow "https://github.com/giabaot400-boop/brewlite-assignment2/blob/main/apps/api/src/orders/order-workflow.service.ts"
click node_stock "https://github.com/giabaot400-boop/brewlite-assignment2/blob/main/apps/api/src/database/stock.ts"
click node_loyalty "https://github.com/giabaot400-boop/brewlite-assignment2/blob/main/apps/api/src/orders/loyalty.ts"
click node_postgres "https://github.com/giabaot400-boop/brewlite-assignment2/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_catalog,node_cart toneBlue
class node_web_auth,node_auth_routes,node_auth_controller,node_auth_service,node_auth_guard toneAmber
class node_order_controller,node_order_service,node_order_reader,node_action_controller,node_workflow,node_stock,node_loyalty toneMint
class node_product_controller,node_product_service,node_postgres toneRose
class node_customer toneIndigo
```

## Components

### Web experience

- [Product catalog](https://github.com/giabaot400-boop/brewlite-assignment2/blob/main/apps/web/src/features/products/components/menu.tsx): `apps/web/src/features/products/components/menu.tsx`
- [Cart and checkout](https://github.com/giabaot400-boop/brewlite-assignment2/tree/main/apps/web/src/features/cart): `apps/web/src/features/cart`

### Authentication

- [Auth client](https://github.com/giabaot400-boop/brewlite-assignment2/blob/main/apps/web/src/features/auth/auth-client.ts): `apps/web/src/features/auth/auth-client.ts`
- [Auth BFF routes](https://github.com/giabaot400-boop/brewlite-assignment2/tree/main/apps/web/src/app/api/auth): `apps/web/src/app/api/auth`
- [Auth controller](https://github.com/giabaot400-boop/brewlite-assignment2/blob/main/apps/api/src/auth/auth.controller.ts): `apps/api/src/auth/auth.controller.ts`
- [Auth service](https://github.com/giabaot400-boop/brewlite-assignment2/blob/main/apps/api/src/auth/auth.service.ts): `apps/api/src/auth/auth.service.ts`
- [Auth guard](https://github.com/giabaot400-boop/brewlite-assignment2/blob/main/apps/api/src/auth/auth.guard.ts): `apps/api/src/auth/auth.guard.ts`

### Ordering and checkout

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

### API and persistence

- [Products API](https://github.com/giabaot400-boop/brewlite-assignment2/blob/main/apps/api/src/products/products.controller.ts): `apps/api/src/products/products.controller.ts`
- [Product queries](https://github.com/giabaot400-boop/brewlite-assignment2/blob/main/apps/api/src/products/products-prisma.service.ts): `apps/api/src/products/products-prisma.service.ts`
- [PostgreSQL](https://github.com/giabaot400-boop/brewlite-assignment2/blob/main/apps/api/src/database/prisma.service.ts): `apps/api/src/database/prisma.service.ts`

### Other components

- **Customer**

## Connections

- Customer → Product catalog: browses (evidence: `README.md`)
- Customer → Cart and checkout: checks out (evidence: `README.md`)
- Auth client → Auth BFF routes: requests (evidence: `apps/web/src/features/auth/auth-client.ts`)
- Auth controller → Auth service: delegates to (evidence: `apps/api/src/auth/auth.controller.ts`)
- Auth guard → Auth service: validates with (evidence: `apps/api/src/auth/auth.guard.ts`)
- Auth service → PostgreSQL: reads and writes (evidence: `apps/api/src/auth/auth.service.ts`)
- Products API → Product queries: delegates to (evidence: `apps/api/src/products/products.controller.ts`)
- Product queries → PostgreSQL: queries (evidence: `apps/api/src/products/products-prisma.service.ts`)
- Order endpoints → Order creation: creates order (evidence: `apps/api/src/orders/orders.controller.ts`)
- Order endpoints → Order reads: reads orders (evidence: `apps/api/src/orders/orders.controller.ts`)
- Order creation → Stock and reservations: reserves stock (evidence: `apps/api/src/orders/orders.service.ts`)
- Order creation → PostgreSQL: transacts (evidence: `apps/api/src/orders/orders.service.ts`)
- Order reads → PostgreSQL: reads (evidence: `apps/api/src/orders/orders-reader.service.ts`)
- Payment and cancel → Order workflow: dispatches actions (evidence: `apps/api/src/orders/order-actions.controller.ts`)
- Order workflow → Stock and reservations: updates 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 workflow → PostgreSQL: transacts (evidence: `apps/api/src/orders/order-workflow.service.ts`)
