# hasintha-hewage/secret-santa-hq architecture

> Architecture diagram of the GitHub repository hasintha-hewage/secret-santa-hq, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/hasintha-hewage/secret-santa-hq
- Repository: https://github.com/hasintha-hewage/secret-santa-hq

## Overview

Secret Santa HQ manages organizer accounts and gift-exchange events, then creates private participant assignments and supports the exchange through magic-link portals. The main flow is organizer sign-in, event and participant setup, exclusions, fair shuffle, private invitations, participant acknowledgement and wishlist/Q&A, and a guarded reveal. Settings, notifications, and the mailroom are additional capabilities. The graph combines sampled API and library evidence with README-documented features; unsampled page-to-API wiring is not asserted.

Main entry points: [`src/lib/db.ts`](https://github.com/hasintha-hewage/secret-santa-hq/blob/main/src/lib/db.ts) (SQLite database), [`src/lib/auth.ts`](https://github.com/hasintha-hewage/secret-santa-hq/blob/main/src/lib/auth.ts) (Sessions and auth), [`src/components/AppProvider.tsx`](https://github.com/hasintha-hewage/secret-santa-hq/blob/main/src/components/AppProvider.tsx) (App state and preferences), [`src/app/api/events/[id]/shuffle/route.ts`](https://github.com/hasintha-hewage/secret-santa-hq/blob/main/src/app/api/events/%5Bid%5D/shuffle/route.ts) (Assignment shuffle)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_identity["Identity and settings"]
  node_auth_ui["Sign-in<br/>[page.tsx]"]
  node_auth_api["Authentication API"]
  node_auth_service["Sessions and auth<br/>[auth.ts]"]
  node_settings_ui["Preferences<br/>[page.tsx]"]
  node_settings_api["Settings API<br/>[route.ts]"]
end

subgraph group_organizing["Exchange organizing"]
  node_dashboard["Event dashboard<br/>[page.tsx]"]
  node_events_api["Event collection API<br/>[route.ts]"]
  node_event_detail["Event management API<br/>[route.ts]"]
  node_event_page["Event workspace<br/>[page.tsx]"]
  node_event_operations["Participants and exclusions"]
  node_shuffle_api["Assignment shuffle<br/>[route.ts]"]
  node_shuffle_logic["Fair derangement<br/>[shuffle.ts]"]
  node_reveal_api["Reveal assignments<br/>[route.ts]"]
  node_reveal_ui["Grand reveal"]
  node_pairings_ui["Pairing matrix"]
end

subgraph group_participant["Participant experience"]
  node_portal_ui["Magic-link portal<br/>[page.tsx]"]
  node_portal_api["Portal data API<br/>[route.ts]"]
  node_participant_actions["Participant actions"]
  node_gift_box["Gift reveal box<br/>[GiftUnwrapBox.tsx]"]
end

subgraph group_delivery["Notifications and mail"]
  node_email_service["Email dispatch<br/>[email.ts]"]
  node_mailroom_api["Mailroom API<br/>[route.ts]"]
  node_mailroom_ui["Mailroom outbox<br/>[page.tsx]"]
end

subgraph group_shared["Shared services and UI"]
  node_database[("SQLite database<br/>[db.ts]")]
  node_app_provider["App state and preferences<br/>[AppProvider.tsx]"]
  node_copy_service["Adaptive copy<br/>[copy.ts]"]
  node_sound_service["Holiday sounds<br/>[sounds.ts]"]
  node_nav_ui["Navigation<br/>[Navbar.tsx]"]
end

node_organizer(("Organizer"))
node_participant_actor(("Participant"))

node_organizer -->|"signs in"| node_auth_ui
node_organizer -->|"organizes events"| node_dashboard
node_organizer -->|"sets preferences"| node_settings_ui
node_participant_actor -->|"opens magic link"| node_portal_ui
node_auth_api -->|"checks sessions"| node_auth_service
node_auth_service -->|"reads user data"| node_database
node_settings_api -->|"checks session"| node_auth_service
node_settings_api -->|"updates settings"| node_database
node_dashboard -.->|"manages events"| node_events_api
node_events_api -->|"checks session"| node_auth_service
node_events_api -->|"reads and creates"| node_database
node_event_page -.->|"manages event"| node_event_detail
node_event_detail -->|"checks session"| node_auth_service
node_event_detail -->|"reads and updates"| node_database
node_event_operations -.->|"stores event data"| node_database
node_shuffle_api -->|"checks session"| node_auth_service
node_shuffle_api -->|"computes assignments"| node_shuffle_logic
node_shuffle_api -->|"stores pairings"| node_database
node_shuffle_api -->|"dispatches invitations"| node_email_service
node_email_service -->|"records delivery"| node_database
node_email_service -->|"sends magic link"| node_participant_actor
node_reveal_api -.->|"reveals pairings"| node_database
node_event_page -.->|"requests reveal"| node_reveal_ui
node_reveal_ui -->|"shows assignments"| node_pairings_ui
node_portal_ui -.->|"loads portal"| node_portal_api
node_portal_api -->|"reads participant data"| node_database
node_portal_ui -->|"unwraps assignment"| node_gift_box
node_portal_ui -.->|"updates wishlist and messages"| node_participant_actions
node_participant_actions -.->|"stores participant updates"| node_database
node_participant_actions -.->|"notifies organizer"| node_email_service
node_mailroom_ui -.->|"views outbox"| node_mailroom_api
node_mailroom_api -->|"reads delivery records"| node_database
node_app_provider -->|"refreshes session"| node_auth_api
node_app_provider -->|"saves preferences"| node_settings_api
node_app_provider -->|"selects copy"| node_copy_service
node_app_provider -->|"plays effects"| node_sound_service
node_nav_ui -->|"uses app state"| node_app_provider

click node_auth_ui "https://github.com/hasintha-hewage/secret-santa-hq/blob/main/src/app/auth/page.tsx"
click node_auth_api "https://github.com/hasintha-hewage/secret-santa-hq/tree/main/src/app/api/auth"
click node_auth_service "https://github.com/hasintha-hewage/secret-santa-hq/blob/main/src/lib/auth.ts"
click node_settings_ui "https://github.com/hasintha-hewage/secret-santa-hq/blob/main/src/app/settings/page.tsx"
click node_settings_api "https://github.com/hasintha-hewage/secret-santa-hq/blob/main/src/app/api/settings/route.ts"
click node_dashboard "https://github.com/hasintha-hewage/secret-santa-hq/blob/main/src/app/dashboard/page.tsx"
click node_events_api "https://github.com/hasintha-hewage/secret-santa-hq/blob/main/src/app/api/events/route.ts"
click node_event_detail "https://github.com/hasintha-hewage/secret-santa-hq/blob/main/src/app/api/events/%5Bid%5D/route.ts"
click node_event_page "https://github.com/hasintha-hewage/secret-santa-hq/blob/main/src/app/events/%5Bid%5D/page.tsx"
click node_event_operations "https://github.com/hasintha-hewage/secret-santa-hq/tree/main/src/app/api/events/%5Bid%5D"
click node_shuffle_api "https://github.com/hasintha-hewage/secret-santa-hq/blob/main/src/app/api/events/%5Bid%5D/shuffle/route.ts"
click node_shuffle_logic "https://github.com/hasintha-hewage/secret-santa-hq/blob/main/src/lib/shuffle.ts"
click node_reveal_api "https://github.com/hasintha-hewage/secret-santa-hq/blob/main/src/app/api/events/%5Bid%5D/reveal/route.ts"
click node_reveal_ui "https://github.com/hasintha-hewage/secret-santa-hq/blob/main/src/components/GrandRevealModal.tsx"
click node_pairings_ui "https://github.com/hasintha-hewage/secret-santa-hq/blob/main/src/components/RevealedPairingsMatrix.tsx"
click node_portal_ui "https://github.com/hasintha-hewage/secret-santa-hq/blob/main/src/app/participant/%5Btoken%5D/page.tsx"
click node_portal_api "https://github.com/hasintha-hewage/secret-santa-hq/blob/main/src/app/api/participant/%5Btoken%5D/route.ts"
click node_participant_actions "https://github.com/hasintha-hewage/secret-santa-hq/tree/main/src/app/api/participant/%5Btoken%5D"
click node_gift_box "https://github.com/hasintha-hewage/secret-santa-hq/blob/main/src/components/GiftUnwrapBox.tsx"
click node_email_service "https://github.com/hasintha-hewage/secret-santa-hq/blob/main/src/lib/email.ts"
click node_mailroom_api "https://github.com/hasintha-hewage/secret-santa-hq/blob/main/src/app/api/mailroom/route.ts"
click node_mailroom_ui "https://github.com/hasintha-hewage/secret-santa-hq/blob/main/src/app/mailroom/page.tsx"
click node_database "https://github.com/hasintha-hewage/secret-santa-hq/blob/main/src/lib/db.ts"
click node_app_provider "https://github.com/hasintha-hewage/secret-santa-hq/blob/main/src/components/AppProvider.tsx"
click node_copy_service "https://github.com/hasintha-hewage/secret-santa-hq/blob/main/src/lib/copy.ts"
click node_sound_service "https://github.com/hasintha-hewage/secret-santa-hq/blob/main/src/lib/sounds.ts"
click node_nav_ui "https://github.com/hasintha-hewage/secret-santa-hq/blob/main/src/components/Navbar.tsx"

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_auth_ui,node_auth_api,node_auth_service,node_settings_ui,node_settings_api toneBlue
class node_dashboard,node_events_api,node_event_detail,node_event_page,node_event_operations,node_shuffle_api,node_shuffle_logic,node_reveal_api,node_reveal_ui,node_pairings_ui toneAmber
class node_portal_ui,node_portal_api,node_participant_actions,node_gift_box toneMint
class node_email_service,node_mailroom_api,node_mailroom_ui toneRose
class node_database,node_app_provider,node_copy_service,node_sound_service,node_nav_ui,node_organizer,node_participant_actor toneIndigo
```

## Components

### Identity and settings

- [Sign-in](https://github.com/hasintha-hewage/secret-santa-hq/blob/main/src/app/auth/page.tsx): `src/app/auth/page.tsx`
- [Authentication API](https://github.com/hasintha-hewage/secret-santa-hq/tree/main/src/app/api/auth): `src/app/api/auth`
- [Sessions and auth](https://github.com/hasintha-hewage/secret-santa-hq/blob/main/src/lib/auth.ts): `src/lib/auth.ts`
- [Preferences](https://github.com/hasintha-hewage/secret-santa-hq/blob/main/src/app/settings/page.tsx): `src/app/settings/page.tsx`
- [Settings API](https://github.com/hasintha-hewage/secret-santa-hq/blob/main/src/app/api/settings/route.ts): `src/app/api/settings/route.ts`

### Exchange organizing

- [Event dashboard](https://github.com/hasintha-hewage/secret-santa-hq/blob/main/src/app/dashboard/page.tsx): `src/app/dashboard/page.tsx`
- [Event collection API](https://github.com/hasintha-hewage/secret-santa-hq/blob/main/src/app/api/events/route.ts): `src/app/api/events/route.ts`
- [Event management API](https://github.com/hasintha-hewage/secret-santa-hq/blob/main/src/app/api/events/%5Bid%5D/route.ts): `src/app/api/events/[id]/route.ts`
- [Event workspace](https://github.com/hasintha-hewage/secret-santa-hq/blob/main/src/app/events/%5Bid%5D/page.tsx): `src/app/events/[id]/page.tsx`
- [Participants and exclusions](https://github.com/hasintha-hewage/secret-santa-hq/tree/main/src/app/api/events/%5Bid%5D): `src/app/api/events/[id]`
- [Assignment shuffle](https://github.com/hasintha-hewage/secret-santa-hq/blob/main/src/app/api/events/%5Bid%5D/shuffle/route.ts): `src/app/api/events/[id]/shuffle/route.ts`
- [Fair derangement](https://github.com/hasintha-hewage/secret-santa-hq/blob/main/src/lib/shuffle.ts): `src/lib/shuffle.ts`
- [Reveal assignments](https://github.com/hasintha-hewage/secret-santa-hq/blob/main/src/app/api/events/%5Bid%5D/reveal/route.ts): `src/app/api/events/[id]/reveal/route.ts`
- [Grand reveal](https://github.com/hasintha-hewage/secret-santa-hq/blob/main/src/components/GrandRevealModal.tsx): `src/components/GrandRevealModal.tsx`
- [Pairing matrix](https://github.com/hasintha-hewage/secret-santa-hq/blob/main/src/components/RevealedPairingsMatrix.tsx): `src/components/RevealedPairingsMatrix.tsx`

### Participant experience

- [Magic-link portal](https://github.com/hasintha-hewage/secret-santa-hq/blob/main/src/app/participant/%5Btoken%5D/page.tsx): `src/app/participant/[token]/page.tsx`
- [Portal data API](https://github.com/hasintha-hewage/secret-santa-hq/blob/main/src/app/api/participant/%5Btoken%5D/route.ts): `src/app/api/participant/[token]/route.ts`
- [Participant actions](https://github.com/hasintha-hewage/secret-santa-hq/tree/main/src/app/api/participant/%5Btoken%5D): `src/app/api/participant/[token]`
- [Gift reveal box](https://github.com/hasintha-hewage/secret-santa-hq/blob/main/src/components/GiftUnwrapBox.tsx): `src/components/GiftUnwrapBox.tsx`

### Notifications and mail

- [Email dispatch](https://github.com/hasintha-hewage/secret-santa-hq/blob/main/src/lib/email.ts): `src/lib/email.ts`
- [Mailroom API](https://github.com/hasintha-hewage/secret-santa-hq/blob/main/src/app/api/mailroom/route.ts): `src/app/api/mailroom/route.ts`
- [Mailroom outbox](https://github.com/hasintha-hewage/secret-santa-hq/blob/main/src/app/mailroom/page.tsx): `src/app/mailroom/page.tsx`

### Shared services and UI

- [SQLite database](https://github.com/hasintha-hewage/secret-santa-hq/blob/main/src/lib/db.ts): `src/lib/db.ts`
- [App state and preferences](https://github.com/hasintha-hewage/secret-santa-hq/blob/main/src/components/AppProvider.tsx): `src/components/AppProvider.tsx`
- [Adaptive copy](https://github.com/hasintha-hewage/secret-santa-hq/blob/main/src/lib/copy.ts): `src/lib/copy.ts`
- [Holiday sounds](https://github.com/hasintha-hewage/secret-santa-hq/blob/main/src/lib/sounds.ts): `src/lib/sounds.ts`
- [Navigation](https://github.com/hasintha-hewage/secret-santa-hq/blob/main/src/components/Navbar.tsx): `src/components/Navbar.tsx`

### Other components

- **Organizer**
- **Participant**

## Connections

- Organizer → Sign-in: signs in (evidence: `README.md`)
- Organizer → Event dashboard: organizes events (evidence: `README.md`)
- Organizer → Preferences: sets preferences (evidence: `README.md`)
- Participant → Magic-link portal: opens magic link (evidence: `README.md`)
- Authentication API → Sessions and auth: checks sessions (evidence: `src/app/api/auth/me/route.ts`)
- Sessions and auth → SQLite database: reads user data (evidence: `src/lib/auth.ts`)
- Settings API → Sessions and auth: checks session (evidence: `src/app/api/settings/route.ts`)
- Settings API → SQLite database: updates settings (evidence: `src/app/api/settings/route.ts`)
- Event dashboard → Event collection API: manages events
- Event collection API → Sessions and auth: checks session (evidence: `src/app/api/events/route.ts`)
- Event collection API → SQLite database: reads and creates (evidence: `src/app/api/events/route.ts`)
- Event workspace → Event management API: manages event
- Event management API → Sessions and auth: checks session (evidence: `src/app/api/events/[id]/route.ts`)
- Event management API → SQLite database: reads and updates (evidence: `src/app/api/events/[id]/route.ts`)
- Participants and exclusions → SQLite database: stores event data (evidence: `src/app/api/events/[id]/route.ts`)
- Assignment shuffle → Sessions and auth: checks session (evidence: `src/app/api/events/[id]/shuffle/route.ts`)
- Assignment shuffle → Fair derangement: computes assignments (evidence: `src/app/api/events/[id]/shuffle/route.ts`)
- Assignment shuffle → SQLite database: stores pairings (evidence: `src/app/api/events/[id]/shuffle/route.ts`)
- Assignment shuffle → Email dispatch: dispatches invitations (evidence: `src/app/api/events/[id]/shuffle/route.ts`)
- Email dispatch → SQLite database: records delivery (evidence: `src/lib/email.ts`)
- Email dispatch → Participant: sends magic link (evidence: `README.md`)
- Reveal assignments → SQLite database: reveals pairings (evidence: `src/app/api/events/[id]/reveal/route.ts`)
- Event workspace → Grand reveal: requests reveal
- Grand reveal → Pairing matrix: shows assignments (evidence: `src/components/GrandRevealModal.tsx`)
- Magic-link portal → Portal data API: loads portal
- Portal data API → SQLite database: reads participant data (evidence: `src/app/api/participant/[token]/route.ts`)
- Magic-link portal → Gift reveal box: unwraps assignment (evidence: `README.md`)
- Magic-link portal → Participant actions: updates wishlist and messages
- Participant actions → SQLite database: stores participant updates (evidence: `src/app/api/participant/[token]/route.ts`)
- Participant actions → Email dispatch: notifies organizer (evidence: `src/app/api/participant/[token]/acknowledge/route.ts`)
- Mailroom outbox → Mailroom API: views outbox
- Mailroom API → SQLite database: reads delivery records (evidence: `src/app/api/mailroom/route.ts`)
- App state and preferences → Authentication API: refreshes session (evidence: `src/components/AppProvider.tsx`)
- App state and preferences → Settings API: saves preferences (evidence: `src/components/AppProvider.tsx`)
- App state and preferences → Adaptive copy: selects copy (evidence: `src/components/AppProvider.tsx`)
- App state and preferences → Holiday sounds: plays effects (evidence: `src/components/AppProvider.tsx`)
- Navigation → App state and preferences: uses app state (evidence: `src/components/Navbar.tsx`)
