How letsgettechnical/elecretanta works
1. High-level shape
- This is a Next.js App Router application with a mix of server-rendered pages and route handlers under app/.
- The product domain is a Secret Santa / gift exchange platform centered on user profiles, exchange groups, recipient matching, and AI-generated gift ideas.
2. Primary user-facing surfaces
- Public/auth pages live under app/auth, app/page.tsx, and app/gift-exchanges/[id]-style routes.
- Core authenticated flows include:
- onboarding/profile completion
- creating or joining a group
- viewing an exchange dashboard
- editing an exchange
- waiting for matching/suggestions
- reviewing profile and gift exchange details
- The route structure suggests a strongly page-driven app rather than a single SPA shell.
3. Authentication and session boundary
- Auth is built around Supabase Auth with a Google login flow.
- app/auth/callback/route.ts handles the OAuth callback.
- context/AuthContextProvider.tsx and lib/supabase/{client,server,middleware}.ts indicate a split between:
- browser client access
- server-side session-aware access
- middleware enforcement for protected routes
- middleware.ts is the central boundary for guarding authenticated pages and keeping sessions in sync.
4. Domain model and persistence
- The repository defines explicit types in app/types/ for the main entities:
- profile
- giftExchange
- giftExchangeMember
- giftSuggestion
- These types map directly to the core architecture: users have profiles, profiles belong to exchange membership records, exchanges hold budget and state, and suggestions are generated per recipient/exchange.
5. Gift exchange lifecycle
- Exchange CRUD is exposed through app/api/gift-exchanges/route.ts and nested routes under app/api/gift-exchanges/[id]/.
- Important sub-flows:
- manage exchange metadata
- manage members via /members
- trigger a draw via /draw
- fetch suggestions for an exchange via /giftSuggestions
- The page components under app/gift-exchanges/[id]/ mirror those backend capabilities and likely act as the main orchestration layer for the exchange lifecycle.
6. AI gift suggestion pipeline
- AI is not just a UI feature; it has a dedicated backend path:
- lib/generateAndStoreSuggestions.ts
- lib/generateAndUpdateNewGiftSuggestion.ts
- app/api/giftSuggestions/route.ts
- app/api/gift-exchanges/[id]/giftSuggestions/route.ts
- The README and library names indicate suggestions are computed from:
- recipient profile data
- interests/hobbies
- gift preferences
- budget constraints
- “avoid” items
- app/api/openaiConfig/config.ts and OPENAI_API_KEY show OpenAI as the core external inference service.
- There is also a lib/getAmazonImage.ts, suggesting enrichment of suggestions with product imagery or search results.
7. Background/cron processing
- The repo includes a dedicated cron subsystem under app/api/cron/.
- It is split into small functions:
- checkAuthorization
- fetchGiftExchanges
- processGiftExchanges
- This implies a scheduled job flow where Vercel or an external scheduler hits /api/cron, the request is authorized, active exchanges are fetched, and pending exchanges are processed in batch.
- This is the main asynchronous backend path separate from user-triggered interactions.
8. Profile and media handling
- Profile management has both page and API layers:
- app/profile/[id]/page.tsx
- app/api/profile/route.ts
- app/api/profile/[id]/route.ts
- app/api/getUserAvatar/route.ts and lib/getUserAvatar.ts indicate external avatar retrieval or profile-image lookup.
- Onboarding includes a dedicated form flow under app/onboarding/onboarding-form, and the README notes users can provide preferences via text or image, so profile capture is part structured form, part media-assisted input.
9. UI composition and design system
- The components/ directory is a broad reusable component system, heavily aligned with shadcn/ui / Radix-style primitives and Tailwind styling.
- Higher-level domain components exist alongside primitives:
- GiftExchangeHeader
- GroupCard
- InviteCard
- MembersList
- GiftSuggestionCard
- CompletedExchangeCard
- ProfileCard
- This separation suggests the UI is composed from a shared primitive layer plus domain-specific screens rather than page-local ad hoc components.
10. State, feedback, and client-side UX
- There is local client state support via hooks/useLocalStorage.ts and a toast system under components/Toast*, components/Toaster, and hooks/use-toast.ts.
- Loading and waiting states are explicitly modeled with components like:
- LoadingCard
- LoadingSkeleton
- LoadingSpinner
- GlobalGiftSpinner
- WaitingForSuggestions
- This matters architecturally because the exchange/suggestion flow appears asynchronous and the UI is built to handle in-progress states cleanly.
11. Infrastructure and runtime dependencies
- Supabase is the persistence/auth backbone.
- OpenAI provides AI suggestion generation.
- Google credentials in the README suggest external Google services are used for login and/or image/search-related functionality.
- The app is designed for Vercel deployment, reinforced by vercel.json and the cron route pattern.
12. Quality gates and development tooling
- The repo uses Jest for unit/component tests and Playwright for browser automation.
- Storybook is present for isolated UI development.
- ESLint, Prettier, Tailwind, and TypeScript define the front-end engineering baseline.
- This indicates the project is component-heavy and UI correctness is a major concern, alongside domain logic in the gift-exchange backend.
13. Key architectural boundaries to draw
- A good diagram should separate:
- browser/UI pages and reusable components
- auth/session middleware
- Supabase-backed data access
- AI suggestion generation
- scheduled cron processing
- The main data flow is: user auth → profile onboarding → exchange creation/joining → draw/matching → suggestion generation → recipient/member views, with cron jobs handling deferred processing in the background.
Main entry points: generateAndStoreSuggestions.ts Suggestion Engine · [id]/route.ts Exchange Actions · server.ts Supabase Server · cron/route.ts Cron Job
Components 25
Public & Auth
Entry pages and authentication flow.
- Home · App entry and public landing route.
app/page.tsx - Login · Sign-in surface for authenticated access.
app/auth/login/page.tsx - OAuth Callback · Supabase Google OAuth callback handler.
app/auth/callback/route.ts
Core App
Authenticated product surfaces for onboarding, dashboard, profiles, and exchanges.
- Onboarding · Profile completion and preference capture flow.
app/onboarding/page.tsx - Dashboard · Authenticated landing area for current exchanges and actions.
app/dashboard/page.tsx - Create Group · Flow for creating a new gift exchange group.
app/create-group-page/page.tsx - Exchange View · Main gift exchange detail and orchestration page.
app/gift-exchanges/[id]/page.tsx - Edit Exchange · Editing surface for exchange metadata and members.
app/gift-exchanges/[id]/edit/page.tsx - Profile View · Public or member profile view by id.
app/profile/[id]/page.tsx
API Backend
Route handlers for persistence, exchange orchestration, and async processing.
- Exchange API · CRUD and member management for gift exchanges.
app/api/gift-exchanges/route.ts - Exchange Actions · Per-exchange draw, member, and suggestion route handlers.
app/api/gift-exchanges/[id]/route.ts - Profile API · Profile lookup and update handlers.
app/api/profile/route.ts - Suggestions API · Endpoints for generating and reading gift suggestions.
app/api/giftSuggestions/route.ts - Cron Job · Authorized batch processor for active exchanges.
app/api/cron/route.ts
Services & Data
Supabase, AI, and other server-side helpers.
- Supabase Client · Browser-side Supabase access layer.
lib/supabase/client.ts - Supabase Server · Server-side Supabase access for pages and routes.
lib/supabase/server.ts - Route Guard · Session sync and protection boundary for app routes.
middleware.ts - Suggestion Engine · Generates and stores AI gift suggestions.
lib/generateAndStoreSuggestions.ts - Draw Engine · Executes recipient assignment for an exchange.
lib/drawGiftExchange.ts - OpenAI Config · OpenAI API configuration used by suggestion generation.
app/api/openaiConfig/config.ts - Avatar Lookup · Retrieves or resolves user avatar imagery.
lib/getUserAvatar.ts - Amazon Image · Enriches gift ideas with product imagery.
lib/getAmazonImage.ts
Shared UI
Reusable components and client-side state used across pages.
- Auth Context · Browser session state and auth-aware client context.
context/AuthContextProvider.tsx - Shared UI · Reusable primitives and domain-specific UI building blocks.
components/Button/button.tsx - Toast System · Global notification and feedback UI state.
components/Toaster/Toaster.tsx
Connections 29
- Home → Login: start auth · Public users move into the login flow.
- Login → OAuth Callback: oauth · Google/Supabase callback completes sign-in.
- OAuth Callback → Auth Context: session · Established session is consumed by the client auth context.
- Route Guard → Dashboard: protect · Guards authenticated pages and session state.
- Route Guard → Onboarding: protect · Allows or redirects onboarding based on session state.
- Auth Context → Supabase Client: client auth · Browser context wraps client-side Supabase usage.
- Dashboard → Create Group: create · Dashboard links into new exchange creation.
- Dashboard → Exchange View: open · Dashboard navigates to existing exchanges.
- Onboarding → Profile API: save profile · Profile completion persists through profile endpoints.
- Profile View → Profile API: load profile · Profile views fetch profile data from the API.
- Create Group → Exchange API: create exchange · Group creation persists as a gift exchange record.
- Exchange View → Exchange Actions: manage exchange · Exchange detail page drives draw, members, and suggestions.
- Edit Exchange → Exchange Actions: edit members · Edit screen updates exchange state and membership.
- Exchange Actions → Draw Engine: draw · Recipient assignment uses matching logic.
- Exchange Actions → Suggestion Engine: generate · Exchange-specific suggestions are computed on demand.
- Suggestions API → Suggestion Engine: compute · Standalone suggestion endpoints invoke the AI pipeline.
- Suggestion Engine → OpenAI Config: openai · Pipeline is configured by OpenAI credentials and settings.
- Suggestion Engine → Amazon Image: enrich · Gift ideas may be enriched with external product imagery.
- Cron Job → Supabase Server: batch read/write · Cron processing uses server-side data access.
- Cron Job → Suggestion Engine: defer work · Scheduled jobs process pending exchanges and suggestion generation.
- Cron Job → Draw Engine: process draws · Background processing can finalize exchange matching.
- Exchange API → Supabase Server: persist · Exchange CRUD uses server-side Supabase access.
- Profile API → Supabase Server: persist · Profile handlers use server-side Supabase access.
- Exchange Actions → Supabase Server: persist · Per-exchange actions read and write through Supabase.
- Suggestion Engine → Supabase Server: store · Generated suggestions are written back to persistence.
- Shared UI → Exchange View: compose ui · Shared components form the main exchange screens.
- Shared UI → Onboarding: compose ui · Reusable UI powers onboarding forms and selectors.
- Toast System → Shared UI: feedback · Toast primitives are used across the shared component layer.
- Avatar Lookup → Profile View: images · Profile screens can resolve user avatars.