# team-2-sweet-creatures/team-2-gunita-kopi architecture

> Architecture diagram of the GitHub repository team-2-sweet-creatures/team-2-gunita-kopi, 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/team-2-sweet-creatures/team-2-gunita-kopi
- Repository: https://github.com/team-2-sweet-creatures/team-2-gunita-kopi

## Overview

Gunita Kopi is a coffee-shop POS and inventory system. Baristas browse the catalog, build and check out orders, and can continue offline with local order storage and later sync; owners manage products, recipe costing, stock, staff, suppliers, and reports. Both web areas use server-side session/API handlers that dispatch to the backend, where role checks, route handlers, domain services, and Supabase-backed data access enforce business operations. The README documents offline sync and reporting capabilities, though their detailed implementation paths were not sampled; links to those branches are therefore conservative.

Main entry points: [`src/server/routes`](https://github.com/team-2-sweet-creatures/team-2-gunita-kopi/tree/main/src/server/routes) (API routes), [`src/server/lib/supabase-user.ts`](https://github.com/team-2-sweet-creatures/team-2-gunita-kopi/blob/main/src/server/lib/supabase-user.ts) (Supabase and RLS), [`src/auth/session-server.ts`](https://github.com/team-2-sweet-creatures/team-2-gunita-kopi/blob/main/src/auth/session-server.ts) (Session handling), [`src/staff/lib/api-client.ts`](https://github.com/team-2-sweet-creatures/team-2-gunita-kopi/blob/main/src/staff/lib/api-client.ts) (Staff API client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_front["Web experiences"]
  node_owner["Owner portal"]
  node_staff["Barista POS"]
  node_owner_proxy["Owner server proxy"]
  node_staff_proxy["Staff server proxy"]
  node_owner_client["Owner API client<br/>[api-client.ts]"]
  node_staff_client["Staff API client<br/>[api-client.ts]"]
  node_pos_checkout["POS checkout<br/>[checkout.ts]"]
  node_admin_auth["Owner sign-in"]
  node_staff_auth["Staff sign-in"]
end

subgraph group_backend["Backend operations"]
  node_dispatch["API dispatcher<br/>[dispatch.ts]"]
  node_routes["API routes"]
  node_request["Request validation<br/>[request.ts]"]
  node_responses["API responses<br/>[response.ts]"]
  node_contracts["API contracts"]
end

subgraph group_domain["Business domains"]
  node_orders["Orders<br/>[service.ts]"]
  node_products["Products and costing<br/>[service.ts]"]
  node_inventory["Ingredients and stock<br/>[service.ts]"]
  node_suppliers["Suppliers<br/>[service.ts]"]
  node_reports["Reports and dashboard<br/>[service.ts]"]
  node_users["Users and employees<br/>[service.ts]"]
end

subgraph group_offline["Offline POS"]
  node_sync["Order sync<br/>[service.ts]"]
  node_outbox[("Offline order outbox<br/>[outbox.ts]")]
  node_offline_sync["Offline sync client<br/>[sync.ts]"]
end

subgraph group_security["Identity and data"]
  node_authz["Role authorization<br/>[auth.ts]"]
  node_session["Session handling<br/>[session-server.ts]"]
  node_supabase[("Supabase and RLS<br/>[supabase-user.ts]")]
end

node_owner_actor(("Shop owner"))
node_barista_actor(("Barista"))
node_supabase_auth["Supabase Auth"]

node_owner_actor -->|"manages"| node_owner
node_barista_actor -->|"takes orders"| node_staff
node_owner -.->|"requests data"| node_owner_client
node_staff -.->|"requests data"| node_staff_client
node_owner_client -.->|"calls server API"| node_owner_proxy
node_staff_client -.->|"calls server API"| node_staff_proxy
node_owner_proxy -->|"dispatches in process"| node_dispatch
node_staff_proxy -->|"dispatches in process"| node_dispatch
node_dispatch -->|"routes requests"| node_routes
node_routes -->|"checks roles"| node_authz
node_routes -->|"parses input"| node_request
node_routes -->|"wraps results"| node_responses
node_routes -->|"calls checkout"| node_orders
node_routes -->|"calls product service"| node_products
node_routes -->|"calls ingredient service"| node_inventory
node_routes -->|"records stock"| node_inventory
node_routes -->|"validates against"| node_contracts
node_routes -.->|"calls supplier service"| node_suppliers
node_routes -.->|"serves reporting"| node_reports
node_routes -.->|"serves user admin"| node_users
node_routes -.->|"dispatches sync"| node_sync
node_pos_checkout -.->|"submits orders"| node_staff_client
node_pos_checkout -.->|"saves offline"| node_outbox
node_offline_sync -.->|"reads pending orders"| node_outbox
node_offline_sync -.->|"sends sync request"| node_staff_client
node_session -->|"uses API handler"| node_dispatch
node_session -.->|"authenticates users"| node_supabase_auth
node_authz -->|"verifies and scopes access"| node_supabase
node_orders -.->|"reads and writes data"| node_supabase
node_products -.->|"reads and writes data"| node_supabase
node_inventory -.->|"reads and writes data"| node_supabase
node_sync -.->|"applies synced orders"| node_supabase
node_admin_auth -.->|"uses sign-in handlers"| node_session
node_staff_auth -.->|"uses sign-in handlers"| node_session

click node_owner "https://github.com/team-2-sweet-creatures/team-2-gunita-kopi/tree/main/src/app/(owner)/admin/(app)"
click node_staff "https://github.com/team-2-sweet-creatures/team-2-gunita-kopi/tree/main/src/app/(staff)/staff/(pos)"
click node_owner_proxy "https://github.com/team-2-sweet-creatures/team-2-gunita-kopi/blob/main/src/owner/lib/session-handlers.ts"
click node_staff_proxy "https://github.com/team-2-sweet-creatures/team-2-gunita-kopi/blob/main/src/staff/lib/session-handlers.ts"
click node_owner_client "https://github.com/team-2-sweet-creatures/team-2-gunita-kopi/blob/main/src/owner/lib/api-client.ts"
click node_staff_client "https://github.com/team-2-sweet-creatures/team-2-gunita-kopi/blob/main/src/staff/lib/api-client.ts"
click node_pos_checkout "https://github.com/team-2-sweet-creatures/team-2-gunita-kopi/blob/main/src/staff/features/pos/checkout.ts"
click node_admin_auth "https://github.com/team-2-sweet-creatures/team-2-gunita-kopi/tree/main/src/app/(owner)/admin/(auth)"
click node_staff_auth "https://github.com/team-2-sweet-creatures/team-2-gunita-kopi/tree/main/src/app/(staff)/staff/(auth)"
click node_dispatch "https://github.com/team-2-sweet-creatures/team-2-gunita-kopi/blob/main/src/server/dispatch.ts"
click node_routes "https://github.com/team-2-sweet-creatures/team-2-gunita-kopi/tree/main/src/server/routes"
click node_request "https://github.com/team-2-sweet-creatures/team-2-gunita-kopi/blob/main/src/server/lib/request.ts"
click node_authz "https://github.com/team-2-sweet-creatures/team-2-gunita-kopi/blob/main/src/server/lib/auth.ts"
click node_responses "https://github.com/team-2-sweet-creatures/team-2-gunita-kopi/blob/main/src/server/lib/response.ts"
click node_contracts "https://github.com/team-2-sweet-creatures/team-2-gunita-kopi/tree/main/src/contracts"
click node_orders "https://github.com/team-2-sweet-creatures/team-2-gunita-kopi/blob/main/src/server/modules/orders/service.ts"
click node_products "https://github.com/team-2-sweet-creatures/team-2-gunita-kopi/blob/main/src/server/modules/products/service.ts"
click node_inventory "https://github.com/team-2-sweet-creatures/team-2-gunita-kopi/blob/main/src/server/modules/ingredients/service.ts"
click node_suppliers "https://github.com/team-2-sweet-creatures/team-2-gunita-kopi/blob/main/src/server/modules/suppliers/service.ts"
click node_reports "https://github.com/team-2-sweet-creatures/team-2-gunita-kopi/blob/main/src/server/modules/reports/service.ts"
click node_users "https://github.com/team-2-sweet-creatures/team-2-gunita-kopi/blob/main/src/server/modules/users/service.ts"
click node_sync "https://github.com/team-2-sweet-creatures/team-2-gunita-kopi/blob/main/src/server/modules/sync/service.ts"
click node_outbox "https://github.com/team-2-sweet-creatures/team-2-gunita-kopi/blob/main/src/staff/offline/outbox.ts"
click node_offline_sync "https://github.com/team-2-sweet-creatures/team-2-gunita-kopi/blob/main/src/staff/offline/sync.ts"
click node_session "https://github.com/team-2-sweet-creatures/team-2-gunita-kopi/blob/main/src/auth/session-server.ts"
click node_supabase "https://github.com/team-2-sweet-creatures/team-2-gunita-kopi/blob/main/src/server/lib/supabase-user.ts"

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_owner,node_staff,node_owner_proxy,node_staff_proxy,node_owner_client,node_staff_client,node_pos_checkout,node_admin_auth,node_staff_auth toneBlue
class node_dispatch,node_routes,node_request,node_responses,node_contracts toneAmber
class node_orders,node_products,node_inventory,node_suppliers,node_reports,node_users toneMint
class node_sync,node_outbox,node_offline_sync toneRose
class node_authz,node_session,node_supabase,node_owner_actor,node_barista_actor,node_supabase_auth toneIndigo
```

## Components

### Web experiences

- [Owner portal](https://github.com/team-2-sweet-creatures/team-2-gunita-kopi/tree/main/src/app/(owner)/admin/(app)): `src/app/(owner)/admin/(app)`
- [Barista POS](https://github.com/team-2-sweet-creatures/team-2-gunita-kopi/tree/main/src/app/(staff)/staff/(pos)): `src/app/(staff)/staff/(pos)`
- [Owner server proxy](https://github.com/team-2-sweet-creatures/team-2-gunita-kopi/blob/main/src/owner/lib/session-handlers.ts): `src/owner/lib/session-handlers.ts`
- [Staff server proxy](https://github.com/team-2-sweet-creatures/team-2-gunita-kopi/blob/main/src/staff/lib/session-handlers.ts): `src/staff/lib/session-handlers.ts`
- [Owner API client](https://github.com/team-2-sweet-creatures/team-2-gunita-kopi/blob/main/src/owner/lib/api-client.ts): `src/owner/lib/api-client.ts`
- [Staff API client](https://github.com/team-2-sweet-creatures/team-2-gunita-kopi/blob/main/src/staff/lib/api-client.ts): `src/staff/lib/api-client.ts`
- [POS checkout](https://github.com/team-2-sweet-creatures/team-2-gunita-kopi/blob/main/src/staff/features/pos/checkout.ts): `src/staff/features/pos/checkout.ts`
- [Owner sign-in](https://github.com/team-2-sweet-creatures/team-2-gunita-kopi/tree/main/src/app/(owner)/admin/(auth)): `src/app/(owner)/admin/(auth)`
- [Staff sign-in](https://github.com/team-2-sweet-creatures/team-2-gunita-kopi/tree/main/src/app/(staff)/staff/(auth)): `src/app/(staff)/staff/(auth)`

### Backend operations

- [API dispatcher](https://github.com/team-2-sweet-creatures/team-2-gunita-kopi/blob/main/src/server/dispatch.ts): `src/server/dispatch.ts`
- [API routes](https://github.com/team-2-sweet-creatures/team-2-gunita-kopi/tree/main/src/server/routes): `src/server/routes`
- [Request validation](https://github.com/team-2-sweet-creatures/team-2-gunita-kopi/blob/main/src/server/lib/request.ts): `src/server/lib/request.ts`
- [API responses](https://github.com/team-2-sweet-creatures/team-2-gunita-kopi/blob/main/src/server/lib/response.ts): `src/server/lib/response.ts`
- [API contracts](https://github.com/team-2-sweet-creatures/team-2-gunita-kopi/tree/main/src/contracts): `src/contracts`

### Business domains

- [Orders](https://github.com/team-2-sweet-creatures/team-2-gunita-kopi/blob/main/src/server/modules/orders/service.ts): `src/server/modules/orders/service.ts`
- [Products and costing](https://github.com/team-2-sweet-creatures/team-2-gunita-kopi/blob/main/src/server/modules/products/service.ts): `src/server/modules/products/service.ts`
- [Ingredients and stock](https://github.com/team-2-sweet-creatures/team-2-gunita-kopi/blob/main/src/server/modules/ingredients/service.ts): `src/server/modules/ingredients/service.ts`
- [Suppliers](https://github.com/team-2-sweet-creatures/team-2-gunita-kopi/blob/main/src/server/modules/suppliers/service.ts): `src/server/modules/suppliers/service.ts`
- [Reports and dashboard](https://github.com/team-2-sweet-creatures/team-2-gunita-kopi/blob/main/src/server/modules/reports/service.ts): `src/server/modules/reports/service.ts`
- [Users and employees](https://github.com/team-2-sweet-creatures/team-2-gunita-kopi/blob/main/src/server/modules/users/service.ts): `src/server/modules/users/service.ts`

### Offline POS

- [Order sync](https://github.com/team-2-sweet-creatures/team-2-gunita-kopi/blob/main/src/server/modules/sync/service.ts): `src/server/modules/sync/service.ts`
- [Offline order outbox](https://github.com/team-2-sweet-creatures/team-2-gunita-kopi/blob/main/src/staff/offline/outbox.ts): `src/staff/offline/outbox.ts`
- [Offline sync client](https://github.com/team-2-sweet-creatures/team-2-gunita-kopi/blob/main/src/staff/offline/sync.ts): `src/staff/offline/sync.ts`

### Identity and data

- [Role authorization](https://github.com/team-2-sweet-creatures/team-2-gunita-kopi/blob/main/src/server/lib/auth.ts): `src/server/lib/auth.ts`
- [Session handling](https://github.com/team-2-sweet-creatures/team-2-gunita-kopi/blob/main/src/auth/session-server.ts): `src/auth/session-server.ts`
- [Supabase and RLS](https://github.com/team-2-sweet-creatures/team-2-gunita-kopi/blob/main/src/server/lib/supabase-user.ts): `src/server/lib/supabase-user.ts`

### Other components

- **Shop owner**
- **Barista**
- **Supabase Auth**

## Connections

- Shop owner → Owner portal: manages
- Barista → Barista POS: takes orders
- Owner portal → Owner API client: requests data
- Barista POS → Staff API client: requests data
- Owner API client → Owner server proxy: calls server API
- Staff API client → Staff server proxy: calls server API
- Owner server proxy → API dispatcher: dispatches in process (evidence: `src/owner/lib/session-handlers.ts`)
- Staff server proxy → API dispatcher: dispatches in process (evidence: `src/staff/lib/session-handlers.ts`)
- API dispatcher → API routes: routes requests (evidence: `src/server/dispatch.ts`)
- API routes → Role authorization: checks roles (evidence: `src/server/routes/orders/route.ts`)
- API routes → Request validation: parses input (evidence: `src/server/routes/orders/route.ts`)
- API routes → API responses: wraps results (evidence: `src/server/routes/orders/route.ts`)
- API routes → Orders: calls checkout (evidence: `src/server/routes/orders/route.ts`)
- API routes → Products and costing: calls product service (evidence: `src/server/routes/products/route.ts`)
- API routes → Ingredients and stock: calls ingredient service (evidence: `src/server/routes/ingredients/route.ts`)
- API routes → Ingredients and stock: records stock (evidence: `src/server/routes/stock-transactions/route.ts`)
- API routes → API contracts: validates against (evidence: `src/server/routes/orders/route.ts`)
- API routes → Suppliers: calls supplier service (evidence: `src/server/routes/suppliers/route.ts`)
- API routes → Reports and dashboard: serves reporting
- API routes → Users and employees: serves user admin (evidence: `src/server/routes/users/route.ts`)
- API routes → Order sync: dispatches sync (evidence: `src/server/routes/sync/route.ts`)
- POS checkout → Staff API client: submits orders
- POS checkout → Offline order outbox: saves offline
- Offline sync client → Offline order outbox: reads pending orders
- Offline sync client → Staff API client: sends sync request
- Session handling → API dispatcher: uses API handler (evidence: `src/owner/lib/session-handlers.ts`)
- Session handling → Supabase Auth: authenticates users
- Role authorization → Supabase and RLS: verifies and scopes access (evidence: `src/server/lib/auth.ts`)
- Orders → Supabase and RLS: reads and writes data
- Products and costing → Supabase and RLS: reads and writes data
- Ingredients and stock → Supabase and RLS: reads and writes data
- Order sync → Supabase and RLS: applies synced orders
- Owner sign-in → Session handling: uses sign-in handlers
- Staff sign-in → Session handling: uses sign-in handlers
