# dawoodmdbr/tixora architecture

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

- Interactive diagram: https://gitdiagram.com/dawoodmdbr/tixora
- Repository: https://github.com/dawoodmdbr/tixora

## Overview

1. **Overall shape**
   - Tixora is a single-page React storefront with a separate admin area, deployed as a Vite app on Vercel.
   - The browser handles most UI and state, while a small `/api` layer provides server-only operations: order creation, payment verification, geo-based currency detection, and signed image uploads.

2. **Client-side application shell**
   - `src/main.tsx` boots the app, mounts routing, global styling, and Vercel Analytics.
   - `src/App.tsx` defines the route structure and shared layout concerns, with dedicated error and 404 pages for failure boundaries.

3. **Public storefront routes**
   - Route-level pages in `src/pages` cover the customer journey: home, shop, product exploration, wishlist, checkout, login, and about.
   - The homepage is composed from `src/components/home`, while the shop and product interactions rely on reusable UI in `src/components/ui` and `src/components/layout`.

4. **Checkout flow**
   - Checkout is a multi-step wizard split across `src/components/checkout`: information, shipping, payment, review, and progress.
   - The flow culminates in a manual payment handoff, not a gateway integration: customers are shown bank/WhatsApp payment details from `src/lib/payment.ts`, then the order is confirmed through backend order creation and later admin verification.

5. **State management boundaries**
   - Zustand stores in `src/store` hold the main client state: cart, wishlist/UI, currency preference, and admin auth.
   - Cart and currency are persisted in `localStorage`, so the storefront can resume across sessions without requiring server round trips.

6. **Supabase as the primary data layer**
   - Supabase provides both Postgres storage and auth.
   - The browser uses the anon key via `src/lib/supabase.ts`, while serverless functions use the service-role client from `api/_lib/supabaseAdmin.ts`.
   - The critical tables are `products`, `orders`, and `order_items`; product reads/writes and all order persistence ultimately center on these tables.

7. **Product catalog and admin CRUD**
   - Product data is not local mock data; it lives in Supabase and is consumed by storefront listing pages, recommendation widgets, and the admin product management screens.
   - Admin product editing lives under `src/pages/admin` and `src/components/admin`, with product forms and detail modals coordinating CRUD and image management.

8. **Cloudinary image pipeline**
   - Product images are hosted in Cloudinary, not in Supabase.
   - The admin upload flow requests a signed upload payload from `/api/cloudinary-sign.ts`, which keeps Cloudinary secrets server-side while allowing the browser to upload assets directly.

9. **Serverless backend functions**
   - `/api/create-order.ts` creates orders and order items, validates input, applies rate limiting, and sends a confirmation email.
   - `/api/verify-payment.ts` is an admin-only endpoint that marks an order as paid and sends the follow-up verification email.
   - `/api/detect-location.ts` uses Vercel geo/IP headers to choose a default currency.
   - The functions share server-only helpers in `api/_lib`, especially rate limiting and the service-role Supabase client.

10. **Admin access model**
   - Admin routes are protected by `ProtectedRoute` and Supabase auth.
   - There is no public sign-up path in the app; admins are expected to be provisioned manually in Supabase.
   - This means the admin panel is a gated operational interface, not a second public product surface.

11. **Currency and localization behavior**
   - `src/store/currencyStore.ts` drives multi-currency display across the store, supporting several currencies with PKR as the base.
   - Initial currency selection can come from geo-IP detection, with a manual override via the currency selector and persisted user choice afterward.

12. **Data and UX composition**
   - Static category metadata lives in `src/data/categories.ts`, while shared type contracts are centralized in `src/types` and `src/lib/database.types.ts`.
   - Product cards, modals, cart sidebar, navbar, and footer form the reusable shell around route pages, while motion-based effects add presentation polish but do not change the underlying architecture.

13. **Operational boundaries and deployment**
   - `vercel.json` rewrites all non-API requests to `index.html`, which is what enables React Router deep links on refresh.
   - `api/tsconfig.json` is separate from the frontend config because serverless functions run in a Node environment, distinct from the browser bundle.

14. **Security and trust boundaries**
   - The frontend is allowed to talk directly to Supabase only where RLS permits it; order data should not be publicly writable/readable outside the serverless layer.
   - Secrets such as the Supabase service role key, Resend API key, and Cloudinary secret remain server-only, while the public anon key and Cloudinary cloud name are intentionally exposed to the browser.

