How hectordev2/corrales-web works
1. High-level shape
- This is a Next.js 16 App Router application for a restaurant business, split into three user-facing areas: public customer site, admin panel, and delivery panel.
- The main runtime is the browser + Next.js server, with most persistent data stored in Supabase.
2. Route architecture
- The src/app tree is organized by route groups:
- /(public) for the customer-facing site: home, menu, checkout, reservas, nosotros.
- /(admin)/admin for management screens, including product CRUD.
- /(delivery)/delivery for courier order handling.
- /login for authentication.
- /api/payment/charge for payment processing.
- Each route group has its own layout, which is a clean boundary for shared navigation and page chrome.
3. Primary backend dependency: Supabase
- Supabase provides PostgreSQL, Auth, Storage, and Realtime.
- The app relies on Supabase for:
- product catalog and variants,
- orders and order status,
- reservations,
- user profiles and roles,
- product image storage,
- realtime updates for the admin order view.
- The repo includes SQL migrations under supabase/migrations, so the database schema and policies are part of the application architecture, not an external afterthought.
4. Authentication and authorization boundary
- Access control is role-based: public, admin, and delivery.
- The README says roles are enforced with Supabase RLS using a DB function like current_user_role().
- src/middleware.ts likely adds route protection at the Next.js edge/server boundary, while the database enforces the real security rules.
- This means the auth model is layered: UI routing + middleware + database policies.
5. Data access layer
- src/lib/api/* is the main application data boundary.
- The modules are separated by domain:
- products.ts for catalog CRUD and image upload,
- orders.ts for order creation,
- admin.ts for admin operations like assignments and order updates,
- reservations.ts for booking records,
- delivery.ts for courier-related queries/actions.
- This layer isolates Supabase calls from UI components, which is the main backend-facing abstraction in the repo.
6. Customer ordering flow
- The public menu page fetches products and variants, displays them in cards, and lets users add items to a cart.
- Cart state is held in Zustand (src/store/cart.ts) rather than in the database, so the cart is a client-side session state boundary.
- Checkout combines cart contents with customer details and delivery/recojo choice, then sends an order through the application’s order layer.
- Payment is integrated with Culqi, with a dedicated API route for the charge/webhook path.
7. Admin operations flow
- The admin area is centered on operational management of orders and products.
- Order management is realtime-driven, using Supabase Realtime to update active orders without manual refresh.
- Admin actions include changing order status, assigning delivery staff, canceling orders, and viewing daily stats.
- Product management includes create/edit/soft-delete, variant management, and image upload to Supabase Storage.
8. Delivery workflow
- The delivery panel is a separate route group, focused on orders assigned to the authenticated courier.
- The presence of a “self-assign” migration indicates delivery users can take ownership of orders through database-backed workflow rules.
- This is a distinct operational view over the same order data, not a separate subsystem or database.
9. Content and media storage
- Product photos live in a public Supabase Storage bucket named product-images.
- The admin product editor supports preview before upload and image replacement, so the storage bucket is part of the catalog management path.
- Because images are public, the menu UI can render them without auth, while write access remains restricted by storage policies.
10. Forms and validation
- Form-heavy flows use react-hook-form plus Zod schemas.
- The important validated forms are checkout and reservation, and likely the admin product form as well.
- This creates a clear boundary between UI input handling and domain validation.
11. Shared UI and presentation layers
- Reusable components are grouped by domain under src/components/*, with shared layout pieces in components/layout.
- The app uses Tailwind CSS v4 and Material Symbols, so most visual structure is component-driven rather than CSS-module driven.
- Common shell elements like header, bottom navigation, cart button, and mobile menu are shared across public pages.
12. Database-centric business logic
- The migrations show that important workflows are implemented in SQL, including seed data, order creation RPCs, delivery assignment, and storage/RLS setup.
- That means some critical business rules live in the database layer rather than in Next.js code, which matters for any architecture diagram.
- The generated database.types.ts indicates the frontend is typed directly against the Supabase schema.
13. Operational concerns
- The project includes PWA support via next-pwa, so the public experience is designed to be installable/offline-friendly to some extent.
- vitest setup suggests the repo has room for unit tests around the data layer and UI behavior, though the README notes tests are still a future improvement.
- Tooling like ESLint, Prettier, and TypeScript define a strongly typed frontend codebase with standard Next.js build/runtime behavior.
14. Core system diagram to keep in mind
- The main interaction loop is:
- browser UI → Next.js pages/components → Supabase data layer,
- browser UI → cart state in Zustand → checkout/order submission,
- admin/delivery UI → Supabase Realtime / RLS-protected operations,
- checkout/payment path → Next.js API route → Culqi.
- In short: Next.js is the orchestration layer; Supabase is the system of record; Culqi is the payment provider; Zustand is only local session state.
Main entry points: supabase-server.ts Supabase client · (public) Public site · layout.tsx Root layout · orders.ts Orders API
Components 26
App routes
Next.js App Router entrypoints and route groups
- Root layout · Global app shell and shared metadata/styles
src/app/layout.tsx - Public site · Customer-facing pages for home, menu, checkout, reservations, and about
src/app/(public) - Admin area · Management screens under the admin route group
src/app/(admin) - Delivery area · Courier workflow screens under the delivery route group
src/app/(delivery) - Login · Authentication entry point
src/app/login/page.tsx - Charge API · Server endpoint for payment processing
src/app/api/payment/charge/route.ts
Shared UI
Reusable presentation components and page shells
- Site chrome · Shared header, bottom nav, cart button, and mobile menu
src/components/layout
Feature flows
Customer, admin, and delivery experiences
- Home view · Hero and landing content for the public site
src/components/home - Menu view · Product browsing and add-to-cart experience
src/components/menu - Checkout flow · Cart review and customer checkout submission
src/components/checkout - Reservations · Reservation entry and validation flow
src/components/reservas - Admin dashboard · Order management, stats, and product administration
src/components/admin - Delivery view · Assigned-order workflow for delivery staff
src/components/delivery
Data layer
Client/server Supabase access and local state
- Cart store · Client-side cart session state
src/store/cart.ts - User store · Local user/session state used by the app
src/store/user.ts - Products API · Catalog CRUD, variants, and image upload operations
src/lib/api/products.ts - Orders API · Customer order creation and order retrieval
src/lib/api/orders.ts - Admin API · Order status, assignment, and administrative mutations
src/lib/api/admin.ts - Delivery API · Courier-specific order queries and actions
src/lib/api/delivery.ts - Reservations API · Reservation persistence and retrieval
src/lib/api/reservations.ts - Route guard · Edge/server route protection for role-based access
src/middleware.ts
Backend platform
Supabase schema, auth, storage, and payment integration
- Supabase client · Server-side Supabase access wrapper
src/lib/supabase-server.ts - DB types · Typed schema bindings for the frontend
src/types/database.types.ts - Migrations · Database schema, RPCs, RLS policies, triggers, and storage setup
supabase/migrations - Product images · Public product image bucket in Supabase Storage
supabase/migrations/20260409000000_product_images_storage.sql - Culqi · External payment processing provider
Connections 34
- Root layout → Public site: wraps · Global shell contains the public route group
- Root layout → Admin area: wraps · Global shell contains the admin route group
- Root layout → Delivery area: wraps · Global shell contains the delivery route group
- Root layout → Login: renders · Global app shell also serves the login page
- Public site → Home view: hosts · Public pages render the home experience
- Public site → Menu view: hosts · Public pages render the menu/catalog experience
- Public site → Checkout flow: hosts · Public pages render checkout
- Public site → Reservations: hosts · Public pages render reservation booking
- Admin area → Admin dashboard: hosts · Admin route group renders operational screens
- Delivery area → Delivery view: hosts · Delivery route group renders courier screens
- Site chrome → Home view: shared with · Common navigation and page chrome appear across public views
- Site chrome → Menu view: shared with · Common navigation and page chrome appear across public views
- Menu view → Cart store: uses · Menu browsing writes into client cart state
- Checkout flow → Cart store: reads · Checkout consumes the current cart contents
- Checkout flow → Orders API: submits · Checkout creates an order through the order layer
- Reservations → Reservations API: submits · Reservation form persists booking data
- Admin dashboard → Admin API: manages · Admin screens update orders and assignments
- Admin dashboard → Products API: manages · Admin product CRUD goes through the product layer
- Delivery view → Delivery API: queries · Courier view reads assigned orders and updates status
- Login → User store: updates · Login/session state is reflected locally
- Route guard → Admin area: protects · Role-based route protection for admin paths
- Route guard → Delivery area: protects · Role-based route protection for delivery paths
- Products API → Supabase client: calls · Product operations use the server-side Supabase client
- Orders API → Supabase client: calls · Order creation and reads use Supabase
- Admin API → Supabase client: calls · Admin mutations go through Supabase
- Delivery API → Supabase client: calls · Delivery operations go through Supabase
- Reservations API → Supabase client: calls · Reservation persistence uses Supabase
- Supabase client → DB types: typed by · Data access is aligned with generated database types
- Supabase client → Migrations: backed by · Supabase client reads and writes the migrated schema
- Migrations → Product images: defines · Migrations provision public product image storage
- Products API → Product images: uploads · Product images are stored in Supabase Storage
- Orders API → Culqi: charges · Payment flow hands off to Culqi via the charge API
- Charge API → Culqi: integrates · API route mediates payment provider interaction
- Charge API → Orders API: completes · Payment completion is tied to the order workflow