# uneven-coder/tournament-prototype architecture

> Architecture diagram of the GitHub repository uneven-coder/tournament-prototype, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/uneven-coder/tournament-prototype
- Repository: https://github.com/uneven-coder/tournament-prototype

## Overview

1. **Overall shape**
This is a Next.js App Router prototype for tournament management. The repository is split into three main layers: route-driven UI under `app/`, reusable UI and feature components under `components/`, and local persistence/data access under `lib/db/` backed by `data/tournament.sqlite`.

2. **Route topology**
The UI is organized by route groups: `app/(auth)` for login/register screens and `app/(app)` for the authenticated product area. The authenticated group contains pages for dashboard, tournaments, teams, profile, matches, scoring, schedule, attendance, approvals, venues, leaderboard, rules, settings, and related subflows like score entry and match creation/results. Most route files are thin page entry points that compose feature components.

3. **App shell and navigation**
`app/(app)/layout.tsx` is the persistent application frame, backed by `components/blocks/app-shell.tsx` and `app-shell-client.tsx`. This is the main boundary for global navigation, page chrome, and client-side app state. The README describes a header/sidebar style shell with active navigation and user info, so the architecture centers around a shared layout rather than per-page navigation.

4. **Authentication boundary**
Authentication is split into `app/(auth)/login`, `app/(auth)/register`, and several API routes under `app/api/auth/*` such as login, signup, admin login/register, magic link, session, and verify. The implementation is prototype-style: session state is held client-side in context, while the API routes simulate credential checks against the seeded SQLite data. This means auth is both a UI flow and a mocked server boundary.

5. **Data access layer**
`lib/db/connection.ts`, `schema.ts`, `queries.ts`, `seed.ts`, and `id.ts` form the persistence subsystem. The app reads and writes through this layer instead of directly touching the SQLite file from UI code. The README indicates the database is auto-seeded on first API hit, so the data layer is responsible for initializing demo records and keeping the prototype stateful across requests.

6. **API surface**
`app/api/` exposes the functional backend for the prototype. There are endpoints for tournaments, teams, venues, users, rules, profile, registry, approvals, attendance, leaderboard, matches, games, fixed events, and score submission. These routes are the integration point between UI actions and the SQLite-backed data layer, and they simulate create/update/delete behavior even though the product is not wired to a real production backend.

7. **State management**
Global client state is intentionally split by concern in `lib/hooks/`: `user-context.tsx`, `teams-context.tsx`, and `tournaments-context.tsx`, plus a shared provider composition in `providers.tsx`. This matches the README’s guidance: authentication state, team data, and tournament data are separated rather than using one monolithic store. The app shell and many pages likely consume these contexts to keep lists and session state in sync after API interactions.

8. **Feature component layer**
`components/features/` contains domain-focused form and editor blocks such as `auth-form.tsx`, `profile-settings.tsx`, `teams-manager.tsx`, and `tournament-form.tsx`. These are the main reusable business UI units, sitting above the primitive UI library and below the route pages. This separation keeps page files small and makes it easier to reuse forms across create/edit flows.

9. **UI system**
The UI is built on shadcn-style primitives in `components/ui/` with `components.json`, Tailwind via `globals.css`, and theme support in `components/theme-provider.tsx`. This layer provides buttons, inputs, cards, tables, dialogs, tabs, toasts, and form controls used across the app. Architecturally, this is the presentation foundation shared by every route and feature component.

10. **Page families and subflows**
Several route groups represent distinct product workflows rather than independent pages: tournament creation/detail under `app/(app)/tournaments`, score entry under `app/(app)/score-entry`, and match browsing/results under `app/(app)/matches` and `app/(app)/match-results`. Similarly, `participants`, `registry`, `sessions`, `roles`, and `access-links` suggest administrative and operational screens around the core tournament model. These are best viewed as domain slices around the same underlying tournament/team/match data.

