# dreilol/streak-app architecture

> Architecture diagram of the GitHub repository dreilol/streak-app, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dreilol/streak-app
- Repository: https://github.com/dreilol/streak-app

## Overview

Tumbler Streak is a Next.js and Supabase RFID check-in dashboard. A student views their streak and recent check-ins; an ESP32 can submit a tag to the tap function, while administrators can manage students, batches, sections, and pauses or simulate a tap. The dashboard also provides a live leaderboard and student search. The graph follows documented routes, imports, and queries; the function excerpts were not provided, so uncertain function-to-database behavior is omitted. SQL defines the Supabase data and access-policy layer.

Main entry points: [`lib/supabase-browser.ts`](https://github.com/dreilol/streak-app/blob/main/lib/supabase-browser.ts) (Browser Supabase client), [`app/admin/page.tsx`](https://github.com/dreilol/streak-app/blob/main/app/admin/page.tsx) (Admin console), [`app/page.tsx`](https://github.com/dreilol/streak-app/blob/main/app/page.tsx) (Leaderboard), [`app/streak/page.tsx`](https://github.com/dreilol/streak-app/blob/main/app/streak/page.tsx) (My streak)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Student dashboard"]
  node_leaderboard["Leaderboard<br/>[page.tsx]"]
  node_my_streak["My streak<br/>[page.tsx]"]
  node_student_search["Student search<br/>[page.tsx]"]
  node_navigation["Navigation and auth<br/>[Nav.tsx]"]
  node_login["Login<br/>[page.tsx]"]
  node_streak_hook["Personal streak data<br/>[useMyStreak.ts]"]
  node_leaderboard_hook["Leaderboard data<br/>[useLeaderboard.ts]"]
end

subgraph group_admin["Administration"]
  node_admin_route["Admin console<br/>[page.tsx]"]
  node_student_admin["Student management<br/>[StudentsTab.tsx]"]
  node_batch_admin["Batch management<br/>[BatchesTab.tsx]"]
  node_section_admin["Section management<br/>[SectionsTab.tsx]"]
  node_pause_admin["Pause management<br/>[PausesTab.tsx]"]
end

subgraph group_domain["Streak domain"]
  node_streak_rules["Streak calculations<br/>[streak.ts]"]
  node_pause_rules["Pause matching<br/>[pauses.ts]"]
  node_level_rules["Level progression<br/>[levels.ts]"]
  node_level_display["Level progress display<br/>[LevelProgress.tsx]"]
end

subgraph group_backend["Supabase services"]
  node_browser_client["Browser Supabase client"]
  node_data_types["Profile and log types<br/>[types.ts]"]
  node_database[("Supabase data and policies<br/>[schema.sql]")]
end

subgraph group_device["RFID check-in"]
  node_tap_function["RFID tap endpoint<br/>[index.ts]"]
  node_simulate_function["Simulated tap endpoint<br/>[index.ts]"]
  node_tap_logger["Tap logging helper<br/>[log-tap.ts]"]
  node_cors["CORS helper<br/>[cors.ts]"]
end

node_student(("Student"))
node_administrator(("Administrator"))
node_esp32(("ESP32 reader"))
node_supabase_service["Supabase service"]

node_student -->|"views"| node_leaderboard
node_student -->|"views"| node_my_streak
node_student -->|"searches"| node_student_search
node_administrator -->|"manages"| node_admin_route
node_esp32 -->|"submits tag"| node_tap_function
node_admin_route -->|"renders tab"| node_student_admin
node_admin_route -->|"renders tab"| node_batch_admin
node_admin_route -->|"renders tab"| node_section_admin
node_admin_route -->|"renders tab"| node_pause_admin
node_admin_route -->|"queries profile"| node_browser_client
node_student_admin -->|"queries data"| node_browser_client
node_batch_admin -->|"queries data"| node_browser_client
node_section_admin -->|"queries data"| node_browser_client
node_pause_admin -->|"queries data"| node_browser_client
node_leaderboard -->|"loads rows"| node_leaderboard_hook
node_leaderboard -->|"loads sections and pauses"| node_browser_client
node_leaderboard_hook -->|"queries profiles"| node_browser_client
node_leaderboard_hook -->|"calculates streak"| node_streak_rules
node_leaderboard -->|"matches pauses"| node_pause_rules
node_leaderboard -->|"assigns levels"| node_level_rules
node_my_streak -->|"loads profile and logs"| node_streak_hook
node_streak_hook -->|"queries profile and logs"| node_browser_client
node_my_streak -->|"calculates streak"| node_streak_rules
node_my_streak -->|"matches pauses"| node_pause_rules
node_my_streak -->|"renders progress"| node_level_display
node_level_display -->|"calculates progress"| node_level_rules
node_student_search -->|"searches profiles"| node_browser_client
node_student_search -->|"calculates streak"| node_streak_rules
node_student_search -->|"assigns levels"| node_level_rules
node_navigation -->|"checks auth"| node_browser_client
node_login -->|"uses auth"| node_browser_client
node_browser_client -->|"connects"| node_supabase_service
node_supabase_service -.->|"reads and writes"| node_database
node_tap_function -->|"uses helper"| node_cors
node_tap_function -->|"uses helper"| node_tap_logger
node_simulate_function -->|"uses helper"| node_cors
node_admin_route -.->|"requests simulation"| node_simulate_function
node_tap_function -.->|"handles check-in"| node_supabase_service
node_simulate_function -.->|"handles simulation"| node_supabase_service

click node_leaderboard "https://github.com/dreilol/streak-app/blob/main/app/page.tsx"
click node_my_streak "https://github.com/dreilol/streak-app/blob/main/app/streak/page.tsx"
click node_student_search "https://github.com/dreilol/streak-app/blob/main/app/students/page.tsx"
click node_navigation "https://github.com/dreilol/streak-app/blob/main/components/Nav.tsx"
click node_login "https://github.com/dreilol/streak-app/blob/main/app/login/page.tsx"
click node_streak_hook "https://github.com/dreilol/streak-app/blob/main/hooks/useMyStreak.ts"
click node_leaderboard_hook "https://github.com/dreilol/streak-app/blob/main/hooks/useLeaderboard.ts"
click node_admin_route "https://github.com/dreilol/streak-app/blob/main/app/admin/page.tsx"
click node_student_admin "https://github.com/dreilol/streak-app/blob/main/app/admin/_components/StudentsTab.tsx"
click node_batch_admin "https://github.com/dreilol/streak-app/blob/main/app/admin/_components/BatchesTab.tsx"
click node_section_admin "https://github.com/dreilol/streak-app/blob/main/app/admin/_components/SectionsTab.tsx"
click node_pause_admin "https://github.com/dreilol/streak-app/blob/main/app/admin/_components/PausesTab.tsx"
click node_streak_rules "https://github.com/dreilol/streak-app/blob/main/lib/streak.ts"
click node_pause_rules "https://github.com/dreilol/streak-app/blob/main/lib/pauses.ts"
click node_level_rules "https://github.com/dreilol/streak-app/blob/main/lib/levels.ts"
click node_level_display "https://github.com/dreilol/streak-app/blob/main/components/LevelProgress.tsx"
click node_browser_client "https://github.com/dreilol/streak-app/blob/main/lib/supabase-browser.ts"
click node_data_types "https://github.com/dreilol/streak-app/blob/main/lib/types.ts"
click node_database "https://github.com/dreilol/streak-app/blob/main/supabase/schema.sql"
click node_tap_function "https://github.com/dreilol/streak-app/blob/main/supabase/functions/tap/index.ts"
click node_simulate_function "https://github.com/dreilol/streak-app/blob/main/supabase/functions/simulate-tap/index.ts"
click node_tap_logger "https://github.com/dreilol/streak-app/blob/main/supabase/functions/_shared/log-tap.ts"
click node_cors "https://github.com/dreilol/streak-app/blob/main/supabase/functions/_shared/cors.ts"

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_leaderboard,node_my_streak,node_student_search,node_navigation,node_login,node_streak_hook,node_leaderboard_hook toneBlue
class node_admin_route,node_student_admin,node_batch_admin,node_section_admin,node_pause_admin toneAmber
class node_streak_rules,node_pause_rules,node_level_rules,node_level_display toneMint
class node_browser_client,node_data_types,node_database toneRose
class node_tap_function,node_simulate_function,node_tap_logger,node_cors,node_student,node_administrator,node_esp32,node_supabase_service toneIndigo
```

## Components

### Student dashboard

- [Leaderboard](https://github.com/dreilol/streak-app/blob/main/app/page.tsx): `app/page.tsx`
- [My streak](https://github.com/dreilol/streak-app/blob/main/app/streak/page.tsx): `app/streak/page.tsx`
- [Student search](https://github.com/dreilol/streak-app/blob/main/app/students/page.tsx): `app/students/page.tsx`
- [Navigation and auth](https://github.com/dreilol/streak-app/blob/main/components/Nav.tsx): `components/Nav.tsx`
- [Login](https://github.com/dreilol/streak-app/blob/main/app/login/page.tsx): `app/login/page.tsx`
- [Personal streak data](https://github.com/dreilol/streak-app/blob/main/hooks/useMyStreak.ts): `hooks/useMyStreak.ts`
- [Leaderboard data](https://github.com/dreilol/streak-app/blob/main/hooks/useLeaderboard.ts): `hooks/useLeaderboard.ts`

### Administration

- [Admin console](https://github.com/dreilol/streak-app/blob/main/app/admin/page.tsx): `app/admin/page.tsx`
- [Student management](https://github.com/dreilol/streak-app/blob/main/app/admin/_components/StudentsTab.tsx): `app/admin/_components/StudentsTab.tsx`
- [Batch management](https://github.com/dreilol/streak-app/blob/main/app/admin/_components/BatchesTab.tsx): `app/admin/_components/BatchesTab.tsx`
- [Section management](https://github.com/dreilol/streak-app/blob/main/app/admin/_components/SectionsTab.tsx): `app/admin/_components/SectionsTab.tsx`
- [Pause management](https://github.com/dreilol/streak-app/blob/main/app/admin/_components/PausesTab.tsx): `app/admin/_components/PausesTab.tsx`

### Streak domain

- [Streak calculations](https://github.com/dreilol/streak-app/blob/main/lib/streak.ts): `lib/streak.ts`
- [Pause matching](https://github.com/dreilol/streak-app/blob/main/lib/pauses.ts): `lib/pauses.ts`
- [Level progression](https://github.com/dreilol/streak-app/blob/main/lib/levels.ts): `lib/levels.ts`
- [Level progress display](https://github.com/dreilol/streak-app/blob/main/components/LevelProgress.tsx): `components/LevelProgress.tsx`

### Supabase services

- [Browser Supabase client](https://github.com/dreilol/streak-app/blob/main/lib/supabase-browser.ts): `lib/supabase-browser.ts`
- [Profile and log types](https://github.com/dreilol/streak-app/blob/main/lib/types.ts): `lib/types.ts`
- [Supabase data and policies](https://github.com/dreilol/streak-app/blob/main/supabase/schema.sql): `supabase/schema.sql`

### RFID check-in

- [RFID tap endpoint](https://github.com/dreilol/streak-app/blob/main/supabase/functions/tap/index.ts): `supabase/functions/tap/index.ts`
- [Simulated tap endpoint](https://github.com/dreilol/streak-app/blob/main/supabase/functions/simulate-tap/index.ts): `supabase/functions/simulate-tap/index.ts`
- [Tap logging helper](https://github.com/dreilol/streak-app/blob/main/supabase/functions/_shared/log-tap.ts): `supabase/functions/_shared/log-tap.ts`
- [CORS helper](https://github.com/dreilol/streak-app/blob/main/supabase/functions/_shared/cors.ts): `supabase/functions/_shared/cors.ts`

### Other components

- **Student**
- **Administrator**
- **ESP32 reader**
- **Supabase service**

## Connections

- Student → Leaderboard: views (evidence: `README.md`)
- Student → My streak: views (evidence: `README.md`)
- Student → Student search: searches (evidence: `app/students/page.tsx`)
- Administrator → Admin console: manages (evidence: `app/admin/page.tsx`)
- ESP32 reader → RFID tap endpoint: submits tag (evidence: `README.md`)
- Admin console → Student management: renders tab (evidence: `app/admin/page.tsx`)
- Admin console → Batch management: renders tab (evidence: `app/admin/page.tsx`)
- Admin console → Section management: renders tab (evidence: `app/admin/page.tsx`)
- Admin console → Pause management: renders tab (evidence: `app/admin/page.tsx`)
- Admin console → Browser Supabase client: queries profile (evidence: `app/admin/page.tsx`)
- Student management → Browser Supabase client: queries data (evidence: `app/admin/_components/StudentsTab.tsx`)
- Batch management → Browser Supabase client: queries data (evidence: `app/admin/_components/BatchesTab.tsx`)
- Section management → Browser Supabase client: queries data (evidence: `app/admin/_components/SectionsTab.tsx`)
- Pause management → Browser Supabase client: queries data (evidence: `app/admin/_components/PausesTab.tsx`)
- Leaderboard → Leaderboard data: loads rows (evidence: `app/page.tsx`)
- Leaderboard → Browser Supabase client: loads sections and pauses (evidence: `app/page.tsx`)
- Leaderboard data → Browser Supabase client: queries profiles (evidence: `hooks/useLeaderboard.ts`)
- Leaderboard data → Streak calculations: calculates streak (evidence: `hooks/useLeaderboard.ts`)
- Leaderboard → Pause matching: matches pauses (evidence: `app/page.tsx`)
- Leaderboard → Level progression: assigns levels (evidence: `app/page.tsx`)
- My streak → Personal streak data: loads profile and logs (evidence: `app/streak/page.tsx`)
- Personal streak data → Browser Supabase client: queries profile and logs (evidence: `hooks/useMyStreak.ts`)
- My streak → Streak calculations: calculates streak (evidence: `app/streak/page.tsx`)
- My streak → Pause matching: matches pauses (evidence: `app/streak/page.tsx`)
- My streak → Level progress display: renders progress (evidence: `app/streak/page.tsx`)
- Level progress display → Level progression: calculates progress (evidence: `components/LevelProgress.tsx`)
- Student search → Browser Supabase client: searches profiles (evidence: `app/students/page.tsx`)
- Student search → Streak calculations: calculates streak (evidence: `app/students/page.tsx`)
- Student search → Level progression: assigns levels (evidence: `app/students/page.tsx`)
- Navigation and auth → Browser Supabase client: checks auth (evidence: `components/Nav.tsx`)
- Login → Browser Supabase client: uses auth (evidence: `app/login/page.tsx`)
- Browser Supabase client → Supabase service: connects (evidence: `README.md`)
- Supabase service → Supabase data and policies: reads and writes
- RFID tap endpoint → CORS helper: uses helper (evidence: `supabase/functions/tap/index.ts`)
- RFID tap endpoint → Tap logging helper: uses helper (evidence: `supabase/functions/tap/index.ts`)
- Simulated tap endpoint → CORS helper: uses helper (evidence: `supabase/functions/simulate-tap/index.ts`)
- Admin console → Simulated tap endpoint: requests simulation (evidence: `README.md`)
- RFID tap endpoint → Supabase service: handles check-in
- Simulated tap endpoint → Supabase service: handles simulation
