# lekyucv/tc-team-football architecture

> Architecture diagram of the GitHub repository lekyucv/tc-team-football, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/lekyucv/tc-team-football
- Repository: https://github.com/lekyucv/tc-team-football

## Overview

TC TEAM is a Vietnamese internal football-team management PWA. Members view upcoming matches, register for a place or waitlist, submit payment proof, and track match credits; admins manage matches, members, payments, team funds, and backups. Match scheduling and allocation, payment verification, accounting, and notifications are distinct operational stages. The graph emphasizes documented workflows and sampled call sites; some broader feature links rely on the README because many routes were not sampled.

Main entry points: [`db/schema.ts`](https://github.com/lekyucv/tc-team-football/blob/main/db/schema.ts) (D1 database), [`app/api/bootstrap/route.ts`](https://github.com/lekyucv/tc-team-football/blob/main/app/api/bootstrap/route.ts) (Portal bootstrap), [`app/lib/registrations.ts`](https://github.com/lekyucv/tc-team-football/blob/main/app/lib/registrations.ts) (Seat allocation), [`app/lib/schedule.ts`](https://github.com/lekyucv/tc-team-football/blob/main/app/lib/schedule.ts) (Scheduling rules)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["PWA experience"]
  node_pwa["Team interface<br/>[tc-app.tsx]"]
  node_adminui["Admin interface<br/>[page.tsx]"]
end

subgraph group_api["Application API"]
  node_bootstrap["Portal bootstrap<br/>[route.ts]"]
  node_matchapi["Match APIs<br/>[route.ts]"]
  node_registerapi["Registration APIs<br/>[route.ts]"]
  node_community["Community view<br/>[route.ts]"]
  node_adminmatch["Admin match API<br/>[route.ts]"]
  node_adminfund["Admin fund API<br/>[route.ts]"]
  node_insights["Member insights<br/>[member-insights.ts]"]
end

subgraph group_matches["Match operations"]
  node_scheduling["Scheduling rules<br/>[schedule.ts]"]
  node_registrations["Seat allocation<br/>[registrations.ts]"]
  node_rounds["Match rounds<br/>[route.ts]"]
  node_timer["Match timers<br/>[match-timer.ts]"]
  node_timezone["Vietnam time rules<br/>[timezone.ts]"]
end

subgraph group_finance["Payments and funds"]
  node_payment["Payment confirmation"]
  node_proofs["Payment proofs<br/>[payment-proofs.ts]"]
  node_sepay["SePay reconciliation<br/>[sepay.ts]"]
  node_accounting["Team accounting<br/>[accounting.ts]"]
  node_credits["Match credits<br/>[match-credits.ts]"]
end

subgraph group_platform["Identity and data"]
  node_backups["Backup and restore<br/>[backups.ts]"]
  node_server["Sessions and server<br/>[server.ts]"]
  node_db[("D1 database<br/>[schema.ts]")]
  node_notifications["Notifications<br/>[notifications.ts]"]
end

node_member(("Member"))
node_admin(("Admin"))
node_drive["Google Drive"]
node_sepayservice["SePay service"]
node_openai["OpenAI vision"]
node_push["Web Push"]

node_member -->|"uses"| node_pwa
node_admin -->|"manages"| node_adminui
node_pwa -.->|"loads portal data"| node_bootstrap
node_adminui -.->|"loads admin data"| node_bootstrap
node_bootstrap -->|"gets session and database"| node_server
node_bootstrap -->|"loads upcoming matches"| node_scheduling
node_bootstrap -->|"migrates legacy credits"| node_payment
node_bootstrap -->|"reads portal data"| node_db
node_member -->|"requests a place"| node_registerapi
node_registerapi -.->|"handles registration"| node_registrations
node_registrations -->|"checks match phase"| node_scheduling
node_registrations -->|"reads and writes registrations"| node_db
node_registrations -->|"queues notices"| node_notifications
node_matchapi -.->|"serves match schedule"| node_scheduling
node_scheduling -->|"uses HCM timestamps"| node_timezone
node_scheduling -->|"reads and creates matches"| node_db
node_community -->|"summarizes member history"| node_insights
node_community -->|"reads community data"| node_db
node_adminmatch -->|"reconciles match"| node_registrations
node_adminmatch -->|"records pitch costs"| node_accounting
node_adminmatch -->|"reads and updates match"| node_db
node_adminfund -->|"reads and writes fund records"| node_db
node_adminfund -->|"checks admin access"| node_server
node_member -->|"submits payment proof"| node_proofs
node_proofs -.->|"analyzes bill image"| node_openai
node_sepayservice -->|"sends transactions"| node_sepay
node_sepay -->|"confirms matched payment"| node_payment
node_payment -->|"credits verified top-up"| node_credits
node_payment -->|"updates payment records"| node_db
node_adminfund -.->|"summarizes fund activity"| node_accounting
node_backups -->|"stores backups"| node_drive
node_backups -.->|"backs up and restores data"| node_db
node_notifications -.->|"delivers web push"| node_push
node_server -->|"stores session hashes"| node_db
node_admin -.->|"records match results"| node_rounds
node_admin -.->|"manages match timers"| node_timer

click node_pwa "https://github.com/lekyucv/tc-team-football/blob/main/app/tc-app.tsx"
click node_adminui "https://github.com/lekyucv/tc-team-football/blob/main/app/admin/page.tsx"
click node_bootstrap "https://github.com/lekyucv/tc-team-football/blob/main/app/api/bootstrap/route.ts"
click node_matchapi "https://github.com/lekyucv/tc-team-football/blob/main/app/api/matches/route.ts"
click node_registerapi "https://github.com/lekyucv/tc-team-football/blob/main/app/api/matches/%5Bid%5D/register/route.ts"
click node_community "https://github.com/lekyucv/tc-team-football/blob/main/app/api/community/route.ts"
click node_adminmatch "https://github.com/lekyucv/tc-team-football/blob/main/app/api/admin/matches/%5Bid%5D/route.ts"
click node_adminfund "https://github.com/lekyucv/tc-team-football/blob/main/app/api/admin/fund/route.ts"
click node_scheduling "https://github.com/lekyucv/tc-team-football/blob/main/app/lib/schedule.ts"
click node_registrations "https://github.com/lekyucv/tc-team-football/blob/main/app/lib/registrations.ts"
click node_rounds "https://github.com/lekyucv/tc-team-football/blob/main/app/api/match-results/route.ts"
click node_timer "https://github.com/lekyucv/tc-team-football/blob/main/app/lib/match-timer.ts"
click node_payment "https://github.com/lekyucv/tc-team-football/blob/main/app/lib/payment-confirmation.ts"
click node_proofs "https://github.com/lekyucv/tc-team-football/blob/main/app/lib/payment-proofs.ts"
click node_sepay "https://github.com/lekyucv/tc-team-football/blob/main/app/lib/sepay.ts"
click node_accounting "https://github.com/lekyucv/tc-team-football/blob/main/app/lib/accounting.ts"
click node_credits "https://github.com/lekyucv/tc-team-football/blob/main/app/lib/match-credits.ts"
click node_backups "https://github.com/lekyucv/tc-team-football/blob/main/app/lib/backups.ts"
click node_server "https://github.com/lekyucv/tc-team-football/blob/main/app/lib/server.ts"
click node_db "https://github.com/lekyucv/tc-team-football/blob/main/db/schema.ts"
click node_timezone "https://github.com/lekyucv/tc-team-football/blob/main/app/lib/timezone.ts"
click node_insights "https://github.com/lekyucv/tc-team-football/blob/main/app/lib/member-insights.ts"
click node_notifications "https://github.com/lekyucv/tc-team-football/blob/main/app/lib/notifications.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_pwa,node_adminui toneBlue
class node_bootstrap,node_matchapi,node_registerapi,node_community,node_adminmatch,node_adminfund,node_insights toneAmber
class node_scheduling,node_registrations,node_rounds,node_timer,node_timezone toneMint
class node_payment,node_proofs,node_sepay,node_accounting,node_credits toneRose
class node_backups,node_server,node_db,node_notifications,node_member,node_admin,node_drive,node_sepayservice,node_openai,node_push toneIndigo
```

## Components

### PWA experience

- [Team interface](https://github.com/lekyucv/tc-team-football/blob/main/app/tc-app.tsx): `app/tc-app.tsx`
- [Admin interface](https://github.com/lekyucv/tc-team-football/blob/main/app/admin/page.tsx): `app/admin/page.tsx`

### Application API

- [Portal bootstrap](https://github.com/lekyucv/tc-team-football/blob/main/app/api/bootstrap/route.ts): `app/api/bootstrap/route.ts`
- [Match APIs](https://github.com/lekyucv/tc-team-football/blob/main/app/api/matches/route.ts): `app/api/matches/route.ts`
- [Registration APIs](https://github.com/lekyucv/tc-team-football/blob/main/app/api/matches/%5Bid%5D/register/route.ts): `app/api/matches/[id]/register/route.ts`
- [Community view](https://github.com/lekyucv/tc-team-football/blob/main/app/api/community/route.ts): `app/api/community/route.ts`
- [Admin match API](https://github.com/lekyucv/tc-team-football/blob/main/app/api/admin/matches/%5Bid%5D/route.ts): `app/api/admin/matches/[id]/route.ts`
- [Admin fund API](https://github.com/lekyucv/tc-team-football/blob/main/app/api/admin/fund/route.ts): `app/api/admin/fund/route.ts`
- [Member insights](https://github.com/lekyucv/tc-team-football/blob/main/app/lib/member-insights.ts): `app/lib/member-insights.ts`

### Match operations

- [Scheduling rules](https://github.com/lekyucv/tc-team-football/blob/main/app/lib/schedule.ts): `app/lib/schedule.ts`
- [Seat allocation](https://github.com/lekyucv/tc-team-football/blob/main/app/lib/registrations.ts): `app/lib/registrations.ts`
- [Match rounds](https://github.com/lekyucv/tc-team-football/blob/main/app/api/match-results/route.ts): `app/api/match-results/route.ts`
- [Match timers](https://github.com/lekyucv/tc-team-football/blob/main/app/lib/match-timer.ts): `app/lib/match-timer.ts`
- [Vietnam time rules](https://github.com/lekyucv/tc-team-football/blob/main/app/lib/timezone.ts): `app/lib/timezone.ts`

### Payments and funds

- [Payment confirmation](https://github.com/lekyucv/tc-team-football/blob/main/app/lib/payment-confirmation.ts): `app/lib/payment-confirmation.ts`
- [Payment proofs](https://github.com/lekyucv/tc-team-football/blob/main/app/lib/payment-proofs.ts): `app/lib/payment-proofs.ts`
- [SePay reconciliation](https://github.com/lekyucv/tc-team-football/blob/main/app/lib/sepay.ts): `app/lib/sepay.ts`
- [Team accounting](https://github.com/lekyucv/tc-team-football/blob/main/app/lib/accounting.ts): `app/lib/accounting.ts`
- [Match credits](https://github.com/lekyucv/tc-team-football/blob/main/app/lib/match-credits.ts): `app/lib/match-credits.ts`

### Identity and data

- [Backup and restore](https://github.com/lekyucv/tc-team-football/blob/main/app/lib/backups.ts): `app/lib/backups.ts`
- [Sessions and server](https://github.com/lekyucv/tc-team-football/blob/main/app/lib/server.ts): `app/lib/server.ts`
- [D1 database](https://github.com/lekyucv/tc-team-football/blob/main/db/schema.ts): `db/schema.ts`
- [Notifications](https://github.com/lekyucv/tc-team-football/blob/main/app/lib/notifications.ts): `app/lib/notifications.ts`

### Other components

- **Member**
- **Admin**
- **Google Drive**
- **SePay service**
- **OpenAI vision**
- **Web Push**

## Connections

- Member → Team interface: uses (evidence: `README.md`)
- Admin → Admin interface: manages (evidence: `README.md`)
- Team interface → Portal bootstrap: loads portal data
- Admin interface → Portal bootstrap: loads admin data
- Portal bootstrap → Sessions and server: gets session and database (evidence: `app/api/bootstrap/route.ts`)
- Portal bootstrap → Scheduling rules: loads upcoming matches (evidence: `app/api/bootstrap/route.ts`)
- Portal bootstrap → Payment confirmation: migrates legacy credits (evidence: `app/api/bootstrap/route.ts`)
- Portal bootstrap → D1 database: reads portal data (evidence: `app/api/bootstrap/route.ts`)
- Member → Registration APIs: requests a place (evidence: `README.md`)
- Registration APIs → Seat allocation: handles registration
- Seat allocation → Scheduling rules: checks match phase (evidence: `app/lib/registrations.ts`)
- Seat allocation → D1 database: reads and writes registrations (evidence: `app/lib/registrations.ts`)
- Seat allocation → Notifications: queues notices (evidence: `app/lib/registrations.ts`)
- Match APIs → Scheduling rules: serves match schedule
- Scheduling rules → Vietnam time rules: uses HCM timestamps (evidence: `app/lib/schedule.ts`)
- Scheduling rules → D1 database: reads and creates matches (evidence: `app/lib/schedule.ts`)
- Community view → Member insights: summarizes member history (evidence: `app/api/community/route.ts`)
- Community view → D1 database: reads community data (evidence: `app/api/community/route.ts`)
- Admin match API → Seat allocation: reconciles match (evidence: `app/api/admin/matches/[id]/route.ts`)
- Admin match API → Team accounting: records pitch costs (evidence: `app/api/admin/matches/[id]/route.ts`)
- Admin match API → D1 database: reads and updates match (evidence: `app/api/admin/matches/[id]/route.ts`)
- Admin fund API → D1 database: reads and writes fund records (evidence: `app/api/admin/fund/route.ts`)
- Admin fund API → Sessions and server: checks admin access (evidence: `app/api/admin/fund/route.ts`)
- Member → Payment proofs: submits payment proof (evidence: `README.md`)
- Payment proofs → OpenAI vision: analyzes bill image (evidence: `README.md`)
- SePay service → SePay reconciliation: sends transactions (evidence: `README.md`)
- SePay reconciliation → Payment confirmation: confirms matched payment (evidence: `app/api/admin/sepay/route.ts`)
- Payment confirmation → Match credits: credits verified top-up (evidence: `app/lib/payment-confirmation.ts`)
- Payment confirmation → D1 database: updates payment records (evidence: `app/lib/payment-confirmation.ts`)
- Admin fund API → Team accounting: summarizes fund activity
- Backup and restore → Google Drive: stores backups (evidence: `README.md`)
- Backup and restore → D1 database: backs up and restores data
- Notifications → Web Push: delivers web push (evidence: `README.md`)
- Sessions and server → D1 database: stores session hashes (evidence: `app/lib/server.ts`)
- Admin → Match rounds: records match results
- Admin → Match timers: manages match timers
