Architecture
A multi-surface Shopify app built on Remix, powered by five extensions, communicating through App Proxy and Session Tokens, backed by Supabase and the EU VIES API.
System Architecture Diagram
End-to-end data flow from Shopify storefront surfaces through authentication layers to backend services and external APIs.
+=====================================================================+ | SHOPIFY ECOSYSTEM | | +-------------------+ +-------------------+ +-----------------+ | | | Cart Page | | Checkout (Plus) | | Thank You Page | | | | App Block | | UI Extension | | UI Extension | | | | App Embed (Drawer) | | (Preact) | | (Preact) | | | +--------+----------+ +--------+----------+ +-------+---------+ | | | | | | | +--------+----------+ +--------+----------+ +-------+---------+ | | | Customer Account | | Shopify Function | | Shopify Admin | | | | UI Extension | | Cart Validation | | Webhooks | | | | (Preact) | | (WASM/JS) | | Admin API | | | +--------+----------+ +-------------------+ +-------+---------+ | +===========|=============================================|===========+ | | | | App Proxy HMAC Session Token JWT Webhook HMAC | | | v v v +=====================================================================+ | VAT VALIDATOR APP (Fly.io) | | | | +-------------------------------------------------------------------+ | | Remix 2.x Framework | | | | | | /api/proxy/* /api/validate /webhooks/* | | | /api/proxy/settings /api/thankyou/* /health | | | /api/proxy/customer /api/account/* /app/* (admin) | | +-------------------------------------------------------------------+ | | Service Layer | | | | | | Format Validator VIES Client Cache Service | | | Abuse Protection Tax Exemption Reverse Charge | | | Order Metafield Customer MF Shop Settings | | | Admin API Retry Stats Service | | +-------------------------------------------------------------------+ +===========|======================|======================|===========+ | | | v v v +-------------------+ +---------------------+ +---------------------+ | Supabase | | VIES API | | Shopify Admin API | | PostgreSQL | | EU VAT Validation | | GraphQL | | Cache + Settings | | HTTP/XML | | Metafields/Tax | | Stats + Logs | | ~100 req/min | | Orders/Customers | +-------------------+ +---------------------+ +---------------------+
Project Structure
A Remix-based monorepo housing the admin app, five Shopify extensions, shared utilities, database migrations, and comprehensive tests.
vat-validator/ ├── app/ # Remix application │ ├── routes/ # API endpoints + Admin pages │ ├── services/ # Business logic (11 services) │ ├── lib/ # Utilities, VIES client, auth │ └── types/ # TypeScript interfaces ├── extensions/ # 5 Shopify extensions │ ├── vat-cart-widget/ # Theme App Extension (App Block + App Embed) │ ├── vat-cart-validation/ # Shopify Function (Cart Validation) │ ├── vat-checkout-ui/ # UI Extension (Plus only, Preact) │ ├── vat-thank-you/ # UI Extension (Preact) │ └── vat-customer-account/# UI Extension (Preact) ├── shared/ # Build-time shared code │ ├── vat-formats.ts # Country regex patterns (27 EU + XI) │ ├── format-validator.ts# Client-side format validation │ └── types.ts # Shared TypeScript types ├── supabase/ # Database │ └── migrations/ # PostgreSQL migration files ├── tests/ # Vitest test suites │ ├── unit/ # Unit tests │ ├── integration/ # Integration tests │ └── e2e/ # End-to-end tests ├── docs/plans/ # Phase plans (29 documents) ├── shopify.app.toml # Shopify app config ├── fly.toml # Fly.io deployment config └── Dockerfile # Container build
Extension Architecture
Five purpose-built extensions cover every customer touchpoint, from cart to post-purchase, using Theme App Extensions, UI Extensions, and a Shopify Function.
blocks/vat-input.liquid
assets/vat-cart.js
assets/vat-drawer.js
locales/en.default.json
src/run.ts
input.graphql
shopify.extension.toml
src/Checkout.tsx
src/components/VatInput.tsx
src/hooks/useVatValidation.ts
src/ThankYou.tsx
src/components/VatPostCheckout.tsx
src/hooks/useOrderVat.ts
src/AccountPage.tsx
src/components/VatProfile.tsx
src/hooks/useCustomerVat.ts
Communication Patterns
Four distinct communication patterns handle authentication and data flow between Shopify surfaces and the VAT Validator backend.
Shared Code Strategy
Extensions cannot import from the app directory. A prebuild script copies shared modules into each extension at build time, ensuring consistent validation logic across all surfaces.
Service Layer
Eleven specialized services handle everything from VAT format validation to tax exemption management, organized by responsibility domain.
API Routes
Nine API endpoints serve the five surfaces and system needs, each with appropriate authentication for its communication pattern.
| Route | Method | Auth | Surface | Description |
|---|---|---|---|---|
/api/proxy/validate |
POST | HMAC | cart | Cart VAT validation |
/api/proxy/customer-vat |
GET | HMAC | cart | Customer VAT auto-populate |
/api/proxy/settings |
GET | HMAC | cart | Widget settings |
/api/validate |
POST | JWT | checkout | Checkout validation |
/api/thankyou/save-vat |
POST | JWT | thank_you | Save VAT to order |
/api/thankyou/check-vat |
GET | JWT | thank_you | Check existing VAT |
/api/account/validate |
POST | JWT | account | Account VAT management |
/webhooks/* |
POST | Webhook | system | Webhook handlers |
/health |
GET | None | system | Health check |
Performance Requirements
Latency targets across all endpoints, with cached responses returning in under 100ms and VIES-dependent calls bounded by upstream API performance.
| Endpoint | P50 | P95 | P99 |
|---|---|---|---|
| App Proxy cached | 80ms | 150ms | 300ms |
| App Proxy VIES | 600ms | 1500ms | 3000ms |
/api/validate cached |
50ms | 100ms | 200ms |
/api/validate VIES |
500ms | 1500ms | 3000ms |
/api/proxy/settings |
30ms | 80ms | 150ms |
| Admin pages | 200ms | 500ms | 1000ms |
Caching Strategy
A three-tier caching architecture minimizes VIES API calls while ensuring validation results stay fresh. Each layer reduces latency and protects against upstream failures.