# uoawdcc/esports-club architecture

> Architecture diagram of the GitHub repository uoawdcc/esports-club, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/uoawdcc/esports-club
- Repository: https://github.com/uoawdcc/esports-club

## Overview

##### Project Type and Purpose
- This is a full‑stack Next.js application (“src/app”, “next.config.ts”) for club membership and tournament management.
- It uses React on the frontend, Next API routes on the backend, and a Postgres database hosted via Supabase.
- Auth is handled by NextAuth (see “src/app/api/auth/[...nextauth]”) with possible Google OAuth.
- Deployment runs on Fly.io with GitHub Actions CI/CD.

##### File Structure to Extract Main Components
- Frontend UI (client‑side React):
– src/app/(frontend) for pages & layouts
– src/components/ui for shared UI elements
– Tailwind CSS in globals.css & postcss.config.mjs
- API Layer (serverless functions):
– src/app/api/auth for NextAuth routes
– src/server for any custom server logic (mockCreateUser)
- Data Access Layer:
– src/libs/db (Drizzle config & schema) connecting to Supabase Postgres
– src/libs/env for environment variables
– potentially Prisma if in use (badged in README)
- State / Data Fetching:
– src/components/providers/query (TanStack Query)
– src/hooks/api for custom hooks
- Authentication:
– next-auth integration in src/auth.ts & API routes
- Infrastructure & DevOps:
– Dockerfile, fly.toml / fly.staging.toml for container & Fly.io
– GitHub Actions workflows for build & deploy (build.yml, fly-deploy*.yml)

a. Frontend Browser (clients)
– Connects over HTTPS to Next.js server
– Houses React UI, interacts with Query Client Provider
b. Next.js Server (Node.js on Fly.io)
– Serves SSR/SSG pages from src/app
– Exposes API routes under /api/auth
– Hosts middleware.ts for request handling (auth guard, routing)
c. Authentication Service
– NextAuth engine, using Google OAuth (external)
– Reads/writes user sessions to Supabase Auth or your own DB
d. Database Layer (Supabase Postgres)
– Accessed via Drizzle ORM (drizzle.config.ts → src/libs/db)
– Stores users, memberships, tournaments, profiles
e. External Services
– Google OAuth for sign‑in
– Fly.io platform for deployment
– GitHub Actions for CI/CD

