Architecture Overview
Gully Sports is built with modern web technologies following best practices for performance, scalability, and maintainability.
Tech Stackβ
Frontendβ
- Next.js 15 - React framework with App Router
- React 19 - UI library with Server Components
- TypeScript - Type-safe JavaScript
- Tailwind CSS 4 - Utility-first CSS framework
Backendβ
- Next.js API Routes - Server-side endpoints
- Prisma - Type-safe ORM
- CockroachDB - Distributed SQL database
- Supabase - Authentication & user management
Payment Processingβ
- Intuit QuickBooks Payments - Payment processing & accounting
- Square - Payment processing
Image Storageβ
- Vercel Blob - CDN-backed image storage
Deploymentβ
- Vercel - Hosting & CI/CD (recommended)
- Compatible: Netlify, Railway, DigitalOcean, AWS
Core Architecture Patternsβ
Dual Database Architectureβ
βββββββββββββββββββ ββββββββββββββββββββ
β Supabase β β CockroachDB β
β (Auth Only) β β (App Data) β
βββββββββββββββββββ€ ββββββββββββββββββββ€
β β’ Users (Auth) ββββββββββΆβ β’ Users (Data) β
β β’ Sessions β Sync β β’ Products β
β β’ OAuth β β β’ Bookings β
β β’ Tokens β β β’ Orders β
βββββββββββββββββββ β β’ Lanes β
β β’ Payments β
ββββββββββββββββββββ
Why Dual Database?
- Separation of Concerns: Auth logic separate from business data
- Supabase Strengths: Built-in auth, OAuth providers, email verification
- CockroachDB Strengths: Distributed SQL, high availability, PostgreSQL compatible
- Automatic Sync: User data synchronized between databases
Learn more about Database Setup β
Feature Flag Systemβ
Control major features via environment variables:
// utils/featureFlags.ts
export const ENABLE_LANE_RENTAL =
process.env.NEXT_PUBLIC_ENABLE_LANE_RENTAL === "true";
export const PAYMENT_PROVIDER =
process.env.NEXT_PUBLIC_PAYMENT_PROVIDER || "intuit";
Benefits:
- Toggle features without code changes
- A/B testing capability
- Gradual feature rollout
- Environment-specific features
Learn more about Feature Flags β
Checkout Session Managementβ
Modern session-based checkout with clean URLs:
// utils/checkoutSession.ts
export function createCheckoutSession(
items: CheckoutItem[],
email?: string
): string {
const session = {
sessionId: generateSessionId(),
amount: calculateTotal(items),
items,
email,
expiresAt: Date.now() + 30 * 60 * 1000, // 30 min
};
localStorage.setItem("checkout_session", JSON.stringify(session));
return session.sessionId;
}
Features:
- 30-minute session expiration
- Automatic session extension
- Backward compatible with URL params
- Migration path to backend sessions
Learn more about Checkout Sessions β
Application Layersβ
1. Presentation Layer (UI)β
Location: src/app/ and src/components/
src/
βββ app/
β βββ page.tsx # Homepage
β βββ shop/ # E-commerce
β βββ bookings/ # Lane bookings
β βββ checkout/ # Payment flow
β βββ admin/ # Admin dashboard
βββ components/
βββ Header.tsx # Navigation
βββ Footer.tsx # Site footer
βββ AuthButtons.tsx # Auth UI
2. API Layer (Backend)β
Location: src/app/api/
src/app/api/
βββ products/ # Public product API
βββ bookings/ # Public booking API
βββ payments/ # Payment processing
β βββ submit/
βββ admin/ # Protected admin API
βββ products/
βββ lanes/
βββ upload/
βββ intuit/
3. Business Logic Layerβ
Location: src/utils/
src/utils/
βββ featureFlags.ts # Feature configuration
βββ intuitPayments.ts # Intuit logic
βββ squarePayments.ts # Square logic
βββ checkoutSession.ts # Checkout management
βββ adminAuth.ts # Admin authorization
βββ userSync.ts # Database synchronization
4. Data Layerβ
Location: prisma/
prisma/
βββ schema.prisma # Database schema
βββ migrations/ # Migration history
βββ seed.js # Sample data
Request Flow Examplesβ
User Registrationβ
1. User clicks "Sign Up"
β
2. Supabase Auth (client-side)
β
3. POST /api/auth/callback
β
4. Create User in CockroachDB (server-side)
β
5. Store Supabase ID for mapping
β
6. Redirect to homepage (authenticated)
Product Purchaseβ
1. User adds items to cart (client-side state)
β
2. Click "Checkout"
β
3. Create checkout session (localStorage)
β
4. Navigate to /checkout (clean URL)
β
5. Load payment SDK (Intuit or Square)
β
6. User enters payment details
β
7. SDK tokenizes payment (PCI compliant)
β
8. POST /api/payments/submit with token
β
9. Server processes payment
β
10. Create Order in database
β
11. Clear checkout session
β
12. Redirect to success page
Admin Product Managementβ
1. Admin logs in (Supabase Auth)
β
2. Middleware checks admin role
β
3. Load /admin/inventory
β
4. GET /api/admin/products
β
5. Prisma query to CockroachDB
β
6. Return products with images
β
7. Admin uploads new image
β
8. POST /api/admin/upload (get signed URL)
β
9. Client uploads to Vercel Blob
β
10. POST /api/admin/products/[id]/images
β
11. Save image URL in database
β
12. Display updated product
Security Architectureβ
Authentication Flowβ
ββββββββββββ ββββββββββββββββ βββββββββββββββ
β Client ββββββΆβ Supabase ββββββΆβ Middleware β
β β β Auth β β (Check) β
ββββββββββββ ββββββββββββββββ βββββββββββββββ
β
βΌ
βββββββββββββββββ
β Protected β
β Route β
βββββββββββββββββ
Authorization Layersβ
- Client-Side: UI elements hidden/shown based on auth state
- Middleware: Route protection for admin pages
- API Routes: Server-side role verification
- Database: Row-level security via Prisma queries
Payment Securityβ
- PCI Compliance: Card data never touches server
- Tokenization: Provider SDKs handle sensitive data
- HTTPS Only: All payment requests encrypted
- Idempotency Keys: Prevent duplicate transactions
- Server Validation: Double-check amounts server-side
Performance Optimizationsβ
Frontendβ
- Next.js Image: Automatic optimization, lazy loading
- Code Splitting: Automatic with App Router
- Server Components: Reduced JavaScript bundle
- Caching: Static generation where possible
- Prefetching: Next.js Link prefetching
Backendβ
- Database Indexes: On frequently queried fields
- Prisma Select: Only fetch needed fields
- Connection Pooling: Efficient database connections
- Edge Functions: Vercel Edge for global performance
Imagesβ
- Vercel Blob: CDN-backed storage
- Next.js Image: WebP/AVIF conversion
- Lazy Loading: Load images as they enter viewport
- Responsive Sizes: Serve appropriate image sizes
Scalability Considerationsβ
Horizontal Scalingβ
- Stateless API: No server-side sessions
- Database: CockroachDB scales horizontally
- Images: CDN distribution
- Checkout Sessions: Currently localStorage (migrate to Redis)
Vertical Scalingβ
- Database Connections: Configure connection pool
- API Routes: Serverless auto-scaling
- Caching: Add Redis for sessions/cache
Development Workflowβ
# 1. Clone repository
git clone <repo-url>
cd gully-store-consumer-app
# 2. Install dependencies
npm install
# 3. Set up environment
cp .env.example .env.local
# 4. Initialize database
npx prisma generate
npx prisma db push
# 5. Run development server
npm run dev
# 6. Open browser
http://localhost:3000
Deployment Architectureβ
ββββββββββββββββββββββββββββββββββββββββββββ
β Vercel Edge β
β ββββββββββ ββββββββββ ββββββββββ β
β β Edge 1 β β Edge 2 β β Edge 3 β β
β ββββββββββ ββββββββββ ββββββββββ β
ββββββββββββββββββββββββββββββββββββββββββββ
β
ββββββββββββββββββββββββββββββββββββββββββββ
β Next.js Application β
β βββββββββββββββ ββββββββββββββββ β
β β Frontend β β API Routes β β
β β (React) β β (Serverless) β β
β βββββββββββββββ ββββββββββββββββ β
ββββββββββββββββββββββββββββββββββββββββββββ
β β
ββββββββββββββββ ββββββββββββββββββ
β Vercel Blob β β CockroachDB β
β (Images) β β (Data) β
ββββββββββββββββ ββββββββββββββββββ
β β
ββββββββββββββββ ββββββββββββββββββ
β Supabase β β Payment APIs β
β (Auth) β β (Intuit/Square)β
ββββββββββββββββ ββββββββββββββββββ
Related Documentationβ
- Database Setup Guide β - Learn about CockroachDB and Supabase setup
- Feature Flags β - Understand feature flag configuration
- Payment Integrations β - Intuit and Square payment setup
- Checkout Sessions β - Session management details
- Admin Setup β - Configure admin access and dashboard
Need help with architecture decisions? Open an issue on GitHub or check our documentation sections above.