# secondsaturday/second-saturday architecture

> Architecture diagram of the GitHub repository secondsaturday/second-saturday, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-08). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/secondsaturday/second-saturday
- Repository: https://github.com/secondsaturday/second-saturday

## Overview

1. **Overall shape**
   - This is a **Next.js 15 App Router frontend** backed by a **Convex serverless backend**, with **Clerk** handling identity and **Capacitor** packaging the same app for iOS and Android.
   - The runtime boundary is split between:
     - `src/` for UI, routing, client-side state, and browser/mobile integration
     - `convex/` for database access, business logic, scheduled jobs, storage, and HTTP/webhook handlers

2. **Primary user-facing flows**
   - The app is organized around a few product domains: **circles**, **submissions**, **newsletters**, **notifications**, and **invites**.
   - Route groups under `src/app/dashboard/...` and `src/app/invite/...` map directly to those workflows, while `src/app/sign-in`, `src/app/sign-up`, and `src/app/complete-profile` cover onboarding and auth completion.

3. **Frontend composition**
   - `src/app/` contains the route-level pages and layouts.
   - `src/components/` holds reusable UI and feature components, with subfolders for `dashboard`, `circles`, `submissions`, `newsletter`, and `auth`.
   - `src/screens/` contains more screen-oriented compositions, such as the multi-circle submission experience.

4. **State and integration boundary in the UI**
   - Client-side behavior is concentrated in `src/hooks/` and `src/providers/`.
   - Providers wire up cross-cutting services such as **PostHog**, **OneSignal**, and **Capacitor**.
   - Hooks manage concerns like auth analytics, upload blocking, countdown timers, timezone sync, media query responsiveness, and debouncing.

5. **Backend architecture**
   - `convex/schema.ts` defines the persistent data model.
   - Feature modules such as `circles.ts`, `memberships.ts`, `submissions.ts`, `newsletters.ts`, `notifications.ts`, `videos.ts`, `files.ts`, `users.ts`, and `prompts.ts` implement the application’s server-side business logic as Convex functions.
   - `convex/_generated/` is the typed client/server interface consumed by the Next.js app.

6. **Data and business flow**
   - The frontend calls Convex queries/mutations/actions to read and modify state.
   - Typical flows are:
     - user authenticates through Clerk
     - app loads profile/circle data from Convex
     - user creates or joins circles, submits content, or reads newsletters
     - Convex persists the change and triggers downstream effects like notifications or emails

7. **Media and video pipeline**
   - Media handling is split across `src/lib/image.ts`, `src/lib/video.ts`, and upload-oriented components like `MediaUploader`.
   - The backend includes dedicated files for `videoActions.ts`, `videos.ts`, and `files.ts`, indicating that media is not just stored in the UI layer but processed through Convex-backed workflows.
   - `test/integration/mux-upload.test.ts` and `test/integration/mux-webhooks.test.ts` show that **Mux** is a core external service for video upload and webhook-driven state updates.

8. **Email and newsletter subsystem**
   - Email generation lives in `src/emails/` and backend delivery logic is in `convex/emails.ts`, `convex/newsletters.ts`, `convex/newsletterEmails.ts`, and `convex/newsletterReads.ts`.
   - This suggests a pipeline where Convex assembles recipient/engagement state, renders email content, and sends via **Resend**.
   - Newsletter reading and engagement are modeled server-side rather than as purely presentational UI.

9. **Notifications and push delivery**
   - Push notification integration spans `src/lib/onesignal.ts`, `src/providers/onesignal-provider.tsx`, and backend modules like `convex/notificationPush.ts` and `convex/notifications.ts`.
   - The architecture likely uses Convex as the source of truth for notification events, with OneSignal as the external delivery channel.

10. **Auth and routing boundaries**
   - Clerk is the identity boundary for both client and server flows.
   - `src/middleware.ts` likely enforces route protection and session-aware redirects.
   - The app has dedicated sign-in/sign-up routes and a `complete-profile` step, implying that authentication and profile completion are intentionally separated.

