# bhuvi-ship-it/smart-sport-strategy architecture

> Architecture diagram of the GitHub repository bhuvi-ship-it/smart-sport-strategy, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/bhuvi-ship-it/smart-sport-strategy
- Repository: https://github.com/bhuvi-ship-it/smart-sport-strategy

## Overview

##### Project Type and Purpose
- Full-stack single-page application (SPA) for athlete management.
- Frontend: React + Vite, deployed on Vercel.
- Backend: Supabase (Auth, Database, Storage, Realtime).
- External AI service via OpenRouter (for chat/analytics).

##### File Structure Highlights
- src/pages & src/components → UI layer, role-based screens (Athlete, Coach, Medical, Scout).
- src/context → React Contexts (AuthContext, AIContext) managing global state.
- src/integrations/supabase → Supabase client setup and types.
- src/services/databaseService.ts → CRUD abstraction over Supabase.
- src/services/openRouterService.ts → Proxy to OpenAI models.
- tailwind.config.ts, postcss.config.js, vite.config.ts → Build & styling config.
- public/ → Static assets (robots.txt, index.html).

##### README Insights
- Confirms architecture: Frontend (Vite+React) → Supabase backend → Vercel hosting.
- Highlights role-based features and real-time data.

##### Main Components
a. Users & Roles
– Athlete, Coach, Medical Staff, Scout (external actors).
b. Frontend Layer (React SPA on Vercel)
– UI Components (Pages, Layout, Dashboard widgets).
– Context Layer (AuthContext, AIContext).
– Service Layer (databaseService, openRouterService).
c. Backend Services
– Supabase Auth (JWT, role-based access).
– Supabase Database (PostgreSQL) – data tables for athletes, performance, health logs, etc.
– Supabase Storage (media uploads).
– Realtime/Subscriptions (for live chat & updates).
d. External AI Service
– OpenRouter/OpenAI API endpoint for chat/analytics.
e. Hosting/CDN
– Vercel serving the SPA.

##### Relationships and Data Flows
- User → Browser → Vercel (SPA)
- SPA ↔ Supabase Auth (login/signup, JWT exchange)
- SPA ↔ Supabase Database (CRUD for athletes, performance, health, scouting)
- SPA ↔ Supabase Storage (image/video uploads)
- SPA ↔ Supabase Realtime (live chat & dashboards)
- SPA ↔ OpenRouterService → OpenAI (chatbot, AI summaries)

##### Architectural Patterns & Principles
- Component-based UI (atomic & feature folders)
- Context API for cross-cutting concerns (auth, AI state)
- Service abstraction for external calls (databaseService, openRouterService)
- Role-based access control enforced by Supabase policies
- Real-time updates via Supabase subscriptions

##### Technologies & Frameworks
- React + TypeScript + Vite
- Supabase (Auth, Postgres, Storage, Realtime)
- Tailwind CSS (styling)
- OpenRouter / OpenAI (AI service)
- Vercel (hosting)

