# longlivewama/digital-loyalty-cards architecture

> Architecture diagram of the GitHub repository longlivewama/digital-loyalty-cards, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/longlivewama/digital-loyalty-cards
- Repository: https://github.com/longlivewama/digital-loyalty-cards

## Overview

This is a Next.js coffee-shop loyalty-card platform: customers sign up, choose Apple or Google Wallet (or show a QR), and staff scan the shared member identity to manage stamps and rewards. Supabase holds the single balance; wallet passes reflect that state, with Apple push updates and Google object updates. The graph preserves dashboard, campaign, statistics, export, and review-nudge capabilities. Some route implementations were not excerpted, so uncertain wiring is omitted; documented workflow links cite the README.

Main entry points: [`app/api/admin/member/[id]/route.ts`](https://github.com/longlivewama/digital-loyalty-cards/blob/coffee-google-wallet/app/api/admin/member/%5Bid%5D/route.ts) (Member Actions API), [`app/dashboard`](https://github.com/longlivewama/digital-loyalty-cards/tree/coffee-google-wallet/app/dashboard) (Staff Dashboard), [`app/api/join/route.ts`](https://github.com/longlivewama/digital-loyalty-cards/blob/coffee-google-wallet/app/api/join/route.ts) (Signup Handler), [`lib/apns.ts`](https://github.com/longlivewama/digital-loyalty-cards/blob/coffee-google-wallet/lib/apns.ts) (Apple Push Service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_signup_wallet["Signup and Wallets"]
  node_join_form["Signup Form<br/>[page.tsx]"]
  node_join_api["Signup Handler<br/>[route.ts]"]
  node_member_store[("Member Records")]
  node_added_page["Wallet Choice<br/>[page.tsx]"]
  node_added_client["Wallet Choice UI<br/>[AddedClient.tsx]"]
  node_apple_download["Apple Pass Download<br/>[route.ts]"]
  node_apple_pass["Apple Pass Builder<br/>[pass.ts]"]
  node_stamp_strip["Stamp Strip Renderer<br/>[stampStrip.ts]"]
  node_google_save["Google Save Link<br/>[route.ts]"]
  node_google_wallet["Google Wallet Objects<br/>[googleWallet.ts]"]
end

subgraph group_loyalty_staff["Loyalty and Staff"]
  node_member_page["Scanned Member Page<br/>[page.tsx]"]
  node_member_actions["Stamp and Redeem UI<br/>[MemberActions.tsx]"]
  node_member_api["Member Actions API<br/>[route.ts]"]
  node_loyalty_rules["Reward Calculations<br/>[loyalty.ts]"]
  node_events["Member Event Log<br/>[events.ts]"]
end

subgraph group_wallet_sync["Wallet Updates"]
  node_apple_webservice["Apple Wallet Web Service"]
  node_apns["Apple Push Service<br/>[apns.ts]"]
  node_broadcast["Campaign and Refresh<br/>[broadcast.ts]"]
end

subgraph group_operations["Shop Operations"]
  node_dashboard["Staff Dashboard"]
  node_settings["Shop Settings<br/>[settings.ts]"]
  node_review_nudges["Review Nudges<br/>[reviews.ts]"]
  node_review_redirect["Review Link Redirect<br/>[route.ts]"]
  node_stats["Loyalty Statistics<br/>[page.tsx]"]
  node_csv_export["Member CSV Export<br/>[route.ts]"]
end

node_customer(("Customer"))
node_staff(("Shop Staff"))
node_supabase[("Supabase Database")]
node_apple_service{{"Apple Wallet"}}
node_google_service{{"Google Wallet"}}

node_customer -->|"signs up"| node_join_form
node_join_form -->|"submits form"| node_join_api
node_join_api -->|"creates member"| node_supabase
node_join_api -->|"logs signup"| node_events
node_join_api -->|"redirects to"| node_added_page
node_added_page -->|"renders"| node_added_client
node_added_client -->|"offers pass"| node_apple_download
node_added_client -->|"offers save link"| node_google_save
node_apple_download -->|"generates pass"| node_apple_pass
node_apple_pass -->|"renders strip"| node_stamp_strip
node_apple_pass -->|"reads member"| node_supabase
node_google_save -->|"prepares save"| node_google_wallet
node_google_wallet -->|"writes objects"| node_google_service
node_customer -->|"shows QR"| node_staff
node_staff -->|"scans QR"| node_member_page
node_member_page -->|"renders actions"| node_member_actions
node_member_actions -->|"submits changes"| node_member_api
node_member_api -->|"updates balance"| node_supabase
node_member_api -.->|"records changes"| node_events
node_member_page -->|"shows rewards"| node_loyalty_rules
node_apple_service -->|"registers devices"| node_apple_webservice
node_apple_service -->|"requests pass"| node_apple_webservice
node_member_api -.->|"pushes refresh"| node_apns
node_apns -->|"notifies devices"| node_apple_service
node_member_api -.->|"refreshes object"| node_google_wallet
node_dashboard -->|"sends campaigns"| node_broadcast
node_broadcast -->|"pushes campaign"| node_apns
node_dashboard -->|"loads settings"| node_settings
node_dashboard -->|"shows statistics"| node_stats
node_dashboard -->|"exports members"| node_csv_export
node_settings -->|"reads and writes"| node_supabase
node_review_nudges -->|"reads scan history"| node_supabase
node_review_nudges -->|"sends nudge"| node_apns
node_review_redirect -->|"marks reviewed"| node_review_nudges
node_review_redirect -->|"loads review link"| node_settings

click node_join_form "https://github.com/longlivewama/digital-loyalty-cards/blob/coffee-google-wallet/app/join/page.tsx"
click node_join_api "https://github.com/longlivewama/digital-loyalty-cards/blob/coffee-google-wallet/app/api/join/route.ts"
click node_added_page "https://github.com/longlivewama/digital-loyalty-cards/blob/coffee-google-wallet/app/added/%5Bserial%5D/page.tsx"
click node_added_client "https://github.com/longlivewama/digital-loyalty-cards/blob/coffee-google-wallet/app/added/%5Bserial%5D/AddedClient.tsx"
click node_apple_download "https://github.com/longlivewama/digital-loyalty-cards/blob/coffee-google-wallet/app/api/pass/%5Bserial%5D/route.ts"
click node_apple_pass "https://github.com/longlivewama/digital-loyalty-cards/blob/coffee-google-wallet/lib/pass.ts"
click node_stamp_strip "https://github.com/longlivewama/digital-loyalty-cards/blob/coffee-google-wallet/lib/stampStrip.ts"
click node_google_save "https://github.com/longlivewama/digital-loyalty-cards/blob/coffee-google-wallet/app/api/google-pass/%5Bserial%5D/route.ts"
click node_google_wallet "https://github.com/longlivewama/digital-loyalty-cards/blob/coffee-google-wallet/lib/googleWallet.ts"
click node_member_page "https://github.com/longlivewama/digital-loyalty-cards/blob/coffee-google-wallet/app/m/%5Bid%5D/page.tsx"
click node_member_actions "https://github.com/longlivewama/digital-loyalty-cards/blob/coffee-google-wallet/app/_components/MemberActions.tsx"
click node_member_api "https://github.com/longlivewama/digital-loyalty-cards/blob/coffee-google-wallet/app/api/admin/member/%5Bid%5D/route.ts"
click node_loyalty_rules "https://github.com/longlivewama/digital-loyalty-cards/blob/coffee-google-wallet/lib/loyalty.ts"
click node_events "https://github.com/longlivewama/digital-loyalty-cards/blob/coffee-google-wallet/lib/events.ts"
click node_apple_webservice "https://github.com/longlivewama/digital-loyalty-cards/tree/coffee-google-wallet/app/api/wallet/v1"
click node_apns "https://github.com/longlivewama/digital-loyalty-cards/blob/coffee-google-wallet/lib/apns.ts"
click node_broadcast "https://github.com/longlivewama/digital-loyalty-cards/blob/coffee-google-wallet/lib/broadcast.ts"
click node_dashboard "https://github.com/longlivewama/digital-loyalty-cards/tree/coffee-google-wallet/app/dashboard"
click node_settings "https://github.com/longlivewama/digital-loyalty-cards/blob/coffee-google-wallet/lib/settings.ts"
click node_review_nudges "https://github.com/longlivewama/digital-loyalty-cards/blob/coffee-google-wallet/lib/reviews.ts"
click node_review_redirect "https://github.com/longlivewama/digital-loyalty-cards/blob/coffee-google-wallet/app/r/%5Bid%5D/route.ts"
click node_stats "https://github.com/longlivewama/digital-loyalty-cards/blob/coffee-google-wallet/app/dashboard/stats/page.tsx"
click node_csv_export "https://github.com/longlivewama/digital-loyalty-cards/blob/coffee-google-wallet/app/api/admin/export/route.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_join_form,node_join_api,node_member_store,node_added_page,node_added_client,node_apple_download,node_apple_pass,node_stamp_strip,node_google_save,node_google_wallet toneBlue
class node_member_page,node_member_actions,node_member_api,node_loyalty_rules,node_events,node_supabase toneAmber
class node_apple_webservice,node_apns,node_broadcast toneMint
class node_dashboard,node_settings,node_review_nudges,node_review_redirect,node_stats,node_csv_export toneRose
class node_customer,node_staff,node_apple_service,node_google_service toneIndigo
```

## Components

### Signup and Wallets

- [Signup Form](https://github.com/longlivewama/digital-loyalty-cards/blob/coffee-google-wallet/app/join/page.tsx): `app/join/page.tsx`
- [Signup Handler](https://github.com/longlivewama/digital-loyalty-cards/blob/coffee-google-wallet/app/api/join/route.ts): `app/api/join/route.ts`
- **Member Records**
- [Wallet Choice](https://github.com/longlivewama/digital-loyalty-cards/blob/coffee-google-wallet/app/added/%5Bserial%5D/page.tsx): `app/added/[serial]/page.tsx`
- [Wallet Choice UI](https://github.com/longlivewama/digital-loyalty-cards/blob/coffee-google-wallet/app/added/%5Bserial%5D/AddedClient.tsx): `app/added/[serial]/AddedClient.tsx`
- [Apple Pass Download](https://github.com/longlivewama/digital-loyalty-cards/blob/coffee-google-wallet/app/api/pass/%5Bserial%5D/route.ts): `app/api/pass/[serial]/route.ts`
- [Apple Pass Builder](https://github.com/longlivewama/digital-loyalty-cards/blob/coffee-google-wallet/lib/pass.ts): `lib/pass.ts`
- [Stamp Strip Renderer](https://github.com/longlivewama/digital-loyalty-cards/blob/coffee-google-wallet/lib/stampStrip.ts): `lib/stampStrip.ts`
- [Google Save Link](https://github.com/longlivewama/digital-loyalty-cards/blob/coffee-google-wallet/app/api/google-pass/%5Bserial%5D/route.ts): `app/api/google-pass/[serial]/route.ts`
- [Google Wallet Objects](https://github.com/longlivewama/digital-loyalty-cards/blob/coffee-google-wallet/lib/googleWallet.ts): `lib/googleWallet.ts`

### Loyalty and Staff

- [Scanned Member Page](https://github.com/longlivewama/digital-loyalty-cards/blob/coffee-google-wallet/app/m/%5Bid%5D/page.tsx): `app/m/[id]/page.tsx`
- [Stamp and Redeem UI](https://github.com/longlivewama/digital-loyalty-cards/blob/coffee-google-wallet/app/_components/MemberActions.tsx): `app/_components/MemberActions.tsx`
- [Member Actions API](https://github.com/longlivewama/digital-loyalty-cards/blob/coffee-google-wallet/app/api/admin/member/%5Bid%5D/route.ts): `app/api/admin/member/[id]/route.ts`
- [Reward Calculations](https://github.com/longlivewama/digital-loyalty-cards/blob/coffee-google-wallet/lib/loyalty.ts): `lib/loyalty.ts`
- [Member Event Log](https://github.com/longlivewama/digital-loyalty-cards/blob/coffee-google-wallet/lib/events.ts): `lib/events.ts`

### Wallet Updates

- [Apple Wallet Web Service](https://github.com/longlivewama/digital-loyalty-cards/tree/coffee-google-wallet/app/api/wallet/v1): `app/api/wallet/v1`
- [Apple Push Service](https://github.com/longlivewama/digital-loyalty-cards/blob/coffee-google-wallet/lib/apns.ts): `lib/apns.ts`
- [Campaign and Refresh](https://github.com/longlivewama/digital-loyalty-cards/blob/coffee-google-wallet/lib/broadcast.ts): `lib/broadcast.ts`

### Shop Operations

- [Staff Dashboard](https://github.com/longlivewama/digital-loyalty-cards/tree/coffee-google-wallet/app/dashboard): `app/dashboard`
- [Shop Settings](https://github.com/longlivewama/digital-loyalty-cards/blob/coffee-google-wallet/lib/settings.ts): `lib/settings.ts`
- [Review Nudges](https://github.com/longlivewama/digital-loyalty-cards/blob/coffee-google-wallet/lib/reviews.ts): `lib/reviews.ts`
- [Review Link Redirect](https://github.com/longlivewama/digital-loyalty-cards/blob/coffee-google-wallet/app/r/%5Bid%5D/route.ts): `app/r/[id]/route.ts`
- [Loyalty Statistics](https://github.com/longlivewama/digital-loyalty-cards/blob/coffee-google-wallet/app/dashboard/stats/page.tsx): `app/dashboard/stats/page.tsx`
- [Member CSV Export](https://github.com/longlivewama/digital-loyalty-cards/blob/coffee-google-wallet/app/api/admin/export/route.ts): `app/api/admin/export/route.ts`

### Other components

- **Customer**
- **Shop Staff**
- **Supabase Database**
- **Apple Wallet**
- **Google Wallet**

## Connections

- Customer → Signup Form: signs up
- Signup Form → Signup Handler: submits form
- Signup Handler → Supabase Database: creates member (evidence: `app/api/join/route.ts`)
- Signup Handler → Member Event Log: logs signup (evidence: `app/api/join/route.ts`)
- Signup Handler → Wallet Choice: redirects to (evidence: `app/api/join/route.ts`)
- Wallet Choice → Wallet Choice UI: renders (evidence: `app/added/[serial]/page.tsx`)
- Wallet Choice UI → Apple Pass Download: offers pass
- Wallet Choice UI → Google Save Link: offers save link
- Apple Pass Download → Apple Pass Builder: generates pass (evidence: `app/api/pass/[serial]/route.ts`)
- Apple Pass Builder → Stamp Strip Renderer: renders strip (evidence: `lib/pass.ts`)
- Apple Pass Builder → Supabase Database: reads member
- Google Save Link → Google Wallet Objects: prepares save (evidence: `app/api/google-pass/[serial]/route.ts`)
- Google Wallet Objects → Google Wallet: writes objects (evidence: `lib/googleWallet.ts`)
- Customer → Shop Staff: shows QR
- Shop Staff → Scanned Member Page: scans QR
- Scanned Member Page → Stamp and Redeem UI: renders actions (evidence: `app/m/[id]/page.tsx`)
- Stamp and Redeem UI → Member Actions API: submits changes
- Member Actions API → Supabase Database: updates balance
- Member Actions API → Member Event Log: records changes
- Scanned Member Page → Reward Calculations: shows rewards (evidence: `app/m/[id]/page.tsx`)
- Apple Wallet → Apple Wallet Web Service: registers devices
- Apple Wallet → Apple Wallet Web Service: requests pass
- Member Actions API → Apple Push Service: pushes refresh
- Apple Push Service → Apple Wallet: notifies devices
- Member Actions API → Google Wallet Objects: refreshes object
- Staff Dashboard → Campaign and Refresh: sends campaigns (evidence: `app/dashboard/notify/page.tsx`)
- Campaign and Refresh → Apple Push Service: pushes campaign (evidence: `lib/broadcast.ts`)
- Staff Dashboard → Shop Settings: loads settings (evidence: `app/dashboard/settings/page.tsx`)
- Staff Dashboard → Loyalty Statistics: shows statistics
- Staff Dashboard → Member CSV Export: exports members
- Shop Settings → Supabase Database: reads and writes (evidence: `lib/settings.ts`)
- Review Nudges → Supabase Database: reads scan history (evidence: `lib/reviews.ts`)
- Review Nudges → Apple Push Service: sends nudge (evidence: `lib/reviews.ts`)
- Review Link Redirect → Review Nudges: marks reviewed (evidence: `app/r/[id]/route.ts`)
- Review Link Redirect → Shop Settings: loads review link (evidence: `app/r/[id]/route.ts`)
