# yahya-azeem/protection-valley architecture

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

- Interactive diagram: https://gitdiagram.com/yahya-azeem/protection-valley
- Repository: https://github.com/yahya-azeem/protection-valley

## Overview

1. **Repository shape**
   - This is a monorepo with three major runtime areas: a SvelteKit storefront, a Rust serverless API, and Supabase-backed persistence/migrations.
   - Supporting pieces include deployment automation, data import/seed scripts, and an ERPNext Docker setup.

2. **Frontend: SvelteKit customer and admin experience**
   - The UI lives under `src/` and is organized by routes and reusable components.
   - Primary customer-facing pages include catalog, product detail, home, contact, auth flows, privacy/terms, and checkout-related UI.
   - Admin and wholesale flows are present as first-class routes, not bolted on later.

3. **Client-side UI composition**
   - `src/lib/components` holds the reusable surface area: navbar, footer, product cards, cart sidebar, checkout modal, reviews, search overlay, toast, and optimized image rendering.
   - `src/lib/stores.ts` indicates shared client state for cart/auth/products, so the frontend is not purely server-rendered.
   - `src/lib/config.ts`, `constants.ts`, and `types.ts` centralize design tokens, API configuration, and domain types.

4. **Frontend data fetching boundary**
   - Route-level `+page.ts` and `+page.server.ts` files indicate SvelteKit is used for both client navigation and server-side route loading where needed.
   - The frontend likely reads catalog/auth state from the Rust API and/or Supabase, then hydrates interactive cart, search, and checkout flows on the client.

5. **Backend: Rust API as the domain and integration layer**
   - The `api/` and `backend/` directories together represent the Rust backend.
   - `backend/src/handlers` contains endpoint entry points grouped by domain: auth, admin, checkout, eBay, orders, products, and reviews.
   - `backend/src/services` contains the business logic behind those endpoints, separating transport from domain behavior.

6. **Backend service responsibilities**
   - `auth_service`, `product_service`, `order_service`, `review_service`, `shipping_service`, `email_service`, `ebay_service`, and `erpnext_service` show the backend is doing more than CRUD.
   - This layer coordinates external systems, enforces business rules, and handles workflows like syncing inventory, sending email, and order fulfillment.

7. **Authentication and identity**
   - `backend/src/auth/google_provider.rs` suggests Google-based sign-in is part of the auth subsystem.
   - The presence of `complete-profile`, `forgot-password`, `reset-password`, and `register` routes in the frontend, plus auth handlers in the backend, indicates a multi-step user identity flow with profile completion and password recovery.
   - `supabase` migrations include user-related tables and wholesale users, so identity and role/segment data are stored centrally.

8. **Commerce data model in Supabase**
   - Supabase is the primary persistent store, with migrations for products, seed data, users, wholesale users, wholesale pricing, orders, and order flags/tax fields.
   - `supabase/migrations/20260703140000_secure_rls_policies.sql` shows row-level security is a deliberate boundary, meaning access control is enforced at the database layer as well as in app logic.
   - The schema suggests separate treatment of consumer vs wholesale pricing and order lifecycle state.

9. **Catalog and inventory pipeline**
   - The README explicitly calls out eBay Browse API sync and grouping integration.
   - The Rust `ebay_service` plus `scripts/import-products.mjs`, `generate-catalog.mjs`, `generate-seed-sql.mjs`, and related catalog scripts indicate a data pipeline that transforms product sources into the app’s internal catalog model.
   - Static product images under `static/images/products` support a curated catalog presentation, not just live API rendering.

10. **Order fulfillment and back-office integration**
   - Checkout routes and `checkout_handlers`/`order_service` define the commerce transaction boundary.
   - `shipping_service`, `email_service`, and `erpnext_service` imply order placement triggers downstream fulfillment, notification, and ERP/work-order synchronization.
   - The `docker/` ERPNext files suggest a local or deployable ERPNext companion environment for operations.

11. **Deployment and runtime topology**
   - The project is designed for Vercel deployment: Rust serverless functions on the backend and SvelteKit on the frontend.
   - GitHub Actions workflows include deploy automation and a Supabase keep-alive job, so runtime availability depends on hosted services.
   - `terraform/` suggests infrastructure is codified for at least part of the deployment footprint.

