# esangcap/panaderomultibranchesuae architecture

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

- Interactive diagram: https://gitdiagram.com/esangcap/panaderomultibranchesuae
- Repository: https://github.com/esangcap/panaderomultibranchesuae

## Overview

1. This repository is a two-tier bakery operations system: a React/TypeScript single-page frontend and a Supabase-backed serverless backend. The frontend is the user-facing app; the backend is concentrated in Supabase Edge Functions and shared server code under `supabase/functions`.

2. The frontend entrypoint is `src/main.tsx`, which mounts the app shell defined in `src/app/components/Root.tsx`, `Layout.tsx`, and route selection in `src/app/routes.ts`. `App.tsx` and `NotFound.tsx` round out the top-level navigation and fallback path.

3. The UI is organized by business domain, not by generic pages. Major screens include `dashboard`, `pos`, `orders`, `kitchen`, `products`, `inventory`, and `admin`. Each domain folder contains its own page component plus dialogs, tables, tabs, and local types, which makes the architecture easy to map as functional modules.

4. The point-of-sale and product flows are data-driven and split into page-specific hooks and panels. Examples include `usePosPageData.ts`, `useProductsPageData.ts`, `useProductImageSelection.ts`, `POSCartPanel.tsx`, `POSProductsPanel.tsx`, and product/stock adjustment dialogs. This suggests the pages assemble data from shared helpers rather than embedding API logic directly in the visual components.

5. Authentication and session handling are isolated in `src/app/lib/auth.tsx` and the auth screens under `src/app/components/auth`. The app supports staff login, password changes, and admin/developer password management, with branch-aware access control layered on top.

6. The backend is centered on a shared server implementation in `supabase/functions/_shared/panadero-server`. That code is split into route and domain modules such as `auth-routes`, `auth`, `branches`, `users`, `products`, `recipes`, `stock`, `inventory-log`, `orders`, `transfers`, and `branch-scope`, indicating a single backend service surface organized by business capability.

7. There are multiple Edge Function entrypoints, but `make-server-6e9ea444` is the deployment target called out in the README. `supabase/functions/server` appears to be another wrapper, while `diag-health` provides operational health checking. The shared server code is the stable core; the thin function wrappers are deployment/runtime adapters.

8. Persistence is abstracted through a KV-style storage layer in the backend (`kv.ts` and the `kv_store` files). The migrations `20260408180000_optimize_panadero_kv_store.sql` and `20260408213000_split_panadero_kv_domains.sql` show that the data model was optimized by splitting storage domains, so the backend likely stores operational entities in logically separated key/value buckets rather than a monolithic table design.

9. The main business entities are branches, users, products, ingredients, recipes, stock, inventory logs, orders, and transfers. The architecture is branch-aware end to end: the dashboard, admin tools, inventory, POS, and order workflows all need to respect the current branch context and the user’s access scope.

10. Realtime behavior is part of the app architecture. `src/app/lib/realtime.tsx` suggests live updates are used for operational screens such as orders, kitchen, inventory, or transfer status, which is important in a multi-user bakery setting.

11. The frontend uses a shared UI component library under `src/app/components/ui`, along with `tailwind.css`, `theme.css`, and `fonts.css`. This indicates a design-system approach with reusable primitives, loading skeletons, responsive helpers, and modal/dialog patterns across all business modules.

12. Operationally, the repo separates frontend deployment from Edge Function deployment. The README notes that UI changes only need a frontend redeploy, while route changes require deploying `make-server-6e9ea444` first so the app does not call missing backend routes. That boundary is important for understanding release flow and failure modes.

13. There are also developer/admin onboarding paths beyond normal staff usage: branch setup, sample-data initialization, and a developer-email gate. The repo additionally exposes a developer-only build fingerprint (`branch @ commit`), which is a clue that the app is designed to support controlled multi-branch deployments and debugging.

14. In diagram terms, the clearest architecture is: browser SPA at the top, authenticated through Supabase, calling a serverless backend with branch-scoped business logic, and persisting operational data through the KV-backed Supabase layer. The major subdomains are POS/orders, kitchen, inventory/recipes/stock, products, and admin/branch/user management.

