# r14bz/pos-flow architecture

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

- Interactive diagram: https://gitdiagram.com/r14bz/pos-flow
- Repository: https://github.com/r14bz/pos-flow

## Overview

SEMAR is a multi-store retail POS: staff sign in, select a store, manage inventory, ring up sales, and review dashboards/reports. The React client supports demo data or Supabase-backed sessions and tenant data; database RPCs enforce atomic checkout and stock changes. Separate Edge Functions handle employee/admin tasks, QRIS setup and payment confirmation, scheduled reports, and low-stock push delivery. The README documents more UI capabilities than the sampled excerpts expose; those are represented at the app boundary, and unsampled internal links are omitted. Evidence is limited to the supplied excerpts, source index, and README.

Main entry points: [`src/App.jsx`](https://github.com/r14bz/pos-flow/blob/main/src/App.jsx) (POS and dashboard), [`supabase/migrations/202610100001_init_pos.sql`](https://github.com/r14bz/pos-flow/blob/main/supabase/migrations/202610100001_init_pos.sql) (Tenant database and RPCs), [`supabase/functions/create-qris-payment/index.ts`](https://github.com/r14bz/pos-flow/blob/main/supabase/functions/create-qris-payment/index.ts) (Dynamic QRIS creation), [`supabase/functions/notify-low-stock/index.ts`](https://github.com/r14bz/pos-flow/blob/main/supabase/functions/notify-low-stock/index.ts) (Low-stock notifications)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["POS Client"]
  node_app["POS and dashboard<br/>[App.jsx]"]
  node_demo["Demo data<br/>[demoData.js]"]
  node_supabase_client["Supabase client<br/>[supabase.js]"]
end

subgraph group_data["Store Data"]
  node_supabase["Supabase Auth and API"]
  node_store_db[("Tenant database and RPCs")]
end

subgraph group_people["Access Management"]
  node_invite["Employee invitations<br/>[index.ts]"]
  node_manage_employee["Employee management<br/>[index.ts]"]
  node_admin["Platform administration<br/>[index.ts]"]
end

subgraph group_payments["QRIS Payments"]
  node_qris_settings["QRIS settings<br/>[index.ts]"]
  node_crypto["Credential encryption<br/>[qris-crypto.ts]"]
  node_dynamic_qris["Dynamic QRIS creation<br/>[index.ts]"]
  node_static_qris["Static QRIS sales<br/>[index.ts]"]
  node_static_confirm["Manual QRIS confirmation<br/>[index.ts]"]
  node_cancel_qris["QRIS cancellation<br/>[index.ts]"]
  node_expire_qris["QRIS expiry<br/>[index.ts]"]
  node_midtrans["Midtrans gateway"]
  node_webhook["Payment webhook<br/>[index.ts]"]
end

subgraph group_operations["Reports and Alerts"]
  node_report["Daily report<br/>[index.ts]"]
  node_low_stock["Low-stock notifications<br/>[index.ts]"]
  node_push_shared["Web push delivery<br/>[push.ts]"]
  node_fcm["FCM delivery<br/>[fcm.ts]"]
  node_cron_report["Cron report endpoint<br/>[daily-report.js]"]
end

node_staff(("Store staff"))
node_cron(("Scheduled trigger"))
node_push_services["Push services"]

node_staff -->|"uses POS"| node_app
node_app -->|"loads demo"| node_demo
node_app -->|"queries"| node_supabase_client
node_supabase_client -->|"auth and data API"| node_supabase
node_supabase -.->|"reads and writes"| node_store_db
node_app -.->|"manages store data"| node_store_db
node_app -.->|"invites employees"| node_invite
node_app -.->|"manages roles"| node_manage_employee
node_app -.->|"administers platform"| node_admin
node_app -.->|"saves QRIS settings"| node_qris_settings
node_qris_settings -->|"encrypts key"| node_crypto
node_app -.->|"requests payment"| node_dynamic_qris
node_dynamic_qris -->|"decrypts key"| node_crypto
node_dynamic_qris -->|"creates pending sale"| node_store_db
node_dynamic_qris -->|"creates charge"| node_midtrans
node_midtrans -->|"posts status"| node_webhook
node_webhook -->|"decrypts key"| node_crypto
node_webhook -->|"finalizes payment"| node_store_db
node_app -.->|"creates static sale"| node_static_qris
node_static_qris -.->|"reserves sale"| node_store_db
node_app -.->|"confirms payment"| node_static_confirm
node_static_confirm -.->|"finalizes sale"| node_store_db
node_app -.->|"cancels payment"| node_cancel_qris
node_cancel_qris -.->|"updates sale"| node_store_db
node_cron -.->|"runs expiry"| node_expire_qris
node_expire_qris -.->|"releases stock"| node_store_db
node_cron -.->|"triggers report"| node_cron_report
node_cron_report -.->|"invokes function"| node_report
node_report -->|"sends push"| node_push_shared
node_report -.->|"reads report data"| node_store_db
node_app -.->|"requests alert"| node_low_stock
node_low_stock -->|"delivers web push"| node_push_shared
node_low_stock -->|"sends FCM"| node_fcm
node_push_shared -->|"sends notification"| node_push_services
node_fcm -->|"sends notification"| node_push_services
node_low_stock -->|"reads stock and tokens"| node_store_db

click node_app "https://github.com/r14bz/pos-flow/blob/main/src/App.jsx"
click node_demo "https://github.com/r14bz/pos-flow/blob/main/src/lib/demoData.js"
click node_supabase_client "https://github.com/r14bz/pos-flow/blob/main/src/lib/supabase.js"
click node_store_db "https://github.com/r14bz/pos-flow/blob/main/supabase/migrations/202610100001_init_pos.sql"
click node_invite "https://github.com/r14bz/pos-flow/blob/main/supabase/functions/invite-employee/index.ts"
click node_manage_employee "https://github.com/r14bz/pos-flow/blob/main/supabase/functions/manage-employee/index.ts"
click node_admin "https://github.com/r14bz/pos-flow/blob/main/supabase/functions/admin-accounts/index.ts"
click node_qris_settings "https://github.com/r14bz/pos-flow/blob/main/supabase/functions/save-qris-settings/index.ts"
click node_crypto "https://github.com/r14bz/pos-flow/blob/main/supabase/functions/_shared/qris-crypto.ts"
click node_dynamic_qris "https://github.com/r14bz/pos-flow/blob/main/supabase/functions/create-qris-payment/index.ts"
click node_static_qris "https://github.com/r14bz/pos-flow/blob/main/supabase/functions/create-static-qris-sale/index.ts"
click node_static_confirm "https://github.com/r14bz/pos-flow/blob/main/supabase/functions/confirm-static-qris-payment/index.ts"
click node_cancel_qris "https://github.com/r14bz/pos-flow/blob/main/supabase/functions/cancel-qris-payment/index.ts"
click node_expire_qris "https://github.com/r14bz/pos-flow/blob/main/supabase/functions/expire-static-qris-sales/index.ts"
click node_webhook "https://github.com/r14bz/pos-flow/blob/main/supabase/functions/midtrans-webhook/index.ts"
click node_report "https://github.com/r14bz/pos-flow/blob/main/supabase/functions/daily-report/index.ts"
click node_low_stock "https://github.com/r14bz/pos-flow/blob/main/supabase/functions/notify-low-stock/index.ts"
click node_push_shared "https://github.com/r14bz/pos-flow/blob/main/supabase/functions/_shared/push.ts"
click node_fcm "https://github.com/r14bz/pos-flow/blob/main/supabase/functions/_shared/fcm.ts"
click node_cron_report "https://github.com/r14bz/pos-flow/blob/main/api/cron/daily-report.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_app,node_demo,node_supabase_client toneBlue
class node_supabase,node_store_db toneAmber
class node_invite,node_manage_employee,node_admin toneMint
class node_qris_settings,node_crypto,node_dynamic_qris,node_static_qris,node_static_confirm,node_cancel_qris,node_expire_qris,node_midtrans,node_webhook toneRose
class node_report,node_low_stock,node_push_shared,node_fcm,node_cron_report,node_staff,node_cron,node_push_services toneIndigo
```

## Components

### POS Client

- [POS and dashboard](https://github.com/r14bz/pos-flow/blob/main/src/App.jsx): `src/App.jsx`
- [Demo data](https://github.com/r14bz/pos-flow/blob/main/src/lib/demoData.js): `src/lib/demoData.js`
- [Supabase client](https://github.com/r14bz/pos-flow/blob/main/src/lib/supabase.js): `src/lib/supabase.js`

### Store Data

- **Supabase Auth and API**
- [Tenant database and RPCs](https://github.com/r14bz/pos-flow/blob/main/supabase/migrations/202610100001_init_pos.sql): `supabase/migrations/202610100001_init_pos.sql`

### Access Management

- [Employee invitations](https://github.com/r14bz/pos-flow/blob/main/supabase/functions/invite-employee/index.ts): `supabase/functions/invite-employee/index.ts`
- [Employee management](https://github.com/r14bz/pos-flow/blob/main/supabase/functions/manage-employee/index.ts): `supabase/functions/manage-employee/index.ts`
- [Platform administration](https://github.com/r14bz/pos-flow/blob/main/supabase/functions/admin-accounts/index.ts): `supabase/functions/admin-accounts/index.ts`

### QRIS Payments

- [QRIS settings](https://github.com/r14bz/pos-flow/blob/main/supabase/functions/save-qris-settings/index.ts): `supabase/functions/save-qris-settings/index.ts`
- [Credential encryption](https://github.com/r14bz/pos-flow/blob/main/supabase/functions/_shared/qris-crypto.ts): `supabase/functions/_shared/qris-crypto.ts`
- [Dynamic QRIS creation](https://github.com/r14bz/pos-flow/blob/main/supabase/functions/create-qris-payment/index.ts): `supabase/functions/create-qris-payment/index.ts`
- [Static QRIS sales](https://github.com/r14bz/pos-flow/blob/main/supabase/functions/create-static-qris-sale/index.ts): `supabase/functions/create-static-qris-sale/index.ts`
- [Manual QRIS confirmation](https://github.com/r14bz/pos-flow/blob/main/supabase/functions/confirm-static-qris-payment/index.ts): `supabase/functions/confirm-static-qris-payment/index.ts`
- [QRIS cancellation](https://github.com/r14bz/pos-flow/blob/main/supabase/functions/cancel-qris-payment/index.ts): `supabase/functions/cancel-qris-payment/index.ts`
- [QRIS expiry](https://github.com/r14bz/pos-flow/blob/main/supabase/functions/expire-static-qris-sales/index.ts): `supabase/functions/expire-static-qris-sales/index.ts`
- **Midtrans gateway**
- [Payment webhook](https://github.com/r14bz/pos-flow/blob/main/supabase/functions/midtrans-webhook/index.ts): `supabase/functions/midtrans-webhook/index.ts`

### Reports and Alerts

- [Daily report](https://github.com/r14bz/pos-flow/blob/main/supabase/functions/daily-report/index.ts): `supabase/functions/daily-report/index.ts`
- [Low-stock notifications](https://github.com/r14bz/pos-flow/blob/main/supabase/functions/notify-low-stock/index.ts): `supabase/functions/notify-low-stock/index.ts`
- [Web push delivery](https://github.com/r14bz/pos-flow/blob/main/supabase/functions/_shared/push.ts): `supabase/functions/_shared/push.ts`
- [FCM delivery](https://github.com/r14bz/pos-flow/blob/main/supabase/functions/_shared/fcm.ts): `supabase/functions/_shared/fcm.ts`
- [Cron report endpoint](https://github.com/r14bz/pos-flow/blob/main/api/cron/daily-report.js): `api/cron/daily-report.js`

### Other components

- **Store staff**
- **Scheduled trigger**
- **Push services**

## Connections

- Store staff → POS and dashboard: uses POS (evidence: `README.md`)
- POS and dashboard → Demo data: loads demo (evidence: `src/App.jsx`)
- POS and dashboard → Supabase client: queries (evidence: `src/App.jsx`)
- Supabase client → Supabase Auth and API: auth and data API (evidence: `src/lib/supabase.js`)
- Supabase Auth and API → Tenant database and RPCs: reads and writes (evidence: `README.md`)
- POS and dashboard → Tenant database and RPCs: manages store data (evidence: `README.md`)
- POS and dashboard → Employee invitations: invites employees (evidence: `README.md`)
- POS and dashboard → Employee management: manages roles (evidence: `README.md`)
- POS and dashboard → Platform administration: administers platform (evidence: `README.md`)
- POS and dashboard → QRIS settings: saves QRIS settings (evidence: `README.md`)
- QRIS settings → Credential encryption: encrypts key (evidence: `supabase/functions/save-qris-settings/index.ts`)
- POS and dashboard → Dynamic QRIS creation: requests payment (evidence: `README.md`)
- Dynamic QRIS creation → Credential encryption: decrypts key (evidence: `supabase/functions/create-qris-payment/index.ts`)
- Dynamic QRIS creation → Tenant database and RPCs: creates pending sale (evidence: `supabase/functions/create-qris-payment/index.ts`)
- Dynamic QRIS creation → Midtrans gateway: creates charge (evidence: `supabase/functions/create-qris-payment/index.ts`)
- Midtrans gateway → Payment webhook: posts status (evidence: `README.md`)
- Payment webhook → Credential encryption: decrypts key (evidence: `supabase/functions/midtrans-webhook/index.ts`)
- Payment webhook → Tenant database and RPCs: finalizes payment (evidence: `supabase/functions/midtrans-webhook/index.ts`)
- POS and dashboard → Static QRIS sales: creates static sale (evidence: `README.md`)
- Static QRIS sales → Tenant database and RPCs: reserves sale (evidence: `README.md`)
- POS and dashboard → Manual QRIS confirmation: confirms payment (evidence: `README.md`)
- Manual QRIS confirmation → Tenant database and RPCs: finalizes sale (evidence: `README.md`)
- POS and dashboard → QRIS cancellation: cancels payment (evidence: `README.md`)
- QRIS cancellation → Tenant database and RPCs: updates sale (evidence: `README.md`)
- Scheduled trigger → QRIS expiry: runs expiry (evidence: `README.md`)
- QRIS expiry → Tenant database and RPCs: releases stock (evidence: `README.md`)
- Scheduled trigger → Cron report endpoint: triggers report (evidence: `README.md`)
- Cron report endpoint → Daily report: invokes function (evidence: `README.md`)
- Daily report → Web push delivery: sends push (evidence: `supabase/functions/daily-report/index.ts`)
- Daily report → Tenant database and RPCs: reads report data (evidence: `README.md`)
- POS and dashboard → Low-stock notifications: requests alert (evidence: `README.md`)
- Low-stock notifications → Web push delivery: delivers web push (evidence: `supabase/functions/notify-low-stock/index.ts`)
- Low-stock notifications → FCM delivery: sends FCM (evidence: `supabase/functions/notify-low-stock/index.ts`)
- Web push delivery → Push services: sends notification (evidence: `supabase/functions/_shared/push.ts`)
- FCM delivery → Push services: sends notification (evidence: `supabase/functions/_shared/fcm.ts`)
- Low-stock notifications → Tenant database and RPCs: reads stock and tokens (evidence: `supabase/functions/notify-low-stock/index.ts`)