12. **What to show in an architecture diagram**
   - Draw three main zones: browser/SvelteKit UI, Rust API serverless functions, and Supabase database.
   - Add external systems on the side: eBay API, Google auth, email/shipping, and ERPNext.
   - Show the two key data paths: catalog/inventory sync flowing from eBay into Supabase/backend, and checkout/order flow flowing from frontend to Rust services and then to orders/fulfillment systems.

Main entry points: [`supabase/migrations`](https://github.com/yahya-azeem/protection-valley/tree/main/supabase/migrations) (Commerce Schema), [`backend/src/handlers/product_handlers.rs`](https://github.com/yahya-azeem/protection-valley/blob/main/backend/src/handlers/product_handlers.rs) (Commerce Handlers), [`api/index.rs`](https://github.com/yahya-azeem/protection-valley/blob/main/api/index.rs) (API Entry), [`backend/src/services/shipping_service.rs`](https://github.com/yahya-azeem/protection-valley/blob/main/backend/src/services/shipping_service.rs) (Fulfillment Services)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["SvelteKit UI"]
  node_ui_shell["App Shell<br/>sveltekit shell<br/>[+layout.svelte]"]
  node_storefront_routes["Storefront Routes"]
  node_admin_wholesale["Admin & Wholesale<br/>routes"]
  node_ui_components["UI Components<br/>svelte components"]
  node_client_state["Client State<br/>stores/config/types<br/>[stores.ts]"]
  node_route_loaders["Route Loaders<br/>load functions<br/>[+page.ts]"]
end

subgraph group_backend["Rust API"]
  node_api_entry["API Entry<br/>serverless entry<br/>[index.rs]"]
  node_auth_handlers["Auth Handlers<br/>http handlers<br/>[auth_handlers.rs]"]
  node_commerce_handlers["Commerce Handlers<br/>http handlers"]
  node_integration_handlers["Integration Handlers<br/>http handlers<br/>[ebay_handlers.rs]"]
  node_auth_service["Auth Service<br/>domain service<br/>[auth_service.rs]"]
  node_product_service["Product Service<br/>domain service<br/>[product_service.rs]"]
  node_order_service["Order Service<br/>domain service<br/>[order_service.rs]"]
  node_review_service["Review Service<br/>domain service<br/>[review_service.rs]"]
  node_fulfillment_services["Fulfillment Services<br/>integrations"]
  node_ebay_service["eBay Service<br/>integration service<br/>[ebay_service.rs]"]
end

subgraph group_data["Supabase"]
  node_db_schema[("Commerce Schema<br/>sql migrations")]
  node_rls_policies[("RLS Policies<br/>database security")]
  node_seed_data["Seed Data<br/>sql seed<br/>[seed.sql]"]
end

subgraph group_infra["Infra & Ops"]
  node_deploy_automation["Deploy Workflows<br/>ci/cd<br/>[deploy.yml]"]
  node_terraform_stack["Terraform Stack<br/>infra code<br/>[main.tf]"]
  node_erpnext_runtime["ERPNext Runtime<br/>docker setup<br/>[Dockerfile.erpnext]"]
end

subgraph group_external["External Systems"]
  node_ebay_api(("eBay API<br/>external api"))
  node_google_auth(("Google Auth<br/>external identity"))
  node_email_service_ext(("Email Service<br/>external messaging"))
  node_shipping_carrier(("Shipping Carrier<br/>external logistics"))
  node_erpnext_ext(("ERPNext<br/>external erp"))
end

node_ui_shell -->|"navigates"| node_storefront_routes
node_ui_shell -->|"frames"| node_admin_wholesale
node_storefront_routes -->|"composes"| node_ui_components
node_admin_wholesale -->|"composes"| node_ui_components
node_storefront_routes -->|"loads data"| node_route_loaders
node_admin_wholesale -->|"loads data"| node_route_loaders
node_route_loaders -->|"calls"| node_api_entry
node_api_entry -->|"routes to"| node_auth_handlers
node_api_entry -->|"routes to"| node_commerce_handlers
node_api_entry -->|"routes to"| node_integration_handlers
node_auth_handlers -->|"uses"| node_auth_service
node_commerce_handlers -->|"uses"| node_product_service
node_commerce_handlers -->|"uses"| node_order_service
node_commerce_handlers -->|"uses"| node_review_service
node_commerce_handlers -->|"uses"| node_fulfillment_services
node_integration_handlers -->|"uses"| node_ebay_service
node_auth_service -->|"reads/writes"| node_db_schema
node_product_service -->|"reads/writes"| node_db_schema
node_order_service -->|"reads/writes"| node_db_schema
node_review_service -->|"reads/writes"| node_db_schema
node_db_schema -->|"protected by"| node_rls_policies
node_seed_data -->|"populates"| node_db_schema
node_ebay_service -->|"syncs with"| node_ebay_api
node_auth_service -->|"authenticates via"| node_google_auth
node_fulfillment_services -->|"notifies"| node_email_service_ext
node_fulfillment_services -->|"fulfills via"| node_shipping_carrier
node_fulfillment_services -->|"syncs to"| node_erpnext_ext
node_deploy_automation -->|"deploys"| node_api_entry
node_deploy_automation -->|"deploys"| node_ui_shell
node_deploy_automation -->|"migrates"| node_db_schema
node_terraform_stack -->|"provisions"| node_deploy_automation
node_erpnext_runtime -->|"hosts"| node_erpnext_ext
node_integration_handlers -->|"updates"| node_db_schema
node_commerce_handlers -.->|"serves data for"| node_ui_components

click node_ui_shell "https://github.com/yahya-azeem/protection-valley/blob/main/src/routes/+layout.svelte"
click node_storefront_routes "https://github.com/yahya-azeem/protection-valley/tree/main/src/routes"
click node_admin_wholesale "https://github.com/yahya-azeem/protection-valley/tree/main/src/routes/admin"
click node_ui_components "https://github.com/yahya-azeem/protection-valley/tree/main/src/lib/components"
click node_client_state "https://github.com/yahya-azeem/protection-valley/blob/main/src/lib/stores.ts"
click node_route_loaders "https://github.com/yahya-azeem/protection-valley/blob/main/src/routes/catalog/+page.ts"
click node_api_entry "https://github.com/yahya-azeem/protection-valley/blob/main/api/index.rs"
click node_auth_handlers "https://github.com/yahya-azeem/protection-valley/blob/main/backend/src/handlers/auth_handlers.rs"
click node_commerce_handlers "https://github.com/yahya-azeem/protection-valley/blob/main/backend/src/handlers/product_handlers.rs"
click node_integration_handlers "https://github.com/yahya-azeem/protection-valley/blob/main/backend/src/handlers/ebay_handlers.rs"
click node_auth_service "https://github.com/yahya-azeem/protection-valley/blob/main/backend/src/services/auth_service.rs"
click node_product_service "https://github.com/yahya-azeem/protection-valley/blob/main/backend/src/services/product_service.rs"
click node_order_service "https://github.com/yahya-azeem/protection-valley/blob/main/backend/src/services/order_service.rs"
click node_review_service "https://github.com/yahya-azeem/protection-valley/blob/main/backend/src/services/review_service.rs"
click node_fulfillment_services "https://github.com/yahya-azeem/protection-valley/blob/main/backend/src/services/shipping_service.rs"
click node_ebay_service "https://github.com/yahya-azeem/protection-valley/blob/main/backend/src/services/ebay_service.rs"
click node_db_schema "https://github.com/yahya-azeem/protection-valley/tree/main/supabase/migrations"
click node_rls_policies "https://github.com/yahya-azeem/protection-valley/blob/main/supabase/migrations/20260703140000_secure_rls_policies.sql"
click node_seed_data "https://github.com/yahya-azeem/protection-valley/blob/main/supabase/seed.sql"
click node_deploy_automation "https://github.com/yahya-azeem/protection-valley/blob/main/.github/workflows/deploy.yml"
click node_terraform_stack "https://github.com/yahya-azeem/protection-valley/blob/main/terraform/main.tf"
click node_erpnext_runtime "https://github.com/yahya-azeem/protection-valley/blob/main/docker/Dockerfile.erpnext"

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_ui_shell,node_storefront_routes,node_admin_wholesale,node_ui_components,node_client_state,node_route_loaders toneBlue
class node_api_entry,node_auth_handlers,node_commerce_handlers,node_integration_handlers,node_auth_service,node_product_service,node_order_service,node_review_service,node_fulfillment_services,node_ebay_service toneAmber
class node_db_schema,node_rls_policies,node_seed_data toneMint
class node_deploy_automation,node_terraform_stack,node_erpnext_runtime toneRose
class node_ebay_api,node_google_auth,node_email_service_ext,node_shipping_carrier,node_erpnext_ext toneIndigo
```

## Components

### SvelteKit UI

Browser-facing storefront and admin experience.

- [App Shell](https://github.com/yahya-azeem/protection-valley/blob/main/src/routes/+layout.svelte): sveltekit shell · Root layout and shared client navigation for the storefront. · `src/routes/+layout.svelte`
- [Storefront Routes](https://github.com/yahya-azeem/protection-valley/tree/main/src/routes): routes · Customer-facing pages for home, catalog, product, contact, auth, and legal content. · `src/routes`
- [Admin & Wholesale](https://github.com/yahya-azeem/protection-valley/tree/main/src/routes/admin): routes · Admin and wholesale entry points with server-side loading where needed. · `src/routes/admin`
- [UI Components](https://github.com/yahya-azeem/protection-valley/tree/main/src/lib/components): svelte components · Reusable interface pieces like navbar, cart, checkout, search, reviews, and images. · `src/lib/components`
- [Client State](https://github.com/yahya-azeem/protection-valley/blob/main/src/lib/stores.ts): stores/config/types · Shared client-side state plus app constants, config, and domain types. · `src/lib/stores.ts`
- [Route Loaders](https://github.com/yahya-azeem/protection-valley/blob/main/src/routes/catalog/+page.ts): load functions · Page-level client/server loaders for catalog, product, reset-password, and admin flows. · `src/routes/catalog/+page.ts`

### Rust API

Serverless domain and integration layer.

- [API Entry](https://github.com/yahya-azeem/protection-valley/blob/main/api/index.rs): serverless entry · Rust API entrypoint used by the deployment target. · `api/index.rs`
- [Auth Handlers](https://github.com/yahya-azeem/protection-valley/blob/main/backend/src/handlers/auth_handlers.rs): http handlers · Login, register, profile completion, password recovery, and Google sign-in endpoints. · `backend/src/handlers/auth_handlers.rs`
- [Commerce Handlers](https://github.com/yahya-azeem/protection-valley/blob/main/backend/src/handlers/product_handlers.rs): http handlers · Catalog, product, checkout, order, review, and admin endpoints. · `backend/src/handlers/product_handlers.rs`
- [Integration Handlers](https://github.com/yahya-azeem/protection-valley/blob/main/backend/src/handlers/ebay_handlers.rs): http handlers · eBay-facing endpoints for sync and grouping workflows. · `backend/src/handlers/ebay_handlers.rs`
- [Auth Service](https://github.com/yahya-azeem/protection-valley/blob/main/backend/src/services/auth_service.rs): domain service · Authentication and identity business logic, including provider integration. · `backend/src/services/auth_service.rs`
- [Product Service](https://github.com/yahya-azeem/protection-valley/blob/main/backend/src/services/product_service.rs): domain service · Catalog and inventory logic behind storefront and admin product flows. · `backend/src/services/product_service.rs`
- [Order Service](https://github.com/yahya-azeem/protection-valley/blob/main/backend/src/services/order_service.rs): domain service · Checkout and order lifecycle orchestration. · `backend/src/services/order_service.rs`
- [Review Service](https://github.com/yahya-azeem/protection-valley/blob/main/backend/src/services/review_service.rs): domain service · Product review creation and retrieval. · `backend/src/services/review_service.rs`
- [Fulfillment Services](https://github.com/yahya-azeem/protection-valley/blob/main/backend/src/services/shipping_service.rs): integrations · Shipping, email, and ERPNext coordination for downstream order fulfillment. · `backend/src/services/shipping_service.rs`
- [eBay Service](https://github.com/yahya-azeem/protection-valley/blob/main/backend/src/services/ebay_service.rs): integration service · Catalog sync and grouping integration with eBay Browse API. · `backend/src/services/ebay_service.rs`

### Supabase

Database schema, migrations, and seeded commerce data.

- [Commerce Schema](https://github.com/yahya-azeem/protection-valley/tree/main/supabase/migrations): sql migrations · Products, users, wholesale pricing, orders, and order flags/tax fields. · `supabase/migrations`
- [RLS Policies](https://github.com/yahya-azeem/protection-valley/blob/main/supabase/migrations/20260703140000_secure_rls_policies.sql): database security · Row-level security boundary for Supabase access control. · `supabase/migrations/20260703140000_secure_rls_policies.sql`
- [Seed Data](https://github.com/yahya-azeem/protection-valley/blob/main/supabase/seed.sql): sql seed · Initial commerce and catalog seed content. · `supabase/seed.sql`

### Infra & Ops

Deployment automation and companion runtime tooling.

- [Deploy Workflows](https://github.com/yahya-azeem/protection-valley/blob/main/.github/workflows/deploy.yml): ci/cd · GitHub Actions for deployment and Supabase keep-alive automation. · `.github/workflows/deploy.yml`
- [Terraform Stack](https://github.com/yahya-azeem/protection-valley/blob/main/terraform/main.tf): infra code · Infrastructure-as-code for the hosted deployment footprint. · `terraform/main.tf`
- [ERPNext Runtime](https://github.com/yahya-azeem/protection-valley/blob/main/docker/Dockerfile.erpnext): docker setup · Containerized ERPNext companion environment for operations. · `docker/Dockerfile.erpnext`

### External Systems

Third-party services used by the platform.

- **eBay API**: external api · External product and inventory source.
- **Google Auth**: external identity · Third-party sign-in provider used by the auth subsystem.
- **Email Service**: external messaging · Outbound email delivery used for auth and order notifications.
- **Shipping Carrier**: external logistics · Shipping workflow integration used during fulfillment.
- **ERPNext**: external erp · ERP/work-order system synchronized from backend fulfillment workflows.

## Connections

- App Shell → Storefront Routes: navigates · Shared shell frames all customer pages.
- App Shell → Admin & Wholesale: frames · Shared shell also hosts admin and wholesale experiences.
- Storefront Routes → UI Components: composes · Pages build from reusable UI primitives.
- Admin & Wholesale → UI Components: composes · Admin screens reuse the shared component surface.
- Storefront Routes → Route Loaders: loads data · Route pages use SvelteKit load functions for SSR/client data.
- Admin & Wholesale → Route Loaders: loads data · Admin and auth flows rely on server-side page loading.
- Route Loaders → API Entry: calls · Frontend loaders fetch catalog, auth, and checkout data from the API.
- API Entry → Auth Handlers: routes to · API entry dispatches authentication endpoints.
- API Entry → Commerce Handlers: routes to · API entry dispatches commerce and admin endpoints.
- API Entry → Integration Handlers: routes to · API entry dispatches eBay integration endpoints.
- Auth Handlers → Auth Service: uses · Handlers delegate identity logic to the auth service.
- Commerce Handlers → Product Service: uses · Product and catalog endpoints delegate to product logic.
- Commerce Handlers → Order Service: uses · Checkout and order endpoints delegate to order orchestration.
- Commerce Handlers → Review Service: uses · Review endpoints delegate to review logic.
- Commerce Handlers → Fulfillment Services: uses · Order placement triggers shipping, email, and ERPNext coordination.
- Integration Handlers → eBay Service: uses · Integration endpoints delegate to eBay sync logic.
- Auth Service → Commerce Schema: reads/writes · Identity and profile data are persisted in Supabase.
- Product Service → Commerce Schema: reads/writes · Catalog and pricing data live in the commerce schema.
- Order Service → Commerce Schema: reads/writes · Orders and fulfillment flags are stored in Supabase.
- Review Service → Commerce Schema: reads/writes · Reviews are stored alongside product records.
- Commerce Schema → RLS Policies: protected by · Database access is constrained by row-level security.
- Seed Data → Commerce Schema: populates · Seed content initializes the commerce schema.
- eBay Service → eBay API: syncs with · Catalog import and grouping data flow from eBay.
- Auth Service → Google Auth: authenticates via · Google provider supports sign-in and identity linking.
- Fulfillment Services → Email Service: notifies · Backend sends transactional email for checkout and account flows.
- Fulfillment Services → Shipping Carrier: fulfills via · Shipping workflows coordinate with logistics providers.
- Fulfillment Services → ERPNext: syncs to · Orders and back-office updates propagate to ERPNext.
- Deploy Workflows → API Entry: deploys · CI/CD publishes the Rust API runtime.
- Deploy Workflows → App Shell: deploys · CI/CD publishes the SvelteKit frontend.
- Deploy Workflows → Commerce Schema: migrates · Deployment automation coordinates Supabase changes.
- Terraform Stack → Deploy Workflows: provisions · Infrastructure code supports the hosted deployment footprint.
- ERPNext Runtime → ERPNext: hosts · Docker files provide the companion ERPNext environment.
- Integration Handlers → Commerce Schema: updates · eBay sync can update catalog state in the database.
- Commerce Handlers → UI Components: serves data for · Frontend commerce widgets consume API-backed state.
