# t06546666-maker/ae architecture

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

- Interactive diagram: https://gitdiagram.com/t06546666-maker/ae
- Repository: https://github.com/t06546666-maker/ae

## Overview

RewardHub is a multi-role rewards platform: customers discover merchants and offers, earn or redeem rewards, while merchants handle QR checkout and customer orders and administrators manage the network and reporting. The React app routes role-specific workspaces through a shared API to an Express backend and Supabase. The backend also supports campaign notifications and a distinct affiliate settlement engine. Main server internals and unsampled page/API wiring are only partially evidenced, so uncertain relationships are omitted; optional email is documented but not verified in source.

Main entry points: [`server.js`](https://github.com/t06546666-maker/ae/blob/main/server.js) (Express API), [`src/modules/affiliate/redemptions/index.js`](https://github.com/t06546666-maker/ae/blob/main/src/modules/affiliate/redemptions/index.js) (Redemptions), [`src/modules/affiliate/rewards/index.js`](https://github.com/t06546666-maker/ae/blob/main/src/modules/affiliate/rewards/index.js) (Reward ledger), [`src/modules/affiliate/audit/index.js`](https://github.com/t06546666-maker/ae/blob/main/src/modules/affiliate/audit/index.js) (Audit trail)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["User applications"]
  node_admins["Admins and merchants<br/>[App.tsx]"]
  node_customer_app["Customer app<br/>[App.tsx]"]
end

subgraph group_operations["Merchant and admin operations"]
  node_admin_work["Admin workspace<br/>[AdminDashboard.tsx]"]
  node_merchant_work["Merchant workspace"]
  node_merchant_qr["QR checkout<br/>[QrScanner.tsx]"]
  node_field_visits["Field visits<br/>[FieldManager.tsx]"]
end

subgraph group_customer["Customer rewards"]
  node_customer_discovery["Explore and offers<br/>[Explore.tsx]"]
  node_customer_account["Customer account<br/>[Profile.tsx]"]
  node_customer_rewards["Rewards and activity<br/>[useCustomerData.ts]"]
end

subgraph group_backend["Backend services"]
  node_api_client["API client<br/>[api.ts]"]
  node_express["Express API<br/>[server.js]"]
  node_supabase[("Supabase")]
  node_whatsapp["WhatsApp Cloud API"]
  node_email["Resend email"]
end

subgraph group_affiliate["Affiliate settlement"]
  node_network_api["Affiliate networks<br/>[index.js]"]
  node_reward_ledger["Reward ledger<br/>[index.js]"]
  node_redemptions["Redemptions<br/>[index.js]"]
  node_settlements["Settlements<br/>[index.js]"]
  node_payment_provider["Payment provider"]
  node_audit["Audit trail<br/>[index.js]"]
  node_affiliate_db["Affiliate data client<br/>[db.js]"]
  node_money["Money conversion<br/>[money.js]"]
end

node_admins -->|"routes to"| node_admin_work
node_admins -->|"routes to"| node_merchant_work
node_admins -->|"routes to"| node_field_visits
node_customer_app -->|"routes to"| node_customer_discovery
node_customer_app -->|"routes to"| node_customer_account
node_customer_app -->|"uses"| node_customer_rewards
node_merchant_work -.->|"uses"| node_merchant_qr
node_admins -->|"calls"| node_api_client
node_customer_rewards -->|"fetches from"| node_api_client
node_api_client -->|"sends requests"| node_express
node_express -->|"reads and writes"| node_supabase
node_express -->|"sends notifications"| node_whatsapp
node_express -.->|"sends email"| node_email
node_express -->|"mounts"| node_network_api
node_express -->|"mounts"| node_reward_ledger
node_express -->|"mounts"| node_redemptions
node_express -->|"mounts"| node_settlements
node_redemptions -->|"checks entitlement"| node_reward_ledger
node_redemptions -->|"creates payment"| node_payment_provider
node_settlements -->|"uses"| node_payment_provider
node_network_api -->|"queries"| node_affiliate_db
node_reward_ledger -->|"writes ledger"| node_affiliate_db
node_redemptions -->|"reads and writes"| node_affiliate_db
node_settlements -->|"reads and writes"| node_affiliate_db
node_reward_ledger -->|"converts amounts"| node_money
node_redemptions -->|"converts amounts"| node_money
node_network_api -->|"records actions"| node_audit
node_reward_ledger -->|"records actions"| node_audit
node_redemptions -->|"records actions"| node_audit
node_settlements -->|"records actions"| node_audit
node_audit -->|"writes audit logs"| node_affiliate_db

click node_admins "https://github.com/t06546666-maker/ae/blob/main/src/App.tsx"
click node_customer_app "https://github.com/t06546666-maker/ae/blob/main/src/App.tsx"
click node_admin_work "https://github.com/t06546666-maker/ae/blob/main/src/pages/AdminDashboard.tsx"
click node_merchant_work "https://github.com/t06546666-maker/ae/blob/main/src/pages/MerchantOverview.tsx"
click node_merchant_qr "https://github.com/t06546666-maker/ae/blob/main/src/components/QrScanner.tsx"
click node_field_visits "https://github.com/t06546666-maker/ae/blob/main/src/pages/FieldManager.tsx"
click node_customer_discovery "https://github.com/t06546666-maker/ae/blob/main/src/pages/customer/Explore.tsx"
click node_customer_account "https://github.com/t06546666-maker/ae/blob/main/src/pages/customer/Profile.tsx"
click node_customer_rewards "https://github.com/t06546666-maker/ae/blob/main/src/hooks/useCustomerData.ts"
click node_api_client "https://github.com/t06546666-maker/ae/blob/main/src/api.ts"
click node_express "https://github.com/t06546666-maker/ae/blob/main/server.js"
click node_network_api "https://github.com/t06546666-maker/ae/blob/main/src/modules/affiliate/networks/index.js"
click node_reward_ledger "https://github.com/t06546666-maker/ae/blob/main/src/modules/affiliate/rewards/index.js"
click node_redemptions "https://github.com/t06546666-maker/ae/blob/main/src/modules/affiliate/redemptions/index.js"
click node_settlements "https://github.com/t06546666-maker/ae/blob/main/src/modules/affiliate/settlements/index.js"
click node_payment_provider "https://github.com/t06546666-maker/ae/blob/main/src/modules/affiliate/payments/MockPaymentProvider.js"
click node_audit "https://github.com/t06546666-maker/ae/blob/main/src/modules/affiliate/audit/index.js"
click node_affiliate_db "https://github.com/t06546666-maker/ae/blob/main/src/modules/affiliate/common/db.js"
click node_money "https://github.com/t06546666-maker/ae/blob/main/src/modules/affiliate/common/money.js"

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_admins,node_customer_app toneBlue
class node_admin_work,node_merchant_work,node_merchant_qr,node_field_visits toneAmber
class node_customer_discovery,node_customer_account,node_customer_rewards toneMint
class node_api_client,node_express,node_supabase,node_whatsapp,node_email toneRose
class node_network_api,node_reward_ledger,node_redemptions,node_settlements,node_payment_provider,node_audit,node_affiliate_db,node_money toneIndigo
```

## Components

### User applications

- [Admins and merchants](https://github.com/t06546666-maker/ae/blob/main/src/App.tsx): `src/App.tsx`
- [Customer app](https://github.com/t06546666-maker/ae/blob/main/src/App.tsx): `src/App.tsx`

### Merchant and admin operations

- [Admin workspace](https://github.com/t06546666-maker/ae/blob/main/src/pages/AdminDashboard.tsx): `src/pages/AdminDashboard.tsx`
- [Merchant workspace](https://github.com/t06546666-maker/ae/blob/main/src/pages/MerchantOverview.tsx): `src/pages/MerchantOverview.tsx`
- [QR checkout](https://github.com/t06546666-maker/ae/blob/main/src/components/QrScanner.tsx): `src/components/QrScanner.tsx`
- [Field visits](https://github.com/t06546666-maker/ae/blob/main/src/pages/FieldManager.tsx): `src/pages/FieldManager.tsx`

### Customer rewards

- [Explore and offers](https://github.com/t06546666-maker/ae/blob/main/src/pages/customer/Explore.tsx): `src/pages/customer/Explore.tsx`
- [Customer account](https://github.com/t06546666-maker/ae/blob/main/src/pages/customer/Profile.tsx): `src/pages/customer/Profile.tsx`
- [Rewards and activity](https://github.com/t06546666-maker/ae/blob/main/src/hooks/useCustomerData.ts): `src/hooks/useCustomerData.ts`

### Backend services

- [API client](https://github.com/t06546666-maker/ae/blob/main/src/api.ts): `src/api.ts`
- [Express API](https://github.com/t06546666-maker/ae/blob/main/server.js): `server.js`
- **Supabase**
- **WhatsApp Cloud API**
- **Resend email**

### Affiliate settlement

- [Affiliate networks](https://github.com/t06546666-maker/ae/blob/main/src/modules/affiliate/networks/index.js): `src/modules/affiliate/networks/index.js`
- [Reward ledger](https://github.com/t06546666-maker/ae/blob/main/src/modules/affiliate/rewards/index.js): `src/modules/affiliate/rewards/index.js`
- [Redemptions](https://github.com/t06546666-maker/ae/blob/main/src/modules/affiliate/redemptions/index.js): `src/modules/affiliate/redemptions/index.js`
- [Settlements](https://github.com/t06546666-maker/ae/blob/main/src/modules/affiliate/settlements/index.js): `src/modules/affiliate/settlements/index.js`
- [Payment provider](https://github.com/t06546666-maker/ae/blob/main/src/modules/affiliate/payments/MockPaymentProvider.js): `src/modules/affiliate/payments/MockPaymentProvider.js`
- [Audit trail](https://github.com/t06546666-maker/ae/blob/main/src/modules/affiliate/audit/index.js): `src/modules/affiliate/audit/index.js`
- [Affiliate data client](https://github.com/t06546666-maker/ae/blob/main/src/modules/affiliate/common/db.js): `src/modules/affiliate/common/db.js`
- [Money conversion](https://github.com/t06546666-maker/ae/blob/main/src/modules/affiliate/common/money.js): `src/modules/affiliate/common/money.js`

## Connections

- Admins and merchants → Admin workspace: routes to (evidence: `src/App.tsx`)
- Admins and merchants → Merchant workspace: routes to (evidence: `src/App.tsx`)
- Admins and merchants → Field visits: routes to (evidence: `src/App.tsx`)
- Customer app → Explore and offers: routes to (evidence: `src/App.tsx`)
- Customer app → Customer account: routes to (evidence: `src/App.tsx`)
- Customer app → Rewards and activity: uses
- Merchant workspace → QR checkout: uses
- Admins and merchants → API client: calls (evidence: `src/App.tsx`)
- Rewards and activity → API client: fetches from (evidence: `src/hooks/useCustomerData.ts`)
- API client → Express API: sends requests (evidence: `README.md`)
- Express API → Supabase: reads and writes (evidence: `README.md`)
- Express API → WhatsApp Cloud API: sends notifications (evidence: `README.md`)
- Express API → Resend email: sends email (evidence: `README.md`)
- Express API → Affiliate networks: mounts (evidence: `server.js`)
- Express API → Reward ledger: mounts (evidence: `server.js`)
- Express API → Redemptions: mounts (evidence: `server.js`)
- Express API → Settlements: mounts (evidence: `server.js`)
- Redemptions → Reward ledger: checks entitlement (evidence: `src/modules/affiliate/redemptions/index.js`)
- Redemptions → Payment provider: creates payment (evidence: `src/modules/affiliate/redemptions/index.js`)
- Settlements → Payment provider: uses (evidence: `src/modules/affiliate/settlements/index.js`)
- Affiliate networks → Affiliate data client: queries (evidence: `src/modules/affiliate/networks/index.js`)
- Reward ledger → Affiliate data client: writes ledger (evidence: `src/modules/affiliate/rewards/index.js`)
- Redemptions → Affiliate data client: reads and writes (evidence: `src/modules/affiliate/redemptions/index.js`)
- Settlements → Affiliate data client: reads and writes (evidence: `src/modules/affiliate/settlements/index.js`)
- Reward ledger → Money conversion: converts amounts (evidence: `src/modules/affiliate/rewards/index.js`)
- Redemptions → Money conversion: converts amounts (evidence: `src/modules/affiliate/redemptions/index.js`)
- Affiliate networks → Audit trail: records actions (evidence: `src/modules/affiliate/networks/index.js`)
- Reward ledger → Audit trail: records actions (evidence: `src/modules/affiliate/rewards/index.js`)
- Redemptions → Audit trail: records actions (evidence: `src/modules/affiliate/redemptions/index.js`)
- Settlements → Audit trail: records actions (evidence: `src/modules/affiliate/settlements/index.js`)
- Audit trail → Affiliate data client: writes audit logs (evidence: `src/modules/affiliate/audit/index.js`)
