How goasante/mad-buddy works
Purpose and Runtime
Mad Buddy is a privacy-first social-proximity product: approved friends receive coarse “glow”/nearby signals, never coordinates, distances, maps, or location history. It is a TypeScript Next.js App Router application, deployed with Vercel configuration and backed by Supabase/Postgres/Auth/Storage. Primary public entry is app/page.tsx; application routing begins through app/layout.tsx and route groups.
Identity, Sessions, and Route Boundaries
Supabase authentication supports signup, login, password recovery, OAuth callback, and protected application access. Server/client/admin Supabase clients isolate browser, request-scoped, and privileged database access. Route protection is centralized rather than trusted to UI state.
Paths: app/(auth)/actions.ts, app/auth/callback/route.ts, lib/supabase/server.ts, lib/security/route-protection.ts, proxy.ts.
Product Application Shell and Server Actions
Authenticated social features are grouped under (app), with a shared shell and page-level server-action modules. Pages compose feature components while actions invoke domain services and Supabase; this forms the main browser-to-server mutation boundary. The dashboard is the primary post-login experience.
Paths: app/(app)/layout.tsx, components/app-shell/app-shell.tsx, app/(app)/dashboard/page.tsx, app/(app)/profile-actions.ts.
Profile, Friendship, and Privacy-Safe Proximity
Profiles and relationship state govern who can see social signals. Clients submit location updates through a dedicated API; backend proximity code derives safe nearby results and freshness state, while presentation uses glow indicators. This is the critical privacy boundary: raw location must not cross into frontend responses.
Paths: app/api/location/update/route.ts, app/api/friends/nearby/route.ts, lib/proximity/backend.ts, lib/proximity/nearby-service.ts, components/glow/glow-avatar.tsx.
Social Coordination and Community Features
The application expands proximity into friends, circles/groups, events, plans, hangout sessions, invitations, messages, moments/drops, and safety workflows. Feature-specific service/rules layers encode eligibility, permissions, and state transitions, with corresponding app pages/actions as orchestration surfaces.
Paths: lib/social/plans.ts, lib/events/service.ts, lib/messaging/service.ts, lib/content/service.ts, app/(app)/groups/[id]/page.tsx.
Notifications, Engagement, and Scheduled Work
Notifications include in-app APIs and push subscriptions/preferences; engagement provides buddy score, achievements, rankings, and recaps. A cron endpoint drives the job worker/handlers, with idempotency and job-event schema support; GitHub schedules its tick.
Paths: app/api/cron/tick/route.ts, lib/jobs/worker.ts, lib/jobs/handlers.ts, lib/notifications/server.ts, .github/workflows/cron-tick.yml.
Billing, Administration, and Operational Controls
Paystack initializes checkout and receives signed webhooks to synchronize subscriptions and entitlements; premium-access checks gate paid features. Separate admin-auth/admin routes provide governance, report review, enforcement, audit, user, and billing views. Health/readiness, CSP reporting, rate limiting, and structured logging support operation.
Paths: app/api/paystack/webhook/route.ts, lib/paystack/sync.ts, lib/billing/entitlements.ts, app/(admin)/admin/layout.tsx, lib/admin/governance.ts.
Persistence and Schema Evolution
Supabase migrations are the durable contract for profiles, friendships, subscriptions, location/privacy, social features, messaging/realtime, push, safety, administration, jobs, and RLS. Typed database bindings connect application services to this evolving schema.
Paths: supabase/migrations/20260709100000_initial_schema.sql, supabase/migrations/20260717280000_jobs_idempotency_events.sql, supabase/migrations/20260717300000_realtime_messages.sql, lib/supabase/database.types.ts.
Main entry points: server.ts Supabase access · backend.ts Proximity backend · worker.ts Job worker · plans.ts Social domain services
Components 25
Identity & Access
- Public entry · Primary public landing experience.
app/page.tsx - Auth actions
app/(auth)/actions.ts - OAuth callback
app/auth/callback/route.ts - Route protection · Centralizes protected-route access checks.
lib/security/route-protection.ts - Request proxy
proxy.ts
Social Application
- Authenticated shell
app/(app)/layout.tsx - Dashboard · Primary post-login experience.
app/(app)/dashboard/page.tsx - Profile actions
app/(app)/profile-actions.ts - Social domain services · Plans, events, messaging, and content rules.
lib/social/plans.ts - Group page
app/(app)/groups/[id]/page.tsx
Privacy-Safe Proximity
- Location update · Accepts client location updates.
app/api/location/update/route.ts - Nearby signals API · Returns privacy-safe nearby state only.
app/api/friends/nearby/route.ts - Proximity backend · Derives coarse signals without exposing raw coordinates.
lib/proximity/backend.ts - Nearby service · Computes nearby and freshness state.
lib/proximity/nearby-service.ts - Glow indicator · Presents coarse social proximity.
components/glow/glow-avatar.tsx
Operations & Revenue
- Notifications · In-app and push notification delivery.
lib/notifications/server.ts - Cron tick
app/api/cron/tick/route.ts - Job worker · Runs idempotent scheduled work.
lib/jobs/worker.ts - GitHub schedule · Triggers the cron tick.
.github/workflows/cron-tick.yml - Paystack webhook · Receives signed billing events.
app/api/paystack/webhook/route.ts - Entitlements · Synchronizes subscriptions and gates premium access.
lib/billing/entitlements.ts - Admin governance · Governance, enforcement, audit, and billing controls.
lib/admin/governance.ts
Data Platform
- Supabase access · Request-scoped access to Supabase Auth and Postgres.
lib/supabase/server.ts - Typed database contract
lib/supabase/database.types.ts - Supabase schema & RLS · Durable contract for social, privacy, jobs, and realtime data.
supabase/migrations/20260709100000_initial_schema.sql
Connections 24
- Public entry → Auth actions: signup and login
- Auth actions → Supabase access: auth operations
- OAuth callback → Supabase access: OAuth session
- Request proxy → Route protection: enforces access
- Route protection → Authenticated shell: permits authenticated routes
- Authenticated shell → Dashboard: hosts
- Dashboard → Profile actions: mutations
- Profile actions → Social domain services: orchestrates
- Group page → Social domain services: social state
- Social domain services → Supabase access: persists
- Location update → Proximity backend: raw location
- Proximity backend → Nearby service: derives coarse state
- Nearby signals API → Nearby service: safe results
- Nearby signals API → Glow indicator: glow state
- Proximity backend → Supabase access: stores protected location state
- GitHub schedule → Cron tick: scheduled tick
- Cron tick → Job worker: dispatches
- Job worker → Notifications: notification jobs
- Paystack webhook → Entitlements: subscription events
- Entitlements → Supabase access: syncs entitlements
- Admin governance → Supabase access: governance data
- Supabase access → Typed database contract: typed queries
- Typed database contract → Supabase schema & RLS: matches schema
- Job worker → Supabase schema & RLS: job events