##### Final Checklist
[ ] All main components and actors are present
[ ] Data flows and dependencies are directional and unambiguous
[ ] Labels are clear and match codebase terminology
[ ] Architectural patterns (Context API, service layer, real-time) are called out

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Actors
    Athlete["Athlete"]:::external
    Coach["Coach"]:::external
    Medical["Medical Staff"]:::external
    Scout["Scout"]:::external

    %% Hosting
    Vercel["Vercel CDN"]:::external

    %% React SPA
    subgraph "React SPA" 
        style ReactSPA fill:#ADD8E6,stroke:#333,stroke-width:1px
        ReactSPA[/"React SPA"/]:::frontend

        subgraph "Pages"
            Index["Index.tsx"]:::frontend
            Login["Login.tsx"]:::frontend
            SignUp["SignUp.tsx"]:::frontend
            DashboardPg["Dashboard.tsx"]:::frontend
            AthletesList["AthletesList.tsx"]:::frontend
            AddAthletePg["AddAthlete.tsx"]:::frontend
            AthleteProfile["AthleteProfile.tsx"]:::frontend
            PerformancePg["Performance.tsx"]:::frontend
            HealthPg["Health.tsx"]:::frontend
            TrainingPg["Training.tsx"]:::frontend
            AchievementsPg["Achievements.tsx"]:::frontend
            CareerPg["Career.tsx"]:::frontend
            CalendarPg["Calendar.tsx"]:::frontend
            ChatPg["Chat.tsx"]:::frontend
            SettingsPg["Settings.tsx"]:::frontend
            NotFound["NotFound.tsx"]:::frontend
        end

        subgraph "UI Components"
            subgraph "Layout"
                Header["Header.tsx"]:::frontend
                Sidebar["Sidebar.tsx"]:::frontend
                LayoutWrap["Layout.tsx"]:::frontend
            end
            subgraph "Dashboard Widgets"
                PerfChart["PerformanceChart.tsx"]:::frontend
                PerfCard["AthletePerformanceCard.tsx"]:::frontend
                AISummary["AISummaryCard.tsx"]:::frontend
                StatCard["StatCard.tsx"]:::frontend
            end
            subgraph "Athlete Components"
                AddAthleteForm["AddAthleteForm.tsx"]:::frontend
                ImportModal["ImportAthletesModal.tsx"]:::frontend
            end
            subgraph "Chat Components"
                ChatInterface["ChatInterface.tsx"]:::frontend
                ChatInput["ChatInput.tsx"]:::frontend
                ChatMessage["ChatMessage.tsx"]:::frontend
            end
            AuthUI["ProtectedRoute.tsx"]:::frontend
            APIKeySetup["APIKeySetup.tsx"]:::frontend
            ThemeToggle["ThemeToggle.tsx"]:::frontend
        end

        subgraph "Context Layer"
            AuthCtx["AuthContext.tsx"]:::frontend
            AICtx["AIContext.tsx"]:::frontend
        end

        subgraph "Service Layer"
            DBService["databaseService.ts"]:::frontend
            OpenRouterSvc["openRouterService.ts"]:::frontend
        end
    end

    %% Supabase Backend
    subgraph "Supabase" 
        style Supabase fill:#90EE90,stroke:#333,stroke-width:1px
        AuthSvc["Supabase Auth"]:::backend
        DB["Postgres Database"]:::db
        Storage["Supabase Storage"]:::db
        Realtime["Realtime Subscriptions"]:::backend

        subgraph "Integration"
            SupaClient["client.ts"]:::backend
            SupaTypes["types.ts"]:::backend
        end
    end

    %% External AI
    OpenAI["OpenAI API"]:::external

    %% Public & Config
    subgraph "Public & Config"
        HTML["index.html"]:::frontend
        Robots["robots.txt"]:::frontend
        TailwindCfg["tailwind.config.ts"]:::frontend
        PostCSS["postcss.config.js"]:::frontend
        ViteCfg["vite.config.ts"]:::frontend
        SupaConfig["config.toml"]:::backend
    end

    %% Relationships
    Athlete --> ReactSPA
    Coach --> ReactSPA
    Medical --> ReactSPA
    Scout --> ReactSPA

    ReactSPA --> Vercel
    ReactSPA --> AuthSvc
    ReactSPA --> DB
    ReactSPA --> Storage
    ReactSPA --> Realtime
    ReactSPA --> OpenRouterSvc
    OpenRouterSvc --> OpenAI
    AuthSvc --> SupaClient
    DB --> SupaClient
    Storage --> SupaClient
    Realtime --> SupaClient

    %% Click Events for Pages
    click Index "https://github.com/bhuvi-ship-it/smart-sport-strategy/blob/main/src/pages/Index.tsx"
    click Login "https://github.com/bhuvi-ship-it/smart-sport-strategy/blob/main/src/pages/Login.tsx"
    click SignUp "https://github.com/bhuvi-ship-it/smart-sport-strategy/blob/main/src/pages/SignUp.tsx"
    click DashboardPg "https://github.com/bhuvi-ship-it/smart-sport-strategy/blob/main/src/pages/Dashboard.tsx"
    click AthletesList "https://github.com/bhuvi-ship-it/smart-sport-strategy/blob/main/src/pages/AthletesList.tsx"
    click AddAthletePg "https://github.com/bhuvi-ship-it/smart-sport-strategy/blob/main/src/pages/AddAthlete.tsx"
    click AthleteProfile "https://github.com/bhuvi-ship-it/smart-sport-strategy/blob/main/src/pages/AthleteProfile.tsx"
    click PerformancePg "https://github.com/bhuvi-ship-it/smart-sport-strategy/blob/main/src/pages/Performance.tsx"
    click HealthPg "https://github.com/bhuvi-ship-it/smart-sport-strategy/blob/main/src/pages/Health.tsx"
    click TrainingPg "https://github.com/bhuvi-ship-it/smart-sport-strategy/blob/main/src/pages/Training.tsx"
    click AchievementsPg "https://github.com/bhuvi-ship-it/smart-sport-strategy/blob/main/src/pages/Achievements.tsx"
    click CareerPg "https://github.com/bhuvi-ship-it/smart-sport-strategy/blob/main/src/pages/Career.tsx"
    click CalendarPg "https://github.com/bhuvi-ship-it/smart-sport-strategy/blob/main/src/pages/Calendar.tsx"
    click ChatPg "https://github.com/bhuvi-ship-it/smart-sport-strategy/blob/main/src/pages/Chat.tsx"
    click SettingsPg "https://github.com/bhuvi-ship-it/smart-sport-strategy/blob/main/src/pages/Settings.tsx"
    click NotFound "https://github.com/bhuvi-ship-it/smart-sport-strategy/blob/main/src/pages/NotFound.tsx"

    %% Click Events for UI Components
    click Header "https://github.com/bhuvi-ship-it/smart-sport-strategy/blob/main/src/components/layout/Header.tsx"
    click Sidebar "https://github.com/bhuvi-ship-it/smart-sport-strategy/blob/main/src/components/layout/Sidebar.tsx"
    click LayoutWrap "https://github.com/bhuvi-ship-it/smart-sport-strategy/blob/main/src/components/layout/Layout.tsx"
    click PerfChart "https://github.com/bhuvi-ship-it/smart-sport-strategy/blob/main/src/components/dashboard/PerformanceChart.tsx"
    click PerfCard "https://github.com/bhuvi-ship-it/smart-sport-strategy/blob/main/src/components/dashboard/AthletePerformanceCard.tsx"
    click AISummary "https://github.com/bhuvi-ship-it/smart-sport-strategy/blob/main/src/components/dashboard/AISummaryCard.tsx"
    click StatCard "https://github.com/bhuvi-ship-it/smart-sport-strategy/blob/main/src/components/dashboard/StatCard.tsx"
    click AddAthleteForm "https://github.com/bhuvi-ship-it/smart-sport-strategy/blob/main/src/components/athletes/AddAthleteForm.tsx"
    click ImportModal "https://github.com/bhuvi-ship-it/smart-sport-strategy/blob/main/src/components/athletes/ImportAthletesModal.tsx"
    click ChatInterface "https://github.com/bhuvi-ship-it/smart-sport-strategy/blob/main/src/components/chat/ChatInterface.tsx"
    click ChatInput "https://github.com/bhuvi-ship-it/smart-sport-strategy/blob/main/src/components/chat/ChatInput.tsx"
    click ChatMessage "https://github.com/bhuvi-ship-it/smart-sport-strategy/blob/main/src/components/chat/ChatMessage.tsx"
    click AuthUI "https://github.com/bhuvi-ship-it/smart-sport-strategy/blob/main/src/components/auth/ProtectedRoute.tsx"
    click APIKeySetup "https://github.com/bhuvi-ship-it/smart-sport-strategy/blob/main/src/components/settings/APIKeySetup.tsx"
    click ThemeToggle "https://github.com/bhuvi-ship-it/smart-sport-strategy/blob/main/src/components/theme/ThemeToggle.tsx"

    %% Click Events for Context
    click AuthCtx "https://github.com/bhuvi-ship-it/smart-sport-strategy/blob/main/src/context/AuthContext.tsx"
    click AICtx "https://github.com/bhuvi-ship-it/smart-sport-strategy/blob/main/src/context/AIContext.tsx"

    %% Click Events for Services
    click DBService "https://github.com/bhuvi-ship-it/smart-sport-strategy/blob/main/src/services/databaseService.ts"
    click OpenRouterSvc "https://github.com/bhuvi-ship-it/smart-sport-strategy/blob/main/src/services/openRouterService.ts"

    %% Click Events for Supabase Integration
    click SupaClient "https://github.com/bhuvi-ship-it/smart-sport-strategy/blob/main/src/integrations/supabase/client.ts"
    click SupaTypes "https://github.com/bhuvi-ship-it/smart-sport-strategy/blob/main/src/integrations/supabase/types.ts"

    %% Click Events for Public & Config
    click HTML "https://github.com/bhuvi-ship-it/smart-sport-strategy/blob/main/public/index.html"
    click Robots "https://github.com/bhuvi-ship-it/smart-sport-strategy/blob/main/public/robots.txt"
    click TailwindCfg "https://github.com/bhuvi-ship-it/smart-sport-strategy/blob/main/tailwind.config.ts"
    click PostCSS "https://github.com/bhuvi-ship-it/smart-sport-strategy/blob/main/postcss.config.js"
    click ViteCfg "https://github.com/bhuvi-ship-it/smart-sport-strategy/blob/main/vite.config.ts"
    click SupaConfig "https://github.com/bhuvi-ship-it/smart-sport-strategy/blob/main/supabase/config.toml"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef backend fill:#90EE90,stroke:#333,stroke-width:1px
    classDef external fill:#FFD580,stroke:#333,stroke-width:1px
    classDef db fill:#90EE90,stroke:#333,stroke-width:1px
```
