How jayfshrimpton/punttracker works
Purpose and Runtime
Punter’s Journal is a Next.js 14 App Router application for horse-racing bettors to record bets, analyze performance, manage bankroll-related views, and access subscription-gated features. It deploys to Vercel and uses TypeScript, Tailwind, and Recharts. Primary application shell: app/layout.tsx, app/(main)/layout.tsx, and middleware.ts.
User Application and Entry Points
Public entry points include the landing page, authentication, pricing, onboarding, and SEO content pages: app/page.tsx, app/login/page.tsx, app/signup/page.tsx. Auth redirects return through app/auth/callback/page.tsx. Signed-in product routes are grouped under (main), with dashboard, bet management, insights, settings, subscription, and feedback views: app/(main)/dashboard/page.tsx, app/(main)/bets/page.tsx, app/(main)/insights/page.tsx.
Identity, Database, and Authorization Boundary
Supabase supplies Postgres, authentication, and server/client database access. The schema defines core domain tables, RLS policies, and new-user initialization: database-schema.sql. Environment-specific Supabase adapters separate browser, server, privileged service-role, and middleware contexts: lib/supabase/client.ts, lib/supabase/server.ts, lib/supabase/service.ts. API request authentication and protected-feature enforcement are centralized in lib/api-auth.ts and lib/subscription-guard.ts; middleware is the route-level session boundary in middleware.ts.
Bet Lifecycle, Import, and Analytics
The bets API is the core write/read boundary for user betting records: app/api/bets/route.ts. Users can import spreadsheets through a staged parsing/normalization and commit workflow: app/api/bets/import/route.ts, app/api/bets/import/commit/route.ts, lib/bet-import/normalize.ts. Exports are served separately at app/api/bets/export/route.ts. Dashboard and insights consume calculated aggregate statistics via lib/stats.ts, lib/calculations.ts, and analytics endpoints such as app/api/stats/advanced/route.ts and app/api/insights/route.ts; the latter can use Gemini when configured.
Dashboard, Sharing, and Client Presentation
The dashboard assembles user data into summaries, charts, goals, and performance breakdowns: app/(main)/dashboard/page.tsx, components/dashboard/PerformanceCharts.tsx, components/dashboard/InsightsSection.tsx. Shared dashboards use a tokenized server API and a public rendering route, separating private accounts from explicitly shared payloads: app/api/share/create/route.ts, app/api/share/[token]/route.ts, app/share/[token]/page.tsx. Feature visibility is represented in the UI through components/FeatureGate.tsx.
Billing and Subscription State
Stripe checkout, webhook ingestion, and reconciliation govern paid access: app/api/stripe/create-checkout/route.ts, app/api/stripe/webhook/route.ts, lib/stripe/sync-subscription.ts. Subscription eligibility is exposed to the application through app/api/check-subscription/route.ts and enforced server-side by subscription guards. Payments are deliberately controlled by public/server environment flags, allowing deployment with billing disabled.
Administration and Operations
A separate admin route tree and API surface supports user administration, metrics, audit logs, bulk actions, access grants, and outbound email: app/admin/layout.tsx, app/api/admin/users/route.ts, app/api/admin/audit-log/route.ts. Admin authentication is distinct from ordinary user auth: lib/admin-auth.ts. Scheduled Vercel jobs invoke protected cron endpoints for monthly summaries and verification reminders: vercel.json, app/api/cron/monthly-summary/route.ts, app/api/cron/send-verification-reminder/route.ts.
External Messaging and Infrastructure
Resend delivers welcome, summary, administrative, and other transactional emails through lib/resend.ts, lib/email.ts, and app/api/emails/send/route.ts. Cron and server-wide user operations require the Supabase service-role key and CRON_SECRET; these must remain server-only. The production integration boundary is Vercel for deployment/scheduling, Supabase for data/auth, Stripe for payment events, Resend for email, and optionally Gemini for AI-assisted insights.
Main entry points: database-schema.sql Supabase · layout.tsx Protected app shell · route.ts Bets API · page.tsx Bets & insights
Components 21
Web Application
- Public & auth pages · Landing, signup, login, onboarding, and SEO entry points.
app/page.tsx - Protected app shell · Signed-in product route boundary.
app/(main)/layout.tsx - Dashboard · Displays summaries, goals, charts, and performance breakdowns.
app/(main)/dashboard/page.tsx - Bets & insights · Bet management and analysis views.
app/(main)/bets/page.tsx - Feature gate · Represents subscription-based UI visibility.
components/FeatureGate.tsx - Shared dashboard · Renders explicitly shared dashboard payloads.
app/share/[token]/page.tsx - Admin console · Separate administration route tree.
app/admin/layout.tsx
Server APIs
- Session middleware · Route-level Supabase session boundary.
middleware.ts - Bets API · Core read/write boundary for betting records.
app/api/bets/route.ts - Bet import workflow · Stages spreadsheet parsing, normalization, and commit.
app/api/bets/import/route.ts - Stats & insights API · Serves calculated aggregates and AI-assisted insights.
app/api/stats/advanced/route.ts - Sharing API · Creates and retrieves tokenized shared payloads.
app/api/share/create/route.ts - Subscription guard · Central protected-feature enforcement.
lib/subscription-guard.ts - Stripe billing · Checkout creation and webhook ingestion.
app/api/stripe/webhook/route.ts - Admin API · User operations, metrics, audit logs, and access grants.
app/api/admin/users/route.ts - Scheduled jobs · Monthly summaries and verification reminders.
app/api/cron/monthly-summary/route.ts
Connections 25
- Public & auth pages → Session middleware: auth navigation
- Session middleware → Protected app shell: authenticated routes
- Protected app shell → Dashboard: renders
- Protected app shell → Bets & insights: renders
- Protected app shell → Feature gate: uses
- Dashboard → Stats & insights API: loads aggregates
- Bets & insights → Bets API: manages bets
- Bets & insights → Bet import workflow: imports spreadsheet
- Feature gate → Subscription guard: checks eligibility
- Shared dashboard → Sharing API: retrieves token payload
- Session middleware → Supabase: validates session
- Bets API → Subscription guard: protects paid actions
- Bets API → Supabase: reads and writes bets
- Bet import workflow → Bets API: commits normalized bets
- Stats & insights API → Supabase: reads betting data
- Stats & insights API → Gemini: optional insights
- Sharing API → Supabase: stores shared payloads
- Subscription guard → Supabase: reads subscription state
- Stripe billing → Stripe: checkout and webhooks
- Stripe billing → Supabase: reconciles subscription
- Admin console → Admin API: admin operations
- Admin API → Supabase: service-role administration
- Scheduled jobs → Supabase: finds recipients
- Scheduled jobs → Resend: sends scheduled email
- Vercel → Scheduled jobs: scheduled invocation