# raymondcsirak/sunlight-tennis architecture

> Architecture diagram of the GitHub repository raymondcsirak/sunlight-tennis, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/raymondcsirak/sunlight-tennis
- Repository: https://github.com/raymondcsirak/sunlight-tennis

## Overview

##### Main Components

a. Frontend Layer:
- Next.js App Router Structure
- Auth Pages (/auth-pages)
- Protected Routes (/authenticated)
- Profile Management
- Partner Finder System
- Court Booking System
- Training Session Management
- UI Components (shadcn/ui)
- State Management (Client-side)

b. Backend Layer:
- Next.js API Routes
- Server Actions
- Middleware (Authentication)
- Supabase Integration

c. Database Layer (Supabase):
- Authentication System
- Database Tables (visible from migrations):
- Profiles
- Courts
- Training Sessions
- Matches
- Achievements
- Player Stats
- Notifications
- Real-time Subscriptions
- Storage (for avatars)

##### Key Relationships to Highlight

Client → Auth Pages → Supabase Auth → Protected Routes
- Data flow patterns:
Client → API Routes → Supabase → Client
- Real-time connections:
Supabase Real-time → Client
- Storage interactions:
Client → Storage (Avatar Upload) → Supabase Storage

##### Architectural Patterns to Emphasize

- Route Groups (shown by the (auth-pages) and (authenticated) directories)
- Server Components vs Client Components
- API Routes Structure
- Database Schema Relationships

##### Specific Implementation Details

**┌─ User Management ─────┐    ┌─ Game Features ──────┐**
- Authentication     │    │ - Match Making       │
- Profile Management │    │ - Court Booking      │
- Settings          │    │ - Training Sessions  │
- ┘    └────────────────────┘

**┌─ Gamification ───────┐    ┌─ Social Features ────┐**
- XP System         │    │ - Partner Finder     │
- Achievements      │    │ - Notifications      │
- Player Stats      │    │ - Match Responses    │
- ┘    └────────────────────┘

##### Additional Elements

- A section for external integrations (Vercel deployment)
- Middleware placement and function
- Security layer (RLS policies from migrations)
- File storage system for avatars
- Notification system's real-time capabilities

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        FE[Frontend Application]
        UI["UI Components"]:::ui
        NC["Notifications Component"]:::notifications
        PS["Player Stats Component"]:::playerstats
    end

    subgraph "Next.js Layer"
        direction TB
        AP["Auth Pages"]:::auth
        PR["Protected Routes"]:::auth
        MW["Middleware"]:::auth
        
        subgraph "Feature Modules"
            direction TB
            PM["Profile Management"]:::profile
            PF["Partner Finder"]:::partnerfinder
            CB["Court Booking"]:::courts
            TS["Training Sessions"]:::training
            AS["Achievement System"]:::achievements
        end
        
        subgraph "API Layer"
            direction TB
            AR["API Routes"]:::api
            SA["Server Actions"]:::api
        end
    end

    subgraph "Supabase Services"
        direction TB
        Auth["Authentication"]
        RT["Real-time Subscriptions"]
        Storage["File Storage"]
        
        subgraph "Database Tables"
            direction TB
            Profiles[("Profiles")]:::db
            Courts[("Courts")]:::db
            Training[("Training Sessions")]:::db
            Matches[("Matches")]:::db
            Achievements[("Achievements")]:::db
            Stats[("Player Stats")]:::db
            Notif[("Notifications")]:::db
        end
    end

    %% Relationships
    FE --> UI
    FE --> NC
    FE --> PS
    FE --> AP
    AP --> Auth
    Auth --> PR
    PR --> PM
    PR --> PF
    PR --> CB
    PR --> TS
    PR --> AS
    
    PM --> AR
    PF --> AR
    CB --> AR
    TS --> AR
    AS --> AR
    
    AR --> Auth
    SA --> Auth
    
    Auth --> Profiles
    Auth --> Courts
    Auth --> Training
    Auth --> Matches
    Auth --> Achievements
    Auth --> Stats
    Auth --> Notif
    
    RT --> NC
    Storage --> PM

    %% Click Events
    click AP "https://github.com/raymondcsirak/sunlight-tennis/tree/main/app/(auth-pages)"
    click MW "https://github.com/raymondcsirak/sunlight-tennis/blob/main/middleware.ts"
    click PM "https://github.com/raymondcsirak/sunlight-tennis/tree/main/app/(authenticated)/profile"
    click PF "https://github.com/raymondcsirak/sunlight-tennis/tree/main/app/(authenticated)/profile/partner-finder"
    click CB "https://github.com/raymondcsirak/sunlight-tennis/tree/main/app/(authenticated)/profile/courts"
    click TS "https://github.com/raymondcsirak/sunlight-tennis/tree/main/app/(authenticated)/profile/training"
    click AS "https://github.com/raymondcsirak/sunlight-tennis/blob/main/lib/services/achievement.service.ts"
    click NC "https://github.com/raymondcsirak/sunlight-tennis/tree/main/app/_components/notifications"
    click PS "https://github.com/raymondcsirak/sunlight-tennis/tree/main/app/_components/player-stats"
    click UI "https://github.com/raymondcsirak/sunlight-tennis/tree/main/components/ui"
    click AR "https://github.com/raymondcsirak/sunlight-tennis/tree/main/app/api"

    %% Styles
    classDef frontend fill:#2196F3,color:white
    classDef auth fill:#FF5722,color:white
    classDef api fill:#4CAF50,color:white
    classDef db fill:#9C27B0,color:white
    classDef ui fill:#03A9F4,color:white
    classDef notifications fill:#FF9800,color:white
    classDef playerstats fill:#8BC34A,color:white
    classDef profile fill:#00BCD4,color:white
    classDef partnerfinder fill:#009688,color:white
    classDef courts fill:#E91E63,color:white
    classDef training fill:#673AB7,color:white
    classDef achievements fill:#FFC107,color:white

    %% Legend
    subgraph Legend
        L1[Frontend]:::frontend
        L2[Auth Components]:::auth
        L3[API Layer]:::api
        L4[("Database")]:::db
        L5[UI Components]:::ui
        L6[Features]:::profile
    end
```
