# yuberley/sport-wear-shop architecture

> Architecture diagram of the GitHub repository yuberley/sport-wear-shop, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-08-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/yuberley/sport-wear-shop
- Repository: https://github.com/yuberley/sport-wear-shop

## Overview

##### Project type and purpose
- This is a full-stack Next.js (React) web application, bootstrapped with create-next-app.
- It offers both a public client site (product catalog, categories, contact form, promotions) and an authenticated dashboard (product management, configurations, reports).
- It uses Supabase as its backend (database, auth, storage) and deploys on Vercel.

##### File structure
- Top-level files: configuration (next.config.mjs, tsconfig.json, tailwind.config.ts, .eslintrc.json, .prettierrc), environment template (.env.example), package.json.
- public/: static assets.
- src/app/: Next.js App Router routes and layouts.
- /login, /auth/callback, /dashboard, /categories, /product, /[itemType]/[category], /contact, /promotions.
- Each folder contains page.tsx or route.ts for serverless API endpoints.
- src/lib/supabase/: Supabase client initialization, API handlers (handleProducts, handleCategories, etc.), salesApi.
- src/hooks, src/utils, src/constants, src/interfaces: utility modules and type definitions.
- src/providers.tsx: React Context/provider wrappers for theming, auth, or data.

##### README
- Confirms Next.js, how to run locally, links to docs.

a. Main components
- Browser (Client) – user’s web browser
- Next.js Frontend – React components and pages (src/app + src/components)
- Next.js API Routes – serverless functions (e.g. /auth/callback/route.ts)
- Supabase Backend – Auth service, PostgreSQL database, Storage
- Utility modules – hooks, utils, constants, interfaces
- External services – Vercel (hosting & CDN), Google Fonts

b. Relationships & interactions
1. User → Browser → Next.js Frontend (UI rendering, hydration)
2. Frontend → API Routes (fetch REST/JSON) for actions (login callback, CRUD)
3. API Routes (src/lib/supabase/handlers) → Supabase client → Database / Auth / Storage
4. Data ↔ Next.js `getServerSideProps` or server components (page.tsx) → UI
5. Providers wrap the app to supply auth state, theme, and routing context

c. Architectural patterns & design principles
- Front/Back separation via App Router + API routes
- Component-based UI (atoms, molecules, pages)
- Single responsibility: each handler manages one table (products, categories…)
- Layered modules: presentation (components), domain (interfaces, utils), data-access (lib/supabase)

d. Key technologies/frameworks
- Next.js 13+ (App Router, server components, layouts)
- React + TypeScript
- Supabase (PostgreSQL, Auth, Storage)
- Tailwind CSS for styling
- Vercel for deployment

##### Detailed breakdown of components
- Frontend Layer:
- “App Router” (src/app/layout.tsx)
- Public pages: Home (/), Product listing (/product), Item categories (/[itemType]), Contact (/contact), Promotions (/promotions)
- Auth flow: Login pages & callback route
- Dashboard pages: /dashboard, /dashboard/products, /dashboard/configurations, /dashboard/reports
- UI components: Header, SideNav, tables, cards
- API Layer:
- Auth callback route (src/app/auth/callback/route.ts)
- Supabase handlers: handleProducts, handleCategories, handleSizes, handleColors, handleImages
- salesApi (for reports queries)
- Data Layer (Supabase):
- Auth service (sign-in, session management)
- Storage bucket (images)

##### Final recommendations
- Data flows: e.g., “Fetch /api/products → returns JSON → UI ListProducts”.

## Diagram (Mermaid)

