How amalbabu0/ecomerce works
Purpose and Runtime
Pavan Foods is a Phase-1 ecommerce storefront for catalog browsing, authenticated accounts, checkout, operations, and security visibility. It runs on Next.js 16 App Router with TypeScript, deployed to Vercel, backed by Supabase and Razorpay. Root application shell and metadata behavior begin at app/layout.tsx; route access mediation is centralized in proxy.ts.
Route Domains and Entry Points
Public storefront routes cover marketing, category/product discovery, cart, and checkout: app/(marketing)/page.tsx, app/(shop)/products/[slug]/page.tsx, and app/checkout/page.tsx. Authenticated account routes provide profiles, addresses, and order history under app/(account)/account/. Privileged operations are separately mounted at app/admin/layout.tsx and app/developer/layout.tsx, with role enforcement both at routing and server/page boundaries.
Supabase Data, Authentication, and Authorization
Supabase provides Postgres, Auth, Storage, and RLS-controlled API access. Client/server/admin connection boundaries are explicit in lib/supabase/client.ts, lib/supabase/server.ts, and lib/supabase/admin.ts; the latter is service-role-only and therefore reserved for verified server actions. Schema, seed data, database functions, roles, security logs, and storage policies evolve through supabase/migrations/0001_init.sql through supabase/migrations/0010_fix_auth_audit_log_type.sql. Email/password and Google OAuth flows are implemented in features/auth/actions.ts and return through app/api/auth/callback/route.ts.
Catalog and Cart Flow
Server-side catalog queries supply product lists, search, category pages, and PDPs through features/catalog/queries.ts, rendered by routes such as app/(shop)/products/page.tsx. The browser cart is a dedicated client-state boundary in features/cart/store.ts; interaction components such as features/cart/add-to-cart-button.tsx update it, while app/cart/page.tsx presents the current purchase state. Product imagery is served from local public assets and Supabase Storage, with admin uploads targeting the product-images bucket.
Checkout, Order Creation, and Payments
Checkout gathers validated customer/address input in features/checkout/checkout-form.tsx and invokes server-side orchestration in features/checkout/actions.ts. Razorpay server integration and payment-signature verification are isolated in lib/razorpay/server.ts and lib/razorpay/verify.ts. The normal browser verification path is supplemented by Razorpay’s authoritative asynchronous webhook at app/api/razorpay/webhook/route.ts; both paths update payment/order state and record relevant failures. Database-side order creation is established in supabase/migrations/0003_create_order_function.sql.
Administrative Operations
The admin area exposes metrics, order visibility, product creation/deletion, user deletion, and review moderation through app/admin/page.tsx, app/admin/products/new/page.tsx, and features/admin/actions.ts. Admin role originates in immutable-to-users auth.users.app_metadata, is checked from JWT claims, and is revalidated by server actions before service-role operations. Product creation accepts native FormData, validates uploaded file type/size server-side, writes product records, then uploads images; upload failure does not roll back the product.
Security and Developer Observability
Observed security events are logged by server code using lib/security-log.ts: failed authentication, failed checkout verification, and malformed/invalid Razorpay webhooks. Developer-only views in app/developer/page.tsx and app/developer/auth-log/page.tsx query event data and Supabase Auth audit records. The audit log crosses the otherwise protected auth schema through a security-definer database function introduced in supabase/migrations/0008_developer_security_logs.sql; it is not a client-exposed table.
Main entry points: page.tsx Storefront routes · actions.ts Checkout orchestration · admin.ts Supabase connections · security-log.ts Security event log
Components 19
Next.js Web
App Router routes, proxy, and server-side features.
- App shell
app/layout.tsx - Route access proxy · Centralizes route access mediation.
proxy.ts - Storefront routes · Marketing, product discovery, cart, and checkout entry points.
app/(marketing)/page.tsx - Catalog queries · Supplies lists, search, categories, and product pages.
features/catalog/queries.ts - Browser cart · Dedicated client-side purchase state.
features/cart/store.ts - Checkout orchestration · Validates checkout input and creates payment flow.
features/checkout/actions.ts - Auth flows · Email/password and Google OAuth flows.
features/auth/actions.ts - OAuth callback
app/api/auth/callback/route.ts
Supabase
Auth, Postgres, Storage, RLS, and database functions.
- Supabase connections · Service-role access is reserved for verified server operations.
lib/supabase/admin.ts - Supabase platform · Primary data, identity, storage, and policy boundary.
- Schema and DB functions · Defines policies, roles, order creation, and secure audit access.
supabase/migrations/0003_create_order_function.sql - Product images bucket · Stores admin-uploaded product imagery.
Payments
Checkout payment creation and verification.
- Razorpay server API · Creates Razorpay payment operations server-side.
lib/razorpay/server.ts - Payment verification · Verifies browser payment signatures.
lib/razorpay/verify.ts - Razorpay webhook · Authoritative asynchronous payment updates.
app/api/razorpay/webhook/route.ts
Privileged Areas
Role-protected administration and developer visibility.
- Admin operations · Manages metrics, orders, products, users, and reviews.
app/admin/layout.tsx - Admin actions · Revalidates admin role before service-role operations.
features/admin/actions.ts - Security event log · Records auth, checkout verification, and webhook failures.
lib/security-log.ts - Developer observability · Displays security events and Auth audit records.
app/developer/auth-log/page.tsx
Connections 25
- App shell → Storefront routes
- Route access proxy → Storefront routes: mediates access
- Route access proxy → Admin operations: enforces route role
- Route access proxy → Developer observability: enforces route role
- Storefront routes → Catalog queries: renders catalog
- Storefront routes → Browser cart: updates cart
- Storefront routes → Checkout orchestration: submits checkout
- Auth flows → OAuth callback: OAuth return
- Auth flows → Supabase connections: uses auth adapter
- Catalog queries → Supabase connections: server data access
- Supabase connections → Supabase platform: accesses
- Schema and DB functions → Supabase platform: defines
- Checkout orchestration → Razorpay server API: creates payment
- Checkout orchestration → Payment verification: verifies browser result
- Checkout orchestration → Schema and DB functions: creates order
- Payment verification → Supabase platform: updates order state
- Razorpay webhook → Supabase platform: authoritative state update
- Payment verification → Security event log: logs failures
- Razorpay webhook → Security event log: logs invalid events
- Admin operations → Admin actions: invokes
- Admin actions → Supabase connections: verified service role
- Admin actions → Product images bucket: uploads images
- Security event log → Supabase platform: persists events
- Developer observability → Security event log: views events
- Developer observability → Schema and DB functions: reads secure audit log