Main entry points: [`src/pages`](https://github.com/dawoodmdbr/tixora/tree/main/src/pages) (Public pages), [`src/App.tsx`](https://github.com/dawoodmdbr/tixora/blob/main/src/App.tsx) (App shell), [`src/components/admin`](https://github.com/dawoodmdbr/tixora/tree/main/src/components/admin) (Admin UI), [`src/lib/products.ts`](https://github.com/dawoodmdbr/tixora/blob/main/src/lib/products.ts) (Product data)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend app"]
  node_src_main["main<br/>app bootstrap<br/>[main.tsx]"]
  node_src_app["App shell<br/>routing shell<br/>[App.tsx]"]
  node_src_pages_public["Public pages<br/>route pages"]
end

subgraph group_ui["Shared UI"]
  node_src_components_layout["Layout shell<br/>shared layout"]
  node_src_components_home["Home sections<br/>homepage modules"]
  node_src_components_catalog["Catalog UI<br/>storefront components"]
  node_src_components_checkout["Checkout flow<br/>wizard components"]
end

subgraph group_admin["Admin area"]
  node_src_pages_admin["Admin pages<br/>admin routes"]
  node_src_components_admin["Admin UI<br/>admin components"]
end

subgraph group_state["State & data"]
  node_src_store_cart["Cart store<br/>zustand store<br/>[cartStore.ts]"]
  node_src_store_currency["Currency store<br/>zustand store<br/>[currencyStore.ts]"]
  node_src_store_ui["UI store<br/>zustand store<br/>[uiStore.ts]"]
  node_src_store_admin_auth["Admin auth<br/>auth store<br/>[adminAuthStore.ts]"]
  node_src_lib_supabase["Supabase client<br/>browser client<br/>[supabase.ts]"]
  node_src_lib_products["Product data<br/>catalog helpers<br/>[products.ts]"]
  node_src_lib_payment["Payment info<br/>checkout config<br/>[payment.ts]"]
end

subgraph group_server["Serverless API"]
  node_api_create_order["Create order<br/>order function<br/>[create-order.ts]"]
  node_api_verify_payment["Verify payment<br/>admin function<br/>[verify-payment.ts]"]
  node_api_detect_location["Detect location<br/>geo function<br/>[detect-location.ts]"]
  node_api_cloudinary_sign["Cloudinary sign<br/>upload function<br/>[cloudinary-sign.ts]"]
  node_api_lib["API helpers<br/>server helpers"]
end

node_src_main -->|"boots"| node_src_app
node_src_main -->|"initializes"| node_src_store_currency
node_src_app -->|"routes to"| node_src_pages_public
node_src_app -->|"routes to"| node_src_pages_admin
node_src_app -->|"wraps"| node_src_components_layout
node_src_pages_public -->|"uses"| node_src_components_home
node_src_pages_public -->|"uses"| node_src_components_catalog
node_src_pages_public -->|"uses"| node_src_components_checkout
node_src_pages_public -->|"reads/writes"| node_src_store_cart
node_src_pages_public -->|"reads/writes"| node_src_store_currency
node_src_pages_public -->|"reads/writes"| node_src_store_ui
node_src_pages_admin -->|"uses"| node_src_components_admin
node_src_components_admin -->|"checks"| node_src_store_admin_auth
node_src_components_catalog -->|"renders"| node_src_lib_products
node_src_components_home -->|"highlights"| node_src_lib_products
node_src_components_checkout -->|"shows"| node_src_lib_payment
node_src_components_checkout -->|"submits"| node_api_create_order
node_src_components_admin -->|"calls"| node_api_verify_payment
node_src_store_currency -->|"seeds from"| node_api_detect_location
node_src_components_admin -->|"requests"| node_api_cloudinary_sign
node_api_create_order -->|"uses"| node_api_lib
node_api_verify_payment -->|"uses"| node_api_lib
node_api_cloudinary_sign -->|"uses"| node_api_lib
node_src_lib_products -->|"queries"| node_src_lib_supabase
node_src_lib_products -.->|"coordinates with"| node_src_lib_payment
node_src_pages_admin -->|"authenticates"| node_src_lib_supabase

click node_src_main "https://github.com/dawoodmdbr/tixora/blob/main/src/main.tsx"
click node_src_app "https://github.com/dawoodmdbr/tixora/blob/main/src/App.tsx"
click node_src_pages_public "https://github.com/dawoodmdbr/tixora/tree/main/src/pages"
click node_src_pages_admin "https://github.com/dawoodmdbr/tixora/tree/main/src/pages/admin"
click node_src_components_layout "https://github.com/dawoodmdbr/tixora/tree/main/src/components/layout"
click node_src_components_home "https://github.com/dawoodmdbr/tixora/tree/main/src/components/home"
click node_src_components_catalog "https://github.com/dawoodmdbr/tixora/tree/main/src/components/ui"
click node_src_components_checkout "https://github.com/dawoodmdbr/tixora/tree/main/src/components/checkout"
click node_src_components_admin "https://github.com/dawoodmdbr/tixora/tree/main/src/components/admin"
click node_src_store_cart "https://github.com/dawoodmdbr/tixora/blob/main/src/store/cartStore.ts"
click node_src_store_currency "https://github.com/dawoodmdbr/tixora/blob/main/src/store/currencyStore.ts"
click node_src_store_ui "https://github.com/dawoodmdbr/tixora/blob/main/src/store/uiStore.ts"
click node_src_store_admin_auth "https://github.com/dawoodmdbr/tixora/blob/main/src/store/adminAuthStore.ts"
click node_src_lib_supabase "https://github.com/dawoodmdbr/tixora/blob/main/src/lib/supabase.ts"
click node_src_lib_products "https://github.com/dawoodmdbr/tixora/blob/main/src/lib/products.ts"
click node_src_lib_payment "https://github.com/dawoodmdbr/tixora/blob/main/src/lib/payment.ts"
click node_api_create_order "https://github.com/dawoodmdbr/tixora/blob/main/api/create-order.ts"
click node_api_verify_payment "https://github.com/dawoodmdbr/tixora/blob/main/api/verify-payment.ts"
click node_api_detect_location "https://github.com/dawoodmdbr/tixora/blob/main/api/detect-location.ts"
click node_api_cloudinary_sign "https://github.com/dawoodmdbr/tixora/blob/main/api/cloudinary-sign.ts"
click node_api_lib "https://github.com/dawoodmdbr/tixora/tree/main/api/_lib"

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_src_app,node_src_pages_public toneBlue
class node_src_components_layout,node_src_components_home,node_src_components_catalog,node_src_components_checkout toneAmber
class node_src_pages_admin,node_src_components_admin toneMint
class node_src_store_cart,node_src_store_currency,node_src_store_ui,node_src_store_admin_auth,node_src_lib_supabase,node_src_lib_products,node_src_lib_payment toneRose
class node_api_create_order,node_api_verify_payment,node_api_detect_location,node_api_cloudinary_sign,node_api_lib toneIndigo
```

## Components

### Frontend app

React SPA, route shell, and customer-facing pages

- [main](https://github.com/dawoodmdbr/tixora/blob/main/src/main.tsx): app bootstrap · Mounts the React app, router, global styles, and analytics. · `src/main.tsx`
- [App shell](https://github.com/dawoodmdbr/tixora/blob/main/src/App.tsx): routing shell · Defines the route tree, shared layout, and error boundaries. · `src/App.tsx`
- [Public pages](https://github.com/dawoodmdbr/tixora/tree/main/src/pages): route pages · Customer-facing routes for home, shop, product exploration, wishlist, checkout, login, and about. · `src/pages`

### Shared UI

Reusable storefront, checkout, and layout components

- [Layout shell](https://github.com/dawoodmdbr/tixora/tree/main/src/components/layout): shared layout · Navbar, footer, cart sidebar, and policy modal around the storefront. · `src/components/layout`
- [Home sections](https://github.com/dawoodmdbr/tixora/tree/main/src/components/home): homepage modules · Hero, categories, best sellers, ticker, trust badges, and arrivals used on the landing page. · `src/components/home`
- [Catalog UI](https://github.com/dawoodmdbr/tixora/tree/main/src/components/ui): storefront components · Product cards, product modal, currency selector, and cursor/button effects used across browsing. · `src/components/ui`
- [Checkout flow](https://github.com/dawoodmdbr/tixora/tree/main/src/components/checkout): wizard components · Multi-step checkout UI for information, shipping, payment, review, and progress. · `src/components/checkout`

### Admin area

Protected operational screens and admin controls

- [Admin pages](https://github.com/dawoodmdbr/tixora/tree/main/src/pages/admin): admin routes · Protected admin screens for dashboard, analytics, orders, products, and layout. · `src/pages/admin`
- [Admin UI](https://github.com/dawoodmdbr/tixora/tree/main/src/components/admin): admin components · Protected route guard plus product and order modals for CRUD and verification. · `src/components/admin`

### State & data

Client stores, typed models, and catalog/payment helpers

- [Cart store](https://github.com/dawoodmdbr/tixora/blob/main/src/store/cartStore.ts): zustand store · Persistent cart state shared across the storefront. · `src/store/cartStore.ts`
- [Currency store](https://github.com/dawoodmdbr/tixora/blob/main/src/store/currencyStore.ts): zustand store · Manages currency selection, geo-based defaults, and persistence. · `src/store/currencyStore.ts`
- [UI store](https://github.com/dawoodmdbr/tixora/blob/main/src/store/uiStore.ts): zustand store · Holds wishlist and other client UI state. · `src/store/uiStore.ts`
- [Admin auth](https://github.com/dawoodmdbr/tixora/blob/main/src/store/adminAuthStore.ts): auth store · Tracks Supabase-backed admin session state. · `src/store/adminAuthStore.ts`
- [Supabase client](https://github.com/dawoodmdbr/tixora/blob/main/src/lib/supabase.ts): browser client · Public anon-key Supabase access for permitted reads and auth. · `src/lib/supabase.ts`
- [Product data](https://github.com/dawoodmdbr/tixora/blob/main/src/lib/products.ts): catalog helpers · Product and catalog access helpers backed by Supabase and shared types. · `src/lib/products.ts`
- [Payment info](https://github.com/dawoodmdbr/tixora/blob/main/src/lib/payment.ts): checkout config · Bank and WhatsApp payment details shown during manual checkout. · `src/lib/payment.ts`

### Serverless API

Vercel functions and server-only helpers

- [Create order](https://github.com/dawoodmdbr/tixora/blob/main/api/create-order.ts): order function · Validates checkout payloads, rate-limits requests, persists orders, and sends confirmation email. · `api/create-order.ts`
- [Verify payment](https://github.com/dawoodmdbr/tixora/blob/main/api/verify-payment.ts): admin function · Admin-only payment verification that marks orders paid and sends follow-up email. · `api/verify-payment.ts`
- [Detect location](https://github.com/dawoodmdbr/tixora/blob/main/api/detect-location.ts): geo function · Uses Vercel geo/IP headers to choose a default currency. · `api/detect-location.ts`
- [Cloudinary sign](https://github.com/dawoodmdbr/tixora/blob/main/api/cloudinary-sign.ts): upload function · Returns signed upload payloads so the browser can send images directly to Cloudinary. · `api/cloudinary-sign.ts`
- [API helpers](https://github.com/dawoodmdbr/tixora/tree/main/api/_lib): server helpers · Shared rate limiting and service-role Supabase admin client. · `api/_lib`

## Connections

- main → App shell: boots · Entry point mounts the routed application shell.
- main → Currency store: initializes · Currency state is loaded at startup for consistent pricing.
- App shell → Public pages: routes to · App shell exposes the customer-facing routes.
- App shell → Admin pages: routes to · App shell exposes protected admin routes.
- App shell → Layout shell: wraps · Shared layout composes the storefront chrome.
- Public pages → Home sections: uses · Homepage route is built from home sections.
- Public pages → Catalog UI: uses · Shop, wishlist, and product views rely on reusable catalog UI.
- Public pages → Checkout flow: uses · Checkout route assembles the multi-step wizard.
- Public pages → Cart store: reads/writes · Public shopping flows depend on cart state.
- Public pages → Currency store: reads/writes · Price display follows selected currency.
- Public pages → UI store: reads/writes · Wishlist and UI preferences live in client state.
- Admin pages → Admin UI: uses · Admin routes use guarded modals and route protection.
- Admin UI → Admin auth: checks · ProtectedRoute gates access on admin auth state.
- Catalog UI → Product data: renders · Product cards and modals consume catalog data.
- Home sections → Product data: highlights · Landing page sections surface catalog content.
- Checkout flow → Payment info: shows · Payment step presents manual payment instructions.
- Checkout flow → Create order: submits · Checkout finalizes by creating the order server-side.
- Admin UI → Verify payment: calls · Admin verification updates order payment status.
- Currency store → Detect location: seeds from · Initial currency can be inferred from geo/IP lookup.
- Admin UI → Cloudinary sign: requests · Image upload flow fetches signed Cloudinary parameters.
- Create order → API helpers: uses · Order function shares rate limiting and service-role access.
- Verify payment → API helpers: uses · Verification function shares server-only helpers.
- Cloudinary sign → API helpers: uses · Signing endpoint uses server-side Supabase/admin utilities as needed.
- Product data → Supabase client: queries · Catalog helpers read from Supabase.
- Product data → Payment info: coordinates with · Product flows meet checkout/payment presentation.
- Admin pages → Supabase client: authenticates · Admin screens depend on Supabase auth session state.