11. **External webhooks and operational ingress**
   - `src/app/api/webhooks/...` contains Next.js route handlers for **PostHog**, **Sentry**, and **Vercel** webhooks.
   - On the backend side, `convex/http.ts` is the Convex HTTP entrypoint, which is where service webhooks and custom endpoints typically terminate.
   - This creates a clear separation between browser requests and service-to-service callbacks.

12. **Observability**
   - `sentry.client.config.ts`, `sentry.server.config.ts`, and `sentry.edge.config.ts` show Sentry is wired across execution environments.
   - `src/lib/analytics.ts` and the PostHog provider indicate product analytics are a first-class part of the client architecture.
   - `instrumentation.ts` suggests Next.js-level startup instrumentation is also in place.

13. **Mobile packaging**
   - `ios/` and `android/` are native shells around the same web app using **Capacitor**.
   - `capacitor.config.ts` is the bridge between the web build and the native projects.
   - The native projects are thin wrappers: the business logic remains in Next.js/Convex, while mobile-specific setup lives in platform directories.

14. **Testing and delivery pipeline**
   - `test/` contains unit and integration tests around the business domains and integrations, including submissions, newsletters, notifications, auth, and Mux.
   - `e2e/` contains Playwright end-to-end tests for the full user journey.
   - GitHub Actions in `.github/workflows/ci.yml` enforce lint, type check, build, unit, and E2E verification before merge.
   - The repo is therefore architected with strong separation between UI behavior tests, backend integration tests, and full-flow browser tests.

