# comanda-digital-code/frontend-comanda-digital architecture

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

- Interactive diagram: https://gitdiagram.com/comanda-digital-code/frontend-comanda-digital
- Repository: https://github.com/comanda-digital-code/frontend-comanda-digital

## Overview

#### Purpose and runtime
A Next.js App Router frontend for restaurant operations: public menu/table access, authenticated staff workflows, kitchen fulfillment, and manager administration/reporting. It runs as a TypeScript React application with route layouts and Tailwind/global styling. Root bootstrap is `src/app/layout.tsx`; the landing route is `src/app/page.tsx`.

#### Route domains and entry points
Routes are separated into public and protected groups:
- Public customer/auth entry points: `src/app/(public)/menu/page.tsx`, `src/app/(public)/tab/table/[tableNumber]/page.tsx`, `src/app/(public)/login/page.tsx`.
- Protected role workspaces: manager, server, and kitchen routes under `src/app/(protected)/manager`, `src/app/(protected)/server`, and `src/app/(protected)/kitchen`.
- Protected shell and role-specific layouts establish workspace navigation/chrome: `src/app/(protected)/layout.tsx`, `src/app/(protected)/manager/layout.tsx`, `src/app/(protected)/server/layout.tsx`.

#### Authentication and access boundary
Authentication is feature-owned, with provider/context, login/reset forms, token handling, and an auth service:
`src/features/auth/context/AuthProvider.tsx`, `src/features/auth/services/auth.service.ts`, `src/features/auth/tokens/auth.token.ts`.
`src/proxy.ts` is the likely application-wide request/access boundary, while `src/config/role-mapper.ts` and protected route groups support role-directed navigation and authorization behavior.

#### Backend integration and client/server split
Feature services consistently distinguish browser and server API access, insulating UI from the backend contract:
`src/services/api.client.ts`, `src/services/api.server.ts`, `src/features/product/service/product.client.ts`.
Core domain services cover products, categories/extras, employees, tabs, orders, dashboard data, and reports. React Query provisioning in `src/providers/react-query-provider.tsx` is the shared client-side remote-state layer. The frontend depends on an external API; its implementation is not present in this repository.

#### Restaurant transaction flow
The central operational flow is table/tab → order → kitchen → settlement/reporting:
- Servers open and manage tabs, select products, edit orders, and send orders through `src/app/(protected)/server/tabs/open/[id]/page.tsx`, `src/app/(protected)/server/products/select/page.tsx`, and `src/app/(protected)/server/orders/[id]/send/page.tsx`.
- Tab state and order data are modeled and persisted through `src/features/tab/services/tabs.client.service.ts`, `src/features/tab/components/order/service/order.client.ts`, and `src/features/order/services/orders.client.service.ts`.
- Kitchen staff consume and advance fulfillment work through `src/features/kitchen/components/KitchenDashboard.tsx` and `src/features/order/components/KitchenOrdersClient.tsx`.

#### Real-time synchronization
WebSocket infrastructure and domain hooks propagate operational changes to active screens:
`src/services/websocket.ts`, `src/features/order/hooks/useKitchenOrdersRealtime.ts`, `src/features/tab/hooks/useTabsRealtime.ts`.
This boundary is material: server/order/kitchen dashboards render local UI state but must reconcile events from the backend, including typed order and tab event contracts in `src/features/order/types/orderEvents.ts` and `src/features/tab/types/tabEvents.ts`.

#### Management, customer presentation, and outputs
Managers maintain the sellable catalog and staff, then monitor performance:
`src/app/(protected)/manager/products/page.tsx`, `src/app/(protected)/manager/employees/page.tsx`, `src/app/(protected)/manager/dashboard/page.tsx`.
Dashboard hooks/services aggregate KPIs, revenue, rankings, and recent tabs via `src/features/dashboard/services/dashboard.service.ts` and `src/features/dashboard/hooks/use-manager-dashboard-realtime.ts`. QR functionality creates menu/table entry URLs and print/download actions (`src/features/qr/domain/qr.urls.ts`, `src/features/qr/services/qr-print.client.ts`). Cloudinary integration supports media handling through `src/features/cloudinary/services/cloudinary.client.ts`; reporting generates PDF-oriented outputs under `src/features/report/pdf/`.