```mermaid
graph TB
    %% External Entities
    Browser["Browser"]:::external
    GoogleFonts["Google Fonts"]:::external
    Vercel["Vercel"]:::external

    %% Frontend Layer
    subgraph "Next.js Frontend" 
        direction TB
        AppRouter["App Router\n(layout.tsx)"]:::frontend
        GlobalCSS["Global Styles\n(globals.css)"]:::frontend
        Providers["App Providers\n(providers.tsx)"]:::frontend

        subgraph "Public Pages"
            direction TB
            Home["Home\n(page.tsx)"]:::frontend
            ProductListing["Product Listing\n(product/page.tsx)"]:::frontend
            ItemCategories["Item Types\n[itemType]/page.tsx"]:::frontend
            CategoryDetails["Category Details\n[category]/page.tsx"]:::frontend
            CategoriesRoot["Categories Root\n(categories/page.tsx)"]:::frontend
            CategoryBySlug["Category by Slug\n(categories/[category]/page.tsx)"]:::frontend
            Contact["Contact\n(contact/page.tsx)"]:::frontend
            Promotions["Promotions\n(promotions/page.tsx)"]:::frontend
        end

        subgraph "Auth Flow Pages"
            direction TB
            LoginLayout["Login Layout\n(login/layout.tsx)"]:::frontend
            LoginPage["Login Page\n(login/page.tsx)"]:::frontend
            LoginSubmit["Login Submit Btn\n(login/submit-button.tsx)"]:::frontend
        end

        subgraph "Dashboard Pages"
            direction TB
            DashboardLayout["Dashboard Layout\n(dashboard/layout.tsx)"]:::frontend
            DashboardHome["Dashboard Home\n(dashboard/page.tsx)"]:::frontend
            ProductsMgmt["Products Mgmt\n(dashboard/products/page.tsx)"]:::frontend
            CreateProduct["Create Product\n(dashboard/products/create/page.tsx)"]:::frontend
            Configurations["Configurations\n(dashboard/configurations/page.tsx)"]:::frontend
            ReportsPage["Reports\n(dashboard/reports/page.tsx)"]:::frontend
        end
    end

    %% API Layer
    subgraph "API Layer (Serverless)"
        direction TB
        OAuthCallback["OAuth Callback Route\n(auth/callback/route.ts)"]:::api

        subgraph "Supabase Handlers"
            direction TB
            handleProducts["handleProducts.ts"]:::api
            handleCategories["handleCategories.ts"]:::api
            handleSizes["handleSizes.ts"]:::api
            handleColors["handleColors.ts"]:::api
            handleImages["handleImages.ts"]:::api
            handlersIndex["index.ts"]:::api
        end

        SalesApi["salesApi.ts"]:::api
        SupabaseInit["initSupabase.ts"]:::api
        SupabaseClient["clientSupabase.ts"]:::api
    end

    %% Data Layer
    subgraph "Supabase Services"
        direction TB
        AuthService["Auth Service"]:::database
        Database["PostgreSQL DB"]:::database
        Storage["Storage Bucket"]:::database
    end

    %% Connections
    Browser -->|"HTTPS"| AppRouter
    Browser --> GoogleFonts
    AppRouter --> Providers
    Providers --> Home
    Providers --> ProductListing
    Providers --> ItemCategories
    Providers --> CategoryDetails
    Providers --> CategoriesRoot
    Providers --> CategoryBySlug
    Providers --> Contact
    Providers --> Promotions
    Providers --> LoginLayout
    Providers --> DashboardLayout

    LoginPage -->|POST /api/auth| OAuthCallback
    LoginSubmit --> LoginPage

    Home -->|fetch /api/products| handleProducts
    ProductListing -->|fetch /api/products| handleProducts
    ItemCategories -->|fetch /api/categories| handleCategories
    CategoryDetails -->|fetch /api/categories| handleCategories
    CategoriesRoot -->|fetch /api/categories| handleCategories
    CategoryBySlug -->|fetch /api/categories| handleCategories
    Contact -->|POST /api/contact| handlersIndex
    Promotions -->|fetch /api/promotions| handlersIndex

    DashboardHome -->|fetch /api/sales| SalesApi
    ProductsMgmt -->|CRUD /api/products| handleProducts
    CreateProduct -->|POST /api/products| handleProducts
    Configurations -->|fetch /api/colors,sizes| handleColors
    Configurations -->|fetch /api/sizes| handleSizes
    ReportsPage -->|fetch /api/sales| SalesApi

    OAuthCallback -->|auth exchange| AuthService
    handleProducts -->|SQL queries| Database
    handleCategories -->|SQL queries| Database
    handleSizes -->|SQL queries| Database
    handleColors -->|SQL queries| Database
    handleImages -->|manage files| Storage
    SalesApi -->|reports queries| Database

    SupabaseInit --> SupabaseClient
    SupabaseClient --> AuthService
    SupabaseClient --> Database
    SupabaseClient --> Storage

    Vercel --> AppRouter
    Vercel --> OAuthCallback

    %% Click Events
    click AppRouter "https://github.com/yuberley/sport-wear-shop/blob/master/src/app/layout.tsx"
    click GlobalCSS "https://github.com/yuberley/sport-wear-shop/blob/master/src/app/globals.css"
    click Home "https://github.com/yuberley/sport-wear-shop/blob/master/src/app/page.tsx"
    click ProductListing "https://github.com/yuberley/sport-wear-shop/blob/master/src/app/product/page.tsx"
    click ItemCategories "https://github.com/yuberley/sport-wear-shop/blob/master/src/app/[itemType]/page.tsx"
    click CategoryDetails "https://github.com/yuberley/sport-wear-shop/blob/master/src/app/[itemType]/[category]/page.tsx"
    click CategoriesRoot "https://github.com/yuberley/sport-wear-shop/blob/master/src/app/categories/page.tsx"
    click CategoryBySlug "https://github.com/yuberley/sport-wear-shop/blob/master/src/app/categories/[category]/page.tsx"
    click Contact "https://github.com/yuberley/sport-wear-shop/blob/master/src/app/contact/page.tsx"
    click Promotions "https://github.com/yuberley/sport-wear-shop/blob/master/src/app/promotions/page.tsx"
    click LoginLayout "https://github.com/yuberley/sport-wear-shop/blob/master/src/app/login/layout.tsx"
    click LoginPage "https://github.com/yuberley/sport-wear-shop/blob/master/src/app/login/page.tsx"
    click LoginSubmit "https://github.com/yuberley/sport-wear-shop/blob/master/src/app/login/submit-button.tsx"
    click OAuthCallback "https://github.com/yuberley/sport-wear-shop/blob/master/src/app/auth/callback/route.ts"
    click DashboardLayout "https://github.com/yuberley/sport-wear-shop/blob/master/src/app/dashboard/layout.tsx"
    click DashboardHome "https://github.com/yuberley/sport-wear-shop/blob/master/src/app/dashboard/page.tsx"
    click ProductsMgmt "https://github.com/yuberley/sport-wear-shop/blob/master/src/app/dashboard/products/page.tsx"
    click CreateProduct "https://github.com/yuberley/sport-wear-shop/blob/master/src/app/dashboard/products/create/page.tsx"
    click Configurations "https://github.com/yuberley/sport-wear-shop/blob/master/src/app/dashboard/configurations/page.tsx"
    click ReportsPage "https://github.com/yuberley/sport-wear-shop/blob/master/src/app/dashboard/reports/page.tsx"
    click Providers "https://github.com/yuberley/sport-wear-shop/blob/master/src/app/providers.tsx"
    click SupabaseInit "https://github.com/yuberley/sport-wear-shop/blob/master/src/lib/supabase/initSupabase.ts"
    click SupabaseClient "https://github.com/yuberley/sport-wear-shop/blob/master/src/lib/supabase/clientSupabase.ts"
    click handleProducts "https://github.com/yuberley/sport-wear-shop/blob/master/src/lib/supabase/handlers/handleProducts.ts"
    click handleCategories "https://github.com/yuberley/sport-wear-shop/blob/master/src/lib/supabase/handlers/handleCategories.ts"
    click handleSizes "https://github.com/yuberley/sport-wear-shop/blob/master/src/lib/supabase/handlers/handleSizes.ts"
    click handleColors "https://github.com/yuberley/sport-wear-shop/blob/master/src/lib/supabase/handlers/handleColors.ts"
    click handleImages "https://github.com/yuberley/sport-wear-shop/blob/master/src/lib/supabase/handlers/handleImages.ts"
    click handlersIndex "https://github.com/yuberley/sport-wear-shop/blob/master/src/lib/supabase/handlers/index.ts"
    click SalesApi "https://github.com/yuberley/sport-wear-shop/blob/master/src/lib/supabase/salesApi.ts"

    %% Styles
    classDef frontend fill:#e0f7da,stroke:#27632a,stroke-width:1px
    classDef api fill:#ffe4b3,stroke:#b86b00,stroke-width:1px
    classDef database fill:#cce0ff,stroke:#0044cc,stroke-width:1px
    classDef external fill:#f0f0f0,stroke:#666666,stroke-width:1px,stroke-dasharray: 2 2
```
