How esangcap/panaderomultibranchesuae works
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: App.tsx App · auth.tsx Auth · realtime.tsx Realtime · Root.tsx Root
Components 21
Frontend SPA
React/TypeScript app shell, routing, auth, and business screens
- Entry · Bootstraps the SPA
src/main.tsx - Root · Top-level app provider and shell
src/app/components/Root.tsx - Layout · Shared app chrome and navigation frame
src/app/components/Layout.tsx - Routes · Selects domain screens and fallback paths
src/app/routes.ts - App · Main application composition
src/app/App.tsx - Not Found · Fallback route for unknown paths
src/app/components/NotFound.tsx - Auth · Login, signup, and password management
src/app/lib/auth.tsx - Realtime · Live operational data subscriptions
src/app/lib/realtime.tsx - Dashboard · Branch-aware operational overview
src/app/components/dashboard/Dashboard.tsx - POS · Point-of-sale workflow
src/app/components/pos/POS.tsx - Orders · Order monitoring and fulfillment
src/app/components/orders/Orders.tsx - Kitchen · Kitchen execution and status
src/app/components/kitchen/Kitchen.tsx - Products · Product management and stock edits
src/app/components/products/Products.tsx - Inventory · Ingredients, recipes, alerts, and history
src/app/components/inventory/Inventory.tsx - Admin · Branch, user, and transfer management
src/app/components/admin/AdminPanel.tsx
Edge Backend
Supabase Edge Functions and shared server logic
- Edge Entry · Deployment wrapper for the server runtime
supabase/functions/make-server-6e9ea444/index.ts - Server Core · Central Supabase server implementation
supabase/functions/_shared/panadero-server/app.ts - Route Modules · Auth, branch, product, stock, order, and transfer handlers
supabase/functions/_shared/panadero-server/auth-routes.ts - Branch Scope · Branch-aware authorization and scoping
supabase/functions/_shared/panadero-server/branch-scope.ts - KV Store · Key/value persistence abstraction
supabase/functions/_shared/panadero-server/kv.ts
Persistence
KV-backed storage and schema migration layer
- Migrations · KV storage optimization and domain split
supabase/migrations/20260408213000_split_panadero_kv_domains.sql
Connections 27
- 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