How yahya-azeem/protection-valley works
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: migrations Commerce Schema · product_handlers.rs Commerce Handlers · index.rs API Entry · shipping_service.rs Fulfillment Services
Components 27
SvelteKit UI
Browser-facing storefront and admin experience.
- App Shell · Root layout and shared client navigation for the storefront.
src/routes/+layout.svelte - Storefront Routes · Customer-facing pages for home, catalog, product, contact, auth, and legal content.
src/routes - Admin & Wholesale · Admin and wholesale entry points with server-side loading where needed.
src/routes/admin - UI Components · Reusable interface pieces like navbar, cart, checkout, search, reviews, and images.
src/lib/components - Client State · Shared client-side state plus app constants, config, and domain types.
src/lib/stores.ts - Route Loaders · 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 · Rust API entrypoint used by the deployment target.
api/index.rs - Auth Handlers · Login, register, profile completion, password recovery, and Google sign-in endpoints.
backend/src/handlers/auth_handlers.rs - Commerce Handlers · Catalog, product, checkout, order, review, and admin endpoints.
backend/src/handlers/product_handlers.rs - Integration Handlers · eBay-facing endpoints for sync and grouping workflows.
backend/src/handlers/ebay_handlers.rs - Auth Service · Authentication and identity business logic, including provider integration.
backend/src/services/auth_service.rs - Product Service · Catalog and inventory logic behind storefront and admin product flows.
backend/src/services/product_service.rs - Order Service · Checkout and order lifecycle orchestration.
backend/src/services/order_service.rs - Review Service · Product review creation and retrieval.
backend/src/services/review_service.rs - Fulfillment Services · Shipping, email, and ERPNext coordination for downstream order fulfillment.
backend/src/services/shipping_service.rs - eBay 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 · Products, users, wholesale pricing, orders, and order flags/tax fields.
supabase/migrations - RLS Policies · Row-level security boundary for Supabase access control.
supabase/migrations/20260703140000_secure_rls_policies.sql - Seed Data · Initial commerce and catalog seed content.
supabase/seed.sql
Infra & Ops
Deployment automation and companion runtime tooling.
- Deploy Workflows · GitHub Actions for deployment and Supabase keep-alive automation.
.github/workflows/deploy.yml - Terraform Stack · Infrastructure-as-code for the hosted deployment footprint.
terraform/main.tf - ERPNext Runtime · Containerized ERPNext companion environment for operations.
docker/Dockerfile.erpnext
External Systems
Third-party services used by the platform.
- eBay API · External product and inventory source.
- Google Auth · Third-party sign-in provider used by the auth subsystem.
- Email Service · Outbound email delivery used for auth and order notifications.
- Shipping Carrier · Shipping workflow integration used during fulfillment.
- ERPNext · ERP/work-order system synchronized from backend fulfillment workflows.
Connections 34
- 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.