# andhikaliff/bengkelmakan architecture

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

- Interactive diagram: https://gitdiagram.com/andhikaliff/bengkelmakan
- Repository: https://github.com/andhikaliff/bengkelmakan

## Overview

Bengkel Makan is a local SQLite-backed canteen meal-quota management system. Its central workflow is employee directory management, QR scanning with daily duplicate validation, and transaction monitoring/export. Admin, data, and scanner roles govern access; audit logging and configurable scanner/dashboard settings support operations. The README documents major capabilities not fully represented in sampled source; those areas are included where paths are known, with uncertain links omitted. The graph reflects only shown calls and documented relationships.

Main entry points: [`src/lib/sheets.ts`](https://github.com/andhikaliff/bengkelmakan/blob/main/src/lib/sheets.ts) (Canteen data operations), [`src/lib/audit.ts`](https://github.com/andhikaliff/bengkelmakan/blob/main/src/lib/audit.ts) (Audit recording), [`src/lib/auth.ts`](https://github.com/andhikaliff/bengkelmakan/blob/main/src/lib/auth.ts) (Role and sessions), [`src/app/api/cron/send-report/route.ts`](https://github.com/andhikaliff/bengkelmakan/blob/main/src/app/api/cron/send-report/route.ts) (Scheduled reports)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_access["Access &amp; Shell"]
  node_login_ui["Login screen<br/>[page.tsx]"]
  node_auth_api["Login API<br/>[route.ts]"]
  node_auth["Role and sessions<br/>[auth.ts]"]
  node_middleware["Route protection<br/>[middleware.ts]"]
  node_edge_auth["Edge session checks<br/>[auth-edge.ts]"]
  node_navbar["Navigation shell<br/>[Navbar.tsx]"]
  node_icons["Inline icons<br/>[Icons.tsx]"]
  node_role_hook["Current role hook"]
  node_sidebar["Sidebar navigation<br/>[Sidebar.tsx]"]
end

subgraph group_operations["Canteen Operations"]
  node_directory_ui["Employee directory<br/>[page.tsx]"]
  node_employee_api["Employee APIs<br/>[route.ts]"]
  node_employee_bulk_api["Bulk employee API<br/>[route.ts]"]
  node_employee_status_api["Employee status API<br/>[route.ts]"]
  node_scanner_ui["QR scanner<br/>[page.tsx]"]
  node_scan_api["Scan validation API<br/>[route.ts]"]
  node_scanner_modal["Scanner dialog<br/>[ScannerModal.tsx]"]
end

subgraph group_records["Data &amp; Reporting"]
  node_dashboard["Dashboard and transactions<br/>[page.tsx]"]
  node_transactions_api["Transaction API<br/>[route.ts]"]
  node_quota_api["Quota reset API<br/>[route.ts]"]
  node_export_api["Excel export API<br/>[route.ts]"]
  node_excel["Workbook builder<br/>[excel.ts]"]
  node_report_api["Scheduled reports<br/>[route.ts]"]
  node_mailer["Email delivery<br/>[mailer.ts]"]
  node_sheets["Canteen data operations<br/>[sheets.ts]"]
  node_db[("SQLite database access<br/>[db.ts]")]
  node_mutex["Data operation lock<br/>[mutex.ts]"]
end

subgraph group_support["Settings &amp; Audit"]
  node_audit_ui["Audit log screen<br/>[page.tsx]"]
  node_audit_api["Audit log API<br/>[route.ts]"]
  node_audit["Audit recording<br/>[audit.ts]"]
  node_settings_ui["Settings panel<br/>[SettingsModal.tsx]"]
  node_settings_hook["User settings<br/>[use-settings.ts]"]
end

node_staff(("Admin or staff"))
node_scanner_actor(("Canteen scanner"))

node_staff -->|"opens"| node_login_ui
node_login_ui -.->|"submits credentials"| node_auth_api
node_auth_api -->|"verifies and creates session"| node_auth
node_auth_api -->|"records login"| node_audit
node_middleware -->|"checks sessions"| node_edge_auth
node_staff -->|"manages employees"| node_directory_ui
node_directory_ui -.->|"requests directory actions"| node_employee_api
node_employee_api -->|"requires role"| node_auth
node_employee_api -->|"reads and changes employees"| node_sheets
node_employee_api -->|"records changes"| node_audit
node_employee_bulk_api -->|"adds employees"| node_sheets
node_employee_status_api -->|"changes status"| node_sheets
node_scanner_actor -->|"scans QR codes"| node_scanner_ui
node_scanner_ui -.->|"submits scans"| node_scan_api
node_scan_api -->|"validates scan"| node_sheets
node_scan_api -->|"checks role"| node_auth
node_dashboard -.->|"loads transactions"| node_transactions_api
node_transactions_api -->|"requires role"| node_auth
node_transactions_api -->|"fetches transactions"| node_sheets
node_quota_api -->|"resets daily quota"| node_sheets
node_quota_api -->|"records reset"| node_audit
node_export_api -.->|"builds workbook"| node_excel
node_report_api -->|"fetches transactions"| node_sheets
node_report_api -->|"builds attachment"| node_excel
node_report_api -->|"sends report"| node_mailer
node_report_api -->|"records report outcome"| node_audit
node_sheets -->|"queries database"| node_db
node_sheets -->|"serializes operations"| node_mutex
node_audit -->|"persists audit events"| node_db
node_audit_api -->|"requires role"| node_auth
node_audit_api -->|"reads audit records"| node_db
node_staff -->|"reviews activity"| node_audit_ui
node_settings_ui -->|"reads and updates settings"| node_settings_hook
node_navbar -->|"opens settings"| node_settings_ui
node_navbar -->|"gets current role"| node_role_hook
node_navbar -->|"renders icons"| node_icons
node_scanner_ui -->|"uses scanner settings"| node_settings_hook
node_scanner_ui -.->|"opens scan dialog"| node_scanner_modal
node_sidebar -->|"renders icons"| node_icons
node_sidebar -->|"gets current role"| node_role_hook

click node_login_ui "https://github.com/andhikaliff/bengkelmakan/blob/main/src/app/admin/login/page.tsx"
click node_auth_api "https://github.com/andhikaliff/bengkelmakan/blob/main/src/app/api/login/route.ts"
click node_auth "https://github.com/andhikaliff/bengkelmakan/blob/main/src/lib/auth.ts"
click node_middleware "https://github.com/andhikaliff/bengkelmakan/blob/main/src/middleware.ts"
click node_edge_auth "https://github.com/andhikaliff/bengkelmakan/blob/main/src/lib/auth-edge.ts"
click node_directory_ui "https://github.com/andhikaliff/bengkelmakan/blob/main/src/app/admin/employees/page.tsx"
click node_employee_api "https://github.com/andhikaliff/bengkelmakan/blob/main/src/app/api/employees/route.ts"
click node_employee_bulk_api "https://github.com/andhikaliff/bengkelmakan/blob/main/src/app/api/employees/bulk/route.ts"
click node_employee_status_api "https://github.com/andhikaliff/bengkelmakan/blob/main/src/app/api/employees/toggle-status/route.ts"
click node_scanner_ui "https://github.com/andhikaliff/bengkelmakan/blob/main/src/app/scanner/page.tsx"
click node_scan_api "https://github.com/andhikaliff/bengkelmakan/blob/main/src/app/api/scan/route.ts"
click node_dashboard "https://github.com/andhikaliff/bengkelmakan/blob/main/src/app/admin/dashboard/page.tsx"
click node_transactions_api "https://github.com/andhikaliff/bengkelmakan/blob/main/src/app/api/transactions/route.ts"
click node_quota_api "https://github.com/andhikaliff/bengkelmakan/blob/main/src/app/api/reset/route.ts"
click node_export_api "https://github.com/andhikaliff/bengkelmakan/blob/main/src/app/api/export/excel/route.ts"
click node_excel "https://github.com/andhikaliff/bengkelmakan/blob/main/src/lib/excel.ts"
click node_report_api "https://github.com/andhikaliff/bengkelmakan/blob/main/src/app/api/cron/send-report/route.ts"
click node_mailer "https://github.com/andhikaliff/bengkelmakan/blob/main/src/lib/mailer.ts"
click node_sheets "https://github.com/andhikaliff/bengkelmakan/blob/main/src/lib/sheets.ts"
click node_db "https://github.com/andhikaliff/bengkelmakan/blob/main/src/lib/db.ts"
click node_audit_ui "https://github.com/andhikaliff/bengkelmakan/blob/main/src/app/admin/audit-logs/page.tsx"
click node_audit_api "https://github.com/andhikaliff/bengkelmakan/blob/main/src/app/api/audit-logs/route.ts"
click node_audit "https://github.com/andhikaliff/bengkelmakan/blob/main/src/lib/audit.ts"
click node_settings_ui "https://github.com/andhikaliff/bengkelmakan/blob/main/src/components/SettingsModal.tsx"
click node_settings_hook "https://github.com/andhikaliff/bengkelmakan/blob/main/src/lib/use-settings.ts"
click node_navbar "https://github.com/andhikaliff/bengkelmakan/blob/main/src/components/Navbar.tsx"
click node_icons "https://github.com/andhikaliff/bengkelmakan/blob/main/src/components/Icons.tsx"
click node_role_hook "https://github.com/andhikaliff/bengkelmakan/blob/main/src/lib/use-current-role.ts"
click node_mutex "https://github.com/andhikaliff/bengkelmakan/blob/main/src/lib/mutex.ts"
click node_scanner_modal "https://github.com/andhikaliff/bengkelmakan/blob/main/src/components/ScannerModal.tsx"
click node_sidebar "https://github.com/andhikaliff/bengkelmakan/blob/main/src/components/Sidebar.tsx"

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_login_ui,node_auth_api,node_auth,node_middleware,node_edge_auth,node_navbar,node_icons,node_role_hook,node_sidebar toneBlue
class node_directory_ui,node_employee_api,node_employee_bulk_api,node_employee_status_api,node_scanner_ui,node_scan_api,node_scanner_modal toneAmber
class node_dashboard,node_transactions_api,node_quota_api,node_export_api,node_excel,node_report_api,node_mailer,node_sheets,node_db,node_mutex toneMint
class node_audit_ui,node_audit_api,node_audit,node_settings_ui,node_settings_hook toneRose
class node_staff,node_scanner_actor toneIndigo
```

## Components

### Access & Shell

- [Login screen](https://github.com/andhikaliff/bengkelmakan/blob/main/src/app/admin/login/page.tsx): `src/app/admin/login/page.tsx`
- [Login API](https://github.com/andhikaliff/bengkelmakan/blob/main/src/app/api/login/route.ts): `src/app/api/login/route.ts`
- [Role and sessions](https://github.com/andhikaliff/bengkelmakan/blob/main/src/lib/auth.ts): `src/lib/auth.ts`
- [Route protection](https://github.com/andhikaliff/bengkelmakan/blob/main/src/middleware.ts): `src/middleware.ts`
- [Edge session checks](https://github.com/andhikaliff/bengkelmakan/blob/main/src/lib/auth-edge.ts): `src/lib/auth-edge.ts`
- [Navigation shell](https://github.com/andhikaliff/bengkelmakan/blob/main/src/components/Navbar.tsx): `src/components/Navbar.tsx`
- [Inline icons](https://github.com/andhikaliff/bengkelmakan/blob/main/src/components/Icons.tsx): `src/components/Icons.tsx`
- [Current role hook](https://github.com/andhikaliff/bengkelmakan/blob/main/src/lib/use-current-role.ts): `src/lib/use-current-role.ts`
- [Sidebar navigation](https://github.com/andhikaliff/bengkelmakan/blob/main/src/components/Sidebar.tsx): `src/components/Sidebar.tsx`

### Canteen Operations

- [Employee directory](https://github.com/andhikaliff/bengkelmakan/blob/main/src/app/admin/employees/page.tsx): `src/app/admin/employees/page.tsx`
- [Employee APIs](https://github.com/andhikaliff/bengkelmakan/blob/main/src/app/api/employees/route.ts): `src/app/api/employees/route.ts`
- [Bulk employee API](https://github.com/andhikaliff/bengkelmakan/blob/main/src/app/api/employees/bulk/route.ts): `src/app/api/employees/bulk/route.ts`
- [Employee status API](https://github.com/andhikaliff/bengkelmakan/blob/main/src/app/api/employees/toggle-status/route.ts): `src/app/api/employees/toggle-status/route.ts`
- [QR scanner](https://github.com/andhikaliff/bengkelmakan/blob/main/src/app/scanner/page.tsx): `src/app/scanner/page.tsx`
- [Scan validation API](https://github.com/andhikaliff/bengkelmakan/blob/main/src/app/api/scan/route.ts): `src/app/api/scan/route.ts`
- [Scanner dialog](https://github.com/andhikaliff/bengkelmakan/blob/main/src/components/ScannerModal.tsx): `src/components/ScannerModal.tsx`

### Data & Reporting

- [Dashboard and transactions](https://github.com/andhikaliff/bengkelmakan/blob/main/src/app/admin/dashboard/page.tsx): `src/app/admin/dashboard/page.tsx`
- [Transaction API](https://github.com/andhikaliff/bengkelmakan/blob/main/src/app/api/transactions/route.ts): `src/app/api/transactions/route.ts`
- [Quota reset API](https://github.com/andhikaliff/bengkelmakan/blob/main/src/app/api/reset/route.ts): `src/app/api/reset/route.ts`
- [Excel export API](https://github.com/andhikaliff/bengkelmakan/blob/main/src/app/api/export/excel/route.ts): `src/app/api/export/excel/route.ts`
- [Workbook builder](https://github.com/andhikaliff/bengkelmakan/blob/main/src/lib/excel.ts): `src/lib/excel.ts`
- [Scheduled reports](https://github.com/andhikaliff/bengkelmakan/blob/main/src/app/api/cron/send-report/route.ts): `src/app/api/cron/send-report/route.ts`
- [Email delivery](https://github.com/andhikaliff/bengkelmakan/blob/main/src/lib/mailer.ts): `src/lib/mailer.ts`
- [Canteen data operations](https://github.com/andhikaliff/bengkelmakan/blob/main/src/lib/sheets.ts): `src/lib/sheets.ts`
- [SQLite database access](https://github.com/andhikaliff/bengkelmakan/blob/main/src/lib/db.ts): `src/lib/db.ts`
- [Data operation lock](https://github.com/andhikaliff/bengkelmakan/blob/main/src/lib/mutex.ts): `src/lib/mutex.ts`

### Settings & Audit

- [Audit log screen](https://github.com/andhikaliff/bengkelmakan/blob/main/src/app/admin/audit-logs/page.tsx): `src/app/admin/audit-logs/page.tsx`
- [Audit log API](https://github.com/andhikaliff/bengkelmakan/blob/main/src/app/api/audit-logs/route.ts): `src/app/api/audit-logs/route.ts`
- [Audit recording](https://github.com/andhikaliff/bengkelmakan/blob/main/src/lib/audit.ts): `src/lib/audit.ts`
- [Settings panel](https://github.com/andhikaliff/bengkelmakan/blob/main/src/components/SettingsModal.tsx): `src/components/SettingsModal.tsx`
- [User settings](https://github.com/andhikaliff/bengkelmakan/blob/main/src/lib/use-settings.ts): `src/lib/use-settings.ts`

### Other components

- **Admin or staff**
- **Canteen scanner**

## Connections

- Admin or staff → Login screen: opens
- Login screen → Login API: submits credentials
- Login API → Role and sessions: verifies and creates session (evidence: `src/app/api/login/route.ts`)
- Login API → Audit recording: records login (evidence: `src/app/api/login/route.ts`)
- Route protection → Edge session checks: checks sessions (evidence: `src/middleware.ts`)
- Admin or staff → Employee directory: manages employees
- Employee directory → Employee APIs: requests directory actions
- Employee APIs → Role and sessions: requires role (evidence: `src/app/api/employees/route.ts`)
- Employee APIs → Canteen data operations: reads and changes employees (evidence: `src/app/api/employees/route.ts`)
- Employee APIs → Audit recording: records changes (evidence: `src/app/api/employees/route.ts`)
- Bulk employee API → Canteen data operations: adds employees (evidence: `src/app/api/employees/bulk/route.ts`)
- Employee status API → Canteen data operations: changes status (evidence: `src/app/api/employees/toggle-status/route.ts`)
- Canteen scanner → QR scanner: scans QR codes
- QR scanner → Scan validation API: submits scans
- Scan validation API → Canteen data operations: validates scan (evidence: `src/app/api/scan/route.ts`)
- Scan validation API → Role and sessions: checks role (evidence: `src/app/api/scan/route.ts`)
- Dashboard and transactions → Transaction API: loads transactions
- Transaction API → Role and sessions: requires role (evidence: `src/app/api/transactions/route.ts`)
- Transaction API → Canteen data operations: fetches transactions (evidence: `src/app/api/transactions/route.ts`)
- Quota reset API → Canteen data operations: resets daily quota (evidence: `src/app/api/reset/route.ts`)
- Quota reset API → Audit recording: records reset (evidence: `src/app/api/reset/route.ts`)
- Excel export API → Workbook builder: builds workbook (evidence: `src/app/api/export/excel/route.ts`)
- Scheduled reports → Canteen data operations: fetches transactions (evidence: `src/app/api/cron/send-report/route.ts`)
- Scheduled reports → Workbook builder: builds attachment (evidence: `src/app/api/cron/send-report/route.ts`)
- Scheduled reports → Email delivery: sends report (evidence: `src/app/api/cron/send-report/route.ts`)
- Scheduled reports → Audit recording: records report outcome (evidence: `src/app/api/cron/send-report/route.ts`)
- Canteen data operations → SQLite database access: queries database (evidence: `src/lib/sheets.ts`)
- Canteen data operations → Data operation lock: serializes operations (evidence: `src/lib/sheets.ts`)
- Audit recording → SQLite database access: persists audit events (evidence: `src/lib/audit.ts`)
- Audit log API → Role and sessions: requires role (evidence: `src/app/api/audit-logs/route.ts`)
- Audit log API → SQLite database access: reads audit records (evidence: `src/app/api/audit-logs/route.ts`)
- Admin or staff → Audit log screen: reviews activity
- Settings panel → User settings: reads and updates settings (evidence: `src/components/SettingsModal.tsx`)
- Navigation shell → Settings panel: opens settings (evidence: `src/components/Navbar.tsx`)
- Navigation shell → Current role hook: gets current role (evidence: `src/components/Navbar.tsx`)
- Navigation shell → Inline icons: renders icons (evidence: `src/components/Navbar.tsx`)
- QR scanner → User settings: uses scanner settings (evidence: `src/app/scanner/page.tsx`)
- QR scanner → Scanner dialog: opens scan dialog
- Sidebar navigation → Inline icons: renders icons (evidence: `src/components/Sidebar.tsx`)
- Sidebar navigation → Current role hook: gets current role (evidence: `src/components/Sidebar.tsx`)
