Skip to content

Project Structure

Overview of the UberLotto v2 codebase organization.

Top-Level Directory

uberlotto-v2/
├── app/                        # Application source code
│   ├── routes/                 # File-based route definitions (68 files)
│   ├── components/             # React components (~97 files)
│   │   ├── ui/                 # Shadcn/ui primitives (40 files)
│   │   ├── sections/           # Page section components
│   │   ├── skeletons/          # Loading skeleton components
│   │   ├── shared/             # Shared components
│   │   ├── game-card/          # Game card component variants
│   │   ├── game-detail/        # Game detail page components
│   │   ├── lottery/            # Lottery-specific components
│   │   └── prizes/             # Prize display components
│   ├── lib/                    # Core utilities (30 files)
│   ├── store/                  # Zustand state stores (8 files)
│   ├── hooks/                  # Custom React hooks (13 files)
│   ├── graphql/                # GraphQL queries (3 directories)
│   ├── services/               # Business logic services
│   ├── utils/                  # Utility functions (22 files)
│   ├── styles/                 # CSS/SCSS stylesheets
│   ├── providers/              # React context providers
│   ├── shared-types/           # Shared TypeScript types
│   └── entry.server.tsx        # Server entry for SSR
├── public/                     # Static assets (favicons, PWA icons)
├── supabase/                   # Database migrations
│   └── migrations/             # SQL migration files
├── types/                      # Global TypeScript type declarations
├── server.ts                   # Oxygen worker entry point
├── vite.config.ts              # Vite + Hydrogen + PWA configuration
├── tsconfig.json               # TypeScript configuration with path aliases
├── react-router.config.ts      # React Router configuration
├── eslint.config.js            # ESLint configuration
├── components.json             # Shadcn/ui component configuration
├── package.json                # Dependencies and scripts
└── env.d.ts                    # Environment variable type declarations

app/routes/ — Route Definitions

68 route files using React Router v7 file-based routing with the ($locale). prefix for i18n support.

Naming Convention

Routes follow the pattern ($locale).<path-segments>.tsx:

($locale)._index.tsx              → /           (homepage)
($locale).collections.$handle.tsx → /collections/:handle
($locale).products.$handle.tsx    → /products/:handle
($locale).account._index.tsx      → /account
($locale).account.orders.$id.tsx  → /account/orders/:id
($locale).pages.game-detail.tsx   → /pages/game-detail
  • ($locale) — Optional locale prefix (e.g., /en-US/collections/all)
  • _index — Index route for a parent path
  • $param — Dynamic URL parameter
  • _ prefix — Layout/pathless route (e.g., account_ for auth routes)

Route Categories

CategoryFilesExamples
Pages17pages.games-schedule, pages.past-drawings, pages.how-to-play
Account8account._index, account.orders, account.profile, account.load-credit
API10api.plisio-webhook, api.moonpay-webhook, api.shopify-checkout
Commerce5products.$handle, collections.$handle, cart, discount.$code
Content5blogs._index, blogs.$blogHandle.$articleHandle, policies.$handle
System5[robots.txt], [sitemap.xml], sitemap.$type.$page[.xml], search
Auth3account_.login, account_.logout, account_.authorize

API Routes (No UI)

API routes export action and/or loader functions without React components:

api.plisio-invoice.ts           # Create Plisio crypto invoice
api.plisio-webhook.ts           # Handle Plisio payment webhooks
api.plisio-status.ts            # Check Plisio payment status
api.moonpay-sign.ts             # Sign MoonPay widget URLs
api.moonpay-webhook.ts          # Handle MoonPay payment webhooks
api.shopify-checkout.ts         # Create Shopify checkout cart
api.cleanup-pending-transactions.ts  # Cron: expire stale transactions
api.wallet-transactions.ts      # Wallet transaction queries
api.get-product.$handle.ts      # Fetch product by handle
api.get-product-variants.$handle.ts  # Fetch product variants

app/lib/ — Core Utilities

Central library for framework-level utilities and server-side modules.

FilePurpose
context.tsCreates HydrogenRouterContext with storefront, cart, session
session.tsCookie-based session management
fragments.tsShared GraphQL fragments (header, footer, cart)
i18n.tsInternationalization locale extraction
settings.tsApp-wide settings (collection IDs, display config)
auth.tsAuthentication utilities
redirect.tsRedirect helpers
supabase-client.server.tsCustom fetch-based Supabase client (server-only)
supabase-client.tsSupabase client for non-sensitive operations
plisio.server.tsPlisio API integration (server-only)
rate-limiter.server.tsIP and global rate limiting
replay-protection.server.tsWebhook replay attack prevention
security-logger.server.tsSecurity event logging to Supabase
security-types.tsSecurity event type definitions
webhook-validator.server.tsHMAC signature verification
webhook-extractor.server.tsWebhook payload extraction
webhook-processor.server.tsWebhook processing logic
webhook-utils.server.tsWebhook utility functions
amount-validator.server.tsPayment amount validation
shop-limits.server.tsShop-level quantity limits
cart-limits.tsCart quantity limits
mitt.tsEvent emitter (mitt library wrapper)
favorites-events.tsFavorites event system
layout-context.tsLayout context provider
root-data.tsRoot loader data utilities
search.tsSearch utilities
variants.tsProduct variant utilities
utils.tsGeneral utilities (cn() for class merging)