11. **Presentation route**
`app/presentation/[id]/page.tsx` is a separate viewing path, likely for display or shareable tournament presentation mode. It sits outside the main app shell pattern and should be treated as a consumer-facing read-only boundary, distinct from the authenticated management UI.

12. **Key data flow**
The common flow is: user interacts with a page component → feature component handles form/UI state → context or API route is used → SQLite-backed query layer reads/writes data → updated state is reflected back in the UI. Because this is a prototype, the “backend” is intentionally lightweight and many actions are simulated, but the architectural boundary is still clear: route/UI, client state, API, and local database.

Main entry points: [`app/(app)/layout.tsx`](https://github.com/uneven-coder/tournament-prototype/blob/master/app/(app)/layout.tsx) (App Shell Route), [`lib/db/queries.ts`](https://github.com/uneven-coder/tournament-prototype/blob/master/lib/db/queries.ts) (Queries), [`lib/hooks/providers.tsx`](https://github.com/uneven-coder/tournament-prototype/blob/master/lib/hooks/providers.tsx) (Providers), [`app/layout.tsx`](https://github.com/uneven-coder/tournament-prototype/blob/master/app/layout.tsx) (Root Layout)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["App UI"]
  node_root_layout["Root Layout<br/>next-root<br/>[layout.tsx]"]
  node_home_page["Home<br/>landing-page<br/>[page.tsx]"]
  node_auth_layout["Auth Layout<br/>route-shell<br/>[layout.tsx]"]
  node_auth_login["Login<br/>auth-page<br/>[page.tsx]"]
  node_auth_register["Register<br/>auth-page<br/>[page.tsx]"]
  node_app_layout["App Shell Route<br/>app-shell-route<br/>[layout.tsx]"]
  node_dashboard_page["Dashboard<br/>overview-page<br/>[page.tsx]"]
  node_tournaments_page["Tournaments<br/>tournament-hub<br/>[page.tsx]"]
  node_teams_page["Teams<br/>team-page<br/>[page.tsx]"]
  node_matches_page["Matches<br/>match-page<br/>[page.tsx]"]
  node_score_entry_page["Score Entry<br/>workflow-page<br/>[page.tsx]"]
  node_presentation_page["Presentation<br/>read-only-page<br/>[page.tsx]"]
end

subgraph group_api["API Layer"]
  node_auth_api[("Auth API<br/>endpoint-set<br/>[route.ts]")]
  node_tournaments_api[("Tournaments API<br/>resource-api<br/>[route.ts]")]
  node_teams_api[("Teams API<br/>resource-api<br/>[route.ts]")]
  node_matches_api[("Matches API<br/>resource-api<br/>[route.ts]")]
  node_score_api[("Score API<br/>action-api<br/>[route.ts]")]
  node_ops_api[("Ops API<br/>resource-api<br/>[route.ts]")]
end

subgraph group_shared["Shared System"]
  node_app_shell["App Shell<br/>layout-component<br/>[app-shell.tsx]"]
  node_app_shell_client["Shell Client<br/>client-component"]
  node_providers["Providers<br/>state-composition<br/>[providers.tsx]"]
  node_user_context(("User Context<br/>client-state<br/>[user-context.tsx]"))
  node_teams_context(("Teams Context<br/>client-state<br/>[teams-context.tsx]"))
  node_tournaments_context(("Tournaments Context<br/>client-state"))
  node_auth_form["Auth Form<br/>feature-form<br/>[auth-form.tsx]"]
  node_tournament_form["Tournament Form<br/>feature-form"]
  node_teams_manager["Teams Manager<br/>feature-module<br/>[teams-manager.tsx]"]
  node_profile_settings["Profile Settings<br/>feature-module"]
  node_db_connection[("DB Connection<br/>sqlite-core<br/>[connection.ts]")]
  node_db_queries[("Queries<br/>data-access<br/>[queries.ts]")]
  node_db_seed["Seed Data<br/>bootstrap<br/>[seed.ts]"]
end

subgraph group_data["Data Store"]
  node_sqlite_file[("SQLite File<br/>database-file<br/>[tournament.sqlite]")]
end

node_root_layout -->|"routes"| node_home_page
node_root_layout -->|"routes"| node_auth_layout
node_root_layout -->|"routes"| node_app_layout
node_auth_layout -->|"wraps"| node_auth_login
node_auth_layout -->|"wraps"| node_auth_register
node_app_layout -->|"uses"| node_app_shell
node_app_layout -->|"wraps"| node_providers
node_app_shell -->|"composes"| node_app_shell_client
node_providers -->|"includes"| node_user_context
node_providers -->|"includes"| node_teams_context
node_providers -->|"includes"| node_tournaments_context
node_app_layout -->|"navigates"| node_dashboard_page
node_app_layout -->|"navigates"| node_tournaments_page
node_app_layout -->|"navigates"| node_teams_page
node_app_layout -->|"navigates"| node_matches_page
node_app_layout -->|"navigates"| node_score_entry_page
node_app_layout -->|"navigates"| node_presentation_page
node_auth_login -->|"uses"| node_auth_form
node_auth_register -->|"uses"| node_auth_form
node_tournaments_page -->|"uses"| node_tournament_form
node_teams_page -->|"uses"| node_teams_manager
node_dashboard_page -->|"reads"| node_tournaments_context
node_profile_settings -->|"reads"| node_user_context
node_auth_login -->|"calls"| node_auth_api
node_auth_register -->|"calls"| node_auth_api
node_tournaments_page -->|"calls"| node_tournaments_api
node_teams_page -->|"calls"| node_teams_api
node_matches_page -->|"calls"| node_matches_api
node_score_entry_page -->|"calls"| node_score_api
node_presentation_page -->|"reads"| node_matches_api
node_ops_api -->|"reads/writes"| node_db_queries
node_auth_api -->|"reads/writes"| node_db_queries
node_tournaments_api -->|"reads/writes"| node_db_queries
node_teams_api -->|"reads/writes"| node_db_queries
node_matches_api -->|"reads/writes"| node_db_queries
node_score_api -->|"writes"| node_db_queries
node_db_queries -->|"uses"| node_db_connection
node_db_seed -->|"initializes"| node_db_connection
node_db_connection -->|"opens"| node_sqlite_file

click node_root_layout "https://github.com/uneven-coder/tournament-prototype/blob/master/app/layout.tsx"
click node_home_page "https://github.com/uneven-coder/tournament-prototype/blob/master/app/page.tsx"
click node_auth_layout "https://github.com/uneven-coder/tournament-prototype/blob/master/app/(auth)/layout.tsx"
click node_auth_login "https://github.com/uneven-coder/tournament-prototype/blob/master/app/(auth)/login/page.tsx"
click node_auth_register "https://github.com/uneven-coder/tournament-prototype/blob/master/app/(auth)/register/page.tsx"
click node_app_layout "https://github.com/uneven-coder/tournament-prototype/blob/master/app/(app)/layout.tsx"
click node_dashboard_page "https://github.com/uneven-coder/tournament-prototype/blob/master/app/(app)/dashboard/page.tsx"
click node_tournaments_page "https://github.com/uneven-coder/tournament-prototype/blob/master/app/(app)/tournaments/[id]/page.tsx"
click node_teams_page "https://github.com/uneven-coder/tournament-prototype/blob/master/app/(app)/teams/page.tsx"
click node_matches_page "https://github.com/uneven-coder/tournament-prototype/blob/master/app/(app)/matches/page.tsx"
click node_score_entry_page "https://github.com/uneven-coder/tournament-prototype/blob/master/app/(app)/score-entry/page.tsx"
click node_presentation_page "https://github.com/uneven-coder/tournament-prototype/blob/master/app/presentation/[id]/page.tsx"
click node_app_shell "https://github.com/uneven-coder/tournament-prototype/blob/master/components/blocks/app-shell.tsx"
click node_app_shell_client "https://github.com/uneven-coder/tournament-prototype/blob/master/components/blocks/app-shell-client.tsx"
click node_providers "https://github.com/uneven-coder/tournament-prototype/blob/master/lib/hooks/providers.tsx"
click node_user_context "https://github.com/uneven-coder/tournament-prototype/blob/master/lib/hooks/user-context.tsx"
click node_teams_context "https://github.com/uneven-coder/tournament-prototype/blob/master/lib/hooks/teams-context.tsx"
click node_tournaments_context "https://github.com/uneven-coder/tournament-prototype/blob/master/lib/hooks/tournaments-context.tsx"
click node_auth_form "https://github.com/uneven-coder/tournament-prototype/blob/master/components/features/auth-form.tsx"
click node_tournament_form "https://github.com/uneven-coder/tournament-prototype/blob/master/components/features/tournament-form.tsx"
click node_teams_manager "https://github.com/uneven-coder/tournament-prototype/blob/master/components/features/teams-manager.tsx"
click node_profile_settings "https://github.com/uneven-coder/tournament-prototype/blob/master/components/features/profile-settings.tsx"
click node_db_connection "https://github.com/uneven-coder/tournament-prototype/blob/master/lib/db/connection.ts"
click node_db_queries "https://github.com/uneven-coder/tournament-prototype/blob/master/lib/db/queries.ts"
click node_db_seed "https://github.com/uneven-coder/tournament-prototype/blob/master/lib/db/seed.ts"
click node_sqlite_file "https://github.com/uneven-coder/tournament-prototype/blob/master/data/tournament.sqlite"
click node_auth_api "https://github.com/uneven-coder/tournament-prototype/blob/master/app/api/auth/login/route.ts"
click node_tournaments_api "https://github.com/uneven-coder/tournament-prototype/blob/master/app/api/tournaments/route.ts"
click node_teams_api "https://github.com/uneven-coder/tournament-prototype/blob/master/app/api/teams/route.ts"
click node_matches_api "https://github.com/uneven-coder/tournament-prototype/blob/master/app/api/matches/route.ts"
click node_score_api "https://github.com/uneven-coder/tournament-prototype/blob/master/app/api/matches/[id]/score/route.ts"
click node_ops_api "https://github.com/uneven-coder/tournament-prototype/blob/master/app/api/venues/route.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_root_layout,node_home_page,node_auth_layout,node_auth_login,node_auth_register,node_app_layout,node_dashboard_page,node_tournaments_page,node_teams_page,node_matches_page,node_score_entry_page,node_presentation_page toneBlue
class node_auth_api,node_tournaments_api,node_teams_api,node_matches_api,node_score_api,node_ops_api toneAmber
class node_app_shell,node_app_shell_client,node_providers,node_user_context,node_teams_context,node_tournaments_context,node_auth_form,node_tournament_form,node_teams_manager,node_profile_settings,node_db_connection,node_db_queries,node_db_seed toneMint
class node_sqlite_file toneRose
```

## Components

### App UI

Route-driven screens and route shells

- [Root Layout](https://github.com/uneven-coder/tournament-prototype/blob/master/app/layout.tsx): next-root · Global document shell · `app/layout.tsx`
- [Home](https://github.com/uneven-coder/tournament-prototype/blob/master/app/page.tsx): landing-page · Entry point into the prototype · `app/page.tsx`
- [Auth Layout](https://github.com/uneven-coder/tournament-prototype/blob/master/app/(auth)/layout.tsx): route-shell · Login and registration shell · `app/(auth)/layout.tsx`
- [Login](https://github.com/uneven-coder/tournament-prototype/blob/master/app/(auth)/login/page.tsx): auth-page · Sign-in screen · `app/(auth)/login/page.tsx`
- [Register](https://github.com/uneven-coder/tournament-prototype/blob/master/app/(auth)/register/page.tsx): auth-page · Account creation screen · `app/(auth)/register/page.tsx`
- [App Shell Route](https://github.com/uneven-coder/tournament-prototype/blob/master/app/(app)/layout.tsx): app-shell-route · Authenticated product frame · `app/(app)/layout.tsx`
- [Dashboard](https://github.com/uneven-coder/tournament-prototype/blob/master/app/(app)/dashboard/page.tsx): overview-page · Main authenticated landing page · `app/(app)/dashboard/page.tsx`
- [Tournaments](https://github.com/uneven-coder/tournament-prototype/blob/master/app/(app)/tournaments/[id]/page.tsx): tournament-hub · Tournament listing and management · `app/(app)/tournaments/[id]/page.tsx`
- [Teams](https://github.com/uneven-coder/tournament-prototype/blob/master/app/(app)/teams/page.tsx): team-page · Team administration screen · `app/(app)/teams/page.tsx`
- [Matches](https://github.com/uneven-coder/tournament-prototype/blob/master/app/(app)/matches/page.tsx): match-page · Match browsing and operations · `app/(app)/matches/page.tsx`
- [Score Entry](https://github.com/uneven-coder/tournament-prototype/blob/master/app/(app)/score-entry/page.tsx): workflow-page · Manual score submission flow · `app/(app)/score-entry/page.tsx`
- [Presentation](https://github.com/uneven-coder/tournament-prototype/blob/master/app/presentation/[id]/page.tsx): read-only-page · Shareable display view · `app/presentation/[id]/page.tsx`

### API Layer

Local backend endpoints over SQLite

- [Auth API](https://github.com/uneven-coder/tournament-prototype/blob/master/app/api/auth/login/route.ts): endpoint-set · Login, signup, session, and verification routes · `app/api/auth/login/route.ts`
- [Tournaments API](https://github.com/uneven-coder/tournament-prototype/blob/master/app/api/tournaments/route.ts): resource-api · Tournament CRUD endpoints · `app/api/tournaments/route.ts`
- [Teams API](https://github.com/uneven-coder/tournament-prototype/blob/master/app/api/teams/route.ts): resource-api · Team endpoints · `app/api/teams/route.ts`
- [Matches API](https://github.com/uneven-coder/tournament-prototype/blob/master/app/api/matches/route.ts): resource-api · Match CRUD and score endpoints · `app/api/matches/route.ts`
- [Score API](https://github.com/uneven-coder/tournament-prototype/blob/master/app/api/matches/[id]/score/route.ts): action-api · Score submission endpoint · `app/api/matches/[id]/score/route.ts`
- [Ops API](https://github.com/uneven-coder/tournament-prototype/blob/master/app/api/venues/route.ts): resource-api · Approvals, attendance, leaderboard, registry, rules, profile, venues, users · `app/api/venues/route.ts`

### Shared System

Reusable components, state, and persistence

- [App Shell](https://github.com/uneven-coder/tournament-prototype/blob/master/components/blocks/app-shell.tsx): layout-component · Shared header/sidebar frame · `components/blocks/app-shell.tsx`
- [Shell Client](https://github.com/uneven-coder/tournament-prototype/blob/master/components/blocks/app-shell-client.tsx): client-component · Client-side shell behavior · `components/blocks/app-shell-client.tsx`
- [Providers](https://github.com/uneven-coder/tournament-prototype/blob/master/lib/hooks/providers.tsx): state-composition · Composes global client contexts · `lib/hooks/providers.tsx`
- [User Context](https://github.com/uneven-coder/tournament-prototype/blob/master/lib/hooks/user-context.tsx): client-state · Session and user state · `lib/hooks/user-context.tsx`
- [Teams Context](https://github.com/uneven-coder/tournament-prototype/blob/master/lib/hooks/teams-context.tsx): client-state · Teams state cache · `lib/hooks/teams-context.tsx`
- [Tournaments Context](https://github.com/uneven-coder/tournament-prototype/blob/master/lib/hooks/tournaments-context.tsx): client-state · Tournament state cache · `lib/hooks/tournaments-context.tsx`
- [Auth Form](https://github.com/uneven-coder/tournament-prototype/blob/master/components/features/auth-form.tsx): feature-form · Reusable login/register form · `components/features/auth-form.tsx`
- [Tournament Form](https://github.com/uneven-coder/tournament-prototype/blob/master/components/features/tournament-form.tsx): feature-form · Tournament editor component · `components/features/tournament-form.tsx`
- [Teams Manager](https://github.com/uneven-coder/tournament-prototype/blob/master/components/features/teams-manager.tsx): feature-module · Team administration UI · `components/features/teams-manager.tsx`
- [Profile Settings](https://github.com/uneven-coder/tournament-prototype/blob/master/components/features/profile-settings.tsx): feature-module · Account settings editor · `components/features/profile-settings.tsx`
- [DB Connection](https://github.com/uneven-coder/tournament-prototype/blob/master/lib/db/connection.ts): sqlite-core · SQLite connection setup · `lib/db/connection.ts`
- [Queries](https://github.com/uneven-coder/tournament-prototype/blob/master/lib/db/queries.ts): data-access · Persistence query layer · `lib/db/queries.ts`
- [Seed Data](https://github.com/uneven-coder/tournament-prototype/blob/master/lib/db/seed.ts): bootstrap · Initial demo records · `lib/db/seed.ts`

### Data Store

Bundled SQLite database

- [SQLite File](https://github.com/uneven-coder/tournament-prototype/blob/master/data/tournament.sqlite): database-file · Bundled tournament database · `data/tournament.sqlite`

## Connections

- Root Layout → Home: routes · Root entry renders landing page
- Root Layout → Auth Layout: routes · Routes into auth area
- Root Layout → App Shell Route: routes · Routes into authenticated area
- Auth Layout → Login: wraps · Auth shell renders login screen
- Auth Layout → Register: wraps · Auth shell renders registration screen
- App Shell Route → App Shell: uses · Authenticated area uses shared shell
- App Shell Route → Providers: wraps · Injects global client state
- App Shell → Shell Client: composes · Shell includes client-side behavior
- Providers → User Context: includes · Session state provider
- Providers → Teams Context: includes · Teams state provider
- Providers → Tournaments Context: includes · Tournament state provider
- App Shell Route → Dashboard: navigates · Default authenticated landing screen
- App Shell Route → Tournaments: navigates · Tournament management area
- App Shell Route → Teams: navigates · Team management area
- App Shell Route → Matches: navigates · Match operations area
- App Shell Route → Score Entry: navigates · Score submission workflow
- App Shell Route → Presentation: navigates · Presentation/read-only view
- Login → Auth Form: uses · Login screen composes form
- Register → Auth Form: uses · Register screen composes form
- Tournaments → Tournament Form: uses · Create/edit tournament flow
- Teams → Teams Manager: uses · Team administration UI
- Dashboard → Tournaments Context: reads · Dashboard reflects tournament state
- Profile Settings → User Context: reads · Profile UI uses current user state
- Login → Auth API: calls · Authenticates through API
- Register → Auth API: calls · Registers through API
- Tournaments → Tournaments API: calls · Loads and updates tournaments
- Teams → Teams API: calls · Loads and updates teams
- Matches → Matches API: calls · Reads match data
- Score Entry → Score API: calls · Submits scores
- Presentation → Matches API: reads · Presentation consumes match data
- Ops API → Queries: reads/writes · Operational endpoints persist through queries
- Auth API → Queries: reads/writes · Auth operations persist through queries
- Tournaments API → Queries: reads/writes · Tournament persistence
- Teams API → Queries: reads/writes · Team persistence
- Matches API → Queries: reads/writes · Match persistence
- Score API → Queries: writes · Score submission updates state
- Queries → DB Connection: uses · Runs against SQLite connection
- Seed Data → DB Connection: initializes · Seeds demo database on startup
- DB Connection → SQLite File: opens · Connection targets bundled SQLite file
