# smsnalcrz/cafeflow architecture

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

- Interactive diagram: https://gitdiagram.com/smsnalcrz/cafeflow
- Repository: https://github.com/smsnalcrz/cafeflow

## Overview

CafeFlow is an offline-first café POS and operations system. Cashiers build size-specific orders, take cash or GCash payment, and place tickets in the barista queue; completion triggers recipe-based raw-stock deductions. Managers also use reporting, forecasting, waste, audit, account, and security capabilities. The sampled entry point confirms role-based workspace assembly, and the source index confirms API dependencies on shared engines. Several API implementations and client-side request handlers were not sampled, so those connections are shown only where README documentation supports them or are left unverified.

Main entry points: [`index.php`](https://github.com/smsnalcrz/cafeflow/blob/main/index.php) (Role-Based App Shell), [`views/workspaces/pos.php`](https://github.com/smsnalcrz/cafeflow/blob/main/views/workspaces/pos.php) (POS and Queue), [`api/checkout.php`](https://github.com/smsnalcrz/cafeflow/blob/main/api/checkout.php) (Order Checkout), [`core/recipe_engine.php`](https://github.com/smsnalcrz/cafeflow/blob/main/core/recipe_engine.php) (Recipe and Consumption Engine)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_front["Workspaces"]
  node_app["Role-Based App Shell<br/>[index.php]"]
  node_pos["POS and Queue<br/>[pos.php]"]
  node_product_ui["Product Editor<br/>[modal-product.php]"]
  node_payment_ui["Tender and Receipt"]
  node_dashboard["Management Dashboard<br/>[dashboard.php]"]
end

subgraph group_orders["Order Operations"]
  node_checkout["Order Checkout<br/>[checkout.php]"]
  node_queue_api["Queue Retrieval<br/>[fetch_queue.php]"]
  node_complete["Order Completion<br/>[complete_order.php]"]
  node_cancel["Order Cancellation<br/>[cancel_order.php]"]
end

subgraph group_ops["Inventory and Insights"]
  node_inventory["Raw Inventory Management<br/>[inventory_api.php]"]
  node_products["Catalog and Recipes API<br/>[products_api.php]"]
  node_reports["Sales Reporting<br/>[report.php]"]
  node_excel["Excel Report Export<br/>[excel_generator.py]"]
  node_waste["Waste Tracking<br/>[waste_api.php]"]
  node_predictive["Demand Forecasting"]
end

subgraph group_security["Access and Audit"]
  node_accounts["Staff Administration<br/>[accounts_api.php]"]
  node_auth_api["Authentication API<br/>[auth_api.php]"]
  node_auth_core["Sessions and RBAC<br/>[auth.php]"]
  node_totp["Two-Factor Authentication<br/>[totp.php]"]
  node_audit["Audit Logging<br/>[audit.php]"]
  node_audit_api["Audit Review<br/>[audit_api.php]"]
end

subgraph group_platform["Shared Runtime"]
  node_recipes["Recipe and Consumption Engine<br/>[recipe_engine.php]"]
  node_db["Database Access<br/>[db.php]"]
  node_database[("MySQL / MariaDB")]
end

node_cashier(("Cashier / Barista"))

node_cashier -->|"opens"| node_app
node_app -->|"renders role view"| node_pos
node_app -->|"renders management view"| node_dashboard
node_app -->|"renders"| node_product_ui
node_pos -.->|"submits orders"| node_checkout
node_pos -.->|"polls tickets"| node_queue_api
node_payment_ui -.->|"confirms tender"| node_checkout
node_checkout -->|"creates queued orders"| node_complete
node_complete -->|"deducts ingredients"| node_recipes
node_pos -.->|"requests void"| node_cancel
node_products -->|"uses recipe rules"| node_recipes
node_inventory -.->|"supports stock checks"| node_recipes
node_reports -->|"exports worksheets"| node_excel
node_dashboard -.->|"presents sales insights"| node_reports
node_dashboard -->|"presents forecasts"| node_predictive
node_waste -->|"uses consumption rules"| node_recipes
node_auth_api -->|"authenticates users"| node_auth_core
node_auth_api -->|"verifies codes"| node_totp
node_accounts -->|"enforces permissions"| node_auth_core
node_audit_api -->|"reads audit records"| node_audit
node_audit -->|"records security events"| node_auth_core
node_checkout -.->|"persists orders"| node_db
node_db -.->|"connects"| node_database

click node_app "https://github.com/smsnalcrz/cafeflow/blob/main/index.php"
click node_pos "https://github.com/smsnalcrz/cafeflow/blob/main/views/workspaces/pos.php"
click node_product_ui "https://github.com/smsnalcrz/cafeflow/blob/main/views/modals/modal-product.php"
click node_payment_ui "https://github.com/smsnalcrz/cafeflow/blob/main/views/modals/modal-pos-dialogs.php"
click node_checkout "https://github.com/smsnalcrz/cafeflow/blob/main/api/checkout.php"
click node_queue_api "https://github.com/smsnalcrz/cafeflow/blob/main/api/fetch_queue.php"
click node_complete "https://github.com/smsnalcrz/cafeflow/blob/main/api/complete_order.php"
click node_cancel "https://github.com/smsnalcrz/cafeflow/blob/main/api/cancel_order.php"
click node_recipes "https://github.com/smsnalcrz/cafeflow/blob/main/core/recipe_engine.php"
click node_inventory "https://github.com/smsnalcrz/cafeflow/blob/main/api/inventory_api.php"
click node_products "https://github.com/smsnalcrz/cafeflow/blob/main/api/products_api.php"
click node_reports "https://github.com/smsnalcrz/cafeflow/blob/main/api/report.php"
click node_excel "https://github.com/smsnalcrz/cafeflow/blob/main/core/excel_generator.py"
click node_waste "https://github.com/smsnalcrz/cafeflow/blob/main/api/waste_api.php"
click node_predictive "https://github.com/smsnalcrz/cafeflow/blob/main/core/predictive_engine.php"
click node_dashboard "https://github.com/smsnalcrz/cafeflow/blob/main/views/workspaces/dashboard.php"
click node_accounts "https://github.com/smsnalcrz/cafeflow/blob/main/api/accounts_api.php"
click node_auth_api "https://github.com/smsnalcrz/cafeflow/blob/main/api/auth_api.php"
click node_auth_core "https://github.com/smsnalcrz/cafeflow/blob/main/core/auth.php"
click node_totp "https://github.com/smsnalcrz/cafeflow/blob/main/core/totp.php"
click node_audit "https://github.com/smsnalcrz/cafeflow/blob/main/core/audit.php"
click node_audit_api "https://github.com/smsnalcrz/cafeflow/blob/main/api/audit_api.php"
click node_db "https://github.com/smsnalcrz/cafeflow/blob/main/core/db.php"

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_pos,node_product_ui,node_payment_ui,node_dashboard toneBlue
class node_checkout,node_queue_api,node_complete,node_cancel toneAmber
class node_inventory,node_products,node_reports,node_excel,node_waste,node_predictive toneMint
class node_accounts,node_auth_api,node_auth_core,node_totp,node_audit,node_audit_api toneRose
class node_recipes,node_db,node_database,node_cashier toneIndigo
```

## Components

### Workspaces

- [Role-Based App Shell](https://github.com/smsnalcrz/cafeflow/blob/main/index.php): `index.php`
- [POS and Queue](https://github.com/smsnalcrz/cafeflow/blob/main/views/workspaces/pos.php): `views/workspaces/pos.php`
- [Product Editor](https://github.com/smsnalcrz/cafeflow/blob/main/views/modals/modal-product.php): `views/modals/modal-product.php`
- [Tender and Receipt](https://github.com/smsnalcrz/cafeflow/blob/main/views/modals/modal-pos-dialogs.php): `views/modals/modal-pos-dialogs.php`
- [Management Dashboard](https://github.com/smsnalcrz/cafeflow/blob/main/views/workspaces/dashboard.php): `views/workspaces/dashboard.php`

### Order Operations

- [Order Checkout](https://github.com/smsnalcrz/cafeflow/blob/main/api/checkout.php): `api/checkout.php`
- [Queue Retrieval](https://github.com/smsnalcrz/cafeflow/blob/main/api/fetch_queue.php): `api/fetch_queue.php`
- [Order Completion](https://github.com/smsnalcrz/cafeflow/blob/main/api/complete_order.php): `api/complete_order.php`
- [Order Cancellation](https://github.com/smsnalcrz/cafeflow/blob/main/api/cancel_order.php): `api/cancel_order.php`

### Inventory and Insights

- [Raw Inventory Management](https://github.com/smsnalcrz/cafeflow/blob/main/api/inventory_api.php): `api/inventory_api.php`
- [Catalog and Recipes API](https://github.com/smsnalcrz/cafeflow/blob/main/api/products_api.php): `api/products_api.php`
- [Sales Reporting](https://github.com/smsnalcrz/cafeflow/blob/main/api/report.php): `api/report.php`
- [Excel Report Export](https://github.com/smsnalcrz/cafeflow/blob/main/core/excel_generator.py): `core/excel_generator.py`
- [Waste Tracking](https://github.com/smsnalcrz/cafeflow/blob/main/api/waste_api.php): `api/waste_api.php`
- [Demand Forecasting](https://github.com/smsnalcrz/cafeflow/blob/main/core/predictive_engine.php): `core/predictive_engine.php`

### Access and Audit

- [Staff Administration](https://github.com/smsnalcrz/cafeflow/blob/main/api/accounts_api.php): `api/accounts_api.php`
- [Authentication API](https://github.com/smsnalcrz/cafeflow/blob/main/api/auth_api.php): `api/auth_api.php`
- [Sessions and RBAC](https://github.com/smsnalcrz/cafeflow/blob/main/core/auth.php): `core/auth.php`
- [Two-Factor Authentication](https://github.com/smsnalcrz/cafeflow/blob/main/core/totp.php): `core/totp.php`
- [Audit Logging](https://github.com/smsnalcrz/cafeflow/blob/main/core/audit.php): `core/audit.php`
- [Audit Review](https://github.com/smsnalcrz/cafeflow/blob/main/api/audit_api.php): `api/audit_api.php`

### Shared Runtime

- [Recipe and Consumption Engine](https://github.com/smsnalcrz/cafeflow/blob/main/core/recipe_engine.php): `core/recipe_engine.php`
- [Database Access](https://github.com/smsnalcrz/cafeflow/blob/main/core/db.php): `core/db.php`
- **MySQL / MariaDB**

### Other components

- **Cashier / Barista**

## Connections

- Cashier / Barista → Role-Based App Shell: opens
- Role-Based App Shell → POS and Queue: renders role view (evidence: `index.php`)
- Role-Based App Shell → Management Dashboard: renders management view (evidence: `index.php`)
- Role-Based App Shell → Product Editor: renders (evidence: `index.php`)
- POS and Queue → Order Checkout: submits orders
- POS and Queue → Queue Retrieval: polls tickets
- Tender and Receipt → Order Checkout: confirms tender
- Order Checkout → Order Completion: creates queued orders
- Order Completion → Recipe and Consumption Engine: deducts ingredients
- POS and Queue → Order Cancellation: requests void
- Catalog and Recipes API → Recipe and Consumption Engine: uses recipe rules (evidence: `api/products_api.php`)
- Raw Inventory Management → Recipe and Consumption Engine: supports stock checks
- Sales Reporting → Excel Report Export: exports worksheets
- Management Dashboard → Sales Reporting: presents sales insights
- Management Dashboard → Demand Forecasting: presents forecasts
- Waste Tracking → Recipe and Consumption Engine: uses consumption rules (evidence: `api/waste_api.php`)
- Authentication API → Sessions and RBAC: authenticates users (evidence: `api/auth_api.php`)
- Authentication API → Two-Factor Authentication: verifies codes (evidence: `api/auth_api.php`)
- Staff Administration → Sessions and RBAC: enforces permissions (evidence: `api/accounts_api.php`)
- Audit Review → Audit Logging: reads audit records (evidence: `api/audit_api.php`)
- Audit Logging → Sessions and RBAC: records security events (evidence: `core/audit.php`)
- Order Checkout → Database Access: persists orders (evidence: `api/checkout.php`)
- Database Access → MySQL / MariaDB: connects