##### Architectural Patterns & Design Principles
- Client‑Server separation: React SPA vs. Next API routes
- Serverless Functions (API routes) handling auth & data endpoints
- Single Source of Truth in Postgres DB via ORM
- Modular directory structure: “app” for routing, “components” for UI, “libs” for shared logic
- CI/CD pipeline defined in GitHub Actions, Docker container for uniform env

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Browser Client Layer
    subgraph "Browser Client" 
        direction TB
        Page["page.tsx"]:::client
        Layout["layout.tsx"]:::client
        GlobalsCSS["globals.css"]:::client
        ProtectedProfile["profile/page.tsx"]:::client
        StaffPage["staff/page.tsx"]:::client
        MockUserComponent["MockUser.tsx"]:::client
        Button["Button.tsx"]:::client
        GoogleAuthButton["GoogleAuthButton.tsx"]:::client
        SuspenseButton["SuspenseButton.tsx"]:::client
        Footer["Footer.tsx"]:::client
        StandardLayout["StandardLayout.tsx"]:::client
        GoogleSVG["google.tsx"]:::client
        TanstackProvider["TanstackClientProvider.tsx"]:::client
        HookMockUser["MockUser.ts"]:::client
        HookDebounce["useDebounce.tsx"]:::client
    end

    %% Next.js Server Layer
    subgraph "Next.js Server" 
        direction TB
        SSR["SSR/SSG Page Renderer"]:::server
        API["API Endpoints"]:::server
        Middleware["middleware.ts"]:::server
        NextAuthRoute["[...nextauth]/route.ts"]:::server
        AuthConfig["auth.ts"]:::server
        NextAuthTypes["next-auth.d.ts"]:::server
        MockCreateUser["mockCreateUser.ts"]:::server
        DrizzleConfig["drizzle.config.ts"]:::data
        DBIndex["db/index.ts"]:::data
        DBSchema["db/schema.ts"]:::data
        EnvConfig["env/index.ts"]:::server
        EnvExample[".env.example"]:::server
        Routes["routes/index.ts"]:::server
        UtilsIndex["utils/index.ts"]:::server
        ZodLib["zod/index.ts"]:::server
        MotionEase["motion/ease.ts"]:::server
    end

    %% External & Infrastructure
    GoogleOAuth["Google OAuth"]:::external
    DB["Supabase Postgres"]:::data
    CDN["CDN (Fly.io)"]:::infra
    CI["GitHub Actions CI/CD"]:::infra

    %% Connections
    Page -->|HTTP Request| SSR
    SSR -->|Serves Pages| Page
    Page -->|Data Fetch| TanstackProvider
    TanstackProvider -->|HTTP Request| API
    API -->|NextAuth Flow| NextAuthRoute
    NextAuthRoute -->|OAuth Redirect| GoogleOAuth
    NextAuthRoute -->|Session Store| DB
    SSR -->|DB Query| DB
    API -->|Use ORM| DrizzleConfig
    DrizzleConfig -->|Connect| DBIndex
    DBIndex -->|Schema| DBSchema
    SSR -->|Env Vars| EnvConfig
    EnvConfig -->|Load| EnvExample
    Middleware -->|Guards| SSR
    SSR -->|Routes Utils| Routes
    SSR -->|Utils| UtilsIndex
    SSR -->|Validation| ZodLib
    SSR -->|Animation| MotionEase
    SSR -->|Mock Logic| MockCreateUser
    CDN -->|Hosts Static| GlobalsCSS
    CI -->|Deploy| SSR
    CI -->|Config| fly.toml
    CI -->|Config| fly.staging.toml

    %% Click Events
    click Page "https://github.com/uoawdcc/esports-club/blob/main/src/app/(frontend)/page.tsx"
    click Layout "https://github.com/uoawdcc/esports-club/blob/main/src/app/(frontend)/layout.tsx"
    click GlobalsCSS "https://github.com/uoawdcc/esports-club/blob/main/src/app/(frontend)/globals.css"
    click ProtectedProfile "https://github.com/uoawdcc/esports-club/blob/main/src/app/(frontend)/(protected)/profile/page.tsx"
    click StaffPage "https://github.com/uoawdcc/esports-club/blob/main/src/app/(frontend)/(staff)/staff/page.tsx"
    click MockUserComponent "https://github.com/uoawdcc/esports-club/blob/main/src/app/(frontend)/(staff)/staff/_components/MockUser.tsx"
    click Button "https://github.com/uoawdcc/esports-club/blob/main/src/components/ui/button/Button.tsx"
    click GoogleAuthButton "https://github.com/uoawdcc/esports-club/blob/main/src/components/ui/button/GoogleAuthButton.tsx"
    click SuspenseButton "https://github.com/uoawdcc/esports-club/blob/main/src/components/ui/button/SuspenseButton.tsx"
    click Footer "https://github.com/uoawdcc/esports-club/blob/main/src/components/ui/footer/Footer.tsx"
    click StandardLayout "https://github.com/uoawdcc/esports-club/blob/main/src/components/ui/layout/StandardLayout.tsx"
    click GoogleSVG "https://github.com/uoawdcc/esports-club/blob/main/src/components/ui/svg/google.tsx"
    click TanstackProvider "https://github.com/uoawdcc/esports-club/blob/main/src/components/providers/query/TanstackClientProvider.tsx"
    click HookMockUser "https://github.com/uoawdcc/esports-club/blob/main/src/hooks/api/MockUser.ts"
    click HookDebounce "https://github.com/uoawdcc/esports-club/blob/main/src/hooks/useDebounce.tsx"
    click NextAuthRoute "https://github.com/uoawdcc/esports-club/blob/main/src/app/api/auth/[...nextauth]/route.ts"
    click AuthConfig "https://github.com/uoawdcc/esports-club/blob/main/src/auth.ts"
    click NextAuthTypes "https://github.com/uoawdcc/esports-club/blob/main/src/libs/types/next-auth.d.ts"
    click MockCreateUser "https://github.com/uoawdcc/esports-club/blob/main/src/server/mockCreateUser.ts"
    click DrizzleConfig "https://github.com/uoawdcc/esports-club/blob/main/drizzle.config.ts"
    click DBIndex "https://github.com/uoawdcc/esports-club/blob/main/src/libs/db/index.ts"
    click DBSchema "https://github.com/uoawdcc/esports-club/blob/main/src/libs/db/schema.ts"
    click EnvConfig "https://github.com/uoawdcc/esports-club/blob/main/src/libs/env/index.ts"
    click EnvExample "https://github.com/uoawdcc/esports-club/blob/main/.env.example"
    click Routes "https://github.com/uoawdcc/esports-club/blob/main/src/libs/routes/index.ts"
    click UtilsIndex "https://github.com/uoawdcc/esports-club/blob/main/src/libs/utils/index.ts"
    click ZodLib "https://github.com/uoawdcc/esports-club/blob/main/src/libs/zod/index.ts"
    click MotionEase "https://github.com/uoawdcc/esports-club/blob/main/src/libs/motion/ease.ts"
    click Middleware "https://github.com/uoawdcc/esports-club/blob/main/src/middleware.ts"
    click GlobalsCSS "https://github.com/uoawdcc/esports-club/blob/main/postcss.config.mjs"
    click GlobalsCSS "https://github.com/uoawdcc/esports-club/blob/main/src/app/(frontend)/globals.css"
    click CI "https://github.com/uoawdcc/esports-club/blob/main/ .github/workflows/build.yml"
    click CI "https://github.com/uoawdcc/esports-club/blob/main/ .github/workflows/fly-deploy.yml"
    click CI "https://github.com/uoawdcc/esports-club/blob/main/ .github/workflows/fly-deploy-staging.yml"

    %% Styles
    classDef client fill:#cce5ff,stroke:#004085,color:#004085,stroke-width:1px;
    classDef server fill:#d1ecf1,stroke:#0c5460,color:#0c5460,stroke-width:1px;
    classDef data fill:#d4edda,stroke:#155724,color:#155724,stroke-width:1px;
    classDef external fill:#fff3cd,stroke:#856404,color:#856404,stroke-width:1px;
    classDef infra fill:#e2e3e5,stroke:#6c757d,color:#6c757d,stroke-width:1px;
```