Main entry points: [`src/app/App.tsx`](https://github.com/esangcap/panaderomultibranchesuae/blob/main/src/app/App.tsx) (App), [`src/app/lib/auth.tsx`](https://github.com/esangcap/panaderomultibranchesuae/blob/main/src/app/lib/auth.tsx) (Auth), [`src/app/lib/realtime.tsx`](https://github.com/esangcap/panaderomultibranchesuae/blob/main/src/app/lib/realtime.tsx) (Realtime), [`src/app/components/Root.tsx`](https://github.com/esangcap/panaderomultibranchesuae/blob/main/src/app/components/Root.tsx) (Root)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend SPA"]
  node_src_main(("Entry<br/>[main.tsx]"))
  node_root["Root<br/>app shell<br/>[Root.tsx]"]
  node_layout["Layout<br/>[Layout.tsx]"]
  node_routes["Routes<br/>route map<br/>[routes.ts]"]
  node_app["App<br/>top navigation<br/>[App.tsx]"]
  node_notfound["Not Found<br/>fallback view<br/>[NotFound.tsx]"]
  node_auth["Auth<br/>session layer<br/>[auth.tsx]"]
  node_realtime["Realtime<br/>live updates<br/>[realtime.tsx]"]
  node_dashboard["Dashboard<br/>ops screen<br/>[Dashboard.tsx]"]
  node_pos["POS<br/>sales screen<br/>[POS.tsx]"]
  node_orders["Orders<br/>ops screen<br/>[Orders.tsx]"]
  node_kitchen["Kitchen<br/>ops screen<br/>[Kitchen.tsx]"]
  node_products["Products<br/>catalog screen<br/>[Products.tsx]"]
  node_inventory["Inventory<br/>stock screen<br/>[Inventory.tsx]"]
  node_admin["Admin<br/>[AdminPanel.tsx]"]
end

subgraph group_backend["Edge Backend"]
  node_backend_entry(("Edge Entry<br/>function wrapper<br/>[index.ts]"))
  node_server_core["Server Core<br/>shared server<br/>[app.ts]"]
  node_server_routes["Route Modules<br/>domain routes<br/>[auth-routes.ts]"]
  node_branch_scope["Branch Scope<br/>access control<br/>[branch-scope.ts]"]
  node_kv_store[("KV Store<br/>storage adapter<br/>[kv.ts]")]
end

subgraph group_data["Persistence"]
  node_migrations["Migrations<br/>schema ops"]
end

node_src_main -->|"mounts"| node_root
node_root -->|"uses"| node_layout
node_root -->|"delegates"| node_routes
node_routes -->|"renders"| node_app
node_routes -->|"falls back to"| node_notfound
node_app -->|"checks"| node_auth
node_app -->|"navigates"| node_dashboard
node_app -->|"navigates"| node_pos
node_app -->|"navigates"| node_orders
node_app -->|"navigates"| node_kitchen
node_app -->|"navigates"| node_products
node_app -->|"navigates"| node_inventory
node_app -->|"navigates"| node_admin
node_dashboard -->|"subscribes"| node_realtime
node_orders -->|"subscribes"| node_realtime
node_kitchen -->|"subscribes"| node_realtime
node_inventory -->|"subscribes"| node_realtime
node_pos -->|"loads"| node_products
node_pos -->|"depends on"| node_auth
node_products -->|"depends on"| node_auth
node_inventory -->|"depends on"| node_auth
node_admin -->|"depends on"| node_auth
node_backend_entry -->|"boots"| node_server_core
node_server_core -->|"dispatches"| node_server_routes
node_server_routes -->|"enforces"| node_branch_scope
node_server_routes -->|"persists to"| node_kv_store
node_kv_store -.->|"shaped by"| node_migrations

click node_src_main "https://github.com/esangcap/panaderomultibranchesuae/blob/main/src/main.tsx"
click node_root "https://github.com/esangcap/panaderomultibranchesuae/blob/main/src/app/components/Root.tsx"
click node_layout "https://github.com/esangcap/panaderomultibranchesuae/blob/main/src/app/components/Layout.tsx"
click node_routes "https://github.com/esangcap/panaderomultibranchesuae/blob/main/src/app/routes.ts"
click node_app "https://github.com/esangcap/panaderomultibranchesuae/blob/main/src/app/App.tsx"
click node_notfound "https://github.com/esangcap/panaderomultibranchesuae/blob/main/src/app/components/NotFound.tsx"
click node_auth "https://github.com/esangcap/panaderomultibranchesuae/blob/main/src/app/lib/auth.tsx"
click node_realtime "https://github.com/esangcap/panaderomultibranchesuae/blob/main/src/app/lib/realtime.tsx"
click node_dashboard "https://github.com/esangcap/panaderomultibranchesuae/blob/main/src/app/components/dashboard/Dashboard.tsx"
click node_pos "https://github.com/esangcap/panaderomultibranchesuae/blob/main/src/app/components/pos/POS.tsx"
click node_orders "https://github.com/esangcap/panaderomultibranchesuae/blob/main/src/app/components/orders/Orders.tsx"
click node_kitchen "https://github.com/esangcap/panaderomultibranchesuae/blob/main/src/app/components/kitchen/Kitchen.tsx"
click node_products "https://github.com/esangcap/panaderomultibranchesuae/blob/main/src/app/components/products/Products.tsx"
click node_inventory "https://github.com/esangcap/panaderomultibranchesuae/blob/main/src/app/components/inventory/Inventory.tsx"
click node_admin "https://github.com/esangcap/panaderomultibranchesuae/blob/main/src/app/components/admin/AdminPanel.tsx"
click node_backend_entry "https://github.com/esangcap/panaderomultibranchesuae/blob/main/supabase/functions/make-server-6e9ea444/index.ts"
click node_server_core "https://github.com/esangcap/panaderomultibranchesuae/blob/main/supabase/functions/_shared/panadero-server/app.ts"
click node_server_routes "https://github.com/esangcap/panaderomultibranchesuae/blob/main/supabase/functions/_shared/panadero-server/auth-routes.ts"
click node_branch_scope "https://github.com/esangcap/panaderomultibranchesuae/blob/main/supabase/functions/_shared/panadero-server/branch-scope.ts"
click node_kv_store "https://github.com/esangcap/panaderomultibranchesuae/blob/main/supabase/functions/_shared/panadero-server/kv.ts"
click node_migrations "https://github.com/esangcap/panaderomultibranchesuae/blob/main/supabase/migrations/20260408213000_split_panadero_kv_domains.sql"

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_src_main,node_root,node_layout,node_routes,node_app,node_notfound,node_auth,node_realtime,node_dashboard,node_pos,node_orders,node_kitchen,node_products,node_inventory,node_admin toneBlue
class node_backend_entry,node_server_core,node_server_routes,node_branch_scope,node_kv_store toneAmber
class node_migrations toneMint
```

## Components

### Frontend SPA

React/TypeScript app shell, routing, auth, and business screens

- [Entry](https://github.com/esangcap/panaderomultibranchesuae/blob/main/src/main.tsx): react entry · Bootstraps the SPA · `src/main.tsx`
- [Root](https://github.com/esangcap/panaderomultibranchesuae/blob/main/src/app/components/Root.tsx): app shell · Top-level app provider and shell · `src/app/components/Root.tsx`
- [Layout](https://github.com/esangcap/panaderomultibranchesuae/blob/main/src/app/components/Layout.tsx): shell layout · Shared app chrome and navigation frame · `src/app/components/Layout.tsx`
- [Routes](https://github.com/esangcap/panaderomultibranchesuae/blob/main/src/app/routes.ts): route map · Selects domain screens and fallback paths · `src/app/routes.ts`
- [App](https://github.com/esangcap/panaderomultibranchesuae/blob/main/src/app/App.tsx): top navigation · Main application composition · `src/app/App.tsx`
- [Not Found](https://github.com/esangcap/panaderomultibranchesuae/blob/main/src/app/components/NotFound.tsx): fallback view · Fallback route for unknown paths · `src/app/components/NotFound.tsx`
- [Auth](https://github.com/esangcap/panaderomultibranchesuae/blob/main/src/app/lib/auth.tsx): session layer · Login, signup, and password management · `src/app/lib/auth.tsx`
- [Realtime](https://github.com/esangcap/panaderomultibranchesuae/blob/main/src/app/lib/realtime.tsx): live updates · Live operational data subscriptions · `src/app/lib/realtime.tsx`
- [Dashboard](https://github.com/esangcap/panaderomultibranchesuae/blob/main/src/app/components/dashboard/Dashboard.tsx): ops screen · Branch-aware operational overview · `src/app/components/dashboard/Dashboard.tsx`
- [POS](https://github.com/esangcap/panaderomultibranchesuae/blob/main/src/app/components/pos/POS.tsx): sales screen · Point-of-sale workflow · `src/app/components/pos/POS.tsx`
- [Orders](https://github.com/esangcap/panaderomultibranchesuae/blob/main/src/app/components/orders/Orders.tsx): ops screen · Order monitoring and fulfillment · `src/app/components/orders/Orders.tsx`
- [Kitchen](https://github.com/esangcap/panaderomultibranchesuae/blob/main/src/app/components/kitchen/Kitchen.tsx): ops screen · Kitchen execution and status · `src/app/components/kitchen/Kitchen.tsx`
- [Products](https://github.com/esangcap/panaderomultibranchesuae/blob/main/src/app/components/products/Products.tsx): catalog screen · Product management and stock edits · `src/app/components/products/Products.tsx`
- [Inventory](https://github.com/esangcap/panaderomultibranchesuae/blob/main/src/app/components/inventory/Inventory.tsx): stock screen · Ingredients, recipes, alerts, and history · `src/app/components/inventory/Inventory.tsx`
- [Admin](https://github.com/esangcap/panaderomultibranchesuae/blob/main/src/app/components/admin/AdminPanel.tsx): admin screen · Branch, user, and transfer management · `src/app/components/admin/AdminPanel.tsx`

### Edge Backend

Supabase Edge Functions and shared server logic

- [Edge Entry](https://github.com/esangcap/panaderomultibranchesuae/blob/main/supabase/functions/make-server-6e9ea444/index.ts): function wrapper · Deployment wrapper for the server runtime · `supabase/functions/make-server-6e9ea444/index.ts`
- [Server Core](https://github.com/esangcap/panaderomultibranchesuae/blob/main/supabase/functions/_shared/panadero-server/app.ts): shared server · Central Supabase server implementation · `supabase/functions/_shared/panadero-server/app.ts`
- [Route Modules](https://github.com/esangcap/panaderomultibranchesuae/blob/main/supabase/functions/_shared/panadero-server/auth-routes.ts): domain routes · Auth, branch, product, stock, order, and transfer handlers · `supabase/functions/_shared/panadero-server/auth-routes.ts`
- [Branch Scope](https://github.com/esangcap/panaderomultibranchesuae/blob/main/supabase/functions/_shared/panadero-server/branch-scope.ts): access control · Branch-aware authorization and scoping · `supabase/functions/_shared/panadero-server/branch-scope.ts`
- [KV Store](https://github.com/esangcap/panaderomultibranchesuae/blob/main/supabase/functions/_shared/panadero-server/kv.ts): storage adapter · Key/value persistence abstraction · `supabase/functions/_shared/panadero-server/kv.ts`

### Persistence

KV-backed storage and schema migration layer

- [Migrations](https://github.com/esangcap/panaderomultibranchesuae/blob/main/supabase/migrations/20260408213000_split_panadero_kv_domains.sql): schema ops · KV storage optimization and domain split · `supabase/migrations/20260408213000_split_panadero_kv_domains.sql`

## Connections

- Entry → Root: mounts · Bootstraps the application shell
- Root → Layout: uses · Provides the shared page frame
- Root → Routes: delegates · Hands off route selection
- Routes → App: renders · Resolves the primary app composition
- Routes → Not Found: falls back to · Handles unknown paths
- App → Auth: checks · Requires session and login state
- App → Dashboard: navigates · Opens the operations overview
- App → POS: navigates · Opens sales workflow
- App → Orders: navigates · Opens order management
- App → Kitchen: navigates · Opens kitchen workflow
- App → Products: navigates · Opens catalog management
- App → Inventory: navigates · Opens stock and recipes
- App → Admin: navigates · Opens branch and user admin
- Dashboard → Realtime: subscribes · Consumes live operational updates
- Orders → Realtime: subscribes · Tracks order status changes
- Kitchen → Realtime: subscribes · Tracks fulfillment changes
- Inventory → Realtime: subscribes · Tracks stock and log updates
- POS → Products: loads · Uses catalog data for selling
- POS → Auth: depends on · Requires signed-in staff context
- Products → Auth: depends on · Uses authenticated data access
- Inventory → Auth: depends on · Uses authenticated data access
- Admin → Auth: depends on · Restricts management actions
- Edge Entry → Server Core: boots · Loads the shared server runtime
- Server Core → Route Modules: dispatches · Routes requests by business capability
- Route Modules → Branch Scope: enforces · Applies branch-aware access rules
- Route Modules → KV Store: persists to · Reads and writes operational state
- KV Store → Migrations: shaped by · Storage layout evolved through migrations