Server vs Client Convention

Files ending in .server.ts contain server-only code:

typescript
// app/lib/supabase-client.server.ts — NEVER imported by client code
// Contains: SUPABASE_SERVICE_ROLE_KEY usage, direct DB operations

// app/lib/supabase-client.ts — Safe for client import
// Contains: Public anon key operations with RLS protection

WARNING

Importing a .server.ts file from client code will cause a build error. This boundary is enforced by the bundler.

app/store/ — Zustand Stores

Client-side state management using Zustand v5.

StorePurpose
useCartLoadingStore.tsCart loading/updating state
useCartPanelStore.tsCart panel open/close state
useFavoritesStore.tsUser's favorite products
useGlobalStore.tsGlobal app state
useSidebarStore.tsSidebar navigation state
StoreProvider.tsxZustand store context provider
utils.tsStore utility functions

app/hooks/ — Custom Hooks

HookPurpose
useFavorites.tsFavorites CRUD with Shopify metafields
useGameCard.tsGame card data and interactions
useGameCardModal.tsGame card modal state
useInstantCart.tsQuick add-to-cart functionality
useLotteryProducts.tsLottery product data fetching
usePlisioPayment.tsPlisio payment flow management
usePriceAnimation.tsJackpot price animation effects
usePWA.tsPWA install prompt and status
usePWAFallback.tsPWA fallback for unsupported browsers
usePWASplashScreen.tsPWA splash screen management
useQuickView.tsProduct quick view modal
useMinimumLoadingTime.tsEnsures minimum loading indicator display
use-mobile.tsMobile viewport detection

app/graphql/ — GraphQL Queries

Organized by API source:

graphql/
├── customer-account/           # Customer Account API queries
│   ├── CustomerDetailsQuery.ts
│   ├── CustomerOrderQuery.ts
│   ├── CustomerOrdersQuery.ts
│   ├── CustomerAddressMutations.ts
│   ├── CustomerUpdateMutation.ts
│   └── CustomerFavoritesMutation.ts
├── game-detail/                # Game detail page queries
│   └── GameDetailQuery.ts
└── load-credits/               # Credit loading queries
    └── LoadCreditsQuery.ts

TIP

Most Storefront API queries are co-located in route files or in app/lib/fragments.ts. The graphql/ directory is for larger, reusable queries that serve specific features.

app/services/ — Business Logic

ServicePurpose
lottery-product-enrichment.service.tsMatches Shopify products to Supabase jackpot data via custom.game_slug metafield. O(1) slug-based lookup, batch enrichment, deduplication.

app/utils/ — Utility Functions

FilePurpose
jackpot.server.tsFetch jackpot data from Supabase by slug
pastDrawings.server.tsFetch past drawing results from Supabase
shopify-checkout.server.tsCheckout cart creation utilities
validation.server.tsServer-side input validation
calculateNextDrawing.tsNext drawing date calculation
formatJackpotValue.tsJackpot amount formatting
priceCalculations.tsPrice and discount calculations
game-card.tsGame card display utilities
game-logo-mapping.tsGame logo asset mapping
logo-resolver.tsDynamic logo resolution
gameOfTheDay.ts"Game of the Day" selection logic
games.tsGame data utilities
prize-utils.tsPrize tier display utilities
cart/Cart-related utility functions
countries.tsCountry data for address forms
data.tsStatic data constants
dummyData.tsDevelopment placeholder data
browser-detection.tsBrowser/device detection
pwa-helpers.tsPWA utility functions
getUserInitials.tsUser initials from name
debug.tsDevelopment debugging helpers

app/components/ — Component Categories

UI Primitives (components/ui/)

40 Shadcn/ui components configured via components.json (New York style, Lucide icons):

accordion, badge, button, calendar, card, checkbox, dialog, drawer, dropdown-menu, input, pagination, popover, select, separator, sheet, sidebar, skeleton, slider, switch, table, tabs, textarea, toast, tooltip, and more.

Feature Components

ComponentPurpose
GameCard.tsxLottery game card with jackpot display
GamePay.tsxPayment page for game purchases
MoonPayCheckout.tsxMoonPay widget integration
PlisioPaymentModal.tsxPlisio payment modal
LoadCreditPopup.tsxCredit loading amount selector
LoadCreditActions.tsxCredit loading action buttons
Cart.tsx, CartMain.tsx, CartSummary.tsxShopping cart
Favorites.tsx, FavoritesButton.tsxFavorites system
Header.tsx, Footer.tsx, Sidebar.tsxLayout components
InstallPrompt.tsx, PWAProvider.tsxPWA install experience
TransactionHistory.tsxTransaction history display
Search.tsx, SearchResults.tsxSearch functionality

supabase/migrations/ — Database Migrations

SQL migration files for Supabase schema changes. These are applied in order during deployment. See the Database documentation for table schemas.

UberLotto Technical Documentation