Main entry points: [`src/services/api.client.ts`](https://github.com/comanda-digital-code/frontend-comanda-digital/blob/main/src/services/api.client.ts) (API client/server layer), [`src/app/(protected)/manager/dashboard/page.tsx`](https://github.com/comanda-digital-code/frontend-comanda-digital/blob/main/src/app/(protected)/manager/dashboard/page.tsx) (Manager workspace), [`src/app/(protected)/layout.tsx`](https://github.com/comanda-digital-code/frontend-comanda-digital/blob/main/src/app/(protected)/layout.tsx) (Protected workspace shell), [`src/features/tab/services/tabs.client.service.ts`](https://github.com/comanda-digital-code/frontend-comanda-digital/blob/main/src/features/tab/services/tabs.client.service.ts) (Tab & order services)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["App routes"]
  node_root["Root bootstrap<br/>Next.js layout<br/>[layout.tsx]"]
  node_landing["Landing route<br/>public route<br/>[page.tsx]"]
  node_public_routes["Customer &amp; auth routes<br/>public routes<br/>[page.tsx]"]
  node_protected_shell["Protected workspace shell<br/>route layout<br/>[layout.tsx]"]
  node_server_workspace["Server workspace<br/>role routes<br/>[page.tsx]"]
  node_manager_workspace["Manager workspace<br/>role routes<br/>[page.tsx]"]
end

subgraph group_access["Access &amp; data"]
  node_auth["Auth provider &amp; service<br/>auth feature<br/>[AuthProvider.tsx]"]
  node_access_proxy["Request access boundary<br/>proxy<br/>[proxy.ts]"]
  node_api_layer{{"API client/server layer<br/>backend gateway<br/>[api.client.ts]"}}
  node_react_query["Remote-state provider<br/>React Query"]
end

subgraph group_operations["Restaurant operations"]
  node_tab_order["Tab &amp; order services<br/>transaction domain"]
  node_kitchen["Kitchen fulfillment<br/>kitchen UI"]
  node_realtime{{"WebSocket synchronization<br/>realtime gateway<br/>[websocket.ts]"}}
end

subgraph group_management["Management &amp; outputs"]
  node_catalog["Catalog management<br/>product feature<br/>[page.tsx]"]
  node_staff["Staff management<br/>employee feature<br/>[page.tsx]"]
  node_dashboard["Manager dashboard<br/>analytics feature"]
  node_customer_qr["QR menu &amp; table entry<br/>customer presentation<br/>[qr.urls.ts]"]
  node_reports["PDF reporting<br/>report output"]
end

node_external_api{{"External restaurant API<br/>external backend"}}

node_root -->|"renders"| node_landing
node_root -->|"hosts"| node_public_routes
node_root -->|"hosts"| node_protected_shell
node_access_proxy -->|"guards"| node_protected_shell
node_auth -->|"session access"| node_access_proxy
node_protected_shell -->|"routes staff"| node_server_workspace
node_protected_shell -->|"routes managers"| node_manager_workspace
node_public_routes -->|"login"| node_auth
node_auth -->|"auth requests"| node_api_layer
node_react_query -->|"fetches through"| node_api_layer
node_api_layer -->|"HTTP API"| node_external_api
node_server_workspace -->|"opens, edits, sends"| node_tab_order
node_tab_order -->|"persists"| node_api_layer
node_kitchen -->|"advances orders"| node_tab_order
node_realtime -->|"tab/order events"| node_tab_order
node_realtime -->|"fulfillment updates"| node_kitchen
node_realtime -->|"WebSocket events"| node_external_api
node_manager_workspace -->|"maintains"| node_catalog
node_manager_workspace -->|"maintains"| node_staff
node_manager_workspace -->|"monitors"| node_dashboard
node_dashboard -->|"aggregates data"| node_api_layer
node_dashboard -->|"produces outputs"| node_reports
node_customer_qr -->|"links customers"| node_public_routes
node_catalog -->|"manages catalog"| node_api_layer
node_staff -->|"manages employees"| node_api_layer

click node_root "https://github.com/comanda-digital-code/frontend-comanda-digital/blob/main/src/app/layout.tsx"
click node_landing "https://github.com/comanda-digital-code/frontend-comanda-digital/blob/main/src/app/page.tsx"
click node_public_routes "https://github.com/comanda-digital-code/frontend-comanda-digital/blob/main/src/app/(public)/menu/page.tsx"
click node_protected_shell "https://github.com/comanda-digital-code/frontend-comanda-digital/blob/main/src/app/(protected)/layout.tsx"
click node_server_workspace "https://github.com/comanda-digital-code/frontend-comanda-digital/blob/main/src/app/(protected)/server/tabs/open/%5Bid%5D/page.tsx"
click node_manager_workspace "https://github.com/comanda-digital-code/frontend-comanda-digital/blob/main/src/app/(protected)/manager/dashboard/page.tsx"
click node_auth "https://github.com/comanda-digital-code/frontend-comanda-digital/blob/main/src/features/auth/context/AuthProvider.tsx"
click node_access_proxy "https://github.com/comanda-digital-code/frontend-comanda-digital/blob/main/src/proxy.ts"
click node_api_layer "https://github.com/comanda-digital-code/frontend-comanda-digital/blob/main/src/services/api.client.ts"
click node_react_query "https://github.com/comanda-digital-code/frontend-comanda-digital/blob/main/src/providers/react-query-provider.tsx"
click node_tab_order "https://github.com/comanda-digital-code/frontend-comanda-digital/blob/main/src/features/tab/services/tabs.client.service.ts"
click node_kitchen "https://github.com/comanda-digital-code/frontend-comanda-digital/blob/main/src/features/kitchen/components/KitchenDashboard.tsx"
click node_realtime "https://github.com/comanda-digital-code/frontend-comanda-digital/blob/main/src/services/websocket.ts"
click node_catalog "https://github.com/comanda-digital-code/frontend-comanda-digital/blob/main/src/app/(protected)/manager/products/page.tsx"
click node_staff "https://github.com/comanda-digital-code/frontend-comanda-digital/blob/main/src/app/(protected)/manager/employees/page.tsx"
click node_dashboard "https://github.com/comanda-digital-code/frontend-comanda-digital/blob/main/src/features/dashboard/services/dashboard.service.ts"
click node_customer_qr "https://github.com/comanda-digital-code/frontend-comanda-digital/blob/main/src/features/qr/domain/qr.urls.ts"
click node_reports "https://github.com/comanda-digital-code/frontend-comanda-digital/blob/main/src/features/report/pdf/RevenuePdfDocument.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_root,node_landing,node_public_routes,node_protected_shell,node_server_workspace,node_manager_workspace toneBlue
class node_auth,node_access_proxy,node_api_layer,node_react_query toneAmber
class node_tab_order,node_kitchen,node_realtime toneMint
class node_catalog,node_staff,node_dashboard,node_customer_qr,node_reports toneRose
class node_external_api toneNeutral
```

## Components

### App routes

Next.js route entry points and workspace shells.

- [Root bootstrap](https://github.com/comanda-digital-code/frontend-comanda-digital/blob/main/src/app/layout.tsx): Next.js layout · `src/app/layout.tsx`
- [Landing route](https://github.com/comanda-digital-code/frontend-comanda-digital/blob/main/src/app/page.tsx): public route · `src/app/page.tsx`
- [Customer & auth routes](https://github.com/comanda-digital-code/frontend-comanda-digital/blob/main/src/app/(public)/menu/page.tsx): public routes · Menu, table access, and login entry points. · `src/app/(public)/menu/page.tsx`
- [Protected workspace shell](https://github.com/comanda-digital-code/frontend-comanda-digital/blob/main/src/app/(protected)/layout.tsx): route layout · Shared authenticated workspace chrome. · `src/app/(protected)/layout.tsx`
- [Server workspace](https://github.com/comanda-digital-code/frontend-comanda-digital/blob/main/src/app/(protected)/server/tabs/open/%5Bid%5D/page.tsx): role routes · Tab, product selection, and order-send workflows. · `src/app/(protected)/server/tabs/open/[id]/page.tsx`
- [Manager workspace](https://github.com/comanda-digital-code/frontend-comanda-digital/blob/main/src/app/(protected)/manager/dashboard/page.tsx): role routes · Catalog, staff, and dashboard administration. · `src/app/(protected)/manager/dashboard/page.tsx`

### Access & data

Authentication, API access, and shared remote state.

- [Auth provider & service](https://github.com/comanda-digital-code/frontend-comanda-digital/blob/main/src/features/auth/context/AuthProvider.tsx): auth feature · Owns session context, login flows, and tokens. · `src/features/auth/context/AuthProvider.tsx`
- [Request access boundary](https://github.com/comanda-digital-code/frontend-comanda-digital/blob/main/src/proxy.ts): proxy · Applies application-wide access handling. · `src/proxy.ts`
- [API client/server layer](https://github.com/comanda-digital-code/frontend-comanda-digital/blob/main/src/services/api.client.ts): backend gateway · Separates browser and server calls to the external API. · `src/services/api.client.ts`
- [Remote-state provider](https://github.com/comanda-digital-code/frontend-comanda-digital/blob/main/src/providers/react-query-provider.tsx): React Query · `src/providers/react-query-provider.tsx`

### Restaurant operations

Tab, order, kitchen, and real-time workflow.

- [Tab & order services](https://github.com/comanda-digital-code/frontend-comanda-digital/blob/main/src/features/tab/services/tabs.client.service.ts): transaction domain · Persists tabs, order edits, and order lifecycle changes. · `src/features/tab/services/tabs.client.service.ts`
- [Kitchen fulfillment](https://github.com/comanda-digital-code/frontend-comanda-digital/blob/main/src/features/kitchen/components/KitchenDashboard.tsx): kitchen UI · Displays and advances kitchen work. · `src/features/kitchen/components/KitchenDashboard.tsx`
- [WebSocket synchronization](https://github.com/comanda-digital-code/frontend-comanda-digital/blob/main/src/services/websocket.ts): realtime gateway · Reconciles typed tab and order events into active screens. · `src/services/websocket.ts`

### Management & outputs

Catalog, administration, presentation, and reporting.

- [Catalog management](https://github.com/comanda-digital-code/frontend-comanda-digital/blob/main/src/app/(protected)/manager/products/page.tsx): product feature · Product, category, extras, and media operations. · `src/app/(protected)/manager/products/page.tsx`
- [Staff management](https://github.com/comanda-digital-code/frontend-comanda-digital/blob/main/src/app/(protected)/manager/employees/page.tsx): employee feature · `src/app/(protected)/manager/employees/page.tsx`
- [Manager dashboard](https://github.com/comanda-digital-code/frontend-comanda-digital/blob/main/src/features/dashboard/services/dashboard.service.ts): analytics feature · KPIs, revenue, rankings, and recent tabs. · `src/features/dashboard/services/dashboard.service.ts`
- [QR menu & table entry](https://github.com/comanda-digital-code/frontend-comanda-digital/blob/main/src/features/qr/domain/qr.urls.ts): customer presentation · Creates menu/table URLs and print/download actions. · `src/features/qr/domain/qr.urls.ts`
- [PDF reporting](https://github.com/comanda-digital-code/frontend-comanda-digital/blob/main/src/features/report/pdf/RevenuePdfDocument.tsx): report output · `src/features/report/pdf/RevenuePdfDocument.tsx`

### Other components

- **External restaurant API**: external backend · Backend implementation is outside this repository.

## Connections

- Root bootstrap → Landing route: renders
- Root bootstrap → Customer & auth routes: hosts
- Root bootstrap → Protected workspace shell: hosts
- Request access boundary → Protected workspace shell: guards
- Auth provider & service → Request access boundary: session access
- Protected workspace shell → Server workspace: routes staff
- Protected workspace shell → Manager workspace: routes managers
- Customer & auth routes → Auth provider & service: login
- Auth provider & service → API client/server layer: auth requests
- Remote-state provider → API client/server layer: fetches through
- API client/server layer → External restaurant API: HTTP API
- Server workspace → Tab & order services: opens, edits, sends
- Tab & order services → API client/server layer: persists
- Kitchen fulfillment → Tab & order services: advances orders
- WebSocket synchronization → Tab & order services: tab/order events
- WebSocket synchronization → Kitchen fulfillment: fulfillment updates
- WebSocket synchronization → External restaurant API: WebSocket events
- Manager workspace → Catalog management: maintains
- Manager workspace → Staff management: maintains
- Manager workspace → Manager dashboard: monitors
- Manager dashboard → API client/server layer: aggregates data
- Manager dashboard → PDF reporting: produces outputs
- QR menu & table entry → Customer & auth routes: links customers
- Catalog management → API client/server layer: manages catalog
- Staff management → API client/server layer: manages employees