Main entry points: [`src/app`](https://github.com/secondsaturday/second-saturday/tree/main/src/app) (App Router), [`test`](https://github.com/secondsaturday/second-saturday/tree/main/test) (Tests), [`src/app/dashboard`](https://github.com/secondsaturday/second-saturday/tree/main/src/app/dashboard) (Dashboard), [`convex`](https://github.com/secondsaturday/second-saturday/tree/main/convex) (Domain Logic)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_app_router["App Router<br/>next app"]
  node_dashboard_routes["Dashboard<br/>route group"]
  node_auth_routes["Auth Flow<br/>route group"]
  node_invite_routes["Invites<br/>route group"]
  node_ui_components["UI Components<br/>feature ui"]
  node_submission_screen["Submission Screen"]
  node_client_hooks["Client Hooks<br/>client state"]
  node_providers["Providers<br/>integration layer"]
  node_client_lib["Client Lib<br/>browser helpers"]
end

subgraph group_backend["Backend"]
  node_convex_schema[("Schema<br/>data model<br/>[schema.ts]")]
  node_convex_domain["Domain Logic<br/>convex functions"]
  node_convex_runtime["Convex API<br/>generated client"]
  node_convex_http["HTTP Entry<br/>webhook ingress<br/>[http.ts]"]
end

subgraph group_platform["Platform"]
  node_native_shells["Native Shells<br/>capacitor app"]
  node_mobile_bridge["Capacitor Bridge<br/>native bridge"]
  node_external_services(("External Services<br/>integrations"))
  node_observability["Observability<br/>monitoring"]
end

subgraph group_quality["Quality"]
  node_tests["Tests<br/>verification"]
end

node_app_router -->|"routes"| node_dashboard_routes
node_app_router -->|"auth pages"| node_auth_routes
node_app_router -->|"invite pages"| node_invite_routes
node_app_router -->|"wraps"| node_providers
node_dashboard_routes -->|"renders"| node_ui_components
node_dashboard_routes -->|"uses"| node_client_hooks
node_submission_screen -->|"composes"| node_ui_components
node_submission_screen -->|"uses"| node_client_hooks
node_providers -->|"initializes"| node_client_lib
node_client_lib -->|"connects"| node_external_services
node_app_router -->|"calls"| node_convex_runtime
node_ui_components -->|"calls"| node_convex_runtime
node_convex_domain -->|"persists"| node_convex_schema
node_convex_domain -->|"drives"| node_external_services
node_convex_http -->|"receives callbacks"| node_external_services
node_observability -->|"reports to"| node_external_services
node_native_shells -->|"uses"| node_mobile_bridge
node_mobile_bridge -->|"packages"| node_app_router
node_tests -->|"covers"| node_app_router
node_tests -->|"covers"| node_convex_domain
node_tests -->|"simulates"| node_external_services
node_tests -->|"verifies"| node_observability

click node_app_router "https://github.com/secondsaturday/second-saturday/tree/main/src/app"
click node_dashboard_routes "https://github.com/secondsaturday/second-saturday/tree/main/src/app/dashboard"
click node_auth_routes "https://github.com/secondsaturday/second-saturday/tree/main/src/app/sign-in"
click node_invite_routes "https://github.com/secondsaturday/second-saturday/tree/main/src/app/invite"
click node_ui_components "https://github.com/secondsaturday/second-saturday/tree/main/src/components"
click node_submission_screen "https://github.com/secondsaturday/second-saturday/tree/main/src/screens/submissions"
click node_client_hooks "https://github.com/secondsaturday/second-saturday/tree/main/src/hooks"
click node_providers "https://github.com/secondsaturday/second-saturday/tree/main/src/providers"
click node_client_lib "https://github.com/secondsaturday/second-saturday/tree/main/src/lib"
click node_convex_schema "https://github.com/secondsaturday/second-saturday/blob/main/convex/schema.ts"
click node_convex_domain "https://github.com/secondsaturday/second-saturday/tree/main/convex"
click node_convex_runtime "https://github.com/secondsaturday/second-saturday/tree/main/convex/_generated"
click node_convex_http "https://github.com/secondsaturday/second-saturday/blob/main/convex/http.ts"
click node_native_shells "https://github.com/secondsaturday/second-saturday/tree/main/ios"
click node_mobile_bridge "https://github.com/secondsaturday/second-saturday/blob/main/capacitor.config.ts"
click node_observability "https://github.com/secondsaturday/second-saturday/blob/main/sentry.client.config.ts"
click node_tests "https://github.com/secondsaturday/second-saturday/tree/main/test"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_app_router,node_dashboard_routes,node_auth_routes,node_invite_routes,node_ui_components,node_submission_screen,node_client_hooks,node_providers,node_client_lib toneBlue
class node_convex_schema,node_convex_domain,node_convex_runtime,node_convex_http toneAmber
class node_native_shells,node_mobile_bridge,node_external_services,node_observability toneMint
class node_tests toneRose
```

## Components

### Frontend

Next.js App Router UI, shared components, and client-side integrations

- [App Router](https://github.com/secondsaturday/second-saturday/tree/main/src/app): next app · Route-level pages, layouts, auth, dashboard, invites, and API webhooks · `src/app`
- [Dashboard](https://github.com/secondsaturday/second-saturday/tree/main/src/app/dashboard): route group · Authenticated product surfaces for circles, submissions, newsletters, and notifications · `src/app/dashboard`
- [Auth Flow](https://github.com/secondsaturday/second-saturday/tree/main/src/app/sign-in): route group · Sign-in, sign-up, and profile completion routes · `src/app/sign-in`
- [Invites](https://github.com/secondsaturday/second-saturday/tree/main/src/app/invite): route group · Invite acceptance entrypoint and onboarding path · `src/app/invite`
- [UI Components](https://github.com/secondsaturday/second-saturday/tree/main/src/components): feature ui · Reusable dashboard, circle, submission, newsletter, auth, and base UI components · `src/components`
- [Submission Screen](https://github.com/secondsaturday/second-saturday/tree/main/src/screens/submissions): screen · Multi-circle submission composition and workflow · `src/screens/submissions`
- [Client Hooks](https://github.com/secondsaturday/second-saturday/tree/main/src/hooks): client state · Debounce, countdown, timezone sync, auth analytics, upload blocking, and responsiveness · `src/hooks`
- [Providers](https://github.com/secondsaturday/second-saturday/tree/main/src/providers): integration layer · App-wide wiring for PostHog, OneSignal, and Capacitor · `src/providers`
- [Client Lib](https://github.com/secondsaturday/second-saturday/tree/main/src/lib): browser helpers · Analytics, dates, image/video utilities, newsletter helpers, and push support · `src/lib`

### Backend

Convex schema, functions, and server-side workflows

- [Schema](https://github.com/secondsaturday/second-saturday/blob/main/convex/schema.ts): data model · Persistent Convex data model and auth config · `convex/schema.ts`
- [Domain Logic](https://github.com/secondsaturday/second-saturday/tree/main/convex): convex functions · Circles, memberships, submissions, newsletters, notifications, users, prompts, files, videos, and media actions · `convex`
- [Convex API](https://github.com/secondsaturday/second-saturday/tree/main/convex/_generated): generated client · Typed client/server interface consumed by the Next.js app · `convex/_generated`
- [HTTP Entry](https://github.com/secondsaturday/second-saturday/blob/main/convex/http.ts): webhook ingress · Convex HTTP endpoint for external callbacks and custom handlers · `convex/http.ts`

### Platform

Mobile shells, observability, and external ingress

- [Native Shells](https://github.com/secondsaturday/second-saturday/tree/main/ios): capacitor app · Thin iOS and Android wrappers around the web app · `ios`
- [Capacitor Bridge](https://github.com/secondsaturday/second-saturday/blob/main/capacitor.config.ts): native bridge · Build-time bridge between Next.js and mobile shells · `capacitor.config.ts`
- **External Services**: integrations · Clerk, Mux, Resend, OneSignal, PostHog, Sentry, and Vercel callbacks
- [Observability](https://github.com/secondsaturday/second-saturday/blob/main/sentry.client.config.ts): monitoring · Sentry configs, instrumentation, and analytics wiring · `sentry.client.config.ts`

### Quality

Tests and verification across UI, backend, and end-to-end flows

- [Tests](https://github.com/secondsaturday/second-saturday/tree/main/test): verification · Unit, integration, E2E, and CI coverage across core flows and integrations · `test`

## Connections

- App Router → Dashboard: routes · Dashboard and product workflow pages live under the App Router
- App Router → Auth Flow: auth pages · Dedicated sign-in, sign-up, and profile-completion routes
- App Router → Invites: invite pages · Invite acceptance route group
- App Router → Providers: wraps · Root layout installs app-wide providers
- Dashboard → UI Components: renders · Dashboard screens compose reusable UI and feature components
- Dashboard → Client Hooks: uses · Interactive dashboard pages rely on client hooks
- Submission Screen → UI Components: composes · Submission experience is built from shared submission components
- Submission Screen → Client Hooks: uses · Screen behavior depends on countdown, upload, and sync hooks
- Providers → Client Lib: initializes · Providers wire analytics, push, and mobile integration helpers
- Client Lib → External Services: connects · Browser-side helpers integrate with external vendors
- App Router → Convex API: calls · Route handlers and client pages consume typed Convex APIs
- UI Components → Convex API: calls · Feature components read and mutate backend state through Convex
- Domain Logic → Schema: persists · Feature functions operate on the shared data model
- Domain Logic → External Services: drives · Backend workflows trigger emails, push, video, and identity-related side effects
- HTTP Entry → External Services: receives callbacks · Webhook and service ingress terminates in Convex HTTP handlers
- Observability → External Services: reports to · Client and server observability flows send telemetry externally
- Native Shells → Capacitor Bridge: uses · Native shells are configured through the Capacitor bridge
- Capacitor Bridge → App Router: packages · Mobile apps wrap the same Next.js frontend
- Tests → App Router: covers · UI tests validate route behavior and user journeys
- Tests → Domain Logic: covers · Integration tests exercise business logic and side effects
- Tests → External Services: simulates · Tests include Mux, webhook, and delivery integrations
- Tests → Observability: verifies · Observability-related behavior is exercised in test coverage
